ه و ه نزce.sharif.edu/courses/91-92/1/ce415-1/resources/root/lecture notes/chapter2.pdf•any...
Post on 18-Mar-2020
3 Views
Preview:
TRANSCRIPT
� ز�ن ه� و ����� ه���� � ز�ن ه� و ����� ه����
��� دوم��� دوم
ContextContext--Free LanguagesFree Languages
���� ��� �� ��� ����دا�� �� دا��
9191اّول اّول �����ل �����ل
Table Of ContentTable Of Content
• Context-Free Grammars
• Pushdown Automata
• Non-Context-Free Languages
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
ContextContext--Free GrammarsFree Grammars
• A collection of substitution rules(production)
• Each rule → A line in the grammar
• Each line → A variable, an arrow, a string
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
• Each line → A variable, an arrow, a string
• The string → variables and terminals
ContextContext--Free Grammars Free Grammars (Example)(Example)
• An Example: (G1)
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
• Three rules
• Variables: A,B
• Start Variable: A
• Terminals: 0,1,#
DerivationDerivation
• Generating the strings of the language:
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
• G1:
Parse TreeParse Tree
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
ContextContext--Free LanguageFree Language
• All Strings generated in this way
• L(G1) :
• G2 (describes a fragment of the English language):
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
A Derivation ExampleA Derivation Example• Derivation of the sentence “a boy sees” in G2
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
ContextContext--Free Language Free Language (Formal Definition)(Formal Definition)
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
ContextContext--Free Language Free Language ((Formal Definition)Formal Definition)
•u derives v
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
•The language of the grammar:
ExamplesExamples
•G3:
•R (Set of Rules):
•Strings such as: abab, aaabbb, aababb
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
•If: a→( and b →), then: L(G3) →language of all strings of properly nested parentheses
ExamplesExamples
• G4:
• V:
• Σ:
• R (Set of Rules):
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Examples (GExamples (G44))
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Designing ContextDesigning Context--Free GrammarsFree Grammars
• Break the CFL into simpler pieces, if possible
• Construct grammar for each piece
• Combine the rules and the new rule
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
• Combine the rules and the new rule S→S1|S2|…|Sk, where the Si are the start variables for the individual grammars
ExampleExample
• Language:
• :
• :
• Add the rule: to give the
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
• Add the rule: to give the grammar:
Designing ContextDesigning Context--Free GrammarsFree Grammars
• Any DFA can be converted to an equivalent CFG
• Make a variable Ri for each state qi
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
• Make a variable Ri for each state qi
• Add the rule , if
• Add the rule , if qi is an accept state
AmbiguityAmbiguity
• When a grammar can generate the same string in different ways
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
• Undesirable for applications such as programming languages
ExampleExample
• This grammar generates the string ambiguously
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
ambiguously
AmbiguityAmbiguity
• Definition: A string w is ambiguousif it can be derived by at least two derivation (parse) trees.
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
AmbiguityAmbiguity
• Leftmost (Rightmost) derivation: at every step, the leftmost (rightmost) remaining variable is replaced.
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
ExampleExample
G: S → aAB
A → bBb
B → A|ε
Leftmost derivation:
S aAB abBbB abAbB abbBbbB abbbbB abbbb
Rightmost derivation:
S aAB aAA aAbBb aAbb abBbbb abbbb
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
⇒ ⇒ ⇒⇒ ⇒ ⇒
⇒ ⇒⇒
⇒ ⇒⇒
Example (Example (ctdctd))
S
a A B
B bb ε
A
S
Ba
AB
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
B bb ε
A
bb B
ε
bAB
b B
ε
bε
b
Tree 1 Tree2
Example (Example (ctdctd))
• Tree1:Rightmost derivation:
S aAB aA abBb abAb abbBbb abbbb⇒ ⇒ ⇒ ⇒ ⇒⇒⇒
• Tree2Leftmost derivation:
S aAB abBbB abbB abbA abbbBb abbbb
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
⇒⇒⇒⇒ ⇒ ⇒
AmbiguityAmbiguity
• Definition: A string w is ambiguous in a context-free grammar if there are at least two different leftmost (rightmost) derivations or two(rightmost) derivations or twodifferent derivation trees for that string in that grammar. A context-free grammar is ambiguous if it can generates at least one ambiguous string. Otherwise it is unambiguous.
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Inherently Ambiguous Inherently Ambiguous LanguagesLanguages
• Definition: A context-free language is (inherently) ambiguous if all context-free grammars generating it will be ambiguous.will be ambiguous.
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
ExamplesExamples
• The following context-free languages are inherently ambiguous:
• L = {aibjck | i=j or j=k where i,j,k ≥0}• L1 = {aibjck | i=j or j=k where i,j,k ≥0}
• L2 = {aibjckdm | i=j, k=m or i=m, j=k where i,j,k,m ≥1}
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Simplification of CFGSimplification of CFGLet G = (V, Σ, R, S) be a CFG. Suppose R contains a rule of the form
A → x1Bx2
Assume that A and B are different variables and that
B → y1 | y2 | … | yn
is the set of all rules in R which has B as the left side. Let G’ = (V,
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
is the set of all rules in R which has B as the left side. Let G’ = (V, Σ, R’, S) be the grammar in which R’ is constructed by deleting
A → x1Bx2 from R and adding to it
A → x1y1 x2 | x1y2 x2 | … | x1yn x2.
Then
L(G’) = L(G).
Example:Example:
Consider grammar
G: A → a | aaA | abBc,
B → abbA | b
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Using the substitution property, we get
G’: A → a | aaA | ababbAc | abbc,
B → abbA | b
The new grammar G’ is equivalent to G.
Useful VariableUseful Variable
Let G = (V, Σ, R, S) be a CFG. A variable A ∈V is said
to be useful if and only if there is at least one w ∈ L(G)
such that
S *
xAy *
w
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
S *
xAy *
w
with x, y ∈ (V U Σ)*. A variable that is not useful is
called useless. A rule is useless if it involves any useless
variable.
⇒ ⇒
Example:Example:
G: S → aS | A | C
A → a
B → aa
C → aCb
------------------------------------------
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
------------------------------------------
S → aS | A
A → a
B → aa
-------------------------------------------------
S → aS | A
A → a
S A B
Dependency Graph
TheoremTheorem
Let G = (V, Σ, R, S) be a CFG. Then there exists
an equivalent grammar G’ = (V’, Σ’, R’, S) that
does not contain any useless variable or rules.
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
εε rulesrules
Any rule of a context-free grammar of the form
A → ε
is called an ε rule. Any variable A for which the
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
is called an ε rule. Any variable A for which the
derivation
A *
ε
is called nullable.
⇒
Example:Example:G: S → ABaC
A → BC
B → b | ε
C → D | ε
D → d
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
D → d
A, B, C are nullable variables above. Then we have:
S → ABaC | BaC | AaC | ABa | aC | Aa | Ba | a
A → B | C | BC
B → b
C → D
D → d
Theorem:Theorem:
Let G be any context-free grammar with ε not in
L(G). Then there exists an equivalent grammar
G’ having no ε rules.
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Unit rulesUnit rules
Any rule of a context-free grammar of the form
A → B
where A,B ∈V is called a unit rule.
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Example:Example:G: S → Aa | B
B → A | bb
A → a | bc | B
S *
A, S *
B, B *
A, A *
B
------------------------
S → Aa
⇒
S A B
⇒ ⇒⇒
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
S → Aa
B → bb
A → a | bc
------------------------------
S → a | bc | bb | Aa
B → a | bb | bc
A → a | bb | bc
S A B
Dependency graph for unit rules
Theorem:Theorem:
Let G be any context-free grammar without any
ε rule. Then there exists a context-free grammar
G’ that does not have any unit rules and that is
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
equivalent to G.
Theorem:Theorem:
Let L be a context-free language that does not
contain ε. Then there exists a context-free
grammar that generates L and does not have
any useless rules, ε rules, or unit rules.
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
any useless rules, ε rules, or unit rules.
Solution:
• Remove ε rules
• Remove unit rules
• Remove useless rules.
CHOMSKY NORMAL FORMCHOMSKY NORMAL FORM
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
• Any context-free language is generated by a context-free grammar in Chomsky normal form.
ExampleExample
• Step 1: (make a new start variable)
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
• Step 2: Remove ε rules B→ε , shown on the left and A→ε , shown on the right
Example (cont.)Example (cont.)
• Step 3a: Remove unit rules S→S, shown on the left and S0→S, shown on the right
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
• Step 3b: Remove unit rules A→B and A→S
Example (cont.)Example (cont.)
• Step 4: convert the remaining rules into the proper form by adding variables and rules
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
CYK AlgorithmCYK Algorithm(J. Cooke, D.H. Younger, and T. (J. Cooke, D.H. Younger, and T. KasamiKasami))
• Let G = (V, Σ, R, S) be a context-free grammar (in
Chomsky normal form) and w a string of length n
w = a1 a2 …an.
The membership problem is the problem of finding if The membership problem is the problem of finding if
w L(G).
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
∈
CYK Algorithm (CYK Algorithm (ctdctd.).)
• Define
wij = ai … aj
and subsets of V*
We can show
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
*
{ : }ij ijV A V A w= ∈ ⇒
1,{ , 1,..., 1}
{ : , , }ij ik K jk i i j
V A A BC B V C V+
∈ + −
= → ∈ ∈∪
CYK Algorithm (CYK Algorithm (ctdctd.).)
• Then, the algorithm to compute the problem is as follows with the time complexity O(n3):
1. Compute V11, V22, …, Vnn1. Compute V11, V22, …, Vnn
2. Compute V12, V23, …, Vn-1,n
3. Compute V13, V24, …, Vn-2,n
and so on.
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
ExampleExample• Determine whether the string w = aabbb is in the
language generated by the grammar G below
S → AB
A → BB|a
B → AB|bB → AB|b
We have:
• V11 = V22 = {A}, V33 = V44 = V55 = {B},
• V12 = Ø, V23 = {S, B}, V34 = V45 = {A},
• V13 = = V35 = {S, B}, V24 = {A},
• V14 = {A}, V25 = {S, B},
• V15 = {S, B},
so that w L(G).اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
∈
PUSHDOWN AUTOMATAPUSHDOWN AUTOMATA
• Like nondeterministic finite automata, with an extra component: stack
• The stack provides additional
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
• The stack provides additional memory
• Pushdown automata are equivalent in power to context-free
PUSHDOWN AUTOMATAPUSHDOWN AUTOMATA
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
PUSHDOWN AUTOMATAPUSHDOWN AUTOMATA
• Push: Writing a symbol on the stack
• Pop: Removing a symbol
• Recognizes {0n1n|n≥0}
• As each 0 is read from the input, push it
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
• As each 0 is read from the input, push it onto the stack.
• Pop a 0 off the stack for each 1 read.
• Reading the input is finished exactly when the stack becomes empty→Accept
PUSHDOWN AUTOMATAPUSHDOWN AUTOMATA((formal definition)formal definition)
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Example Example 11
• L={0n1n|n≥0}
• Q={q1,q2,q3,q4}
• Σ={0,1}
• Γ={0,$}
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
• Γ={0,$}
• F={q1,q4}
• δ:
Example (cont.)Example (cont.)
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
ExampleExample22
• Give a pushdown automaton for the language:
{aibjck | i,j,k ≥ 0 and i = j or i = k}
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
ExampleExample33
• Give a pushdown automaton for the language:
{wwR | w {0, 1}*}∈
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Equivalence with contextEquivalence with context--free grammarsfree grammars
• A language is context free if and only if some pushdown automaton recognizes it.
• Proof Idea:
–Only if part : Let A be a CFL. Show how
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
–Only if part : Let A be a CFL. Show how to convert the A’s CFG, G into a PDF P that accepts all strings that G generates.
– If part : Let P be a PDA. Show how to convert P into a CFG G that generates all strings that P accepts.
Proof of Proof of ““only ifonly if”” partpart
• Any terminal symbols appearing before the first variable are matched with
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
matched with input.
ProofProof
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Proof (cont.)Proof (cont.)
• (r,u)∈δ(q,a,s) means that when q is the state of the automaton, a is the next input symbol, and s is on the top of the stack, push the string u onto the stack and go on to the state r.
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Proof (cont.)Proof (cont.)
• Q={qstart,qloop,qaccept} Ewhere E is the set of states needed for implementing the shorthand described before.
• Step 1: δ(qstart,ε,ε)={(qloop,S$)}
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
• Step 1: δ(qstart,ε,ε)={(qloop,S$)}
• Step 2:
– (a) δ(qloop,ε,A)={(qloop,w)|where A→w is a rule}
– (b) δ(qloop,a,a)={(qloop,ε)}
– (c) δ(qloop,ε,$)={(qaccept,ε)}
Proof (cont.)Proof (cont.)
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
ExampleExample
• Construct a PDA for the CFG grammar:
S → aTb | b
T → Ta | ε
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Proof of Proof of ““ifif”” partpart• First, we simplify our task by modifying P slightly to give it the
following three features.
– It has a single accept state, qaccept.
– It empties its stack before accepting.
– Each transition either pushes a symbol onto a stack (a push move)
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
– Each transition either pushes a symbol onto a stack (a push move)
or pops one off the stack (a pop move), but does not do both at the
same time.
• Next, for each pair of states p and q in P the grammar will have a
variable Apq. This variable generates all strings that can take P from p
with an empty stack to q with an empty stack. Observe that such
strings can also take P from p to q, regardless of the stack contents at
p, leaving the stack at q in the same condition as it was at p.
•
ProofProof
• Suppose P = (Q, Σ, Γ, δ, q0, {qaccept}). We can construct
CFG G. The variables of G are {Apq | p,q Q}. The
start variable is Aq0,qaccept. Now we describe G’s rules:
– For each p,q,r,s Q, t Γ, and a,b Σε, if δ(p, a, ε)
contains (r,t) and δ(s, b, t) contains (q, ε), put rule
∈
∈
∈ ∈
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
ε
contains (r,t) and δ(s, b, t) contains (q, ε), put rule
Apq→ aArsb in G.
– For each p,q,r Q, put rule Apq→Apr Arq in G.
– Finally, for each p Q, put the rule App→ ε in G.∈
∈
PDA computation corresponding to the rulePDA computation corresponding to the rule AApqpq→A→Aprpr AArqrq
PDA computation corresponding to the rule Apq→ aArsb
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
ClaimsClaims• Claim 1: If Apq generates x, then x can
bring P from p with empty stack to q with empty stack.
– The proof is done by induction on the number of steps in the derivation of x from Apq.of steps in the derivation of x from Apq.
• Claim 2: If x can bring P from p with empty stack to q with empty stack, Apq
generates x.
– The proof is done by induction on the number of steps in the computation of P that goes from p to q with empty stacks on input x.
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Relationship of the regular and contextRelationship of the regular and context--free languagesfree languages
• Every regular language is context-free.
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Deterministic PDAsDeterministic PDAsA pushdown automaton M = (Q, Σ, Γ, δ, q0, F) is said to be
deterministic if it has the following properties:
• ∀q Q, ∀A Γε, ∀a Σ, δ(q, ε, A) ≠ Φ → δ(q, a, A) = Φ
• ∀q Q, ∀A Γ, ∀a Σε, δ(q, a, ε) ≠ Φ → δ(q, a, A) = Φ
• ∀q Q, ∀A Γ , ∀a Σ, δ(q, ε, ε) ≠ Φ → δ(q, a, A) = Φ
∈ ∈
∈
∈
∈ ∈
∈ ∈
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
• ∀q Q, ∀A Γε, ∀a Σ, δ(q, ε, ε) ≠ Φ → δ(q, a, A) = Φ
• ∀q Q, ∀A Γε, ∀a Σε, |δ(q, a, A)| ≤ 1∈
∈ ∈
∈ ∈
∈
Deterministic ContextDeterministic Context--free free LanguagesLanguages
• Definition: A context-free language is said to be deterministic if it can be accepted by some deterministic pushdown automaton.pushdown automaton.
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Example Example 11
• L = {anbn : n≥0} is a deterministic language because it can be accepted by the following deterministic automaton:
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Example Example 2 2
• It can be shown that the language
L1 = {anbn : n≥0} U {anb2n : n≥0}
is nondeterministic. is nondeterministic.
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
NONNON--CONTEXTCONTEXT--FREE LANGUAGESFREE LANGUAGES
• Pumping Lemma for context-free languages:
– If A is a context-free language, then there is a number p (the pumping length) where, if s is any string in A of length at least p, then s may
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
any string in A of length at least p, then s may be divided into five pieces s=uvxyz satisfying the conditions:• For each i≥0, uvixyiz∈A• |vy|>0
• |vxy|≤p
ProofProof• Let G be a CFG for CFL A. Let b be the maximum number
of symbols in the right-hand side of a rule (assume at least 2).
• Then, if the height of the parse tree is at most h, the length of the string generated is at most bh. Conversely, if a generated string is at least bh+1 long, each of its parse a generated string is at least b +1 long, each of its parse tree must be at least h+1 high.
• Let |V| be the number of variables in G. Then, we set p to be b|V|+1. Now if s is a string in A and its length is p or more, any of its parse trees must be at least |V| +1 high, because b|V|+1≥ b|v|+1. We choose the smallest of such parse trees.
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Proof (cont.)Proof (cont.)
Surgery on parse trees
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Example Example 11
• B={anbncn|n≥0}
• Assume that B is a CFL and p is the pumping length.
• s=apbpcp: a member of B and of
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
• s=apbpcp: a member of B and of length at least p
• We show that it can not be pumped
Example Example 1 1 (cont.)(cont.)
• s=uvxyz
• Condition1
–v and y contain one type symbol→
uv2xy2z cannot contain equal number of a’s,
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
uv2xy2z cannot contain equal number of a’s, b’s and c’s.
– Either v or y contain more than one type of symbol→ uv2xy2z cannot contain a’s, b’s and c’s in the correct order.
Example Example 22
• Let D = {ww | w {0,1}*}
• Assume that D is a CFL and p is the pumping length.
• s= 0p10p1: a member of D and of length at • s= 0p10p1: a member of D and of length at least p; it will not work!
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
Example Example 2 2 (cont.)(cont.)
• Let us choose s = 0p1p0p1p
it will work!
• We show that it cannot be pumped
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
• We show that it cannot be pumped
• Note that
s=uvxyz = 0p1p0p1p
End of chapter End of chapter 2 2 ☺☺
اّول�����ل 91 � �� ��� � ز�ن ه� و ����� ه� دا�#"�! ص����
End of chapter End of chapter 2 2 ☺☺
top related