AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES...

70
AUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 UNIT 7: TURING MACHINE David Griol Barres Universidad Carlos III de Madrid

Transcript of AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES...

Page 1: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

AUTOMATA THEORY

AND FORMAL LANGUAGES

2015-16

UNIT 7: TURING MACHINE

David Griol Barres Universidad Carlos III de Madrid

Page 2: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Bibliography

Enrique Alfonseca Cubero, Manuel Alfonseca Cubero, Roberto

Moriyón Salomón. Teoría de Autómatas y Lenguajes Formales.

McGraw-Hill. 2007. Chapters 2 and 9.

John E. Hopcroft, Rajeev Motwani, Jeffrey D. Ullman.

Introduction to Automata Theory, Languages, and

Computation(3rd edition). Pearson Addison Wesley. 2006.

Chapter 8.

Manuel Alfonseca, Justo Sancho, Miguel Martínez Orga. Teoría

de Lenguajes, Gramáticas y Autómatas. Publicaciones R.A.E.C.

1997. Chapters 12 and 13.

Page 3: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

OUTLINE

Introduction

Definition of Turing Machine

Variations of Turing Machines

Universal Turing Machine

Additional issues

Page 4: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

OUTLINE

Introduction

Definition of Turing Machine

Variations of Turing Machines

Universal Turing Machine

Additional issues

Page 5: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Alan Turing 5

23 June 1912 - 7 June 1954

Contributions:

• Mathematics,

• Cryptanalysis,

• Logic,

• …

• Artificial Intelligence.

http://www.alanturing.net

http://www.mathcomp.leeds.ac.uk/turing2012/

Page 6: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

http://www.alanturing.net

http://en.wikipedia.org/wiki/Alan_Turing

Bibliography:

"On Computable Numbers, with an Application to the

Entscheidungsproblem“ 1936

Turing, A.M. Computing machinery and intelligence. Mind, 59, 433-460.

1950

"I propose to consider the question, "Can machines think?“

http://en.wikipedia.org/wiki/Computing_machinery_and_intelligence

http://blog.santafe.edu/wp-

content/uploads/2009/05/turing1950.pdf

Charles Petzold. The Annotated Turing: A Guided Tour Through Alan Turing's

Historic Paper on Computability and the Turing Machine. Wiley. 2008.

www.theannotatedturing.com

6

Alan Turing

Page 7: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Can machines do everything? 7

We have studied:

• Simple languages.

• Application of simple languages to solve restricted problems:

• Analysis.

• Pattern recognition.

• Syntax analysis.

In this unit, we want to answer:

• Which languages can be defined by means of any

computational device?

• Which problems can be solved/computed?

Page 8: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Can machines do everything? 8

Which is the solution?

• He says that she always say the truth.

• She says that he always lies (he never says the truth).

Can a computer answer to any possible question in

a dialog system?

Is a grammar ambiguous?

Is there a solution for XN+YN=ZN, with N>2?

Page 9: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

OUTLINE

Introduction

Definition of Turing Machine

Variations of Turing Machines

Universal Turing Machine

Additional issues

Page 10: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

TAPE

Mov. to the left Mov. to the right

What is a Turing Machine?

10 Mechanical device:

• Infinite tape divided into cells with a head for reading/writing.

• This head can be moved from to left or right or stay in the same

cell.

/ 2 ) 5 )

Q

CONTROL OF STATES

Head for reading/writing

10

Stop

Page 11: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Machine: Operation 11

Operations that a TM carries out:

Being in a state p and reading a symbol in the cell on which the R/W head is, it carries out three actions:

Transits to a new state.

Writes a new symbol in the tape, in the same cell where the current symbol has been read. This symbol replaces the previously read (unless it is the same).

Moves the R/W head to the left, to the right or stops in the same position.

Page 12: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Machine: Initial Situation 12

... b 1 b 0

TAPE

0 1 b 0 b

qo

Initial State

Initial position of the reading head

Symbols included in the alphabet of the tape,

Example: http://www.aturingmachine.com/index.php

Page 13: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Machine: Operation 13

Characteristics of the Tape:

Infinite tape.

It can contain a character in each cell.

It can be read.

It can be written.

Initially it is considered with infinite blank symbols to the right and left of the word.

It can be moved to the left or right (a cell each time) or not move.

Page 14: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Machine: Operation 14

There are many variants of Turing Machines…

… but they all are equivalent.

