SlideShare a Scribd company logo
1 of 50
Download to read offline
Theory of Computation
By Rushabh Wadkar
Topics to be covered
Simplification of Grammar
Normal Forms
Session wind up
Day 7
The Simplification of Grammars
● Method 1: Remove Useless Productions.
● Method 2: Removing λ-Productions.
● Method 3: Removing Unit Productions.
We additionally have the substituting method that we will discuss first
There exists a probability to consider unnecessary variables
when deriving a grammar.
The Simplification of Grammars
Useful Substitution Method.
● Many rules govern generating equivalent grammars by means of
substitutions. Here we give one that is very useful for
simplifying grammars in various ways. What is meant by it is the
removal of certain types of undesirable productions.
● The process does not necessarily result in an actual reduction
of the number of rules.
The Simplification of Grammars
Useful Substitution Method.
● Let G = (V, T, S, P) be a context-free grammar. Suppose that
P contains a production of the form A → x1
Bx2
● Assume that A and B are different variables and that
B → y1
|y2
|...|yn
is the set of all productions in P;
that have B as the left side.
The Simplification of Grammars
Useful Substitution Method.
● Let G’= (V, T, S,P’ ) be the grammar in which is constructed by
deleting A → x1
Bx2
from P.
● And adding to it A → x1
y1
x2
| x1
y1
x2
|...| x1
yn
x2
● Hence L(G’) = L(G)
The Simplification of Grammars
Useful Substitution Method.
Consider G = ({A, B}, {a,b,c}, A, P) with productions
Using the suggested substitution for the variable B, we get the
grammar G’ with productions
The new grammar is equivalent to G.
The Simplification of Grammars
Method 1: Remove Useless Productions.
● One invariably wants to remove productions from a grammar that can
never take part in any derivation. For example, in the grammar whose
entire production set is
● The production S → A clearly plays no role, as A cannot be transformed
into a terminal string. While A can occur in a string derived from S, this
can never lead to a sentence. Removing this production leaves the
language unaffected and is a simplification by any definition.
The Simplification of Grammars
Method 1: Remove Useless Productions.
● Let G = (V, T, S, P) be a context-free grammar. A variable A ∈ V is said to
be useful if and only if there is at least one ω ∈ L (G) such that
with x, y in (VUT)* . In other words, a variable is useful if and only if it
occurs in at least one derivation. A variable that is not useful is called
useless. A production is useless if it involves any useless variable.
The Simplification of Grammars
Method 1: Remove Useless Productions.
● A variable may be useless because there is no way of getting a terminal string from
it. The case just mentioned is of this kind. Another reason a variable may be useless
is shown in the next grammar. In a grammar with start symbol S and productions
the variable B is useless and so is the production B → bA. Although B can derive a
terminal string, there is no way we can achieve
This example illustrates the two
reasons why a variable is useless:
The Simplification of Grammars
Method 1: Remove Useless Productions.
Q. Eliminate useless symbols and productions from G = (V,T,S,P), where V =
{S, A, B, C} and T = {a,b}, with P consisting of
The Simplification of Grammars
Method 1: Remove Useless Productions.
First, we identify the set of variables that can lead to a terminal string. Because A → a and B →aa,
the variables A and B belong to this set. So does S, because S ⇒ A ⇒ a. However, this argument
cannot be made for C, thus identifying it as useless. Removing C and its corresponding
productions, we are led to the grammar G1 with variables V1 = {S, A, B}, terminals T = {a}, and
productions
The Simplification of Grammars
Method 1: Remove Useless Productions.
Next we want to eliminate the variables that cannot be reached from the start variable. For
this, we can draw a dependency graph for the variables. Dependency graphs are a way of
visualizing complex relationships and are found in many applications. For context-free
grammars, a dependency graph has its vertices labeled with variables, with an edge
between vertices C and D if and only if there is a production of the form
The Simplification of Grammars
Method 1: Remove Useless Productions.
A variable is useful only if there is a path from the vertex labeled S to the vertex labeled with
that variable. In our case, B is useless. Removing it and the affected productions and
terminals, we are led to the final answer
And with the production
The Simplification of Grammars
Method 2: Removing λ-Productions
One kind of production that is sometimes undesirable is one in which the right side is the
empty string.
Any production of a context-free grammar of the form A → λ
is called a λ-production. Any variable A for which the derivation
is possible is called nullable.
The Simplification of Grammars
Method 2: Removing λ-Productions
One kind of production that is sometimes undesirable is one in which the right side is the
empty string.
Any production of a context-free grammar of the form A → λ
is called a λ-production. Any variable A for which the derivation
is possible is called nullable.
A grammar may generate a language not containing λ, yet have some λ-productions or
nullable variables. In such cases, the λ-productions can be removed.
The Simplification of Grammars
Method 2: Removing λ-Productions
The Simplification of Grammars
Method 3: Removing Unit Productions
As we have seen productions in which both sides are a single variable are at times
undesirable.
Any production of a context-free grammar of the form A → B,
where A, B ∈ V, is called a unit-production.
The Simplification of Grammars
Method 3: Removing Unit Productions
The Simplification of Grammars
Method 3: Removing Unit Productions
The Simplification of Grammars
Method 3: Removing Unit Productions
The Simplification of Grammars
Method 3: Removing Unit Productions
The Simplification of Grammars
Method 3: Removing Unit Productions
Normal Forms
● Chomsky Normal Form (CNF)
● Greibach Normal Form (GNF)
There are many kinds of normal forms we can establish for context-free
grammars. Some of these, because of their wide usefulness, have been
studied extensively. We consider two of them briefly.
Chomsky Normal Form
A context-free grammar is in Chomsky normal form if all productions
are of the form
A → BC
Or
A → a,
where A, B, C are in V, and a is in T.
Chomsky Normal Form
Examples:
Grammar in CNF Grammar in not CNF
Chomsky Normal Form
The following steps are followed to standardize the grammar using CNF:
● Rule-01: Reduce the grammar completely by:
1.Eliminating ∈ productions
2.Eliminating unit productions
3.Eliminating useless productions
● Rule-02: Replace each production of the form A → B1
B2
B3
….Bn
where n > 2 with A →
B1
C where C → B2
B3
….Bn
. Repeat this step for all the productions having more than
two variables on RHS.
● Rule-03: Replace each production of the form A → aB with A → XB and X → a.
Repeat this step for all the productions having the form A → aB.
Chomsky Normal Form
Q1. Convert the grammar with productions
to Chomsky normal form.
Chomsky Normal Form
Step 1: Eliminate all null and unit productions
No null or unit productions
Step 2: Check for productions already in CNF
There are no productions that are already in CNF.
Step 3: Put Ba, Bb, Bc for a, b, c
Chomsky Normal Form
Step 4: we introduce additional
variables to get the first two
productions into normal form
Chomsky Normal Form
Q2. Convert the given grammar to CNF:
S → aAD
A → aB / bAB
B → b
D → d
Chomsky Normal Form
Step-01:
The given grammar is already completely reduced.
Step-02:
The productions already in chomsky normal form are-
B → b
D → d
These productions will remain as they are.
Chomsky Normal Form
The productions not in chomsky normal form are-
S → aAD
A → aB / bAB
We will convert these productions in chomsky normal
form.
Chomsky Normal Form
Step-03:
Replace the terminal symbols a and b by new variables Ca
and Cb
.
This is done by introducing the following two new productions in the
grammar:
Ca
→ a
Cb
→ b
Now, the productions above modify to:
S → Ca
AD
A → Ca
B / Cb
AB
Chomsky Normal Form
Replace AD and AB by new variables CAD
and CAB
respectively.
This is done by introducing the following two new productions in the
grammar-
CAD
→ AD
CAB
→ AB
Now, the production modifies to-
S → Ca
CAD
A → Ca
B / Cb
CAB
Chomsky Normal Form
Step-04: The resultant grammar is-
S → Ca
CAD
A → Ca
B / Cb
CAB
B → b
D → d
Ca
→ a
Cb
→ b
CAD
→ AD
CAB
→ AB
This grammar is in
chomsky normal form.
Greibach Normal Form
A context-free grammar is said to be in Greibach normal form if all
productions have the form
A → aX,
where a ∈ T and X ∈ V*
Greibach Normal Form
Examples:
Grammar in GNF Grammar in not CNF
Greibach Normal Form
The following steps are followed to standardize the grammar using GNF:
Step 1. Convert the grammar into CNF.
If the given grammar is not in CNF, convert it to CNF.
Step 2. Eliminate left recursion from grammar if it exists.
If CFG contains left recursion, eliminate them.
Step 3. Convert the production rules into GNF form.
If any production rule is not in the GNF form, convert them.
Greibach Normal Form
Q1. Convert the following grammar to GNF
S → XY | Xn | p
X → mX | m
Y → Xn | o
Greibach Normal Form
Here, S does not appear on the right side of any production and there are no unit
or null productions in the production rule set. So, we can skip Step 1 to Step 3.
Step 4:
Now after replacing X in S → XY | Xo | p
With mX | m we obtain
S → mXY | mY | mXo | mo | p.
And after replacing X in Y → Xn | o
with the right side of X → mX | m
we obtain
Y → mXn | mn | o.
Two new productions O → o and P → p
are added to the production set and then
we came to the final GNF as:
S → mXY | mY | mXC | mC | p
X → mX | m
Y → mXD | mD | o
O → o
P → p
Greibach Normal Form
Q2. Consider the given grammar G1:
S → XA|BB
B → b|SB
X → b
A → a
As G1 is already in CNF and there is no left recursion, we can skip step 1 and 2
and directly move to step 3.
Greibach Normal Form
The production rule B->SB is not in GNF, therefore, we substitute S -> XA|BB in
production rule B->SB as:
S → XA|BB
B → b|XAB|BBB
X → b
A → a
Greibach Normal Form
The production rules S->XA and B->XAB is not in GNF, therefore, we substitute
X->b in production rules S->XA and B->XAB as:
S → bA|BB
B → b|bAB|BBB
X → b
A → a
Greibach Normal Form
Removing left recursion (B->BBB),
we get:
S → bA|BB
B → bC|bABC
C → BBC| ε
X → b
A → a
Removing null production (C-> ε),
we get:
S → bA|BB
B → bC|bABC|b|bAB
C → BBC|BB
X → b
A → a
Greibach Normal Form
The production rules S->BB is
not in GNF, therefore, we
substitute B → bC|bABC|b|bAB
in production rules S->BB as:
S → bA|
bCB|bABCB|bB|bABB
B → bC|bABC|b|bAB
C → BBC|BB
X → b
A → a
The production rules C->BB is
not in GNF, therefore, we
substitute B → bC|bABC|b|bAB
in production rules C->BB as:
S → bA|
bCB|bABCB|bB|bABB
B → bC|bABC|b|bAB
C → BBC
C →
bCB|bABCB|bB|bABB
X → b
A → a
The production rules C->BBC
is not in GNF, therefore, we
substitute B → bC|bABC|b|bAB
in production rules C->BBC as:
S → bA|
bCB|bABCB|bB|bABB
B → bC|bABC|b|bAB
C →
bCBC|bABCBC|bBC|bABBC
C → bCB|bABCB|bB|bABB
X → b
A → a
This is in GNF
End of Day 7
www.linkedin.com/in/wadkar-rushabh
@RushabhWadkar
Thank you...
The Simplification of Grammars
Theory of Computation FSM Grammar Minimisation and Normal Forms
Theory of Computation FSM Grammar Minimisation and Normal Forms

