Turing Machines - nd.educpennycu/2018/assets/fa-ToC-10.pdf · Turing Machine Schematic Infinite...

16
Turing Machines Starring Benedict Cumberbatch

Transcript of Turing Machines - nd.educpennycu/2018/assets/fa-ToC-10.pdf · Turing Machine Schematic Infinite...

Page 1: Turing Machines - nd.educpennycu/2018/assets/fa-ToC-10.pdf · Turing Machine Schematic Infinite tape Tape head can read and write symbols (only one at a time) Tape head can move left

Turing MachinesStarring Benedict Cumberbatch

Page 2: Turing Machines - nd.educpennycu/2018/assets/fa-ToC-10.pdf · Turing Machine Schematic Infinite tape Tape head can read and write symbols (only one at a time) Tape head can move left

What is it?

Abstract model of computation

Proposed by Alan Turing in 1936

FSM with unlimited, unrestricted

memory

Can do anything a real computer can

do

Still can’t do everything.

Page 3: Turing Machines - nd.educpennycu/2018/assets/fa-ToC-10.pdf · Turing Machine Schematic Infinite tape Tape head can read and write symbols (only one at a time) Tape head can move left

Turing Machine Schematic

Infinite tape

Tape head can read and write

symbols (only one at a time)

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?

Page 4: Turing Machines - nd.educpennycu/2018/assets/fa-ToC-10.pdf · Turing Machine Schematic Infinite tape Tape head can read and write symbols (only one at a time) Tape head can move left

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?

Page 5: Turing Machines - nd.educpennycu/2018/assets/fa-ToC-10.pdf · Turing Machine Schematic Infinite tape Tape head can read and write symbols (only one at a time) Tape head can move left

Intuition BuilderSample, non-consecutive

snapshots of the TM tape

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

Page 6: Turing Machines - nd.educpennycu/2018/assets/fa-ToC-10.pdf · Turing Machine Schematic Infinite tape Tape head can read and write symbols (only one at a time) Tape head can move left

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!

Page 7: Turing Machines - nd.educpennycu/2018/assets/fa-ToC-10.pdf · Turing Machine Schematic Infinite tape Tape head can read and write symbols (only one at a time) Tape head can move left

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

Page 8: Turing Machines - nd.educpennycu/2018/assets/fa-ToC-10.pdf · Turing Machine Schematic Infinite tape Tape head can read and write symbols (only one at a time) Tape head can move left

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).

Page 9: Turing Machines - nd.educpennycu/2018/assets/fa-ToC-10.pdf · Turing Machine Schematic Infinite tape Tape head can read and write symbols (only one at a time) Tape head can move left

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?

Page 10: Turing Machines - nd.educpennycu/2018/assets/fa-ToC-10.pdf · Turing Machine Schematic Infinite tape Tape head can read and write symbols (only one at a time) Tape head can move left

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 (next slide)

q

0

is q

1

.

Page 11: Turing Machines - nd.educpennycu/2018/assets/fa-ToC-10.pdf · Turing Machine Schematic Infinite tape Tape head can read and write symbols (only one at a time) Tape head can move left

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.

Page 12: Turing Machines - nd.educpennycu/2018/assets/fa-ToC-10.pdf · Turing Machine Schematic Infinite tape Tape head can read and write symbols (only one at a time) Tape head can move left

Example: A = {02^n

| n ≥ 0}

Sample run on input 0000

Page 13: Turing Machines - nd.educpennycu/2018/assets/fa-ToC-10.pdf · Turing Machine Schematic Infinite tape Tape head can read and write symbols (only one at a time) Tape head can move left

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

.

Give the configurations for

computation on 10#10

Page 14: Turing Machines - nd.educpennycu/2018/assets/fa-ToC-10.pdf · Turing Machine Schematic Infinite tape Tape head can read and write symbols (only one at a time) Tape head can move left

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

Page 15: Turing Machines - nd.educpennycu/2018/assets/fa-ToC-10.pdf · Turing Machine Schematic Infinite tape Tape head can read and write symbols (only one at a time) Tape head can move left

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

Page 16: Turing Machines - nd.educpennycu/2018/assets/fa-ToC-10.pdf · Turing Machine Schematic Infinite tape Tape head can read and write symbols (only one at a time) Tape head can move left

Turing Machine PerspectivesDo not require electricity

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

Turing Machine Simulators

https://bit.ly/2q7IKMH