The tape is one-dimensional and infinite by both sides.

Initially:

The tape contains the word, and the rest of elements of the

tape (left and right of the word) are the blank symbol (b or □).

At the beginning, the R/W head is located on the left-most

element of the word.

Page 15: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Machine: Formal Definition 15

Septuple: (Σ, Γ, b, Q, qo, f, F), where:

• Γ: alphabet of symbols in the tape

• Σ Γ: alphabet of input symbols

• b Γ, b Σ : is the blank symbol (the only symbol allowed to be in the

tape infinitely at any step during the computation). It indicates empty

cell (□).

• Q: set of states (finite).

• q0 Q: initial state.

• F Q: set of final states.

• f: transition function

Q x Γ Q x Γ x {L,R,S}

L or -: left R or +: right S or =: stay

Page 16: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Machine: Transition Function 16

f: Transition function, table with double input Q x Q x x {L,R,S}

L: mov. to the left R: mov. to the right S: stop

Empty cells in the table:

• Transitions that are NOT possible The machine stops.

Q / Symbol Symbol

Input State, symbol, movement …

Input State, symbol, movement

,,, …

Page 17: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

M = (∑={0,1}, Γ ={0,1,□}, □, Q = {q0, q1, qF}, q0, F={qF}, f)

Turing Machine: Example 17

Page 18: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

... □ 1 □ 0 0 1 □ □ □

Turing Machine: Example 18

Page 19: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

... □ 1 □ 0 0 1 □ □ □

qo

Turing Machine: Example 19

Page 20: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

... □ 1 □ 0 0 1 □ □ □

q1

Turing Machine: Example 20

Page 21: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

... □ 1 □ 0 0 1 □ □ □

q1

Turing Machine: Example 21

Page 22: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

... □ 1 □ 0 0 1 □ □ □

q1

Turing Machine: Example 22

Page 23: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

... □ 1 □ 0 0 1 □ □ □

q1

Turing Machine: Example 23

Page 24: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

... □ 1 □ 0 0 1 □ □ □

q1

Turing Machine: Example 24

Page 25: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

... □ 1 □ 0 0 1 □ □ □

q1

Turing Machine: Example 25

Page 26: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

... □ 1 □ 0 0 1 □ □ □

q1

Turing Machine: Example 26

Page 27: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

... □ 1 □ 0 0 1 □ □ □

q1

Turing Machine: Example 27

Page 28: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

... □ 1 □ 0 0 1 □ □ □

q1

Turing Machine: Example 28

Page 29: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

... □ 1 □ 0 0 1 □ □ □

q0

Turing Machine: Example 29

Page 30: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

... □ 1 □ 0 0 1 □ □ □

q0

Turing Machine: Example 30

Page 31: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

... □ 1 □ 0 0 1 □ 0 □

qF

Turing Machine: Example 31

Page 32: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

32

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

... □ 1 □ 0 0 1 □ 0 □

qF

Situations without

transitions Stop

0 even

number of 1s

1 odd

number of 1s

Turing Machine: Example 32

Page 33: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

The transition function can be described using also a

diagram with states, i.e. a graph in which:

Nodes represent states.

Archs represent transitions between states.

Each arch is labeled including the requesites and

efects of each transition (initial symbol, symbol that

is rewritten, and direction to move the input

header).

33

Turing Machine: Graph Representation

Page 34: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

q0 q1

qF

34

Turing Machine: Graph Representation

Page 35: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

q0

0 + 0

Current

symbol

that is

read

Symbol that is written

Direction of the movement

q1

qF

35

Turing Machine: Graph Representation

Page 36: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

q0 q1

0 + 0 0 +

0

qF

1 + 1

1 + 1

□ = 0

□ = 1

36

Turing Machine: Graph Representation

Page 37: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

q0 q1

0 + 0 0 +

0

qF

1 + 1

1 + 1

□ = 0

□ = 1

37

Turing Machine: Graph Representation

Page 38: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

f 0 1 □

-> qO q1 * qF

(q0, 0, +) (q1, 0, +)

(q1, 1, +) (q0, 1, +)

(qF, 0, =) (qF, 1, =)

q0 q1

0 + 0 +

qF

1 +

1 +

□ 0

□ 1

38

Turing Machine: Graph Representation

Page 39: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Machine and Languages 39

Turing Machine as TRANSDUCER:

It modifies the content of the tape,

Examples: TM that replaces digits by zeros.

TM that appends a parity bit to the input.

