0% found this document useful (0 votes)
117 views27 pages

Theory of Computation

This CFG generates the language {0n1m2n | n,m ≥ 0}.

Uploaded by

Krishnav Kishor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views27 pages

Theory of Computation

This CFG generates the language {0n1m2n | n,m ≥ 0}.

Uploaded by

Krishnav Kishor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

CSE 105

THEORY OF COMPUTATION

Fall 2017

http://cseweb.ucsd.edu/classes/fa17/cse105-a/
Today's learning goals Sipser Ch 1.4, 2.1
• Apply the Pumping Lemma in proofs of nonregularity
• Identify some nonregular sets
• Define context-free grammars
• Test if a specific string can be generated by a given
context-free grammar
Pumping Lemma Sipser p. 78 Theorem 1.70

# states in DFA
recognizing A

Transition labels
along loop
Proof strategy
To prove that a language L is not regular

• Assume towards a contradiction that it is.


• Use Pumping Lemma to give p, a pumping length for L
• Show that p actually isn't a pumping length for L.
• 
• Conclude that L is not regular.
Another example
Claim: The set {anbman | m,n≥ 0} is not regular.

Proof: …Consider the string s = ……


You must pick s carefully: we want |s|≥p and s in L.
Now we will demonstrate that "s cannot be pumped", thereby contradicting the
assumption that p is a pumping length.
Which choices of s cannot be used to complete the proof?
A. s = apbp B. s = abpa C. s = apbpap D. s = apbap
E. None of the above (all of these choices work).
Another example
Claim: The set {anbman | m,n≥ 0} is not regular.

Proof: …Consider the string s = ……


You must pick s carefully: we want |s|≥p and s in L. Now we will
prove a contradiction with the statement "s can be pumped"
Consider an arbitrary choice of x,y,z such that s = xyz, |y|>0, |
xy|≤p. This means that...What properties are guaranteed about x,y,z?
Consider i=… In this case, xyiz = …, which is not in L, a
contradiction with the Pumping Lemma applying to L and so L
is not regular.
Regular sets: not the end of the story
• Many nice / simple / important sets are not regular
• Limitation of the finite-state automaton model
• Can't "count"
• Can only remember finitely far into the past
• Can't backtrack
• Must make decisions in "real-time"
• We know computers are more powerful than this model…

Which conditions should we relax?


The next model of computation
• Idea: allow some memory of unbounded size
• How?
• Generalization of regular expressions  Context-free grammars
• Generalization for DFA  Pushdown Automata
Birds' eye view
All languages over Σ

Context-free languages over Σ

Regular languages over Σ

Finite languages over Σ


Context-free grammar Sipser Def 2.2, page 102

(V, Σ, R, S)
Variables: finite set of (usually upper case) variables V

Terminals: finite set of alphabet symbols Σ

Rules/Productions: finite set of allowed transformations R

Start variable: origination of each derivation S


Context-free language Sipser p. 104

The language generated by a CFG (V, Σ, R, S) is

{ w in Σ* | Starting with the Start variable and applying one or more


rules, can derive w on RHS}

If G = (V, Σ, R, S) Notation:
the language
generated by G is Terminology: sequence of
denoted L(G). rule applications is
derivation
An example?
Consider the CFG
({S}, {0}, R, S)
where R is the following set of rules
S  0S
S0

Is this a well-formed definition?


A. No: there's more than one rule
B. No: the same LHS gets sent to two different strings.
C. No: one of the string in the RHS has both variables and literals
D. Yes.
E. I don't know.
Context-free language Sipser p. 104

For CFG G = (V, Σ, R, S), L(G) = { w in Σ* | Starting with the Start


variable and applying one or more rules, can derive w on RHS}.

What is the language of the CFG ({S}, {0}, R, S) with


R = {S  0S, S  0} ?

A. {0} B. {0, 0S} C. {0, 00, 000, …}


D. {ε, 0, 00, 000, …} E. I don't know.
Context-free language Sipser p. 104

What is the language of the CFG ({S}, {0,1}, R, S) with


R = the set of rules
S  0S
S  0S | 1S | ε
S  1S
Sε

A. L(0*1*) B. L(0* U 1*) C. L( (0 U 1) *)


D. L ( (0*1*) )* E. I don't know.
Designing a CFG
Can CFGs
Building a CFG to describe the language describe simple
sets?
{ abba }

V = { S, T, V, W }
Σ = { a,b }
R = { S  aT T  bV V  bW W  a }
S
Designing a CFG
Can CFGs
Building a CFG to describe the language describe simple
sets?
{ abba }

V= What's the set of terminals of this CFG?


Σ= A. {a,b}
B. V U S U Σ
R= C. {S, a, b}
D. {a,b, ε}
S= E. I don't know.
Designing a CFG
Can CFGs
Building a CFG to describe the language describe simple
sets?
{ abba }

( { S, T, V, W } , { a,b } , { S  aT , T  bV , V  bW , W  a }, S )

OR

( { S } , { a,b } , { S  abba } , S )
Is every regular language a CFL?
• Approach 1: start with an arbitrary DFA M, build a CFG
that generates L(M).

• Approach 2: build CFGs for {a}, {ε}, {}; then show that the
class of CFL is closed under the regular operations
(union, concatenation, Kleene star).
Approach 1
Claim: Given any DFA M, there is a CFG whose language is L(M).

Construction:
Trace computation using variables to denote state
Given M = (Q,Σ,δ,q0,F) a DFA, define the CFG
V = { Si | qi is in Q }
Σ
R = { Si  aSj | δ(qi,a) = qj } U { Si  ε | qi is in F}
S = S0 Then prove correctness…
Approach 2
If G1 = (V1, Σ, R1, S1) and G2 = (V2, Σ, R2, S2) are CFGs
and G1 describes L1, G2 describes L2, how can we combine
the grammars so we describe L1 U L2 ?

A. G = (V1 U V2, Σ, R1 U R2, S1 U S2)


B. G = (V1 x V2, Σ, R1 x R2, (S1, S2) )
C. We might not always be able to: the class of CFG
describable languages might not be closed under union.
D. I don't know.
Approach 2
If G1 = (V1, Σ, R1, S1) and G2 = (V2, Σ, R2, S2) are CFGs
and G1 describes L1, G2 describes L2, how can we combine
the grammars so we describe L1 U L2 ?
Designing a CFG
We know this
Building a CFG to describe the language set is not
regular!
{ anbn | n ≥ 0 }
Designing a CFG
Building a CFG to describe the language
{ anbn | n ≥ 0 }

One approach:
- what is shortest string in the language?
- how do we go from shorter strings to longer ones?
Designing a CFG
Building a CFG to describe the language
{ anbn | n ≥ 0 }

V={S} Which rules would complete this CFG?


Σ = { a,b }
A. S  ε | ab
R= B. S  ε | aS | Sb
C. S  ε | aSb
S D. We need another variable other than S.
E. I don't know.
Designing a CFG
Also not a
Building a CFG to describe the language regular set
{ 0n1m2n | n,m ≥ 0 }

Hint: work from the outside in.


Designing a CFG
Also not a
Building a CFG to describe the language regular set
{ 0n1m2n | n,m ≥ 0 }

Hint: work from the outside in.


V = { S, T }
Σ = { 0,1,2 }
R = { S  0S2 | T | ε , T  1T | ε }
S

You might also like