SlideShare a Scribd company logo
1 of 13
Eliminating ^ Production and
Unit Production from a CFG
• 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.
Continued……
• Simplification essentially comprises of the
following steps −
• Reduction of CFG
• Removal of Unit Productions
• Removal of Null Productions
Continued…..
• Reduction of CFG
• CFGs are reduced in two phases −
• Phase 1 − Derivation of an equivalent grammar, G’,
from the CFG, G, such that each variable derives some
terminal string.
• Derivation Procedure −
• Step 1 − Include all symbols, W1, that derive some
terminal and initialize i=1.
• Step 2 − Include all symbols, Wi+1, that derive Wi.
• Step 3 − Increment i and repeat Step 2, until Wi+1 = Wi.
• Step 4 − Include all production rules that have Wi in it.
Continued…..
• Phase 2 − Derivation of an equivalent
grammar, G”, from the CFG, G’, such that each
symbol appears in a sentential form.
• Derivation Procedure −
• Step 1 − Include the start symbol in Y1 and
initialize i = 1.
• Step 2 − Include all symbols, Yi+1, that can be
derived from Yi and include all production rules
that have been applied.
• Step 3 − Increment i and repeat Step 2, until Yi+1 =
Yi.
Continued……
• Problem
• Find a reduced grammar equivalent to the grammar G, having production rules, P: S → AC | B, A →
a, C → c | BC, E → aA | e
• Solution
• Phase 1 −
• 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
• Phase 2 −
• Y1 = { S }
• Y2 = { S, A, C } from rule S → AC
• Y3 = { S, A, C, a, c } from rules A → a and C → c
• Y4 = { S, A, C, a, c }
• Since Y3 = Y4, we can derive G” as −
• G” = { { A, C, S }, { a, c }, P, {S}}
• where P: S → AC, A → a, C → c
Continued…….
• 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.
Continued……
• Problem
• Remove unit production from the following −
• S → XY, X → a, Y → Z | b, Z → M, M → N, N → a
• Solution −
• There are 3 unit productions in the grammar −
• Y → Z, Z → M, and M → N
• At first, we will remove M → N.
• As N → a, we add M → a, and M → N is removed.
• The production set becomes
• S → XY, X → a, Y → Z | b, Z → M, M → a, N → a
Continued…….
• Now we will remove Z → M.
• As M → a, we add Z→ a, and Z → M is removed.
• The production set becomes
• S → XY, X → a, Y → Z | b, Z → a, M → a, N → a
• Now we will remove Y → Z.
• As Z → a, we add Y→ a, and Y → Z is removed.
• The production set becomes
• S → XY, X → a, Y → a | b, Z → a, M → a, N → a
• Now Z, M, and N are unreachable, hence we can remove
those.
• The final CFG is unit production free −
• S → XY, X → a, Y → a | b
Continued…..
• 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 → .......… → ε
Continued……
• 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.
Continued……
• Problem
• Remove null production from the following −
• S → ASA | aB | b, A → B, B → b | ∈
• Solution −
• There are two nullable variables − A and B
• At first, we will remove B → ε.
• After removing B → ε, the production set
becomes −
• S→ASA | aB | b | a, A ε B| b | &epsilon, B → b
Continued…..
• Now we will remove A → ε.
• After removing A → ε, the production set
becomes −
• S→ASA | aB | b | a | SA | AS | S, A → B| b, B
→ b
• This is the final production set without null
transition.

More Related Content

Similar to Eliminating ^ production and Unit Production from a CFG.pptx

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
Jisock
 

Similar to Eliminating ^ production and Unit Production from a CFG.pptx (13)

알고리즘 연합캠프 세미나 1-B (Bitwise DP)
알고리즘 연합캠프 세미나 1-B (Bitwise DP)알고리즘 연합캠프 세미나 1-B (Bitwise DP)
알고리즘 연합캠프 세미나 1-B (Bitwise DP)
 
Computer Organization and Architecture Presentation
Computer Organization and Architecture PresentationComputer Organization and Architecture Presentation
Computer Organization and Architecture Presentation
 
Analysis of portal frame by direct stiffness method
Analysis of  portal frame by direct stiffness methodAnalysis of  portal frame by direct stiffness method
Analysis of portal frame by direct stiffness method
 
Block diagram &_overall_transferfunction_of_a_multiloop_control_system
Block diagram &_overall_transferfunction_of_a_multiloop_control_systemBlock diagram &_overall_transferfunction_of_a_multiloop_control_system
Block diagram &_overall_transferfunction_of_a_multiloop_control_system
 
CG-Lecture3.pptx
CG-Lecture3.pptxCG-Lecture3.pptx
CG-Lecture3.pptx
 
Trigonometric ratios and identities 1
Trigonometric ratios and identities 1Trigonometric ratios and identities 1
Trigonometric ratios and identities 1
 
