Unit-4 Toc
Unit-4 Toc
ONLINE CLASS
UNIT-4
PROPERTIES OF CONTEXT FREE LANGUAGES
PRESENTED BY
Mr. K. SANKAR GANESH
AP&HOD/CSE
In a CFG, it may happen that all the production rules and symbols
are not needed for the derivation of strings. Besides, there may be
some null productions and unit productions. Elimination of these
productions and symbols is called simplification of CFGs.
Solution
T = { a, c, e }
W1 = { A, C, E } from rules A → a, C → c and E → aA
W2 = { A, C, E } U { S } from rule S → AC
W3 = { A, C, E, S } U ∅
G’ = { { A, C, E, S }, { a, c, e }, P, {S}}
where P: S → AC, A → a, C → c , E → aA | e
Removal of Unit Productions
Removal Procedure −
Step 3 − Repeat from step 1 until all unit productions are removed.
Removal of Null Productions
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.
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.
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, ∑, δ, q 0, 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
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.
2. The finite control and the tape head which is responsible for reading the current
input symbol. The tape head can move to left to right.
4. Finite set of symbols called external symbols which are used in building the
logic of turing machine.
Instantaneous Description
Instantaneous description is a snapshot of Turing machine at runtime, which is
α1qα2, where α1, α2 ∈ Γ ∗ , q ∈ Q.
String α1 is the tape content to the left of the head, q is the state, α2 is the tape
content to the right of the head (the tape head is on the first symbol of α2).
• Multi-tape Turing Machines have multiple tapes where each tape is accessed
with a separate head.
• Each head can move independently of the other heads. Initially the input is on
tape 1 and others are blank.
• At first, the first tape is occupied by the input and the other tapes are kept blank.
• Next, the machine reads consecutive symbols under its heads and the TM prints a
symbol on each tape and moves its heads.
A Multi-tape Turing machine can be formally described as a 6-tuple (Q, X, B, δ, q 0,
F) where −
•Q is a finite set of states
•X is the tape alphabet
•B is the blank symbol
•δ is a relation on states and symbols where
•δ: Q × Xk → Q × (X × {Left_shift, Right_shift, No_shift })k
•where there is k number of tapes
•q0 is the initial state
•F is the set of final states
Note − Every Multi-tape Turing machine has an equivalent single-tape Turing
machine.
Multi-track Turing machines, a specific type of Multi-tape Turing machine, contain
multiple tracks but just one tape head reads and writes on all tracks. Here, a single
tape head reads n symbols from n tracks at one step. It accepts recursively
enumerable languages like a normal single-track single-tape Turing Machine
accepts.
A Multi-track Turing machine can be formally described as a 6-tuple (Q, X, ∑, δ, q 0,
F) where −
•Q is a finite set of states
•X is the tape alphabet
•∑ is the input alphabet
•δ is a relation on states and symbols where
•δ(Qi, [a1, a2, a3,....]) = (Qj, [b1, b2, b3,....], Left_shift or Right_shift)
•q0 is the initial state
•F is the set of final states
Note − For every single-track Turing Machine S, there is an equivalent multi-track
Turing Machine M such that L(S) = L(M).
Construct a turing machine which accepts the language of aba over ∑ = {a, b}.
Construct TM for the language L ={0n1n} where n>=1.
The simple logic which we will apply is read out each '0' mark it by A and then move
ahead along with the input tape and find out 1 convert it to B. Now, repeat this
process for all a's and b's.
Now we will see how this turing machine work for 0011.
Construct a TM for the language L = {0n1n2n} where n≥1
Solution:
L = {0n1n2n | n≥1} represents language where we use only 3 character, i.e., 0, 1 and 2.
In this, some number of 0's followed by an equal number of 1's and then followed by an equal number
of 2’s.
Any type of string which falls in this category will be accepted by this language.
CFL Closure Property
Example
Let L = { anbn , n ≥ 0}.
Corresponding grammar G will have P: S → aAb| ε