SlideShare a Scribd company logo
1 of 23
Download to read offline
Presented by:
Malaika, Hajira, Anisa
Presented to:
Dr. Fouzia
1/24/2020
CLF has several properties.
Context free languages are closed under union.
Context free languages are closed under concatenation.
Context free languages are closed under Kleene Closure.
Context free languages are closed under Reversal.
Context free languages are closed under Intersection.
Context free languages are closed under Complement.
ontext
Free Languages
Closure Properties
Union
Concatenation
Kleene closure
Reversal
Intersection
Complement
R.G
F.A
R.L
PDA
CFL
CFG
Context Free Language
• A language generated by context
free grammar is known as context
free language.
• The set of all context free language is
identical to the set of languages
accepted by PDA or more powerful
than PDA.
P = production
rule
P = production
rule
V = set of
variable or
non terminal
S = Start
Symbol
Σ = set of
terminal
1/24/2020
Context Free Grammar is Defined by 4 Tuples
• A α
Where
• α ∈ {V υ Σ}*
And
• A ∈ V
Production Rule
• Context free grammar has a production
rule in the form of:
• For generating a language that
generates equal number of a’s and
b’s in the form of anbn.
Where
• L = (an bn | n > = 0)
EXAMPLE:
1/24/2020
G = {(S,A), (a, b), (S aAb, A aAb ∕ ϵ)}
– The start symbol is S
• S aAb (A aAb)
• S aaAbb (A aAb)
• S aaAbb (A aAb)
• S aaaAbbb (A ϵ )
• S aaabbb
Finally we get string aaabbb
o This is of the form
a3b3
EXAMPLE:
Closure
Properties of
Context Free
Languages:
What is Closure Property?
• A set is closed under an operation if
doing the operation on a given set
always produces a member of the
same set.
Example:
o If a and b are two integers. Then
a + b is also an integer.
o So + operation is closed under
addition.
Example:
o If a and b are two integers. Then a / b may not
be an integer.
o So / operation is not closed under integers.
Example:
o If A = { 1, 2, 3, 4}. If a, b ∈ A Then a + b is also
an integer. But a + b may not belong to A.
o So + operation is not closed under addition
Cont.
Kleene starConcatenationUnion
1/24/2020
This means that Closure Property for CFL is:
• When operation is applied to a certain context-
free languages the result will also be a
context-free language.
• Some of the Closure Property of context
free language are there:
Union:
• If L1 and If L2 are
two context free
languages, their
union L1 ∪ L2 will
also be context free.
Example:
• L1 = { anbncm | m >= 0 and n >= 0 } and
• L2 = { anbmcm | n >= 0 and m >= 0 }
• L = L1 ∪ L2 = { anbncm ∪ anbmcm | n >= 0, m >= 0 }
is also context free.
• L1 says number of a’s should be equal to number of
b’s and L2 says number of b’s should be equal to
number of c’s.
• Their union says either of two conditions to be true.
So it is also context free language.
• Note: So CFL are closed under Union.
• If L1 and If L2 are two context free languages,
their concatenation L1.L2 will also be context
free.
Concatenation
Example
• L1 = { an bn | n >= 0 } and L2 = { cm dm | m >= 0 }
• L = L1.L2 = { an bn cm dm | m >= 0 and n >= 0} is also
context free.
• L1 says number of a’s should be equal to number of
b’s. L2 says number of c’s should be equal to number of
d’s.
• Their concatenation says first number of a’s should be
equal to number of b’s, then number of c’s should be
equal to number of d’s.
• So, we can create a PDA.
Kleene Closure
INTERSECTION
&
COMPLEMENT
1/24/2020
INTERSECTION:
The CFG is Not necessarily closed under intersection.
o L1={an bn am | m, n >= 1} is context free language.
• G1 = { S→AB
• AaAb|ab
• BcB|c}
o L2={an bm am | m,n >=1} is context free language.
• G2={SAB
• AaA|a
• BbBc|bc}
o L1∩ L2 = {an bn an | n ≥ 1}, which is known not to be a CFL
(pumping lemma).
o Note: L1∩ L2 can be defined by a TM.
COMPLEMENT
o Assume that CFL is closed under
complementation.
• Let L1 and L2 are CFL.
• L1
c and L2
c are CFL.
• L1
c ∪ L2
c is also a CFL. (As union closed under CFL)
• (L1
c ∪ L2
c)c has to be CFL.
• But
• According to DEMORGANS LAW:
• (L1
c ∪ L2
c)c = L1 ∩ L2 is NOT necessarily a CFL.
CONTRADICTION !!!
• Hence CFL is NOT necessarily closed under
complementation.
A
P
P
L
I
C
A
T
I
O
N
s
Context Free Grammar (CFG) is of great
practical importance.
o It is used for following purposes:
• For defining programming languages
• For translation of programming
languages
• For describing arithmetic expressions
• For construction of compilers
• Data Processing
Question
1. Consider the language L1, L2, L3 as given below.
L1 = { ambn | m, n >= 0 }
L2 = { anbn | n >= 0 }
L3 = { anbncn |n>= 0 }
Which of the following statements is NOT TRUE?
A. Push Down Automata (PDA) can be used to recognize
L1 and L2.
B. L1 is a regular language
C. All the three languages are context free
D. Turing machine can be used to recognized all three
languages.
THANKS