Theory of Computation Unit 4
Theory of Computation Unit 4Theory of Computation Unit 4
Theory of Computation Unit 4
 
Trigonometry Cheat Sheet
Trigonometry Cheat SheetTrigonometry Cheat Sheet
Trigonometry Cheat Sheet
 
Quantitative Analysis For Decision Making
Quantitative Analysis For Decision MakingQuantitative Analysis For Decision Making
Quantitative Analysis For Decision Making
 
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
 
ADVANCED ALGORITHMS-UNIT-3-Final.ppt
ADVANCED   ALGORITHMS-UNIT-3-Final.pptADVANCED   ALGORITHMS-UNIT-3-Final.ppt
ADVANCED ALGORITHMS-UNIT-3-Final.ppt
 
Information security Seminar #7
Information security Seminar #7Information security Seminar #7
Information security Seminar #7
 
Solucionario_de_Chapra_y_Canale_Quinta_E.pdf
Solucionario_de_Chapra_y_Canale_Quinta_E.pdfSolucionario_de_Chapra_y_Canale_Quinta_E.pdf
Solucionario_de_Chapra_y_Canale_Quinta_E.pdf
 

More from SomnathMule5

chapter2-softwareprocessmodels-190805164811.pptx
chapter2-softwareprocessmodels-190805164811.pptxchapter2-softwareprocessmodels-190805164811.pptx
chapter2-softwareprocessmodels-190805164811.pptx
SomnathMule5
 
software engineering CSE675_01_Introduction.ppt
software engineering CSE675_01_Introduction.pptsoftware engineering CSE675_01_Introduction.ppt
software engineering CSE675_01_Introduction.ppt
SomnathMule5
 

More from SomnathMule5 (16)

chapter2-softwareprocessmodels-190805164811.pptx
chapter2-softwareprocessmodels-190805164811.pptxchapter2-softwareprocessmodels-190805164811.pptx
chapter2-softwareprocessmodels-190805164811.pptx
 
Mobile communication Mobile Networking.pptx
Mobile communication Mobile Networking.pptxMobile communication Mobile Networking.pptx
Mobile communication Mobile Networking.pptx
 
Mobile communication and computing GSM protocol stack and frame formatting.pdf
Mobile communication and computing GSM protocol stack and frame formatting.pdfMobile communication and computing GSM protocol stack and frame formatting.pdf
Mobile communication and computing GSM protocol stack and frame formatting.pdf
 
Mobile communication and computing gsm-radio-interface-140720014203-phpapp02.pdf
Mobile communication and computing gsm-radio-interface-140720014203-phpapp02.pdfMobile communication and computing gsm-radio-interface-140720014203-phpapp02.pdf
Mobile communication and computing gsm-radio-interface-140720014203-phpapp02.pdf
 
Mobile communication and computing presentation-161102173611.pdf
Mobile communication and computing presentation-161102173611.pdfMobile communication and computing presentation-161102173611.pdf
Mobile communication and computing presentation-161102173611.pdf
 
Mobile communication and computing gprs.ppt
Mobile communication and computing gprs.pptMobile communication and computing gprs.ppt
Mobile communication and computing gprs.ppt
 
Mbile communication and computingGSM Network.ppt
Mbile communication and computingGSM Network.pptMbile communication and computingGSM Network.ppt
Mbile communication and computingGSM Network.ppt
 
Mobile Communication gsm_introduction.ppt
Mobile Communication gsm_introduction.pptMobile Communication gsm_introduction.ppt
Mobile Communication gsm_introduction.ppt
 
Improving machine learning models unit 5.pptx
Improving machine learning models unit 5.pptxImproving machine learning models unit 5.pptx
Improving machine learning models unit 5.pptx
 
Software requirement specification Unit 3.pptx
Software requirement specification Unit 3.pptxSoftware requirement specification Unit 3.pptx
Software requirement specification Unit 3.pptx
 
unit 3 software requirement and analysis-1.ppt
unit 3 software requirement and analysis-1.pptunit 3 software requirement and analysis-1.ppt
unit 3 software requirement and analysis-1.ppt
 
software engineering Architecture and design Unit 3.pptx
software engineering Architecture and design Unit 3.pptxsoftware engineering Architecture and design Unit 3.pptx
software engineering Architecture and design Unit 3.pptx
 
software engineering CSE675_01_Introduction.ppt
software engineering CSE675_01_Introduction.pptsoftware engineering CSE675_01_Introduction.ppt
software engineering CSE675_01_Introduction.ppt
 
Engineering economics and Management Unit-2.pdf
Engineering economics and Management Unit-2.pdfEngineering economics and Management Unit-2.pdf
Engineering economics and Management Unit-2.pdf
 
DevOps Expt 2.pdf
DevOps Expt 2.pdfDevOps Expt 2.pdf
DevOps Expt 2.pdf
 
