1. UNIT IV
PROPERTIES OF CONTEXT
FREE LANGUAGES
Mrs.D.Jena Catherine Bel,
Assistant Professor, CSE,
Velammal Engineering College
2. UNIT IV
PROPERTIES OF CONTEXT FREE
LANGUAGES
Normal Forms for CFG – Pumping Lemma for CFL – Closure Properties of
CFL – Turing Machines – Programming Techniques for TM.
3. CFG simplification
Simplification essentially comprises of the following steps −
• Removal of Null Productions
• Removal of Unit Productions
• Removal of Useless Symbols
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
3
4. Removal of unit production
Any production rule in the form A → B where A, B ∈ Non-
terminal is called unit production..
Removal Procedure −
• Step 1 − To remove A → B, add production A → x to the
grammar rule whenever B → x occurs in the grammar. [x ∈
Terminal, x can be Null]
• Step 2 − Delete A → B from the grammar.
• Step 3 − Repeat from step 1 until all unit productions are
removed.
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
4
8. Removal of null production
In a CFG, a non-terminal symbol ‘A’ is a nullable variable if there
is a production A → ε or there is a derivation that starts at A and
finally ends up with ε: A → .......… → ε
Removal Procedure
• Step 1 − Find out nullable non-terminal variables which derive
ε.
• Step 2 − For each production A → a, construct all productions
A → x where x is obtained from ‘a’ by removing one or
multiple non-terminals from Step 1.
• Step 3 − Combine the original productions with the result of
step 2 and remove ε - productions.
Mrs.D.Jena
Catherine
Bel,
AP/CSE,
VEC
8
35. What
• A Turing machine is a theoretical computing /
hypothetical machine invented by Alan Turing
35
36. Formal Definition
• A Turing Machine is a 7-tuple M = <Q, Γ, b, Σ, δ, q0,
F> where:
• Q is a finite, non-empty set of states
• Γ is a finite, non-empty set of the tape
alphabet/symbols
• b ∈ Γ is the blank symbol
• Σ ⊆ Γ - {b} is the set of input symbols
• q0 ∈ Q is the initial state
• F ⊆ Q is the set of final (accepting) states
• δ: Q × Γ → Q × Γ × D 36
37. Transition Function
• It tells us how the machine gets one step to the next.
δ(q, X)=(p,Y,D)
• When the machine is in a certain state q є Q and the
head is currently scanning X in the tape, then the
machine
1. replaces the symbol X by Y on the tape
2. goes to state p, and
3. the tape head moves one cell to the left or right
based on D.
37
39. Instantaneous description
• The ID of a TM capture what is going out at any moment i.e. it
contains all the information to exactly capture the "current
state of the computations".
• It contains the following:
• The content of the tape
• The location of the tape head
• The machine’s internal state
X1X2…………..Xi-1qXiXi+1……..Xn
39
42. Language of TM
Let the M = <Q, Γ, b, Σ, δ, q0, F> Then L(M) is the set of
strings w in ∑* such that
For some state p in F and any tape strings α and β
42
43. Examples
• Odd no of 0s
• 0n1n
• anbncn
• Addition
• Proper subtraction
43
44. Odd no of 0s
• Let M be the turing machine
• Let q1 be the initial state.
• If M is in q1; on scanning a, it enters the state q2 and
writes B (blank), move Right.
• If M is in q2; on scanning a, it enters the state q1 and
writes B (blank), move Right.
• If M is in q2 ; on scanning B, it enters the state q3 and writes B,
move Left and halt
44
45. Odd no of 0s
q1aaa
⊢ Bq2aa
⊢ BBq1a
⊢ BBBq2
⊢ BBq3B
45
56. 56
B B B B B B B B B
B
B 0 1 0 c 0 1 0 B
B * B B B B B B B
0
B 0 1 0 c 0 1 0 B
B * B B B * B B B
B
B 0 1 0 c 0 1 0 B
B * * B B * B B B
1
B 0 1 0 c 0 1 0 B
B * * B B * * B B
B
B 0 1 0 c 0 1 0 B
B * * * B * * B B
0
B 0 1 0 c 0 1 0 B
B * * * B * * * B
B
B 0 1 0 c 0 1 0 B