More Related Content

What's hot

1.3.1 deterministic finite automaton
1.3.1 deterministic finite automaton1.3.1 deterministic finite automaton
1.3.1 deterministic finite automatonSampath Kumar S
 
Functions intro
Functions introFunctions intro
Functions introRon Eick
 
1.3.2 non deterministic finite automaton
1.3.2 non deterministic finite automaton1.3.2 non deterministic finite automaton
1.3.2 non deterministic finite automatonSampath Kumar S
 
1.4. finite automaton with ε moves
1.4. finite automaton with ε   moves1.4. finite automaton with ε   moves
1.4. finite automaton with ε movesSampath Kumar S
 
1.9. minimization of dfa
1.9. minimization of dfa1.9. minimization of dfa
1.9. minimization of dfaSampath Kumar S
 
Nondeterministic Finite Automat
Nondeterministic Finite AutomatNondeterministic Finite Automat
Nondeterministic Finite AutomatAdel Al-Ofairi
 
Normal forms cfg
Normal forms   cfgNormal forms   cfg
Normal forms cfgRajendran
 
Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFAkunj desai
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler designRiazul Islam
 
1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfaSampath Kumar S
 
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)Mohammad Ilyas Malik
 
Python tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online TrainingPython tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online TrainingRahul Tandale
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite AutomataRatnakar Mikkili
 
