0% found this document useful (0 votes)
2 views

Lecture 11 Decidability

The document discusses the equivalence of programming languages and Turing Machines (TMs), emphasizing that Turing-complete languages can recognize the same set of languages. It covers the encoding of TMs and other computational models, the decidability of various languages, and the construction of TMs to decide these languages. Additionally, it introduces Chomsky Normal Form for Context-Free Grammars (CFGs) and presents several theorems related to decidable languages.

Uploaded by

Sauron
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lecture 11 Decidability

The document discusses the equivalence of programming languages and Turing Machines (TMs), emphasizing that Turing-complete languages can recognize the same set of languages. It covers the encoding of TMs and other computational models, the decidability of various languages, and the construction of TMs to decide these languages. Additionally, it introduces Chomsky Normal Form for Context-Free Grammars (CFGs) and presents several theorems related to decidable languages.

Uploaded by

Sauron
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Programming languages

• Programming languages like Java, Python,


Scheme, C, … are equivalent to TMs
• We call such languages Turing-complete

Corollary. If two programming languages are Turing-complete,


then they can recognize exactly the same set of languages.

04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L12.1


A universal Turing Machine
• Since TMs and programming languages are equivalent, we can
think of TMs as programs.
• Since programs are strings, we can consider languages whose
elements are programs.

04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.2


Encoding Complex Problems
is connected graph}

1 2

3 4

¿ 𝑮 >¿ ( 𝟏 , 𝟐 ,𝟑 ,𝟒 ) ( ( 𝟏 ,𝟐 ) , ( 𝟏 , 𝟑 ) , ( 𝟏 , 𝟒 ) , ( 𝟑 , 𝟒 ) )
Can we encode a Turing Machine
as a string of 0s and 1s?
• 〈 O 〉 denotes an encoding of object O as a string
start reject
states Q={0,1,…,n-1} state state

0n10m10k10s10t10r10u1… 〈  〉
tape symbols Γ={0,1…,m-1} blank
(first k are input symbols) accept
symbol
state
 : 〈 (p,a), (q,b,L) 〉 = 0p10a10q10b10
04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.4
A universal Turing Machine
• Since TMs and programming languages are equivalent, we can
think of TMs as programs.
• Since programs are strings, we can consider languages whose
elements are programs.
• 〈 M 〉 denotes an encoding of a TM M as a string

Theorem. We can make a Universal TM, a TM that takes any TM


description 〈 M 〉 and a description of any string w as input and
simulates the computation of M on w.
〈M〉 encoding of M
FINITE
CONTROL 〈w〉 tape contents
〈 q0 〉 state
04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.5
Encodings of DFAs, NFAs, CFGs, etc

• Similarly, we can encode DFAs, NFAs, regular expressions,


PDAs, CFGs, etc into strings of 0s and 1s.
• We can define the following languages:
ADFA = { 〈 D,w 〉 | D is a DFA that accepts string w }

ANFA = { 〈 N,w 〉 | N is an NFA that accepts string w }

ACFG = { 〈 G,w 〉 | G is a CFG that generates string w }

04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.6


Theorem. ADFA is decidable.

Proof: The following TM M decides ADFA.


M = `` On input , where is a DFA and is a string:
1. Check if input (to M) is legal, reject if not.
(This step is assumed to be the first step of every algorithm.)
2. Simulate on .

M Current state of

3. Accept if ends in an accept state. O.w. reject.’’


Corollary. ANFA is decidable.
(1. Convert input NFA to an equivalent DFA .)
04/07/2025 L14.7
Slides have been taken from https://cs-people.bu.edu/sofya/cs332/
Theorem. ACFG is decidable.

ACFG = { 〈 G,w 〉 | G is a CFG that generates string w }

04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.8


Chomsky Normal Form for CFGs

• Can have a rule .


• All remaining rules are of the form

• Cannot have on the RHS of any rule.


Lemma. Any CFG can be converted into an equivalent
CFG in Chomsky normal form. (Proof in Sipser.)
Lemma. If G is in Chomsky normal form, any derivation
of string w of length in G has steps.

04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.9


Chomsky Normal Form for CFGs

Lemma. If G is in Chomsky normal form, any derivation


of string of length in G has steps.
Proof idea:
• Only rules of the form increase the number of symbols:
need to apply rules of this form times.
• Only rules of the form replace variables with terminals:
need to apply rules of this form times.

04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.10


Theorem. ACFG is decidable.