More Related Content

What's hot

Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environmentIffat Anjum
 
Turing Machine
Turing MachineTuring Machine
Turing MachineRajendran
 
Context free grammars
Context free grammarsContext free grammars
Context free grammarsRonak Thakkar
 
Church Turing Thesis
Church Turing ThesisChurch Turing Thesis
Church Turing ThesisHemant Sharma
 
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
 
Regular Expression in Compiler design
Regular Expression in Compiler designRegular Expression in Compiler design
Regular Expression in Compiler designRiazul Islam
 
1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets1.10. pumping lemma for regular sets
1.10. pumping lemma for regular setsSampath Kumar S
 
3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cfl3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cflSampath Kumar S
 
Uninformed search /Blind search in AI
Uninformed search /Blind search in AIUninformed search /Blind search in AI
Uninformed search /Blind search in AIKirti Verma
 
Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphsTilakpoudel2
 
Compiler Design
Compiler DesignCompiler Design
Compiler DesignMir Majid
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translationAkshaya Arunan
 
Variants of Turing Machine
Variants of Turing MachineVariants of Turing Machine
Variants of Turing MachineRajendran
 

What's hot (20)

Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environment
 
Finite automata
Finite automataFinite automata
Finite automata
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
 
COMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time EnvironmentsCOMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time Environments
 
Multi Head, Multi Tape Turing Machine
Multi Head, Multi Tape Turing MachineMulti Head, Multi Tape Turing Machine
Multi Head, Multi Tape Turing Machine
 
Turing Machine
Turing MachineTuring Machine
Turing Machine
 
COMPILER DESIGN- Syntax Directed Translation
COMPILER DESIGN- Syntax Directed TranslationCOMPILER DESIGN- Syntax Directed Translation
COMPILER DESIGN- Syntax Directed Translation
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
Context free grammars
Context free grammarsContext free grammars
Context free grammars
 
Church Turing Thesis
Church Turing ThesisChurch Turing Thesis
Church Turing Thesis
 
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)
 
Regular Expression in Compiler design
Regular Expression in Compiler designRegular Expression in Compiler design
Regular Expression in Compiler design
 
1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets
 
3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cfl3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cfl
 
Uninformed search /Blind search in AI
Uninformed search /Blind search in AIUninformed search /Blind search in AI
Uninformed search /Blind search in AI
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
 
Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphs
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
Variants of Turing Machine
Variants of Turing MachineVariants of Turing Machine
Variants of Turing Machine
 

Similar to Closure properties of context free grammar

Presentation (5).pdf
Presentation (5).pdfPresentation (5).pdf
Presentation (5).pdfGaurav447273
 
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
 
9781284077247_PPTx_CH01.pptx
9781284077247_PPTx_CH01.pptx9781284077247_PPTx_CH01.pptx
9781284077247_PPTx_CH01.pptxmainakmail2585
 
RegularLanguage.pptx
RegularLanguage.pptxRegularLanguage.pptx
RegularLanguage.pptxTapasBhadra1
 
Csr2011 june17 15_15_kaminski
Csr2011 june17 15_15_kaminskiCsr2011 june17 15_15_kaminski
Csr2011 june17 15_15_kaminskiCSR2011
 
Conteext-free Grammer
Conteext-free GrammerConteext-free Grammer
Conteext-free GrammerHASHIR RAZA
 