Simplifiaction of grammar
Simplifiaction of grammarSimplifiaction of grammar
Simplifiaction of grammarlavishka_anuj
 

What's hot (20)

optimization of DFA
optimization of DFAoptimization of DFA
optimization of DFA
 
1.3.1 deterministic finite automaton
1.3.1 deterministic finite automaton1.3.1 deterministic finite automaton
1.3.1 deterministic finite automaton
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
 
Automata
AutomataAutomata
Automata
 
Functions intro
Functions introFunctions intro
Functions intro
 
1.3.2 non deterministic finite automaton
1.3.2 non deterministic finite automaton1.3.2 non deterministic finite automaton
1.3.2 non deterministic finite automaton
 
1.4. finite automaton with ε moves
1.4. finite automaton with ε   moves1.4. finite automaton with ε   moves
1.4. finite automaton with ε moves
 
1.9. minimization of dfa
1.9. minimization of dfa1.9. minimization of dfa
1.9. minimization of dfa
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
Nondeterministic Finite Automat
Nondeterministic Finite AutomatNondeterministic Finite Automat
Nondeterministic Finite Automat
 
Normal forms cfg
Normal forms   cfgNormal forms   cfg
Normal forms cfg
 
Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFA
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler design
 
Theory of Computation Unit 4
Theory of Computation Unit 4Theory of Computation Unit 4
Theory of Computation Unit 4
 
