Anda di halaman 1dari 53

DVA337 HT17 – LECTURE 10 PDAs and CFGs

1
WRITTEN ASSIGNMENT
Part 1
 2 A4 pages explaining the halting problem for Turing machines in own words
 Formal treatment of mathematics and language
 Not part of the seminar

Part 2
 2 A4 pages describing a topic related to the course content (finite automata, limitations of
computation)
 Popular science paper – less demands on technical content
 Part of the seminar

2
PAPER STRUCTURE
Papers should be well structured and self contained, e.g.,
 Introduction – introduces the notion of Turing machines, how they compute and the notion of decision
problem.
 The halting problem – explains the halting problem in terms of Turing machines, and shows why the
halting problem is undecidable
 Discussion – discusses the ramifications of the halting problem for moder computer languages.

The text should have good flow and the reasoning should be logical and easy to
follow
As always
 cite your information sources
 do not cite Wikipedia (proper sources please)

3
TOPICS FOR PART 2
There are numerous interesting topics
 Cellular automata
 L-systems for modeling plant growth
 Automata for natural language recognition
 Automata for speech recognition
 Automata for traffic flow modeling
 Automata for fluid dynamics
 Grammars for natural languages
 Presentation of key personas and their contributions to the field (Kurt Gödel, Noam Chomsky, …)
 Lambda calculus
 Complexity and complexity classes; P/NP
Topics should not overlap – overlap makes the seminar boring
 Topics selected in a first-come-first-served manner
 I’ll keep a list of taken subjects on BlackBoard

4
SEMINAR AND DEADLINES
We are probably too many to have a Deadline for 1st part: October 29th
seminar for the whole class
 (depends how many signs up – remember this Deadline for 2nd part: October 23rd
part is mandatory)  day before seminar

Seminar: October 24th


In case we are too many we will make
seminars in smaller groups
 maybe 3 – 4 people in each group

We’ll decide this later – it’s always more


interesting and instructive to have a
whole class seminar

5
TODAY
Push-Down Automata, PDA

NPDA: Non-Deterministic PDA

Formal Definitions for NPDAs

NPDAs Accept Context-Free Languages

Converting NPDA to Context-Free Grammar

6
RECAP
Context-free grammar

Context-free language

7
FINITE ACCEPTERS Instantaneous descriptions

8
LOOKING BACK
A finite accepter has the form M = (Q, Σ, δ, q0, F)
 both DFAs and NFAs are FAs – what is the difference?

9
RECAP, EXTENDED TRANSITION FUNCTION
Language accepted by DFA, M = (Q, Σ, δ, q0, F)

Language accepted by NFA, M = (Q, Σ, δ, q0, F)

10
INSTANTANEOUS DESCRIPTIONS
a, b
What is the state of a FA?
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

How can we describe transitions between states?


 for DFAs and NFAs – any difference?

11
LANGUAGE ACCEPTED BY AN FA
a, b
When does an FA accept a string
 in terms of instantaneous descriptions
q5
a a, b
b a b
q0 a q1 b q2 b q3 a q4

What is the language accepted by an FA


 in terms of instantaneous descriptions

12
EXERCISE
Show the execution of abba
a, b
 as a sequence of instantaneous descriptions

q5
b a a, b
a b
q0 a q1 b q2 b q3 a q4

13
PDA Pushdown Automata

14
LIMITATIONS OF FA
Finite Accepters have finite memory
 states used to encode information about the input string
 finite number of states

For L = { anbn : k ≥ n ≥ 0 } we can create a FA


 upper limit on how many as and bs we want to count

For L = { anbn : n ≥ 0 } we cannot create a FA


 no upper limint on how many as and bs we want to count – no upper limit on size of DFA

We extend the notion of FA by adding a stack; gives us the notion of PDA


 infinite memory – restricted access (push and pop)

15
PUSHDOWN AUTOMATON, PDA
Input String

Stack

States