Syntax Analyzer.pdf
Syntax Analyzer.pdfSyntax Analyzer.pdf
Syntax Analyzer.pdfkenilpatel65
 
2. context free langauages
2. context free langauages2. context free langauages
2. context free langauagesdanhumble
 
01-Introduction&Languages.pdf
01-Introduction&Languages.pdf01-Introduction&Languages.pdf
01-Introduction&Languages.pdfTariqSaeed80
 
flatPresentation.pdf
flatPresentation.pdfflatPresentation.pdf
flatPresentation.pdfSohebMohammad
 
Basics Of C Programming For Beginners In Easiest Way
Basics Of C Programming For Beginners In Easiest WayBasics Of C Programming For Beginners In Easiest Way
Basics Of C Programming For Beginners In Easiest Wayakshay rajpure
 
Basic C Programming language
Basic C Programming languageBasic C Programming language
Basic C Programming languageAbhishek Soni
 
Class9
 Class9 Class9
Class9issbp
 
Computer programming languages19 09-2007
Computer programming languages19 09-2007Computer programming languages19 09-2007
Computer programming languages19 09-2007Prem Chandrakar
 
Theory of computing
Theory of computingTheory of computing
Theory of computingRanjan Kumar
 
Introduction to the theory of computation
Introduction to the theory of computationIntroduction to the theory of computation
Introduction to the theory of computationprasadmvreddy
 

Similar to Closure properties of context free grammar (20)

Presentation (5).pdf
Presentation (5).pdfPresentation (5).pdf
Presentation (5).pdf
 
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
 
9781284077247_PPTx_CH01.pptx
9781284077247_PPTx_CH01.pptx9781284077247_PPTx_CH01.pptx
9781284077247_PPTx_CH01.pptx
 
RegularLanguage.pptx
RegularLanguage.pptxRegularLanguage.pptx
RegularLanguage.pptx
 
Csr2011 june17 15_15_kaminski
Csr2011 june17 15_15_kaminskiCsr2011 june17 15_15_kaminski
Csr2011 june17 15_15_kaminski
 
Conteext-free Grammer
Conteext-free GrammerConteext-free Grammer
Conteext-free Grammer
 
TOC question bank.pdf
TOC question bank.pdfTOC question bank.pdf
TOC question bank.pdf
 
Syntax Analyzer.pdf
Syntax Analyzer.pdfSyntax Analyzer.pdf
Syntax Analyzer.pdf
 
2. context free langauages
2. context free langauages2. context free langauages
2. context free langauages
 
Unit2 Toc.pptx
Unit2 Toc.pptxUnit2 Toc.pptx
Unit2 Toc.pptx
 
01-Introduction&Languages.pdf
01-Introduction&Languages.pdf01-Introduction&Languages.pdf
01-Introduction&Languages.pdf
 
flatPresentation.pdf
flatPresentation.pdfflatPresentation.pdf
flatPresentation.pdf
 
Basics Of C Programming For Beginners In Easiest Way
Basics Of C Programming For Beginners In Easiest WayBasics Of C Programming For Beginners In Easiest Way
Basics Of C Programming For Beginners In Easiest Way
 
Basic C Programming language
Basic C Programming languageBasic C Programming language
Basic C Programming language
 
Class9
 Class9 Class9
Class9
 
Computer programming languages19 09-2007
Computer programming languages19 09-2007Computer programming languages19 09-2007
Computer programming languages19 09-2007
 
Cfg part i
Cfg   part iCfg   part i
Cfg part i
 
Lisp
LispLisp
Lisp
 
Theory of computing
Theory of computingTheory of computing
Theory of computing
 
Introduction to the theory of computation
Introduction to the theory of computationIntroduction to the theory of computation
Introduction to the theory of computation
 

Recently uploaded

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 

Recently uploaded (20)

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 