finite automata
 finite automata finite automata
finite automata
 
1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa
 
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
 
Python tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online TrainingPython tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online Training
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
 
Simplifiaction of grammar
Simplifiaction of grammarSimplifiaction of grammar
Simplifiaction of grammar
 

Similar to Theory of Computation FSM Grammar Minimisation and Normal Forms

Theory of competition topic simplification of cfg, normal form of FG.pptx
Theory of competition topic simplification of cfg, normal form of FG.pptxTheory of competition topic simplification of cfg, normal form of FG.pptx
Theory of competition topic simplification of cfg, normal form of FG.pptxJisock
 
Context Free Languages by S.Mandal-1.ppt
Context Free Languages by S.Mandal-1.pptContext Free Languages by S.Mandal-1.ppt
Context Free Languages by S.Mandal-1.ppt1sonalishipu
 
Natural Language Processing - Writing Grammar
Natural Language Processing - Writing GrammarNatural Language Processing - Writing Grammar
Natural Language Processing - Writing GrammarJasmine Peniel
 
2,Combinational Logic Circuits.pdf
2,Combinational Logic Circuits.pdf2,Combinational Logic Circuits.pdf
2,Combinational Logic Circuits.pdfDamotTesfaye
 
Formal Languages and Automata Theory unit 4
Formal Languages and Automata Theory unit 4Formal Languages and Automata Theory unit 4
Formal Languages and Automata Theory unit 4Srimatre K
 
Lecture 05 syntax analysis 2
Lecture 05 syntax analysis 2Lecture 05 syntax analysis 2
Lecture 05 syntax analysis 2Iffat Anjum
 
Chapter 3.Simplex Method hand out last.pdf
Chapter 3.Simplex Method hand out last.pdfChapter 3.Simplex Method hand out last.pdf
Chapter 3.Simplex Method hand out last.pdfTsegay Berhe
 
Context Free Grammar
Context Free GrammarContext Free Grammar
Context Free GrammarniveditJain
 
Syntactic analysis in NLP
Syntactic analysis in NLPSyntactic analysis in NLP
Syntactic analysis in NLPkartikaVashisht
 
