INHERENT LIMITATIONS OF COMPUTER PROGAMS - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

INHERENT LIMITATIONS OF COMPUTER PROGAMS

Description:

The language of G is the set of strings derived by S. ... by a CFG G = (V, S, R, S) ... Apq generates all strings that take P from p to q without ... – PowerPoint PPT presentation

Number of Views:121
Avg rating:3.0/5.0
Slides: 25
Provided by: nickh4
Category:

less

Transcript and Presenter's Notes

Title: INHERENT LIMITATIONS OF COMPUTER PROGAMS


1
CSci 4011
INHERENT LIMITATIONS OF COMPUTER PROGAMS
2
e,e ?
0,e ? 0
1,0 ? e
e, ? e
1,0 ? e
The language of P is the set of strings it
accepts.
3
CONTEXT-FREE GRAMMARS
A ? 0A1
A ? B
B ?
A
? 0A1
? 00A11
? 00B11
? 0011
A derives 0011 in 4 steps.
The language of G is the set of strings derived
by S.
4
GIVE A CFG FOR
L1 strings of balanced parens
L2 aibjak i, j, k 0 and k i j
5
Suppose L is generated by a CFG G (V, S, R, S)
Construct P (Q, S, G, ?, q, F) that recognizes L
A Language is generated by a CFG ? It is
recognized by a PDA
?
Idea P will derive w 2 L on its stack.
6
(1) Place the marker symbol and the start
variable on the stack
Suppose L is generated by a CFG G (V, S, R, S)
Construct P (Q, S, G, ?, q, F) that recognizes L
(2) Repeat forever
(a) If v is in the stack, and (v ! s) 2 R, push s
on the stack (b) If stack is a string, goto (3)
(3) Loop until stack is empty (a) if top
of stack matches input, pop. (b) on
(e,), accept.
7
Suppose L is generated by a CFG G (V, S, R, S)
Construct P (Q, S, G, ?, q, F) that recognizes L
(qstart) Push S and go to qloop
(qloop) Repeat the following steps forever
(a) On (e,v) where (v ! s) 2 R, push s and go to
qloop
(b) On (?,?), pop ? and go to qloop
(c) On (e,) go to qaccept
(else) get stuck!
8
e,e ? S
e,A ? w for rule A ? w
a,a ? e for terminal a
e, ? e
9
S ? aTb
T ? Ta e
e,e ?
e,e ? T
e,S ? b
e,e ? T
e,e ? S
e,T ? a
e, ? e
e,e ? a
e,T ? e
a,a ? e
b,b ? e
10
A Language is generated by a CFG ? It is
recognized by a PDA
?
11
DFA TO CFG
V0 ! 0V0 1V1 V1 ! e 0V2 1V2 V2 ! e 1V2
0V3 V3 ! 0V0 1V2
For each state qi 2 Q, add variable Vi 2 V. Vi
derives all the strings that take qi to accept
Vi ! ?, where qi 2 F
Vi ! ?Vj, where ?(qi,?) qj
12
A Language is generated by a CFG ? It is
recognized by a PDA
?
Given PDA P (Q, S, G, ?, q, F)
Construct a CFG G (V, S, R, S) such that
L(G)L(P)
First, simplify P so that
(1) It has a single accept state, qaccept
(2) It empties the stack before accepting
(3) Each transition either pushes a symbol or
pops a symbol, but not both
13
SIMPLIFY
e,e ?
0,e ? 0
q1
q0
1,0 ? e
e,e ? e
e,e ? 0
e, ? e
q2
1,0 ? e
q3
e,e ? e
e,e ? 0
q4
e,0 ? e
q5
14
Idea for each pair of states p and q in P, the
grammar will have a variable Apq that generates
all strings that that can take P from p to q
without changing the stack
V Apq p,q?Q
S Aq0qaccept
starting from any stack S in p, P has stack S at
q.
15
none
What strings does Aq0q1 generate?
0n1n n gt 0
What strings does Aq1q2 generate?
What strings does Aq1q3 generate?
none
16
Apq generates all strings that take P from p to q
without changing the stack
Let x be such a string
  • Ps first move on x must be a push
  • Ps last move on x must be a pop

Consider the stack while reading x. Either
1. The first repeat comes at the end of x
2. The stack repeats before the end of x
17
1. The first repeat is at the end of x
stack height
r
s
b
a
input string
p
q
Apq ? aArsb
18
2. The stack repeats before the end of x
stack height
input string
p
r
q
Apq ? AprArq
19
Formally
V Apq p,q?Q
S Aq0qaccept
For each p,q,r,s ? Q, t ? G and a,b ? Se
If (r,t) ? ?(p,a,e) and (q, e) ? ?(s,b,t)
Then add the rule Apq ? aArsb
For each p,q,r ? Q,
add the rule Apq ? AprArq
For each p ? Q,
add the rule App ? e
20
Aqq ? e
Apq ? AprArq
Aq0q3 ? eAq1q2e
Aq1q2 ? 0Aq1q21
Aq1q2 ? 0Aq1q11
none
What strings does Aq0q1 generate?
0n1n n gt 0
What strings does Aq1q2 generate?
What strings does Aq1q3 generate?
none
21
Apq generates x ? x can bring P from p to q
without changing the stack
?
Proof (by induction on the number of steps in the
derivation of x from Apq)
Inductive Step
Base Case
The derivation has 1 step
App ? e
Assume true for derivations of length at most k
and prove true for derivations of length k1
Apq ? x in k1 steps
Apq ? aArsb
Apq ? AprArq
(r,t) ? ?(p,a,e) and (q, e) ? ?(s,b,t)
state
push
state
alphabet
pop
22
Apq generates x ? x can bring P from p to q
without changing the stack
?
Proof (by induction on the number of steps in the
computation of P on input x)
Base Case
The computation has 0 steps
We must show that App ? x
But it must be that x e, so we are done
23
Inductive Step
Assume true for computations of length at most k
and prove true for computations of length k1
Suppose that P has a computation wherein x brings
p to q in k1 steps
Two cases
1. The stack repeats only at the end of this
computation
2. The stack repeats somewhere in the middle of
the computation
24
A Language is generated by a CFG ? It is
recognized by a PDA
Write a Comment
User Comments (0)
About PowerShow.com