pushdown automata and turing machines - intranet...

25
Pushdown Automata Turing Machines Automata determinization Pushdown Automata and Turing Machines Alessandro Barenghi Dipartimento di Elettronica e Informazione Politecnico di Milano barenghi - at - elet.polimi.it October 24, 2012

Upload: vuquynh

Post on 07-Jul-2019

240 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

Pushdown Automata and Turing Machines

Alessandro Barenghi

Dipartimento di Elettronica e InformazionePolitecnico di Milano

barenghi - at - elet.polimi.it

October 24, 2012

Page 2: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

An extended computation model

Pushdown Automata

Finite state automata are a handy model, but are not able tocount an arbitrary number of items

Idea: add a simple memory to the computation model: a stack

The stack is a Last-In-First-Out memory (LIFO)

The read operation on the memory erases the value (popoperation)

The resulting automaton is known as a PushDown Automaton(PDA)

For this computation model the non-determinism enhancesthe computation capability

Page 3: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

Formalization

Definition

A recognizer PDA is formally defined as a 7-tuple(Q, I, Γ, δ, q0,F,Z0), where:

Q, is the set of states of the automataI is the alphabet of the input string which will be checkedΓ is the alphabet of the symbols on the stackδ : Q× I× Γ 7→ Q× (Γ ∪ ε) the transition functionq0 ∈ Q the (unique) initial state from where the automatonstartsF ⊆ Q the set of final accepting states of the automatonZ0 is the symbol which indicates the bottom of the stack

Page 4: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

Structure

Advantages

The main advantage of a PDA is that it is able to count letters

The transition function relies on reading both a symbol fromthe input and a symbol from the stack to perform a transition

Nondeterminism takes place when two transitions have boththe same input and the same stack symbol as a trigger (fromthe same state)...

... or with ε-transitions, as always

Page 5: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

A first attempt

L = anb2n, n ≥ 1

To obtain a synthetic notation, the convention is to denote onan arc <input><stack> | <stack><stack>

q0start q2

q1 q3

bA|A

aZ0|AZ0

aA|AA bA|A

εZ0|Z0

bA|ε

Page 6: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

A first attempt

L = anb2n, n ≥ 1

Eliminating nondeterminism with an extra symbol

q0start q2 q1

q3 q3

bA|A

aZ0|BZ0

aA|AAaB|AB bB|B

bA|AbB|B

bA|ε

bB|ε

Page 7: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

Formalization

Definition

A transducer PDA is formally defined as a 7-tuple(Q, I, Γ, δ, q0,F,Z0,O, η), where:

Q, is the set of states of the automataI is the alphabet of the input string which will be checkedΓ is the alphabet of the symbols on the stackδ : Q× I× Γ 7→ Q× (Γ ∪ ε) the transition functionq0 ∈ Q the (unique) initial state from where the automatonstartsF ⊆ Q the set of final accepting states of the automatonZ0 is the symbol which indicates the bottom of the stackO the output alphabet (may coincide with I)η : Q× I× Γ 7→ {O ∪ ε} × (Γ ∪ ε) the transduction function

Page 8: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

A simple transducer

τ(akbhch) = d3hek , h, k ≥ 1

Hint: “one b is worth two d” is a nice strategy

Notation convention<input><stack> | <stack><stack>,< output >

q0start q1 q2 q3bA|BA, dd

aZ0|AZ0, ε

aA|AA, ε

bB|BB, dd

cB|ε, d

cB|, ε

εA|ε, e

bA|ε, e

Page 9: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

The ultimate computing model

Definition

Willing to further extend the capabilities of the PDA wesubstitute the stack with one (or more) tapes

The resulting automaton is the Turing Machine, which is ableto do anything we define as computablea

The TM is able to choose whether to advance, go back orstand still with the cursor on the tape

Multiple tapes can be added, but they do not increase thecomputing power

aor, at least, Alonso Church believed so, and we pretty much agree

Page 10: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

The ultimate computing model

Definition

For greater comfort, we use a marker symbol Z0 to indicatethe beginning of the tape (in case it’s not there, we can addit)

We assume that the input is positioned on the input tape

All the other tapes, if any, are filled with the blank symbol �

All the actions on the tapes contents are driven by a FSA

Notation:<input tape>,<tape1>, . . . , <tapen> | <tape1>, . . . , <tapen>, (R | S | L)n+1

