Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
CS:4330 Theory of ComputationSpring 2018
Computability TheoryDecidable Problems of CFLs and beyond
Haniel Barbosa
Readings for this lecture
Chapter 4 of [Sipser 1996], 3rd edition. Section 4.1.
Decidable Problems of CFLs
B We now describe algorithms to test
I whether a CFG generates a particular stringI whether the language generated by a CFG is empty
B We consider the language
ACFG = {〈G,w〉 | G is a CFG that generates the string w}
1 / 9
Decidability of CFG generation
TheoremACFG is a decidable language
Proof ideas: how to check G generates w?
I Possibly infinitely many derivations in G, therefore no exhaustive check
I However, if G is in Chomsky normal form then for any w ∈L (G), with|w|= n, n > 0, exactly 2n−1 steps are required for any derivation of w.
I We can then build a TM S that first converts G into Chomsky Normal Formand then checks every possible derivation of 2n−1 steps
S =“On input string 〈G,w〉, where G is a CFG and w is a string:
1. Convert G to an equivalent grammar in Chomsky Normal Form
2. List all derivations with 2n−1 steps, for |w|= n, if n > 0, otherwise list allderivations of 1 step
3. If any of these derivations generates w, accept, otherwise reject.”
2 / 9
Decidability of CFG generation
TheoremACFG is a decidable language
Proof ideas: how to check G generates w?
I Possibly infinitely many derivations in G, therefore no exhaustive check
I However, if G is in Chomsky normal form then for any w ∈L (G), with|w|= n, n > 0, exactly 2n−1 steps are required for any derivation of w.
I We can then build a TM S that first converts G into Chomsky Normal Formand then checks every possible derivation of 2n−1 steps
S =“On input string 〈G,w〉, where G is a CFG and w is a string:
1. Convert G to an equivalent grammar in Chomsky Normal Form
2. List all derivations with 2n−1 steps, for |w|= n, if n > 0, otherwise list allderivations of 1 step
3. If any of these derivations generates w, accept, otherwise reject.”
2 / 9
Decidability of CFG generation
TheoremACFG is a decidable language
Proof ideas: how to check G generates w?
I Possibly infinitely many derivations in G, therefore no exhaustive check
I However, if G is in Chomsky normal form then for any w ∈L (G), with|w|= n, n > 0, exactly 2n−1 steps are required for any derivation of w.
I We can then build a TM S that first converts G into Chomsky Normal Formand then checks every possible derivation of 2n−1 steps
S =“On input string 〈G,w〉, where G is a CFG and w is a string:
1. Convert G to an equivalent grammar in Chomsky Normal Form
2. List all derivations with 2n−1 steps, for |w|= n, if n > 0, otherwise list allderivations of 1 step
3. If any of these derivations generates w, accept, otherwise reject.”
2 / 9
Decidability of CFG generation
TheoremACFG is a decidable language
Proof ideas: how to check G generates w?
I Possibly infinitely many derivations in G, therefore no exhaustive check
I However, if G is in Chomsky normal form then for any w ∈L (G), with|w|= n, n > 0, exactly 2n−1 steps are required for any derivation of w.
I We can then build a TM S that first converts G into Chomsky Normal Formand then checks every possible derivation of 2n−1 steps
S =“On input string 〈G,w〉, where G is a CFG and w is a string:
1. Convert G to an equivalent grammar in Chomsky Normal Form
2. List all derivations with 2n−1 steps, for |w|= n, if n > 0, otherwise list allderivations of 1 step
3. If any of these derivations generates w, accept, otherwise reject.”
2 / 9
Decidability of emptiness testing for CFGs
Theorem
ECFG = {〈G〉 | G is a CFG and L (G) =∅} is a decidable language.
Proof ideas: check whether string of terminals derivable from startI We proceed by solving a more general problem: whether from a nonterminal
a string of terminals is derivable.
I Algorithm proceeds bottom up by marking terminals, then all nonterminalswith rules whose rhs consists only of marked symbols
R =“On input string 〈G〉, where G is a CFG:
1. Mark all terminal symbols in G
2. Repeat until no new nonterminal gets marked:
3. Mark any nonterminal A s.t. G contains a rule A→ u1, . . . , un and eachsymbol ui has already been marked
4. If the start nonterminal of G is marked, accept, otherwise reject.”
3 / 9
Decidability of emptiness testing for CFGs
Theorem
ECFG = {〈G〉 | G is a CFG and L (G) =∅} is a decidable language.
Proof ideas: check whether string of terminals derivable from startI We proceed by solving a more general problem: whether from a nonterminal
a string of terminals is derivable.
I Algorithm proceeds bottom up by marking terminals, then all nonterminalswith rules whose rhs consists only of marked symbols
R =“On input string 〈G〉, where G is a CFG:
1. Mark all terminal symbols in G
2. Repeat until no new nonterminal gets marked:
3. Mark any nonterminal A s.t. G contains a rule A→ u1, . . . , un and eachsymbol ui has already been marked
4. If the start nonterminal of G is marked, accept, otherwise reject.”
3 / 9
Decidability of emptiness testing for CFGs
Theorem
ECFG = {〈G〉 | G is a CFG and L (G) =∅} is a decidable language.
Proof ideas: check whether string of terminals derivable from startI We proceed by solving a more general problem: whether from a nonterminal
a string of terminals is derivable.
I Algorithm proceeds bottom up by marking terminals, then all nonterminalswith rules whose rhs consists only of marked symbols
R =“On input string 〈G〉, where G is a CFG:
1. Mark all terminal symbols in G
2. Repeat until no new nonterminal gets marked:
3. Mark any nonterminal A s.t. G contains a rule A→ u1, . . . , un and eachsymbol ui has already been marked
4. If the start nonterminal of G is marked, accept, otherwise reject.”
3 / 9
Decidability of equality problem for CFGs
Consider the language
EQCFG = {〈G,H〉 | G and H are CFGs and L (G) = L (H)}
Could we proceed to prove its decidability as we did with EQDFA?
NO!
CFGs are not closed under intersection or complement, therefore we cannot usesymmetric difference.
And as we will see later on, EQCFG is indeed undecidable.
4 / 9
Decidability of equality problem for CFGs
Consider the language
EQCFG = {〈G,H〉 | G and H are CFGs and L (G) = L (H)}
Could we proceed to prove its decidability as we did with EQDFA? NO!
CFGs are not closed under intersection or complement, therefore we cannot usesymmetric difference.
And as we will see later on, EQCFG is indeed undecidable.
4 / 9
Decidability of context-free languages
TheoremEvery CFL is decidable.
Proof idea: simulate generation of string by respective CFG
Let G be a CFG and let L (G) = A. Design a TM MG that decides A by buildinga copy of G into MG:MG =“On input string w, where G is a CFG:
1. Run TM S on input 〈G,w〉2. If this machine accepts, accept, otherwise reject.”
5 / 9
Decidability of context-free languages
TheoremEvery CFL is decidable.
Proof idea: simulate generation of string by respective CFG
Let G be a CFG and let L (G) = A. Design a TM MG that decides A by buildinga copy of G into MG:
MG =“On input string w, where G is a CFG:
1. Run TM S on input 〈G,w〉2. If this machine accepts, accept, otherwise reject.”
5 / 9
Decidability of context-free languages
TheoremEvery CFL is decidable.
Proof idea: simulate generation of string by respective CFG
Let G be a CFG and let L (G) = A. Design a TM MG that decides A by buildinga copy of G into MG:MG =“On input string w, where G is a CFG:
1. Run TM S on input 〈G,w〉2. If this machine accepts, accept, otherwise reject.”
5 / 9
Methodology for deciding languages relationships
To solve decidability problems concerning relations between languages onesshould proceed as follows:
B Understand the relationship
B Transform the relationship into an expression using closure operators ondecidable languages
B Designing a TM that constructs the language thus expressed
B Run a TM that decides the language represented by the expression
6 / 9
Example
Consider checking the equivalence of DFAs and Regular Expressions.
B We express this problem as the language
EQDFA,REX = {〈A,R〉 | A is a DFA, R is a regex, and L (A) = L (R)}
B Since regexs can de reduced into DFAs and DFAs are closed undersymmetric difference, we can proceed similarly as we did for proving thedecidability of EQDFA
E =“On input string 〈A,R〉, where A is a DFA and R is a regex:
1. Convert R to an equivalent DFA B
2. Use the TM C, for deciding EQDFA, on input 〈A,B〉3. If C accepts, accept, otherwise reject.”
7 / 9
Example
Consider checking the equivalence of DFAs and Regular Expressions.
B We express this problem as the language
EQDFA,REX = {〈A,R〉 | A is a DFA, R is a regex, and L (A) = L (R)}
B Since regexs can de reduced into DFAs and DFAs are closed undersymmetric difference, we can proceed similarly as we did for proving thedecidability of EQDFA
E =“On input string 〈A,R〉, where A is a DFA and R is a regex:
1. Convert R to an equivalent DFA B
2. Use the TM C, for deciding EQDFA, on input 〈A,B〉3. If C accepts, accept, otherwise reject.”
7 / 9
Another example
Is the problem of testing whether a CFG generates some string 1∗ decidable?
B We can formulate this problem as showing the decidability of
A = {〈G〉 | G is a CFG over {0,1}∗ and L (1∗)∩L (G) 6=∅}
B We know that 1∗ defines a regular language, that L (G) is a CFL, and thatL (1∗)∩L (G) is a CFL.
B We know how to check emptiness of CFLs!
X =“On input string 〈G〉, where G is a CFG:
1. Construct CFG H such that L (H) = L (1∗)∩L (G)
2. Run the TM R, which decides the language ECFG, on input 〈H〉3. If R accepts, reject, otherwise accept.”
8 / 9
Another example
Is the problem of testing whether a CFG generates some string 1∗ decidable?
B We can formulate this problem as showing the decidability of
A = {〈G〉 | G is a CFG over {0,1}∗ and L (1∗)∩L (G) 6=∅}
B We know that 1∗ defines a regular language, that L (G) is a CFL, and thatL (1∗)∩L (G) is a CFL.
B We know how to check emptiness of CFLs!
X =“On input string 〈G〉, where G is a CFG:
1. Construct CFG H such that L (H) = L (1∗)∩L (G)
2. Run the TM R, which decides the language ECFG, on input 〈H〉3. If R accepts, reject, otherwise accept.”
8 / 9
Another example
Is the problem of testing whether a CFG generates some string 1∗ decidable?
B We can formulate this problem as showing the decidability of
A = {〈G〉 | G is a CFG over {0,1}∗ and L (1∗)∩L (G) 6=∅}
B We know that 1∗ defines a regular language, that L (G) is a CFL, and thatL (1∗)∩L (G) is a CFL.
B We know how to check emptiness of CFLs!
X =“On input string 〈G〉, where G is a CFG:
1. Construct CFG H such that L (H) = L (1∗)∩L (G)
2. Run the TM R, which decides the language ECFG, on input 〈H〉3. If R accepts, reject, otherwise accept.”
8 / 9
Another example
Is the problem of testing whether a CFG generates some string 1∗ decidable?
B We can formulate this problem as showing the decidability of
A = {〈G〉 | G is a CFG over {0,1}∗ and L (1∗)∩L (G) 6=∅}
B We know that 1∗ defines a regular language, that L (G) is a CFL, and thatL (1∗)∩L (G) is a CFL.
B We know how to check emptiness of CFLs!
X =“On input string 〈G〉, where G is a CFG:
1. Construct CFG H such that L (H) = L (1∗)∩L (G)
2. Run the TM R, which decides the language ECFG, on input 〈H〉3. If R accepts, reject, otherwise accept.”
8 / 9
Yet another example
Is the language generated by particular regular expressions decidable? Forexample, is the language of regular expressions that contain at least one stringthat has the pattern 111 as a substring decidable?
B We can formulate this problem as showing the decidability of
A = {〈R〉 | R is a regex for a language with at leas one string w = x111y}
B To decide A we need to be able determine whether for any regex R it is thecase that L (R) contains some string x111y.
B I.e. whether L (Σ∗111Σ∗)∩L (R) 6=∅.
Z =“On input string 〈R〉, where R is a regex:
1. Construct the DFA E that accepts L (Σ∗111Σ∗)
2. Construct the DFA B that accepts L (E)∩L (R)
2. Run the TM T , which decides EDFA, on input 〈B〉3. If T accepts, reject, otherwise accept.”
9 / 9
Yet another example
Is the language generated by particular regular expressions decidable? Forexample, is the language of regular expressions that contain at least one stringthat has the pattern 111 as a substring decidable?
B We can formulate this problem as showing the decidability of
A = {〈R〉 | R is a regex for a language with at leas one string w = x111y}
B To decide A we need to be able determine whether for any regex R it is thecase that L (R) contains some string x111y.
B I.e. whether L (Σ∗111Σ∗)∩L (R) 6=∅.
Z =“On input string 〈R〉, where R is a regex:
1. Construct the DFA E that accepts L (Σ∗111Σ∗)
2. Construct the DFA B that accepts L (E)∩L (R)
2. Run the TM T , which decides EDFA, on input 〈B〉3. If T accepts, reject, otherwise accept.”
9 / 9
Yet another example
Is the language generated by particular regular expressions decidable? Forexample, is the language of regular expressions that contain at least one stringthat has the pattern 111 as a substring decidable?
B We can formulate this problem as showing the decidability of
A = {〈R〉 | R is a regex for a language with at leas one string w = x111y}
B To decide A we need to be able determine whether for any regex R it is thecase that L (R) contains some string x111y.
B I.e. whether L (Σ∗111Σ∗)∩L (R) 6=∅.
Z =“On input string 〈R〉, where R is a regex:
1. Construct the DFA E that accepts L (Σ∗111Σ∗)
2. Construct the DFA B that accepts L (E)∩L (R)
2. Run the TM T , which decides EDFA, on input 〈B〉3. If T accepts, reject, otherwise accept.”
9 / 9
Yet another example
Is the language generated by particular regular expressions decidable? Forexample, is the language of regular expressions that contain at least one stringthat has the pattern 111 as a substring decidable?
B We can formulate this problem as showing the decidability of
A = {〈R〉 | R is a regex for a language with at leas one string w = x111y}
B To decide A we need to be able determine whether for any regex R it is thecase that L (R) contains some string x111y.
B I.e. whether L (Σ∗111Σ∗)∩L (R) 6=∅.
Z =“On input string 〈R〉, where R is a regex:
1. Construct the DFA E that accepts L (Σ∗111Σ∗)
2. Construct the DFA B that accepts L (E)∩L (R)
2. Run the TM T , which decides EDFA, on input 〈B〉3. If T accepts, reject, otherwise accept.”
9 / 9