Turing Machine as RECOGNIZER:

• TM that recognizes a language.

• TM that accepts a language.

Page 40: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Machine and Languages 40

Turing Machine as TRANSDUCER:

• Objective: transform the input ( Provide the result

of an operation).

It verifies:

• If the input is well-formed, it must finish in a final state.

• If the input is NOT well-formed, it must finish in a

nonfinal state (shows an error in the input word).

Page 41: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Machine and Languages 41

Turing Machine as RECOGNIZER

• Objective: Decide if the input string is valid or not, following a specific criterion.

Two main concepts: RECOGNIZE, ACCEPT

• A TM RECOGNIZES a language L, if for any input in the tape, w, it stops in a final state iff w L.

• A TM ACCEPTS a language L if, when analyzing a word w, it stops in a final state iff w L.

If the word does not belong to the language, the TM does not need to stop.

Page 42: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Machine: More Examples 42

Machine that replaces 0’s by 1’s.

TM that obtains the successor/predecessor of a number.

TM that duplicates the number of 1’s in the tape.

TM that writes at the end of the word: a zero if the number of 1’s is even or a one if the number of 1’s is odd.

TM that recognizes the languages: a*b*, anbn

MT that recognizes the language anbncn

TM that does not stop.

Page 43: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

43

L={anbn, n 0}

Turing Machine: More Examples

Page 44: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Machine: More Examples 44

Q \ 1 x b

p q x R p x L r b R

q q 1 R q x R p x L

r r 1 R s b S

s

TM =({1,x}, b, {p,q,r,s}, p, f, {s})

Words recognized?

TM that duplicates the number of 1’s that are present in the tape.

Operation?

Diagram of states.

Page 45: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Machine: More Examples 45

state p: when it finds a 1, it changes it by x and transits to q.

• while it finds x, it ignores them, it follows in p and left: f(p,x) (p,x,L)

• when it finds 1, it writes x, it transits to q and right: f(p,1) (q,x,R)

• when it finds a b, it ignores it, it transits to r and right: f(p,b) (r,b,R)

state q: it adds an x to the input string, on the first b that appears to the

right of the same.

• while it finds x and 1, it ignores them, it follows in q and right.

f(q,x) (q,x,R) f(q,1) (q,1,R)

• when it finds a b, it writes x, it transits to p and left.

f(q,b) (p,x,L)

Page 46: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Machine: More Examples 46

state r: it transforms every x into 1, when it has already finished, the

problem has been solved and the TM transits to the final state and stops.

• it changes x by 1, follows in r and right: f(r,x) (r,1,S)

• When it finds a b, it leaves it, goes to the final state and the TM stops:

f(r,b) (s,b,S)

Page 47: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Machine: More Examples 47

Page 48: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Machine: More Examples 48

TM that does not stop. TM that does not stop.

If we considered the number n >=0 as a succession of n+1 “1’s” (the zero corresponds with a one). This TM obtains the following number to the one received as input, i.e., it calculates n+1

Page 49: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

49

Turing Machine: More Examples

TM that recognizes

anbncn, n>=0

Page 50: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

OUTLINE

Introduction

Definition of Turing Machine

Variations of Turing Machines

Universal Turing Machine

Additional issues

Page 51: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

We have defined a generic Turing Machine.

The definition of TM admits many variations, but having the same

computation capacity, i.e. all the variations are equivalent.

Two Turing Machines, TM1 y TM2 are equivalent if both carry out the same

action for all their inputs.

• What does equivalent mean for a Turing Machine?

TM as transducers: for each possible input, at the beginning of the

process, at the end of this the contents of the tape must be the

same.

TM as recognizers: both TM accepts the same words.

If for some input w, one TM does not stop, the second one will not

stop for such input w.

51

Turing Machine: Equivalences

Page 52: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Using the generic TM it is possible to impose restrictions, without they suppose

limitations in the computation capacity.

These restrictions can be imposed on:

• The alphabet of the tape: binary TM. Γ={0,1}. (Not Σ = {0,1} y Γ = {0,1, b}).

• The structure of the tape: Limited TM.

• E.g.: infinite tape only by the right (limited by the left using the input

word).

• Movements (to write, move and change the state)

• E.g.: not to allow that the head remains quiet; not to allow that it

writes and changes simultaneously of state; etc.

52

Turing Machine: Restrictions

Page 53: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Machine with Binary Alphabet

Theorem:

