0% found this document useful (0 votes)
5 views38 pages

Unit-4 Toc

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
5 views38 pages

Unit-4 Toc

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 38

CS8501 THEORY OF COMPUTATION

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.

Simplification essentially comprises of the following steps −


• Removal of useless symbol
• Removal of Unit Productions
• Removal of Null Productions
Removal of useless symbol

In this tutorial we define those symbols that do not participate in


derivation of any string, i.e. the useless symbols, and remove the
useless productions from the grammar.
A symbol X is useful if:
1.If X is generating, i.e., X =>* w, where w ϵ L(G) and w in Vt*, this
means that the string leads to a string of terminal symbols.

2.If X is reachable If there is a derivation S =>* αXβ =>* w, w ϵ L(G),


for same α and β, then X is said to be reachable.
P: S → AC | B, A → a, C → c | BC, E → aA | e

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 ∅

Since W2 = W3, we can derive G’ as −

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

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.
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.

3. A finite set of states through which machine has to undergo.

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

Context-free languages are closed under −


•Union
•Concatenation
•Kleene Star operation
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.`
Kleene Star
If L is a context free language, then L* is also context free.

Example
Let L = { anbn , n ≥ 0}.
Corresponding grammar G will have P: S → aAb| ε

Kleene Star L1 = { anbn }*

The corresponding grammar G1 will have additional productions S1 → SS1 | ε


Context-free languages are not closed under −

•Intersection − If L1 and L2 are context free languages, then L1 ∩ L2


is not necessarily context free.

•Intersection with Regular Language − If L1 is a regular language


and L2 is a context free language, then L1 ∩ L2 is a context free
language.

•Complement − If L1 is a context free language, then L1’ may not be


context free.

You might also like