16
TRANSITIONS OF A PDA
Each transition adds interaction with
stack
 consuming the input q1 a, b / c q2
 consuming the stack (pop)
 adding elements on the stack (push)

λ-transitions allowed
 where and how differs between authors
 let us begin with Linz and then explore the
design space

17
FORMAL DEFINITION
A PDA is a quintuple M = (Q, Σ, Γ, δ, q0, z, F)
q1 a, b / c q2

18
STRING ACCEPTED BY AN NPDA
An NPDA is a quintuple M = (Q, Σ, Γ, δ, q0, z, F)

Execution of an NPDA
 state – instantaneous descriptions

 transitions between states

19
LANGUAGE ACCEPTED BY AN NPDA
String accepted by NPDA?

Language accepted by an NPDA?

20
EXERCISE
Explain how to prove equivalence between
 accept(w) = (q0, w, z) ⊢* (qf, λ, u) and
 accept(w) = (q0, w, λ) ⊢* (qf, λ, λ)

21
DESIGN SPACE OF NPDAS
With δ : Q ⨯ (Σ ∪ { λ }) ⨯ Γ → Pfin(Q ⨯ Γ*)
 could we replace Γ* with Γ in the codomain?

22
DESIGN SPACE OF NPDAS
With δ : Q ⨯ (Σ ∪ { λ }) ⨯ Γ → Pfin(Q ⨯ Γ*)
 should we change Γ to Γ ∪ { λ } in the domain?

23
DESIGN SPACE OF NPDAS
Which one should we work with?

δ : Q ⨯ (Σ ∪ { λ }) ⨯ Γ → Pfin(Q ⨯ Γ*)

δ : Q ⨯ (Σ ∪ { λ }) ⨯ (Γ ∪ { λ }) → P(Q ⨯ Γ)

δ : Q ⨯ (Σ ∪ { λ }) ⨯ (Γ ∪ { λ }) → Pfin(Q ⨯ Γ*)

24
DESIGN SPACE OF NPDAS
For M = (Q, Σ, Γ, δ, q0, z, F) and δ : Q ⨯ (Σ ∪ { λ }) ⨯ Γ → Pfin(Q ⨯ Γ*)
 can we remove z and start with an empty stack?

25
DESIGN SPACE OF NPDAS
Which one should we work with?
M = (Q, Σ, Γ, δ, q0, z, F)
 accept(w) = (q0,w,z) ⊢* (q, λ, u), q ∈ F, u ∈ Γ*

M = (Q, Σ, Γ, δ, q0, F)
 accept(w) = (q0,w,λ) ⊢* (q, λ, u), q ∈ F, , u ∈ Γ*

M = (Q, Σ, Γ, δ, q0, z, F)
 accept(w) = (q0,w,z) ⊢* (q, λ, λ), q ∈ F

M = (Q, Σ, Γ, δ, q0, F)
 accept(w) = (q0,w,λ) ⊢* (q, λ, λ), q ∈ F

26
NPDA Non-deterministic Push-Down
Automata

27
FORMAL DEFINITION
Many choices – some connected
 choose the most convenient, but be clear which one it is!

We will be working with


 M = (Q, Σ, Γ, δ, q0, z, F)
 accept(w) = (q0,w,z) ⊢* (q, λ, u), q ∈ F, u ∈ Γ*
 δ : Q ⨯ (Σ ∪ { λ }) ⨯ (Γ ∪ { λ }) → Pfin(Q ⨯ Γ*)

28
SOURCES OF NON-DETERMINISM

29
EXAMPLE
Create an NPDA for L = { anbn : n ≥ 0 }

30
EXERCISE, ADDITIONAL SLIDES EXAMPLE 1
Show the execution of the following NPDA for a3b3
 in terms of instantaneous descriptions

a,  / a b, a / 

,  /  b, a /  , $ / $
q0 q1 q2 q3
31
EXERCISE
Create NPDA for L = { wwR : w ∈ {a,b}* }

32
EXERCISE   {a, b}

