29
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

  • Upload
    malana

  • View
    24

  • Download
    0

Embed Size (px)

DESCRIPTION

15-453. FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY. Some Homework 1 Statistics: Each question was graded out of 20 points. Max: 100 Mean: 78 Median: 79.02 Std Dev: 15.65. NOTE : Your 1st Project Report is Due Tuesday! Turn in your Homework! (New Homework on the Web). - PowerPoint PPT Presentation

Citation preview

Page 1: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

15-453

Page 2: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Some Homework 1 Statistics:

Each question was graded out of 20 points.

Max: 100Mean: 78 Median: 79.02 Std Dev: 15.65

Page 3: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

NOTE : Your 1st Project Report is

Due Tuesday!

Turn in your Homework!

(New Homework on the Web)

Page 4: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

PDAs ARE EQUIVALENT TO CFGs

THURSDAY Jan 31

Page 5: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

ε,ε → $0,ε → 0

1,0 → ε

1,0 → εε,$ → ε

string pop push

Page 6: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

A → 0A1A → ε

CONTEXT-FREE GRAMMARS

A 0A1 00A11 000A111 000111

variable terminals

(VΣ)*

(yields)A * 000111

(derives)

Production rules

Page 7: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

A Language L is generated by a CFG

L is recognized by a PDA

Page 8: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

A Language L is generated by a CFG

L is recognized by a PDA

Suppose L is generated by a CFG G = (V, Σ, R, S)

Construct P = (Q, Σ, Γ, , q, F) that recognizes L

Page 9: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Suppose L is generated by a CFG G = (V, Σ, R, S)

Construct P = (Q, Σ, Γ, , q, F) that recognizes Lε,ε → S$

ε,$ → ε

For each rule 'A → w’ R:

For each terminal a Σ:ε,A → wR

a,a → ε

Page 10: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

S → aTb

T → Ta | ε

ε,ε → $

ε,$ → ε

ε,ε → Sε,S

→ b

ε,ε → T

ε,T → a

ε,ε → a

ε,ε → T

ε,T → εa,a → εb,b → ε

Page 11: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

S → aTb

T → Ta | ε

ε,ε → $

ε,$ → ε

ε,ε → Sε,S

→ b

ε,ε → T

ε,T → a

ε,ε → a

ε,ε → T

ε,T → εa,a → εb,b → ε

S * ab(derives)

Page 12: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Suppose L is generated by a CFG G = (V, Σ, R, S)

Describe P = (Q, Σ, Γ, , q, F) that recognizes L :

(1) Push $ and then S on the stack

(2) Repeat the following steps forever:

(b) If X is a variable A, guess a rule that matches A and push result into the stack

(c) If X is a terminal, read next symbol from input and compare it to terminal. If they’re different, reject.

(d) If X is $: then accept iff no more input

(a) Pop the stack, call the result X.

Page 13: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

A Language L is generated by a CFG

L is recognized by a PDA

Page 14: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

A Language L is generated by a CFG L is recognized by a PDA

Given PDA P = (Q, Σ, Γ, , q, F)

Construct a CFG G = (V, Σ, R, S) such that L(G) = L(P)

First, simplify P to have the following form:

(1) It has a unique accept state, qacc

(2) It empties the stack before accepting

(3) Each transition either pushes a symbol or pops a symbol, but not both at the same time

Page 15: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

ε,ε → $0,ε → 0

1,0 → ε

1,0 → εε,$ → ε

SIMPLIFY

q0 q1

q2q3

Page 16: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

ε,ε → $0,ε → 0

1,0 → ε

1,0 → εε,$ → ε

SIMPLIFY

q0 q1

q2q3

ε,ε → ε

ε,ε → ε

ε,E → εq4

q5

Qε,ε → E

ε,σ → ε

Page 17: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

ε,ε → $0,ε → 0

1,0 → ε

1,0 → εε,$ → ε

SIMPLIFY

q0 q1

q2q3

ε,ε → D

ε,ε → D

ε,E → ε

q4

q5

Qε,ε → E

ε,σ → ε

q’0

q’3

ε,D → ε

ε,D→ ε

Page 18: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

V = {Apq | p,qQ }

S = Aq0qacc

Idea For Our Grammar G: For every pair of states p and q in PDA P, G will have a variable Apq whose production rules will generate all strings x that can take:

P from p with an empty stack to q with an empty stack

Page 19: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Aq0q1 generates?

Aq1q2 generates?{0n1n | n > 0}

Aq1q3 generates?

ε,ε → $0,ε → 0

1,0 → ε

1,0 → εε,$ → ε

q0 q1

q2q3

ε,ε → D

ε,ε → D

ε,E → ε

q4

q5

Qε,ε → E

ε,σ → ε

q’0

q’3

ε,D → ε

WANT: Apq generates all strings that take p with an empty stack to q with empty stack

Page 20: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

WANT: Apq generates all strings that take p with an empty stack to q with empty stack

Let x be such a string

• P’s first move on x must be a push

• P’s last move on x must be a pop

Two possibilities:

1. The symbol popped at the end is exactly the one pushed at the beginning

2. The symbol popped at the end is not the one pushed at the beginning

Page 21: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

stackheight

inputstring p q

Apq → aArsb

r s

1. The symbol t popped at the end is exactly the one pushed at the beginning

ba push t pop t

x = ayb takes p with empty stack to q with empty stack

δ(p, a, ε) → (r, t)

δ(s, b, t) → (q, ε)

─ ─ ─ ─ x ─ ─ ─ ─

Page 22: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

stackheight

inputstring p r q

Apq → AprArq

2. The symbol popped at the end is not the one pushed at the beginning

Page 23: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

V = {Apq | p, qQ }

S = Aq0qacc

Formally:

For every p, q, r, s Q, t Γ and a, b Σε

If (r, t) (p, a, ε) and (q, ε) (s, b, t)

Then add the rule Apq → aArsb

For every p, q, r Q,

add the rule Apq → AprArq

For every p Q,

add the rule App → ε

Page 24: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Apq generates x

x can bring P from p with an empty stack to q with an empty stack

Proof (by induction on the number of steps in the derivation of x from Apq):

Base Case: The derivation has 1 step: App εInductive Step:Assume true for derivations of length ≤ k and prove true for derivations of length k+1:

Apq * x in k+1 steps

Apq → aArsbApq → AprArq

(r,t) (p,a,ε) and (q, ε) (s,b,t)

state push state alphabet pop

For all x,

Page 25: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Apq generates x

x can bring P from p with an empty stack to q with an empty stack

Proof (by induction on the number of steps in the computation of P from p to q with empty stacks, on input x):

Base Case: The computation has 0 steps

So it starts and end in the same state:We must show that App * x

But it must be that x = ε, so we are done

For all x,

Page 26: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Inductive Step:

Assume true for computations of length ≤ k, we’ll prove true for computations of length k+1

Suppose that P has a computation where x brings p to q with empty stacks in k+1 steps

Two cases:

1. The stack is empty only at the beginning and the end of this computation

2. The stack is empty somewhere in the middle of the computation

Write x as ayb. Ars * y by I.H., use Apq → aArsb

Write x as yz. Apr * y, Arq * z by I.H., Apq → AprArq

Page 27: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

A Language L is generated by a CFG

L is recognized by a PDA

Page 28: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Corollary: Every regular language is context-free

Page 29: FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

WWW.FLAC.WS