Normal Forms for CFG's.pdf
Normal Forms for CFG's.pdfNormal Forms for CFG's.pdf
Normal Forms for CFG's.pdfAmanda Reznor
 
An Introduction to the Finite Element Method
An Introduction to the Finite Element MethodAn Introduction to the Finite Element Method
An Introduction to the Finite Element MethodMohammad Tawfik
 

Similar to Theory of Computation FSM Grammar Minimisation and Normal Forms (20)

Theory of competition topic simplification of cfg, normal form of FG.pptx
Theory of competition topic simplification of cfg, normal form of FG.pptxTheory of competition topic simplification of cfg, normal form of FG.pptx
Theory of competition topic simplification of cfg, normal form of FG.pptx
 
Context free grammar
Context free grammar Context free grammar
Context free grammar
 
Context Free Languages by S.Mandal-1.ppt
Context Free Languages by S.Mandal-1.pptContext Free Languages by S.Mandal-1.ppt
Context Free Languages by S.Mandal-1.ppt
 
Natural Language Processing - Writing Grammar
Natural Language Processing - Writing GrammarNatural Language Processing - Writing Grammar
Natural Language Processing - Writing Grammar
 
2,Combinational Logic Circuits.pdf
2,Combinational Logic Circuits.pdf2,Combinational Logic Circuits.pdf
2,Combinational Logic Circuits.pdf
 
Unit iii
Unit iiiUnit iii
Unit iii
 
Formal Languages and Automata Theory unit 4
Formal Languages and Automata Theory unit 4Formal Languages and Automata Theory unit 4
Formal Languages and Automata Theory unit 4
 
CFG to CNF
CFG to CNFCFG to CNF
CFG to CNF
 
Lp (2)
Lp (2)Lp (2)
Lp (2)
 
Lecture 05 syntax analysis 2
Lecture 05 syntax analysis 2Lecture 05 syntax analysis 2
Lecture 05 syntax analysis 2
 
Minimization Technique .ppt
 Minimization Technique .ppt Minimization Technique .ppt
Minimization Technique .ppt
 
Chapter 3.Simplex Method hand out last.pdf
Chapter 3.Simplex Method hand out last.pdfChapter 3.Simplex Method hand out last.pdf
Chapter 3.Simplex Method hand out last.pdf
 
Context Free Grammar
Context Free GrammarContext Free Grammar
Context Free Grammar
 
Syntactic analysis in NLP
Syntactic analysis in NLPSyntactic analysis in NLP
Syntactic analysis in NLP
 
Cd2 [autosaved]
Cd2 [autosaved]Cd2 [autosaved]
Cd2 [autosaved]
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Simplex algorithm
Simplex algorithmSimplex algorithm
Simplex algorithm
 
Normal Forms for CFG's.pdf
Normal Forms for CFG's.pdfNormal Forms for CFG's.pdf
Normal Forms for CFG's.pdf
 
3 handouts section2-5
3 handouts section2-53 handouts section2-5
3 handouts section2-5
 
An Introduction to the Finite Element Method
An Introduction to the Finite Element MethodAn Introduction to the Finite Element Method
An Introduction to the Finite Element Method
 

More from Rushabh2428

Theory of Computation Grammar Concepts and Problems
Theory of Computation Grammar Concepts and ProblemsTheory of Computation Grammar Concepts and Problems
Theory of Computation Grammar Concepts and ProblemsRushabh2428
 
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping LemmaTheory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping LemmaRushabh2428
 
Theory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and ProblemsTheory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and ProblemsRushabh2428
 
Theory of Computation Basics of Finite Acceptors
Theory of Computation Basics of Finite AcceptorsTheory of Computation Basics of Finite Acceptors
Theory of Computation Basics of Finite AcceptorsRushabh2428
 
Theory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and GrammarTheory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and GrammarRushabh2428
 
Theory of Computation Introduction Session
Theory of Computation Introduction SessionTheory of Computation Introduction Session
Theory of Computation Introduction SessionRushabh2428
 

More from Rushabh2428 (6)