Given a generic TM , there is an equivalent TM with binary alphabet in the tape, Γ = {0,1}

M-> M(2

IMPORTANT: it is Γ = {0,1} and Σ Γ , not Σ = {0,1} and Γ = {0,1, b}

Different descriptions in the bibliography

(According to section 2.2.3, Alfonseca 2007)

53

Turing Machine with Binary Alphabet

Page 54: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Submachines (Subroutines)

Same concept that functions, methods, procedures

(subprograms).

A TM can, during its execution, invoke to another

one.

DEFINITION:

• A submachine of Turing is a TM that can receive

arguments (i.e. symbols) to carry out a specific task

specify, and can be invoked with another TM.

54

Page 55: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Submachines (Subroutines)

When a TM M1 invokes another TM M2 with an

argument σ, the parameter in the definition of the

submachine is replaced by the symbol by means it

has been invoked: M2(σ).

• M2(σ) is executed:

Using the same tape that M1.

From the initial state of M2.

With the R/W head of M2 on the same position where it

was in M1.

55

Page 56: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Submachines (Subroutines)

To use Turing Submachines does not mean that the

computability capacity (calculation) of TM is

increased.

Example:

• Design a TM (using submachines) that recognizes the

words of the language L={anbn, n 0}

56

Page 57: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Submachines (Subroutines)

Máquinas de Turing

57

Example: L={anbn, n 0}

Page 58: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Submachines (Subroutines) 58

Example: L={anbn, n 0}

Page 59: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Submachines (Subroutines) 59

Search by the left

Example: L={anbn, n 0}

(Second version)

Page 60: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Submachines (Subroutines) 60

λ; Search by the left, RIGHT

λ; Search by the right, LEFT Example: L={anbn, n 0}

(using submachines)

Page 61: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Turing Submachines (Subroutines) 61

Example: TM to search a

symbol a by the right.

Page 62: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

OUTLINE

Definition of Turing Machine

Variations of Turing Machines

Universal Turing Machine

Additional issues

Page 63: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Universal Turing Machine

It is possible to define a TM that simulates the

execution of EVERY TURING MACHINE.

This machine is called

UNIVERSAL TURING MACHINE (U)

63

Page 64: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Universal Turing Machine

Universal Turing machine: U

• Input:

Description of the TM.

Input string (word): w.

• What does U(TM, w) simulate?

It simulates the operation of TM, transition by transition.

• If TM accepts w, then U stops in a final state for that

word.

• If TM does not accept w, U does not stop or it stops in a

non-final state for this word.

64

Page 65: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Universal Turing Machine

Universal Turing Machine: U

• It simulates a TM.

• What does it happen if TM never stops?

65

Page 66: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Universal Turing Machine: Undecidability

HALTING PROBLEM

• Remember: “The output of the machine—i.e., the solution

to a mathematical query—can be read from the system

once the TM has stopped.”

• However, in the case of Gödel’s undecidable

propositions, the machine would never stop, and this

became known as the “halting problem.”

• It is not possible to decide if, given an input word w, the

machine will stop or will be always running.

• There is not a TM that answers this question.

66

Page 67: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

OUTLINE

Definition of Turing Machine

Variations of Turing Machines

Universal Turing Machine

Additional issues

Page 68: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Design issues 68

The solution of the problem is the transition table, but

this is not enough to complete an exercise.

It is essential to think and describe the algorithm

before to be implemented, as well as the behavior of

each one of the states.

It is precise to evaluate the machine with a significant

set of inputs. There are maybe “difficult” cases that

have to be considered.

Many TM operates on input tapes with a specific

configuration, that normally we do not verify.

Page 69: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Design issues 69

Any solution is not valid, you must think the algorithm

very well and verify that it works for every case.

If TM must operate as if it had “memory”, additional

states can be incorporated (in more complicated

machines, the input data can be written in specific

positions of the tape).

If a TM must remember positions within the tape, they

usually use additional markers.

If the task can be divided in several sequential

subtasks (or subprogram), then do it.

Page 70: AUTOMATA THEORY AND FORMAL LANGUAGES 2015 · PDF fileAUTOMATA THEORY AND FORMAL LANGUAGES 2015-16 ... Teoría de Autómatas y Lenguajes Formales. ... de Lenguajes, Gramáticas y Autómatas

Binary Turing Machine with LEGO:

http://www.youtube.com/watch?v=cYw2ewoO6c4

70

Design issues