Create NPDA for L = { w : w ∈ {a,b}*, |w|a = |w|b }

33
EXERCISE
Show execution for aabbba for the following NPDA

a, $ / 0$ b, $ / 1$
a, 0 / 00 b, 1 / 11
a,1 /  b, 0 / 

, $ / $
q1 q2
34
ADDITIONAL SLIDES, EXAMPLE 2
See for execution example for

a, $ / 0$ b, $ / 1$
a, 0 / 00 b, 1 / 11
a,1 /  b, 0 / 

, $ / $
q1 q2
35
NPDAS ACCEPT
CONTEXT-FREE LANGUAGES
36
NPDAS ACCEPT CONTEXT-FREE LANGUAGES
Theorem: NPDAs accept exactly the context-free languages.
Proof:

37
Converting
NPDA TO CFG Context-Free Grammars
to NPDAs

38
CFG TO NPDA
How can we build an NPDA from
 S → aSTb | b
 T → Ta | λ

39
ADDITIONAL SLIDES, EXAMPLE 3
See for execution example for

40
CFG TO NPDA
For any production For any terminal
Aw a

, A / w a, a / 

,  / S , $ / $
q0 q1 q2

41
CFG TO NPDA
The generated NPDA simulates a leftmost derivation  , S / aSTb
 S → aSTb | b , S / b
 T → Ta | λ a, a / 
 , T / Ta
b, b / 
, T / 
S ⇒ aSTb ⇒ abTb ⇒ abTab ⇒ abab
,  / S , $ / $
q0 q1 q2

42
CFG TO NPDA
Lemma: the generated NPDA simulates a leftmost derivation.
S ⇒* w if and only if (q0, w, z) ⊢* (qf, λ, z)
Proof:

43
GREIBACH NORMAL FORM
A normal form of a grammatical class is a restricted form that is as expressive as the
full grammatical class
 the restricted form may make an argument or proof easier (have we seen this before?)

A context-free grammar is on Greibach normal form if


 all productions are on the form A → ax, where a ∈ T and x ∈ V*

The Greibach normal form is a normal form


 each context-free grammar G such that λ ∉ L(G) can be put on Greibach normal form

44
CFG TO NPDA
Lemma: the generated NPDA simulates a leftmost derivation.
if S ⇒* w then (q0, w, z) ⊢* (qf, λ, z)
Proof:

45
CFG TO NPDA
Lemma: if S ⇒* wx then (q1, ww’, Sz) ⊢* (q1, w’, xz)
Proof:

46
CFG TO NPDA
Lemma: if S ⇒* wx then (q1, ww’, Sz) ⊢* (q1, w’, xz)
Inductive step:

47
CFG TO NPDA
Lemma: the generated NPDA simulates a leftmost derivation.
if (q0, w, z) ⊢* (qf, λ, z) then S ⇒* w
Proof:

48
CONVERTING NPDAS
TO CONTEXT-FREE GRAMMARS
49
NPDA TO CFG
Lemma: for any M ∈ NPDA, there exists a G ∈CFG such that L(M) = L(G)
Proof: By construction. The construction is a bit complex, but also quite hard to
illustrate properly.

I will only give a hint on the intuition behind the idea, and refer to Linz pages 190 to
195 for an explanation of the construction.

The additional slides, example 4 illustrates the construction.

50
LOOK BACK, NFA TO RLG
How did it work?
 states to non-terminals
 alphabet to terminals
 transitions to production rules
 final states to λ

51
NPDA TO CFG
NFA to RLG
 states to non-terminals
 alphabet to terminals
 transitions to production rules
 final states to λ

NPDA to CFG
 alphabet to terminal
 transitions to production rules
 what about the stack? encoded in the non-terminals!

52
SUMMARY
Variations on the formulation of NPDAs
Instantaneous descriptions for
 DFA/NFA
 DPDA/NPDA

CFG to NPDA
 3-state NPDA

53

Anda mungkin juga menyukai