Theory of Computation Grammar Concepts and Problems
Theory of Computation Grammar Concepts and ProblemsTheory of Computation Grammar Concepts and Problems
Theory of Computation Grammar Concepts and Problems
 
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping LemmaTheory of Computation Regular Expressions, Minimisation & Pumping Lemma
Theory of Computation Regular Expressions, Minimisation & Pumping Lemma
 
Theory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and ProblemsTheory of Computation FSM Conversions and Problems
Theory of Computation FSM Conversions and Problems
 
Theory of Computation Basics of Finite Acceptors
Theory of Computation Basics of Finite AcceptorsTheory of Computation Basics of Finite Acceptors
Theory of Computation Basics of Finite Acceptors
 
Theory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and GrammarTheory of Computation Basic Concepts and Grammar
Theory of Computation Basic Concepts and Grammar
 
Theory of Computation Introduction Session
Theory of Computation Introduction SessionTheory of Computation Introduction Session
Theory of Computation Introduction Session
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

Theory of Computation FSM Grammar Minimisation and Normal Forms

  • 1. Theory of Computation By Rushabh Wadkar
  • 2. Topics to be covered Simplification of Grammar Normal Forms Session wind up Day 7
  • 3. The Simplification of Grammars ● Method 1: Remove Useless Productions. ● Method 2: Removing λ-Productions. ● Method 3: Removing Unit Productions. We additionally have the substituting method that we will discuss first There exists a probability to consider unnecessary variables when deriving a grammar.
  • 4. The Simplification of Grammars Useful Substitution Method. ● Many rules govern generating equivalent grammars by means of substitutions. Here we give one that is very useful for simplifying grammars in various ways. What is meant by it is the removal of certain types of undesirable productions. ● The process does not necessarily result in an actual reduction of the number of rules.
  • 5. The Simplification of Grammars Useful Substitution Method. ● Let G = (V, T, S, P) be a context-free grammar. Suppose that P contains a production of the form A → x1 Bx2 ● Assume that A and B are different variables and that B → y1 |y2 |...|yn is the set of all productions in P; that have B as the left side.
  • 6. The Simplification of Grammars Useful Substitution Method. ● Let G’= (V, T, S,P’ ) be the grammar in which is constructed by deleting A → x1 Bx2 from P. ● And adding to it A → x1 y1 x2 | x1 y1 x2 |...| x1 yn x2 ● Hence L(G’) = L(G)
  • 7. The Simplification of Grammars Useful Substitution Method. Consider G = ({A, B}, {a,b,c}, A, P) with productions Using the suggested substitution for the variable B, we get the grammar G’ with productions The new grammar is equivalent to G.
  • 8. The Simplification of Grammars Method 1: Remove Useless Productions. ● One invariably wants to remove productions from a grammar that can never take part in any derivation. For example, in the grammar whose entire production set is ● The production S → A clearly plays no role, as A cannot be transformed into a terminal string. While A can occur in a string derived from S, this can never lead to a sentence. Removing this production leaves the language unaffected and is a simplification by any definition.
  • 9. The Simplification of Grammars Method 1: Remove Useless Productions. ● Let G = (V, T, S, P) be a context-free grammar. A variable A ∈ V is said to be useful if and only if there is at least one ω ∈ L (G) such that with x, y in (VUT)* . In other words, a variable is useful if and only if it occurs in at least one derivation. A variable that is not useful is called useless. A production is useless if it involves any useless variable.
  • 10. The Simplification of Grammars Method 1: Remove Useless Productions. ● A variable may be useless because there is no way of getting a terminal string from it. The case just mentioned is of this kind. Another reason a variable may be useless is shown in the next grammar. In a grammar with start symbol S and productions the variable B is useless and so is the production B → bA. Although B can derive a terminal string, there is no way we can achieve This example illustrates the two reasons why a variable is useless:
  • 11. The Simplification of Grammars Method 1: Remove Useless Productions. Q. Eliminate useless symbols and productions from G = (V,T,S,P), where V = {S, A, B, C} and T = {a,b}, with P consisting of
  • 12. The Simplification of Grammars Method 1: Remove Useless Productions. First, we identify the set of variables that can lead to a terminal string. Because A → a and B →aa, the variables A and B belong to this set. So does S, because S ⇒ A ⇒ a. However, this argument cannot be made for C, thus identifying it as useless. Removing C and its corresponding productions, we are led to the grammar G1 with variables V1 = {S, A, B}, terminals T = {a}, and productions
  • 13. The Simplification of Grammars Method 1: Remove Useless Productions. Next we want to eliminate the variables that cannot be reached from the start variable. For this, we can draw a dependency graph for the variables. Dependency graphs are a way of visualizing complex relationships and are found in many applications. For context-free grammars, a dependency graph has its vertices labeled with variables, with an edge between vertices C and D if and only if there is a production of the form
  • 14. The Simplification of Grammars Method 1: Remove Useless Productions. A variable is useful only if there is a path from the vertex labeled S to the vertex labeled with that variable. In our case, B is useless. Removing it and the affected productions and terminals, we are led to the final answer And with the production
  • 15. The Simplification of Grammars Method 2: Removing λ-Productions One kind of production that is sometimes undesirable is one in which the right side is the empty string. Any production of a context-free grammar of the form A → λ is called a λ-production. Any variable A for which the derivation is possible is called nullable.
  • 16. The Simplification of Grammars Method 2: Removing λ-Productions One kind of production that is sometimes undesirable is one in which the right side is the empty string. Any production of a context-free grammar of the form A → λ is called a λ-production. Any variable A for which the derivation is possible is called nullable. A grammar may generate a language not containing λ, yet have some λ-productions or nullable variables. In such cases, the λ-productions can be removed.
  • 17. The Simplification of Grammars Method 2: Removing λ-Productions
  • 18. The Simplification of Grammars Method 3: Removing Unit Productions As we have seen productions in which both sides are a single variable are at times undesirable. Any production of a context-free grammar of the form A → B, where A, B ∈ V, is called a unit-production.
  • 19. The Simplification of Grammars Method 3: Removing Unit Productions
  • 20. The Simplification of Grammars Method 3: Removing Unit Productions
  • 21. The Simplification of Grammars Method 3: Removing Unit Productions
  • 22. The Simplification of Grammars Method 3: Removing Unit Productions
  • 23. The Simplification of Grammars Method 3: Removing Unit Productions
  • 24. Normal Forms ● Chomsky Normal Form (CNF) ● Greibach Normal Form (GNF) There are many kinds of normal forms we can establish for context-free grammars. Some of these, because of their wide usefulness, have been studied extensively. We consider two of them briefly.
  • 25. Chomsky Normal Form A context-free grammar is in Chomsky normal form if all productions are of the form A → BC Or A → a, where A, B, C are in V, and a is in T.
  • 26. Chomsky Normal Form Examples: Grammar in CNF Grammar in not CNF
  • 27. Chomsky Normal Form The following steps are followed to standardize the grammar using CNF: ● Rule-01: Reduce the grammar completely by: 1.Eliminating ∈ productions 2.Eliminating unit productions 3.Eliminating useless productions ● Rule-02: Replace each production of the form A → B1 B2 B3 ….Bn where n > 2 with A → B1 C where C → B2 B3 ….Bn . Repeat this step for all the productions having more than two variables on RHS. ● Rule-03: Replace each production of the form A → aB with A → XB and X → a. Repeat this step for all the productions having the form A → aB.
  • 28. Chomsky Normal Form Q1. Convert the grammar with productions to Chomsky normal form.
  • 29. Chomsky Normal Form Step 1: Eliminate all null and unit productions No null or unit productions Step 2: Check for productions already in CNF There are no productions that are already in CNF. Step 3: Put Ba, Bb, Bc for a, b, c
  • 30. Chomsky Normal Form Step 4: we introduce additional variables to get the first two productions into normal form
  • 31. Chomsky Normal Form Q2. Convert the given grammar to CNF: S → aAD A → aB / bAB B → b D → d
  • 32. Chomsky Normal Form Step-01: The given grammar is already completely reduced. Step-02: The productions already in chomsky normal form are- B → b D → d These productions will remain as they are.
  • 33. Chomsky Normal Form The productions not in chomsky normal form are- S → aAD A → aB / bAB We will convert these productions in chomsky normal form.
  • 34. Chomsky Normal Form Step-03: Replace the terminal symbols a and b by new variables Ca and Cb . This is done by introducing the following two new productions in the grammar: Ca → a Cb → b Now, the productions above modify to: S → Ca AD A → Ca B / Cb AB
  • 35. Chomsky Normal Form Replace AD and AB by new variables CAD and CAB respectively. This is done by introducing the following two new productions in the grammar- CAD → AD CAB → AB Now, the production modifies to- S → Ca CAD A → Ca B / Cb CAB
  • 36. Chomsky Normal Form Step-04: The resultant grammar is- S → Ca CAD A → Ca B / Cb CAB B → b D → d Ca → a Cb → b CAD → AD CAB → AB This grammar is in chomsky normal form.
  • 37. Greibach Normal Form A context-free grammar is said to be in Greibach normal form if all productions have the form A → aX, where a ∈ T and X ∈ V*
  • 38. Greibach Normal Form Examples: Grammar in GNF Grammar in not CNF
  • 39. Greibach Normal Form The following steps are followed to standardize the grammar using GNF: Step 1. Convert the grammar into CNF. If the given grammar is not in CNF, convert it to CNF. Step 2. Eliminate left recursion from grammar if it exists. If CFG contains left recursion, eliminate them. Step 3. Convert the production rules into GNF form. If any production rule is not in the GNF form, convert them.
  • 40. Greibach Normal Form Q1. Convert the following grammar to GNF S → XY | Xn | p X → mX | m Y → Xn | o
  • 41. Greibach Normal Form Here, S does not appear on the right side of any production and there are no unit or null productions in the production rule set. So, we can skip Step 1 to Step 3. Step 4: Now after replacing X in S → XY | Xo | p With mX | m we obtain S → mXY | mY | mXo | mo | p. And after replacing X in Y → Xn | o with the right side of X → mX | m we obtain Y → mXn | mn | o. Two new productions O → o and P → p are added to the production set and then we came to the final GNF as: S → mXY | mY | mXC | mC | p X → mX | m Y → mXD | mD | o O → o P → p
  • 42. Greibach Normal Form Q2. Consider the given grammar G1: S → XA|BB B → b|SB X → b A → a As G1 is already in CNF and there is no left recursion, we can skip step 1 and 2 and directly move to step 3.
  • 43. Greibach Normal Form The production rule B->SB is not in GNF, therefore, we substitute S -> XA|BB in production rule B->SB as: S → XA|BB B → b|XAB|BBB X → b A → a
  • 44. Greibach Normal Form The production rules S->XA and B->XAB is not in GNF, therefore, we substitute X->b in production rules S->XA and B->XAB as: S → bA|BB B → b|bAB|BBB X → b A → a
  • 45. Greibach Normal Form Removing left recursion (B->BBB), we get: S → bA|BB B → bC|bABC C → BBC| ε X → b A → a Removing null production (C-> ε), we get: S → bA|BB B → bC|bABC|b|bAB C → BBC|BB X → b A → a
  • 46. Greibach Normal Form The production rules S->BB is not in GNF, therefore, we substitute B → bC|bABC|b|bAB in production rules S->BB as: S → bA| bCB|bABCB|bB|bABB B → bC|bABC|b|bAB C → BBC|BB X → b A → a The production rules C->BB is not in GNF, therefore, we substitute B → bC|bABC|b|bAB in production rules C->BB as: S → bA| bCB|bABCB|bB|bABB B → bC|bABC|b|bAB C → BBC C → bCB|bABCB|bB|bABB X → b A → a The production rules C->BBC is not in GNF, therefore, we substitute B → bC|bABC|b|bAB in production rules C->BBC as: S → bA| bCB|bABCB|bB|bABB B → bC|bABC|b|bAB C → bCBC|bABCBC|bBC|bABBC C → bCB|bABCB|bB|bABB X → b A → a This is in GNF
  • 47. End of Day 7 www.linkedin.com/in/wadkar-rushabh @RushabhWadkar Thank you...