Turing Machines - University of Notre Damecpennycu/2019/assets/fall/TOC/13 Turing Mac… · Practice Turing Machines: C = {ai bj ck | i x j = k and i,j,k ≥ 1} Performs elementary

Post on 25-Jul-2020

0 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

Turing MachinesStarring Benedict Cumberbatch

Turing MachinesStarring Benedict Cumberbatch

What is it?

Abstract model of computation

(yes, another one)

Proposed by Alan Turing in 1936

FSM with unlimited, unrestricted memory

Can do anything a “real” computer can do

Still can’t do “everything”

(be patient my young padawans)

Also, Why should you care?

Turing Machine Schematic

Features:

● Infinite tape

● Tape head can read and write

symbols (only one at a time)

● Can read symbols MORE THAN

ONCE!!!

● Tape head can move left or right

● Tape initially contains input string

and everything else is blank

● Halts as soon as it reaches an accept

or reject state

How is this different from

FSMs or PDAs?

Intuition Builder B = {w#w | w ∈ {0,1}*}

With a Turing machine, what

algorithm would you use to decide

whether or not a string is within this

language?

Intuition BuilderSample, non-consecutive

snapshots of the TM tape

B = {w#w | w ∈ {0,1}*}

Turing Machine Formal DefinitionM = (Q, Σ, Γ, δ, q

0

, q

accept

, q

reject

),

where Q, Σ, and Γ are finite sets, and

1. Q is the set of states,

2. Σ is the input alphabet not containing the blank symbol ⊔,

3. Γ is the tape alphabet, where ⊔ ∈ Γ and Σ ⊂ Γ,

4. δ: Q ⨯ Γ ⟶ Q ⨯ Γ ⨯ {L, R} is the transition function,

5. q

0

∈ Q is the start state,

6. q

accept

∈ Q is the accept state, and

7. q

reject

∈ Q is the reject state, where q

accept

≠ q

reject

.

Can’t define

computation yet!

Defining a Turing Machine ConfigurationThings that must be tracked:

1. Current state

2. Current tape contents

3. Current head location

These 3 things are the configuration of

the TM.

For a state q and two strings u and v over

the tape alphabet Γ, we write uqv for the

configuration:

● Current state is q,

● Current tape contents is uv,

● Current head location is the first

symbol of v, and

● Tape contains only ⊔ after v.

Example Configuration: 1011q

7

01111

Turing Machine Formal Definition of ComputationM receives input w = w

1

w

2

…w

n

∈ Σ* on the

leftmost n squares of the tape, and the rest of the

tape is blank.

Configuration C

1

yields configuration C

2

if the TM

can legally go from C

1

to C

2

in a single step.

For a, b, and c in Γ, as well as u and v in Γ*, and

states q

i

and q

j

in Q:

● uaq

i

bv yields uq

j

acv if δ(q

i

, b) = (q

j

, c, L)

● uaq

i

bv yields uacq

j

v if δ(q

i

, b) = (q

j

, c, R)

Special case: Left movement when head is at first

position. q

i

bv yields q

j

cv.

Start Configuration of M: q

0

w

Accepting and Rejecting configurations have state

q

accept

and q

reject

, respectively.

A TM accepts input w if a sequence of

configurations C

1

, C

2

, … , C

k

exists, where

1. C

1

is the start configuration of M on w,

2. Each C

i

yields C

i + 1

, and

3. C

k

is an accepting configuration.

Collection of strings recognized by M (or, the

Language of M) is denoted as L(M).

Example: A = {02^n

| n ≥ 0}

General Approach:

1. Sweep left to right, crossing off every

other 0.

2. If, in step 1, the tape contained a

single 0, accept.

3. If, in step 1, the tape contained more

than a single 0 and the # of 0’s was

odd, reject.

4. Return to the head of the left-hand

end of the tape.

5. Go to step 1.

Q = {q

1

, q

2

, q

3

, q

4

, q

5

, q

accept

, q

reject

}

Σ = {0}

Γ = {0, x, ⊔}

δ is a state diagram

q

0

is q

1

.

Example: A = {02^n

| n ≥ 0}

General Approach:

1. Sweep left to right, crossing off every

other 0.

2. If, in step 1, the tape contained a

single 0, accept.

3. If, in step 1, the tape contained more

than a single 0 and the # of 0’s was

odd, reject.

4. Return to the head of the left-hand

end of the tape.

5. Go to step 1.

Example: A = {02^n

| n ≥ 0}

Sample run on input 0000

Types of Languages: Recognizable and DecidableTuring-Recognizable

● Call a language

Turing-recognizable if some

Turing machine recognizes it.

● Also known as a recursively

enumerable language.

Turing-Decidable

● Call a language Turing-decidable if

some Turing machine decides it.

● Also known as decidable.

● Also known as a recursive

language.

Types of Languages: Recognizable and DecidableTuring-Recognizable

● Call a language

Turing-recognizable if some

Turing machine recognizes it.

● Also known as a recursively

enumerable language.

Turing-Decidable

● Call a language Turing-decidable if

some Turing machine decides it.

● Also known as decidable.

● Also known as a recursive

language.

What’s the Difference?

Example: B = {w#w | w ∈ {0,1}*}

Design a TM to decide B.

Example: B = {w#w | w ∈ {0,1}*}

Q = {q

1

, …, q

8

, q

accept

, q

reject

}

Σ = {0, 1, #}

Γ = {0, 1, #, x, ⊔}

δ is a state diagram

q

0

is q

1

.

Example: B = {w#w | w ∈ {0,1}*}

Give the configurations for

computation on 10#10

1. q

110#10

2. xq

30#10

3. x0q

3#10

4. x0#q

510

5. x0q

6#x0

6. xq

70#x0

7. q

7x0#x0

8. xq

10#x0

9. xxq

2#x0

10. xx#q

4x0

11. xx#xq

40

12. xx#q

6xx

13. xxq

6#xx

14. xq

7x#xx

15. xxq

1#xx

16. xx#q

8xx

17. xx#xq

8x

18. xx#xxq

8

19. xx#xx⊔q

accept

\begin{tikzpicture} \node[state, initial] (0) {$q_0$}; \node[state, right of=0] (1) {$q_1$}; \node[state, right of=1] (2) {$q_2$}; \node[state, right of=2] (3) {$q_3$}; \node[state, right of=3] (4) {$q_4$}; \node[state, below of=1, node distance=3.5cm] (5) {$q_5$}; \node[state, right of=5] (6) {$q_6$}; \node[state, right of=6] (7) {$q_7$}; \node[state, right of=7] (8) {$q_8$}; \node[state, above of=1, node distance=3cm] (9) {$q_9$}; \node[state, ellipse, right of=9, accepting] (10) {$q_\textrm{accept}$}; \draw (0) edge node{${\tt 0} \rightarrow {\tt x},{\text R}$} (1); \draw (0) edge node[below, sloped] {${\tt 1} \rightarrow {\tt x},{\text R}$} (5); \draw (0) edge node[above, sloped] {${\tt \#} \rightarrow {\text R}$} (9); \draw (1) edge[loop above, align=left] node[above]{${\tt 0} \rightarrow {\text R}$ \\ ${\tt 1} \rightarrow {\text R}$} (1); \draw (1) edge node {${\tt \#} \rightarrow {\text R}$} (2); \draw (2) edge[loop above, align=left] node[above]{${\tt x} \rightarrow {\text R}$} (2); \draw (2) edge node {${\tt 0} \rightarrow {\tt x},{\text L}$} (3); \draw (3) edge[loop above, align=left] node[above]{${\tt x} \rightarrow {\text L}$} (3); \draw (3) edge node {${\tt \#} \rightarrow {\text L}$} (4); \draw (4) edge[loop above, align=left] node[above]{${\tt 0} \rightarrow {\text L}$ \\ ${\tt 1} \rightarrow {\text L}$} (4); \draw (4) edge[bend left=20] node[above] {${\tt x} \rightarrow {\text R}$} (0); \draw (5) edge[loop above, align=left] node[above]{${\tt 0} \rightarrow {\text R}$ \\ ${\tt 1} \rightarrow {\text R}$} (5); \draw (5) edge node {${\tt \#} \rightarrow {\text R}$} (6); \draw (6) edge[loop above, align=left] node[above]{${\tt x} \rightarrow {\text R}$} (6); \draw (6) edge node {${\tt 1} \rightarrow {\tt x},{\text L}$} (7); \draw (7) edge[loop above, align=left] node[above]{${\tt x} \rightarrow {\text L}$} (7); \draw (7) edge node {${\tt \#} \rightarrow {\text L}$} (8); \draw (8) edge[loop above, align=left] node[above]{${\tt 0} \rightarrow {\text L}$ \\ ${\tt 1} \rightarrow {\text L}$} (8); \draw (8) edge[bend left,in= 105,out=45,looseness=1.3] node[above, sloped] {${\tt x} \rightarrow {\text R}$} (0); \draw (9) edge[loop above, align=left] node[above]{${\tt x} \rightarrow {\text R}$} (9); \draw (9) edge node {${\tt \sqcup} \rightarrow {\text R}$} (10);\end{tikzpicture}

Practice Turing Machines:C = {ai bj ck

| i x j = k and i,j,k ≥ 1}

● Performs elementary

arithmetic

● Parts can perform like a FSA

● Needs a method to identify

the left side of the string

(a left-hand detector)

E = {#x

1

#x

2

# … #x

l

|

x

i

∈ {0,1}* and

x

i

≠ x

j

for each i ≠ j }

● Element distinctness problem

● Introduces the idea of

“marking” a cell

Turing Machine PerspectivesDo not require electricity:

https://www.youtube.com/watch?v=vo8izCKHiF0

Turing Machine Simulators:

https://bit.ly/2q7IKMH

Smallest possible TM:

https://bit.ly/345JJPm

top related