2. Syllabus
● Normal Forms for Context- Free Grammars: Eliminating
useless symbols, Eliminating €-Productions. Chomsky Normal
form Griebech Normal form.
● Pumping Lemma for Context-Free Languages: Statement of
pumping lemma, Applications
● Closure Properties of Context-Free Languages: Closure
properties of CFL’s, Decision Properties of CFL's
● Turing Machines: Introduction to Turing Machine, Formal
Description, Instantaneous description, The language of a
Turing machine
3. Normal Forms for Context- Free
Grammars:
● The goal is to show that every CFL (without ε) is generated by a
CFG in which all productions are of the form A ! BC or A
! a, where A, B, C are variables, and a is a terminal.
● A number of simplifications is inevitable:
i. The elimination of useless symbols.
ii. The elimination of ε or null productions.
iii. The elimination of unit productions
4.
5. The elimination of useless symbols
● The elimination of useless symbols, “variables & terminals
that do not appear in any derivation of a terminal string from
the start symbol”.
● Condition of Useless Symbol :
i)We will entitle any variable useful only when it is deriving
any terminal.
Ii) If a symbol is deriving a terminal but not reachable from
Start state.
● Example:
6. ● Notice that a and b generate themselves “terminals”, S
generates a, and A generates b. B is not generating.
● After eliminating B:
● Notice that only S and a are reachable after eliminating the
non-generating B.
● A is not reachable; so it should be eliminated.
● The result :
7. The elimination of ε-productions
● The elimination of ε-productions, those of the form A ! ε
for some variable A.
● Example:
8.
9. The elimination of unit productions
● The elimination of unit productions, those of the form A ! B
for variables A and B.
● We will apply below steps to remove Unit production:
● Write production without Unit production
● Check what we are missing because of Step 1
10. Example:
1:
S -> Aa/B/c
B -> A/bb
A -> a/bc/B
Sol:
S -> Aa/c/bb/a/bc
A -> a/bc/bb
2:
S -> AC
A -> a
C -> B/d
B -> D
D -> E
E -> b
Sol:
S -> AC
A -> a
C -> d/b
12. CNF for CFG
● We have to check following form on a Context free
grammar.
All the productions should be of the form mentioned below:
● A -> BC or A -> a
NON Terminal--> NT. NT
or
NT--> T
13.
Advantage of CNF
● Length of each production is restricted
● Derivation tree or parse tree obtained from CNF is
always binary tree
● Number of steps required to derive string of length |
w| = (2|w| -1)
● It is easy to apply CYK algorithm
14. Convert given grammar into CNF
Example Solution
S -> bA/aB
A -> bAA/aS/a
B->aBB/bS/b
S->ASB|epsilon
A->aAS|a
B->SbS|A|bb
15. Greibach Normal Form
A CFG is in Greibach Normal Form if the Productions are in
the following forms −
A → b
A → bD1…Dn
S → ε
21. PUMPING LEMMA
● Pumping Lemma, here also, is used as a tool to prove that
a language is not CFL.
● f L is a CFL, there exists an integer n, such that for all x ∈ L
with |x| ≥ n, there exists u, v, w, x, y ∈ Σ∗, such that x =
uvwxy, and
I. |vx| ≥ 1
II. |vwx| ≤ n
III. for all i ≥ 0: uvi
wxi
y ∈ L
Problem or application: Find out whether the language L
= {xnynzn | n ≥ 1} is context free or not.
25. Union
● Union : If L1 and If L2 are two context free languages, their
union L1 ∪ L2 will also be context free. For example,
L1 = { anbncm | m >= 0 and n >= 0 } and L2 = { anbmcm | n
>= 0 and m >= 0 }
L3 = L1 ∪ L2 = { anbncm ∪ anbmcm | n >= 0, m >= 0 } is also
context free.
L1 says number of a’s should be equal to number of b’s and
L2 says number of b’s should be equal to number of c’s.
Their union says either of two conditions to be true. So it is
also context free language.
● Note: So CFL are closed under Union.
26. Concatenation
● Concatenation : If L1 and If L2 are two context free languages,
their concatenation L1.L2 will also be context free. For
example,
L1 = { anbn | n >= 0 } and L2 = { cmdm | m >= 0 }
L3 = L1.L2 = { anbncmdm | m >= 0 and n >= 0} is also context
free.
L1 says number of a’s should be equal to number of b’s and L2
says number of c’s should be equal to number of d’s. Their
concatenation says first number of a’s should be equal to
number of b’s, then number of c’s should be equal to number of
d’s. So, we can create a PDA which will first push for a’s, pop
for b’s, push for c’s then pop for d’s. So it can be accepted by
pushdown automata, hence context free.
● Note: So CFL are closed under Concatenation.
27. Kleene Closure
● Kleene Closure : If L1 is context free, its Kleene
closure L1* will also be context free. For example,
L1 = { anbn | n >= 0 }
L1* = { anbn | n >= 0 }* is also context free.
● Note :So CFL are closed under Kleen Closure.
28. Intersection
● Intersection : If L1 and If L2 are two context free
languages, their intersection L1 ∩ L2 need not be context
free. For example,
L1 = { anbncm | n >= 0 and m >= 0 } and L2 = (ambncn | n >=
0 and m >= 0 }
L3 = L1 ∩ L2 = { anbncn | n >= 0 } need not be context free.
L1 says number of a’s should be equal to number of b’s and
L2 says number of b’s should be equal to number of c’s.
Their intersection says both conditions need to be true, but
push down automata can compare only two. So it cannot be
accepted by pushdown automata, hence not context free.
● Note : So CFL are not closed under Intersection
29. Complementation
● Complementation : Similarly, complementation of
context free language L1 which is ∑* – L1, need not
be context free.
● Note :So CFL are not closed under Complementation
30. Decision Properties
● Emptiness
➢ Remove useless symbols and productions
➢ If S is useless, then L(G) is empty.
● Membership
➢ Unlike FAs, we can’t just run the string through the machine and see where
it goes since PDAs are non-deterministic.
➢ Must consider all possible paths
● Finiteness
➢ Just as with RLs, a language is infinite if there is a string x with length
between n and 2n
➢ With RLs n = number of states in an FA
➢ With CFLs n = 2p+1 where p is the number of variables in the CFG
➢ Systematically generate all strings with lengths between n and 2n
➢ Run through membership algorithm
➢ If one passes, L is infinite, if all fail, L is finite s
32. Turing Machine
● A Turing Machine is an accepting device which accepts the
languages (recursively enumerable set) generated by type 0
grammars. It was invented in 1936 by Alan Turing.
● Comparison with the previous automaton
Machine Stack Data
Structure
Deterministic?
Finite Automaton N.A Yes
Pushdown
Automaton
Last In First
Out(LIFO)
No
Turing Machine Infinite tape Yes
33. Definition
● A Turing Machine (TM) is a mathematical model which consists of an infinite
length tape divided into cells on which input is given. It consists of a head
which reads the input tape. A state register stores the state of the Turing
machine. After reading an input symbol, it is replaced with another symbol,
its internal state is changed, and it moves from one cell to the right or left. If
the TM reaches the final state, the input string is accepted, otherwise rejected.
● A TM can be formally described as a 7-tuple (Q, X, ∑, δ, q0, B, F) where −
● Q is a finite set of states
● X is the tape alphabet
● ∑ is the input alphabet
● δ is a transition function; δ : Q × X → Q × X × {Left shift, Right shift}.
● q0 is the initial state
● B / is the blank symbol
● F is the set of final states
40. ● A Turing machine is somewhat similar to a finite
automaton, but there are important differences
1. A Turing machine can both write on the tape and read
from it.
2. The read-write head can move both to the left and to
the right.
3. The tape is infinite.
4. The special states for rejecting and accepting take
immediate effect.
41. Example
Turing machine M = (Q, X, ∑, δ, q0, B, F) with
Q = {q0, q1, q2, qf}
X = {a, b}
∑ = {1}
q0 = {q0}
B = blank symbol
F = {qf }
δ is given by − table
● Here the transition 1Rq1 implies that the write symbol is 1, the tape moves
right, and the next state is q1. Similarly, the transition 1Lq2 implies that the
write symbol is 1, the tape moves left, and the next state is q2.
Tape
alphabet
symbol
Present State
‘q0’
Present State
‘q1’
Present State
‘q2’
a 1Rq1 1Lq0 1Lqf
b 1Lq2 1Rq1 1Rqf
42. Types of TM
● Turing machines with two-dimensional tapes – They have one read-write
head, one finite control and one two-dimensional tape.
● Turing machines with multiple tapes – They have one finite control and
over one tape with a read-write head for each tape.
● Turing machines with multiple heads – They have one finite control, one
tape, and over one read-write head.
● Turing machines with infinite tape – They have one finite control and one
tape extending in both directions infinitely.
● Nondeterministic Turing machines – They have the ability to perform any
action from a given set of actions rather than performing a definite
predetermined action.