ACFG = { 〈 G,w 〉 | G is a CFG that generates string w }


Proof: The following TM M decides ACFG.
M = `` On input , where is a CFG and is a string:
1. Convert G to Chomsky normal form.
2. Let .
3. Test all derivations with steps.
4. Accept if any derived . O.w. reject.’’

04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.11


Examples of decidable languages

ADFA = { 〈 D,w 〉 | D is a DFA that accepts string w }

ANFA = { 〈 N,w 〉 | N is an NFA that accepts string w }

ACFG = { 〈 G,w 〉 | G is a CFG that generates string w }

04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.12


More decidable languages

EDFA = { 〈 D 〉 | D is a DFA that recognizes the empty language }

EQDFA = { 〈〉 | are DFAs and }

ECFG = { 〈 G 〉 | G is a CFG that generates the empty language}

04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.13


Theorem. EDFA is decidable.

EDFA = { is a DFA that recognizes .}


Proof: The following TM M decides EDFA.
M = `` On input , where is a DFA:
1. Use BFS to determine if an accepting state of D
is reachable from from its start state.
2. Accept if not. O.w. reject.’’

04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.14


Theorem. EQDFA is decidable.

EQDFA = { are DFAs & }


Proof: The following TM M decides EQDFA.
M = `` On input , where are DFAs:
1. Construct a DFA D that recognizes
the set difference of and .
2. Run the decider for EDFA on <D>.
3. If it accepts, accept. O.w. reject.’’

04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.15


Theorem. ECFG is decidable.

ECFG = { is a CFG that recognizes .}


Proof: The following TM M decides ECFG.
M = `` On input , where is a CFG:
1. Mark all terminals in G.
2. Repeat until no new variable is marked:
3. Mark any variable A where G has a rule A and
each variable/terminal on the RHS is already marked.
4. Accept if the start variable is unmarked. O.w. reject.’’

04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.16


Exercises

• Prove that the following language is decidable:


RDFA = { 〈 D,w 〉 | D is a DFA that rejects string w }

• Formulate the following problem as a language and prove that it


is decidable:
Given a PDA and a string, determine if the PDA accepts the string.

APDA = { 〈 P,w 〉 | P is a PDA that accepts string w }


Can a TM just simulate P on w, accept if it accepts and reject o.w.?

04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.17


Exercise

A decider for APDA can, on input <P, w>


A. simulate P on w, accept if it accepts and reject o.w.
B. convert P to an equivalent CFG G and then run a
decider for ACFG, accept if it accepts and reject o.w.
C. convert P to an equivalent CFG G and then run a
decider for ACFG, accept if it rejects and accept o.w.
D. None of the above.
E. More than one choice above works.
Last lecture

• We can encode DFAs, NFAs, regular expressions, PDAs, CFGs,


etc into strings of 0s and 1s.
• The following languages are decidable:
ADFA = { 〈 D,w 〉 | D is a DFA that accepts string w }

ANFA = { 〈 N,w 〉 | N is an NFA that accepts string w }

ACFG = { 〈 G,w 〉 | G is a CFG that generates string w }

04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.19


Decidable languages: more examples

EDFA = { 〈 D 〉 | D is a DFA that recognizes the empty language }

EQDFA = { 〈〉 | are DFAs and }

ECFG = { 〈 G 〉 | G is a CFG that generates the empty language}

Theorem. Every CFL is decidable.

04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.20


Theorem. Every CFL is decidable.

Proof: Let G be a CFG for L.


Design a TM that decides L.
• Is it a good idea to convert G to an equivalent
PDA P and have simulate P?
M = `` On input :
1. Run the decider for ACFG on input <G,w>.
2. Accept if yes. O.w. reject.’’

04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.21


Classes of languages

recognizable

decidable
CFL

regular

04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.22


Theorem. INFINITEDFA is decidable.

INFINITEDFA = { 〈 D 〉 | D is a DFA and L(D) is infinite}


Idea: Let be the number of states in D.
L(D) is infinite iff D accepts a string of length
Proof: The following TM M decides INFINITEDFA.
M = `` On input , where is a DFA:
1. Let be the number of states in D.
2. Let C be a DFA for {w | |w| ≥ n}.
3. Build a DFA B for L(C) ∩ L(D).
4. Run a decider for EDFA on
5. Accept if it rejects. O.w. reject.’’
04/07/2025 Slides have been taken from https://cs-people.bu.edu/sofya/cs332/ L14.23

You might also like