Page 11: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

Formalization

Definition

A k-tapes transducer TM is formally defined as a 7-tuple(Q, I, Γ, δ, q0,F,Z0), where:

Q, is the set of states of the automataI ∪ {�} is the alphabet of the input string which will becheckedΓ ∪ {�} is the alphabet of the symbols on the tapesδ : Q× I× Γk 7→ Q× Γk × {R,S , L}k+1 the transition functionq0 ∈ Q the (unique) initial state from where the automatonstartsF ⊆ Q the set of final accepting states of the automaton

Page 12: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

A first example

L = anbncn, n ≥ 1

The trick is that we can sweep over the memory tape as manytimes as we want

q0start q1 q2 q3

q4

a�|Z0, (S,R)

a�|A, (R,R)

b�|�, (S , L)

bA|A, (R, L)

cZ0|Z0, (S ,R)

��|�, (S , S)

cA|A, (R,R)

Page 13: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

A bit more complex

L = anbn÷2cn÷2, n ≥ 1

A slight deviation from the common idea of counting

More than a single solution possible (it’s the same as saying :“devise a program that writes such strings”)

One method to perform division: stop on the input tape,continue in memory

Other methods involve writing twice the symbols on the tape

Page 14: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

A bit more complex

q0start q1 q2 q4 q10

q6q3

q5 q9

q7 q8

a�|Z0, (S, R)

a�|A, (R, R)

b�|�, (S, L)

��|�, (S, L)

bA|A, (S, L)

cZ0|Z0, (S, R)

cA|A, (S, L)cZ0|Z0, (S, R)

�A|A, (S, L)

�A|A, (S, R)

��|�, (S, S)

cA|A, (S, R)

cA|A, (R, R)

�Z0|Z0, (S, S)

��|�, (S, S)

bA|A, (R, L)

Page 15: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

FSA determinization

Removing nondeterminism

Removing nondeterminism from an FSA(QND−FSA, IND−FSA, δND−FSA, q0ND−FSA,FND−FSA) is “easy”,although comes at a price

The state set of the deterministic FSA is (in the worst case) is℘(QND−FSA), thus | ℘(QND−FSA) |= 2QND−FSA

Luckily some of them may not be reachable and can beeliminated

The algorithm for determinization applies step by step thedefinition

Starting from q0ND−FSA add a state as soon as a transitiongoes there

A state is final if at least one of the ND-FSA statesrepresented by it was final

Page 16: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

FSA determinization

ND-FSA

q0start

q1

q2

q3

0,1

0

0,1

1

1

1

0

Page 17: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

FSA determinization

Expanding q0

q0start

q1

q1q2

1

0

Page 18: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

FSA determinization

Expanding q1

q0start

q1 q3

q1q2

q1q3

1

0

0

1

Page 19: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

FSA determinization

Expanding q3

q0start

q1q3q2

q1q2

q1q3

1

0

1

0 0 1

Page 20: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

FSA determinization

Expanding q2

q0start

q1q2q3

q1q2

q1q3

1

0

1

0

1

0

1

Page 21: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

FSA determinization

Expanding q13

q0start

q1

q2

q12q3

q13

q23

q013

101

0

1

0

0

1

0

1

Page 22: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

FSA determinization

Expanding q013

q0start

q1

q2

q12q3

q13

q23

q01

q013

q123

101

0

1

0

0

1

0

1

0

1

Page 23: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

FSA determinization

Expanding q123

q0start

q1

q2

q12q3

q13

q23

q01

q013

q123

101

0

1

0

0

1

0

1

01

0

1

Page 24: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

FSA determinization

Expanding q01

q0start

q1

q2

q12q3

q13

q23

q01

q013

q123

101

0

1

0

0

1

0

1

01

0,1

0

1

Page 25: Pushdown Automata and Turing Machines - Intranet DEIBhome.deib.polimi.it/barenghi/lib/exe/fetch.php?media=teaching:pda_mt_design.pdf · Pushdown AutomataTuring MachinesAutomata determinization

Pushdown Automata Turing Machines Automata determinization

FSA determinization

Expanding q23

q0start

q1

q2

q12q3

q13

q23

q01

q013

q123

101

0

1

0

0

1

0

1

01

0,1

0

1

0

1