Closure properties of context free grammar

  • 1. Presented by: Malaika, Hajira, Anisa Presented to: Dr. Fouzia 1/24/2020
  • 2. CLF has several properties. Context free languages are closed under union. Context free languages are closed under concatenation. Context free languages are closed under Kleene Closure. Context free languages are closed under Reversal. Context free languages are closed under Intersection. Context free languages are closed under Complement. ontext Free Languages Closure Properties Union Concatenation Kleene closure Reversal Intersection Complement
  • 4. Context Free Language • A language generated by context free grammar is known as context free language. • The set of all context free language is identical to the set of languages accepted by PDA or more powerful than PDA.
  • 5. P = production rule P = production rule V = set of variable or non terminal S = Start Symbol Σ = set of terminal 1/24/2020 Context Free Grammar is Defined by 4 Tuples
  • 6. • A α Where • α ∈ {V υ Σ}* And • A ∈ V Production Rule • Context free grammar has a production rule in the form of:
  • 7. • For generating a language that generates equal number of a’s and b’s in the form of anbn. Where • L = (an bn | n > = 0) EXAMPLE:
  • 8. 1/24/2020 G = {(S,A), (a, b), (S aAb, A aAb ∕ ϵ)} – The start symbol is S • S aAb (A aAb) • S aaAbb (A aAb) • S aaAbb (A aAb) • S aaaAbbb (A ϵ ) • S aaabbb Finally we get string aaabbb o This is of the form a3b3 EXAMPLE:
  • 10. What is Closure Property? • A set is closed under an operation if doing the operation on a given set always produces a member of the same set. Example: o If a and b are two integers. Then a + b is also an integer. o So + operation is closed under addition.
  • 11. Example: o If a and b are two integers. Then a / b may not be an integer. o So / operation is not closed under integers. Example: o If A = { 1, 2, 3, 4}. If a, b ∈ A Then a + b is also an integer. But a + b may not belong to A. o So + operation is not closed under addition Cont.
  • 12. Kleene starConcatenationUnion 1/24/2020 This means that Closure Property for CFL is: • When operation is applied to a certain context- free languages the result will also be a context-free language. • Some of the Closure Property of context free language are there:
  • 13. Union: • If L1 and If L2 are two context free languages, their union L1 ∪ L2 will also be context free.
  • 14. Example: • L1 = { anbncm | m >= 0 and n >= 0 } and • L2 = { anbmcm | n >= 0 and m >= 0 } • L = L1 ∪ L2 = { anbncm ∪ anbmcm | n >= 0, m >= 0 } is also context free. • L1 says number of a’s should be equal to number of b’s and L2 says number of b’s should be equal to number of c’s. • Their union says either of two conditions to be true. So it is also context free language. • Note: So CFL are closed under Union.
  • 15. • If L1 and If L2 are two context free languages, their concatenation L1.L2 will also be context free. Concatenation
  • 16. Example • L1 = { an bn | n >= 0 } and L2 = { cm dm | m >= 0 } • L = L1.L2 = { an bn cm dm | m >= 0 and n >= 0} is also context free. • L1 says number of a’s should be equal to number of b’s. L2 says number of c’s should be equal to number of d’s. • Their concatenation says first number of a’s should be equal to number of b’s, then number of c’s should be equal to number of d’s. • So, we can create a PDA.
  • 19. 1/24/2020 INTERSECTION: The CFG is Not necessarily closed under intersection. o L1={an bn am | m, n >= 1} is context free language. • G1 = { S→AB • AaAb|ab • BcB|c} o L2={an bm am | m,n >=1} is context free language. • G2={SAB • AaA|a • BbBc|bc} o L1∩ L2 = {an bn an | n ≥ 1}, which is known not to be a CFL (pumping lemma). o Note: L1∩ L2 can be defined by a TM.
  • 20. COMPLEMENT o Assume that CFL is closed under complementation. • Let L1 and L2 are CFL. • L1 c and L2 c are CFL. • L1 c ∪ L2 c is also a CFL. (As union closed under CFL) • (L1 c ∪ L2 c)c has to be CFL. • But • According to DEMORGANS LAW: • (L1 c ∪ L2 c)c = L1 ∩ L2 is NOT necessarily a CFL. CONTRADICTION !!! • Hence CFL is NOT necessarily closed under complementation.
  • 21. A P P L I C A T I O N s Context Free Grammar (CFG) is of great practical importance. o It is used for following purposes: • For defining programming languages • For translation of programming languages • For describing arithmetic expressions • For construction of compilers • Data Processing
  • 22. Question 1. Consider the language L1, L2, L3 as given below. L1 = { ambn | m, n >= 0 } L2 = { anbn | n >= 0 } L3 = { anbncn |n>= 0 } Which of the following statements is NOT TRUE? A. Push Down Automata (PDA) can be used to recognize L1 and L2. B. L1 is a regular language C. All the three languages are context free D. Turing machine can be used to recognized all three languages.