<<

Discrete Math. and II. Turing SFWR ENG 2FA3

Ryszard Janicki

Winter 2014

Acknowledgments: Material based on Automata and by Dexter C. Kozen (Chapters 27 and 28).

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 1 / 19 Introduction

In this lecture we introduce the most powerful of the automata: Turing machines (TMs), It is named after , who invented them in 1936 Turing machines can compute any normally considered computable TMs were invented long before real appeared They came at a time when mathematicians were trying to come to grips with the notion of eective Several alternative formalisms evolved in the attempt to nail down eectively computable

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 2 / 19 Introduction

These several alternative formalisms are: Turing machines (Alan Turing) handle strings over Σ

Post systems (Emil Post)

µ-recursive functions (Kurt Gödel) handle the natural

A-calculus (, Stephan C. Kleene) handles terms built from combinator symbols

Combinatory logic (Moses Schönnkel, Haskell B. Curry) handles terms built from combinator symbols

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 3 / 19 Introduction

The one that most closely resembles a modern is the Turing

Besides the most know model, there are also many variations nondeterministic multitape multidimensional tape two-way innite tapes

They can all simulate one another

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 4 / 19 Introduction

All these mathematicians were looking at the same thing from dierent angles (Not a coincidence)

They soon came to the realization that the commonality among all these systems must be the notion of eective computability

Alonzo Church gave voice to this thought, and it has since become known as Church's thesis (or the Church-Turing thesis)

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 5 / 19 Introduction

It is not a theorem, but rather a declaration

All these formalisms capture precisely our intuition about what it means to be eectively computable in principle, no more and no less

Very likely that the most compelling development leading to the acceptance of Church's thesis was the Turing machine (model considered readily programmable)

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 6 / 19 Informal Description of Turing Machines

We will be considering a deterministic, one-tape Turing machine

This is the standard model

There are many variations, apparently more powerful or less powerful but in reality not (for more details on this point see textbook Lecture 30)

TM has a nite set of states Q a semi-innite tape that is delimited on the left end by an endmarker ` and is innite to the right a head that can move left and right over the tape, reading and writing symbols

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 7 / 19 Informal Description of Turing Machines

a b ba b a . . . .

Two−way, read/write

Q

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 8 / 19 Formal Description of Turing Machines

Denition A deterministic one-tape Turing machine is a 9- s t , where M = (Q, Σ, Γ, `, [ , δ, , , ) Q is a nite set (the states); Σ is a nite set (the input alphabet); Γ is a nite set (the tape alphabet) containing Σ as a ; , the blank symbol; [ ∈ Γ − Σ `, the left endmarker; δ : Q × Γ −→ Q × Γ × {, R}, the transition function; s ∈ Q, the start state; t ∈ Q, the accept state; and r ∈ Q, the reject state, r 6= t.

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 9 / 19 Formal Description of Turing Machines

Intuitively, δ (p, a) = (q, b, d) means, "When in state p scanning symbol a, write b on that tape cell, move the head in direction d, and enter state q.

The symbols L and R stand for left and right, respectively We restrict TMs so that

∀(p | p ∈ Q : ∃(q | q ∈ Q : δ (p, `) = (q, `, R)))

We also require that

∀(b | b ∈ Γ: ∃(c, c0 | c, c0 ∈ Γ: δ (t, b) = (t, c, d) ∧ δ (r, b) = (r, c0, d 0)))

We refer to the state set and transition function collectively as the nite control

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 10 / 19 Formal Description of Turing Machines

Example We are considering a TM that accepts the non-context-free set {anbncn | n ≥ 0}

Q = {s, q1, ··· , q10, t, r}

Σ = {a, b, c}

S Γ = Σ {`, [ , a}

a is just an extra useful symbol in the tape alphabet (NOT a special symbol)

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 11 / 19 Formal Description of Turing Machines

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 12 / 19 Congurations and Acceptance

We dene a conguration to be an element of ω y ∗ IN Q × {y [ | ∈ Γ } × A conguration is a global state giving a snapshot of all relevant information about a TM computation at some instant in time The conguration (p, z, n) species a current state p of the nite control, current tape contents z, and current position of the read/write head n ≥ 0 We usually denote congurations by α, β, γ The start conguration on input x ∈ Σ∗ is the conguration s x ω 0 ( , ` [ , ) The last component 0 means that the machine is initially scanning the left endmarker `

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 13 / 19 Congurations and Acceptance

Denition

A Turing Machine is said to halt on input x if it either accepts x or rejects x (the machine doesn't really grind to a halt in the literal sense)

It is possible that it neither accepts nor rejects, in which case it is said to loop on input x

A Turing machine is said to be total if it halts on all inputs

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 14 / 19 Congurations and Acceptance

Denition We call a set of strings

recursively enumerable (r.e.) if it is L(M) for some Turing machine M

co-r.e. if its complement is r.e.

recursive if it is L(M) for some total Turing machine M

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 15 / 19 Congurations and Acceptance

Example Consider the non-CFL {ww | w ∈ {a, b}∗} It is a recursive set, because we can construct a Turing machine that accepts all its strings The TM scans out to the rst blank symbol [ , counting the of symbols mod 2 to make sure x is of even length and rejecting immediately if not It lays down a right endmarker a, then repeatedly scans back and forth over the input In each pass from right to left, it marks the rst unmarked a or b it sees with ' (prime to the left) In each pass from left to right, it marks the rst unmarked a or b it sees with ` (prime to the right) It continues this until all symbols are marked

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 16 / 19 Congurations and Acceptance

Example On input aabbaaabba the initial tape contents are

` aabbaaabba [ [ [ ···

1 ` aabbaaabb´a a [ [ [ ···

2 ` `aabbaaabb´a a [ [ [ ··· 3 ´ ` `aabbaaabb´a a [ [ [ ··· 4 ´ ` `a`abbaaabb´a a [ [ [ ··· 5 ´´ ` `a`abbaaabb´a a [ [ [ ··· 6 ` ´´ ` `a`abbaaabb´a a [ [ [ ··· 7 ` ´´ ` `a`abbaa´abb´a a [ [ [ ··· 8 `` ´´ bbaaabba [ aa [ ` `` ´ ´ a [ ···

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 17 / 19 Congurations and Acceptance

Example ((Continued))

1 `` ´´ ` `a`abba´a´abb´a a [ [ [ ··· 2 `` ´´ ` `a`abb`a´a´abb´a a [ [ [ ··· 3 `` ´´ abba [ abba [ [ [ ` [ ` ` ´ ´ a ··· 4 `` ´´ bba [ [ bba [ [ [ ` [ [ ` ´ a ··· 5 ` ´ ` [ [ [ b`a [ [ [ b´a a [ [ [ ···

6 a [ [ [ [ a [ [ [ ` [ [ [ [ ` ´ a ··· 7 It accepts ` [ [ [ [ [ [ [ [ [ [ a [ [ [ ···

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 18 / 19 and Semidecidability

Denition (Decidable) A property P of strings is said to be decidable if the set of all strings having property P is a recursive set.

A property P of strings is said to be decidable if there is a total Turing machine that accepts input strings that have property P and rejects those that do not. Denition (Semidecidable) A property P of strings is said to be semidecidable if the set of strings having property P is an r.e. set.

A property P is said to be semidecidable if there is a Turing machine that on input x accepts if x has property P and rejects or loops if not.

Ryszard Janicki Discrete Math. and Logic II. Turing Machines 19 / 19