DevOps Expt 1.pdf
DevOps Expt 1.pdfDevOps Expt 1.pdf
DevOps Expt 1.pdf
 

Recently uploaded

Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manual
BalamuruganV28
 
Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
Kira Dess
 
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
drjose256
 
Seizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksSeizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networks
IJECEIAES
 

Recently uploaded (20)

Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailing
 
Insurance management system project report.pdf
Insurance management system project report.pdfInsurance management system project report.pdf
Insurance management system project report.pdf
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.ppt
 
Intro to Design (for Engineers) at Sydney Uni
Intro to Design (for Engineers) at Sydney UniIntro to Design (for Engineers) at Sydney Uni
Intro to Design (for Engineers) at Sydney Uni
 
Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manual
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptx
 
Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
 
Software Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdfSoftware Engineering Practical File Front Pages.pdf
Software Engineering Practical File Front Pages.pdf
 
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...
 
5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...
 
Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTUUNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
 
Circuit Breakers for Engineering Students
Circuit Breakers for Engineering StudentsCircuit Breakers for Engineering Students
Circuit Breakers for Engineering Students
 
Seizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networksSeizure stage detection of epileptic seizure using convolutional neural networks
Seizure stage detection of epileptic seizure using convolutional neural networks
 
Independent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging StationIndependent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging Station
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptx
 
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfInstruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
 

Eliminating ^ production and Unit Production from a CFG.pptx

  • 1. Eliminating ^ Production and Unit Production from a CFG
  • 2. • 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.
  • 3. Continued…… • Simplification essentially comprises of the following steps − • Reduction of CFG • Removal of Unit Productions • Removal of Null Productions
  • 4. Continued….. • Reduction of CFG • CFGs are reduced in two phases − • Phase 1 − Derivation of an equivalent grammar, G’, from the CFG, G, such that each variable derives some terminal string. • Derivation Procedure − • Step 1 − Include all symbols, W1, that derive some terminal and initialize i=1. • Step 2 − Include all symbols, Wi+1, that derive Wi. • Step 3 − Increment i and repeat Step 2, until Wi+1 = Wi. • Step 4 − Include all production rules that have Wi in it.
  • 5. Continued….. • Phase 2 − Derivation of an equivalent grammar, G”, from the CFG, G’, such that each symbol appears in a sentential form. • Derivation Procedure − • Step 1 − Include the start symbol in Y1 and initialize i = 1. • Step 2 − Include all symbols, Yi+1, that can be derived from Yi and include all production rules that have been applied. • Step 3 − Increment i and repeat Step 2, until Yi+1 = Yi.
  • 6. Continued…… • Problem • Find a reduced grammar equivalent to the grammar G, having production rules, P: S → AC | B, A → a, C → c | BC, E → aA | e • Solution • Phase 1 − • 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 • Phase 2 − • Y1 = { S } • Y2 = { S, A, C } from rule S → AC • Y3 = { S, A, C, a, c } from rules A → a and C → c • Y4 = { S, A, C, a, c } • Since Y3 = Y4, we can derive G” as − • G” = { { A, C, S }, { a, c }, P, {S}} • where P: S → AC, A → a, C → c
  • 7. Continued……. • 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.
  • 8. Continued…… • Problem • Remove unit production from the following − • S → XY, X → a, Y → Z | b, Z → M, M → N, N → a • Solution − • There are 3 unit productions in the grammar − • Y → Z, Z → M, and M → N • At first, we will remove M → N. • As N → a, we add M → a, and M → N is removed. • The production set becomes • S → XY, X → a, Y → Z | b, Z → M, M → a, N → a
  • 9. Continued……. • Now we will remove Z → M. • As M → a, we add Z→ a, and Z → M is removed. • The production set becomes • S → XY, X → a, Y → Z | b, Z → a, M → a, N → a • Now we will remove Y → Z. • As Z → a, we add Y→ a, and Y → Z is removed. • The production set becomes • S → XY, X → a, Y → a | b, Z → a, M → a, N → a • Now Z, M, and N are unreachable, hence we can remove those. • The final CFG is unit production free − • S → XY, X → a, Y → a | b
  • 10. Continued….. • 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 → .......… → ε
  • 11. Continued…… • 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.
  • 12. Continued…… • Problem • Remove null production from the following − • S → ASA | aB | b, A → B, B → b | ∈ • Solution − • There are two nullable variables − A and B • At first, we will remove B → ε. • After removing B → ε, the production set becomes − • S→ASA | aB | b | a, A ε B| b | &epsilon, B → b
  • 13. Continued….. • Now we will remove A → ε. • After removing A → ε, the production set becomes − • S→ASA | aB | b | a | SA | AS | S, A → B| b, B → b • This is the final production set without null transition.