Title: CS 3240: Languages and Computation
1CS 3240 Languages and Computation
- Decidable Languages and The Halting Problem
2Decidability
- A language is decidable if some Turing machine
decides it - Not all languages are decidable
- How to show a language is decidable?
- Write a decider that decides it
- Accepts w iff w is in the language
- Must halt on all inputs
3DFA Acceptance Problem
- Consider the language ADFA ltB,wgt B is a DFA
that accepts the string w - Theorem ADFA is a decidable language
- Proof Consider the following TM, M
- On input string ltB,wgt, where B is a DFA and w is
an input to B - Simulate B on input w
- If simulation ends in accept state, accept.
Otherwise, reject.
4NFA Acceptance Problem
- Consider the language
- ANFA ltB,wgt B is a NFA that accepts the
string w - Theorem ANFA is a decidable language
- Proof Consider the following TM, NOn input
string ltB,wgt - Convert B to a DFA C
- Run TM M from previous slide on ltC,wgt
- If M accepts, accept. Otherwise, reject.
5RE Acceptance Problem
- Consider the language
- AREX ltR,wgt R is an RE that generates the
string w - Theorem AREX is a decidable language
- Proof Consider the following TM, P
- On input string ltR,wgt
- Convert R to a DFA C using algorithm discussed in
class and in text - Run TM M from earlier slide on ltC,wgt
- If M accepts, accept. Otherwise, reject.
6Emptiness Testing Problem
- Consider the language
- EDFA ltAgt A is a DFA and L(A) ?
- Theorem EDFA is a decidable language
- Proof Consider the following TM, T
- On input string ltAgt, where A is a DFA
- Mark the start state
- Repeat until no new states get marked
- Mark any state that has a transition coming into
it from any state already marked - If no accept states are marked, accept.
Otherwise, reject.
7DFA Equivalence Problem
- EQDFA ltA,Bgt A and B are DFAs and L(A)
L(B) - Theorem EQDFA is a decidable language
- Proof Consider the following language
- (L(A) ? L(B)) ? (L(A) ? L(B))
8DFA Equivalence Problem
- (L(A) ? L(B)) ? (L(A) ? L(B))
-
9DFA Equivalence Problem
- EQDFA ltA,Bgt A and B are DFAs and L(A)
L(B) - Theorem EQDFA is a decidable language
- Proof idea Consider DFA C that accepts L(C)
(L(A) ? L(B)) ? (L(A) ? L(B)) - How do we know such a DFA exists?
- If L(C) ?, then L(A) L(B)
10TM That Decides EQDFA
- On input string ltA,Bgt, where A and B are DFAs
- Create DFA C such that
- L(C) (L(A) ? L(B)) ? (L(A) ? L(B))
- Submit C to Turing machine T that decides EDFA
- If T accepts C, accept. Otherwise, reject.
11Deciders and CFGs
- Consider the following language
- ACFG ltG,wgt G is a CFG that generates string
w - Is ACFG decidable?
- How can we get a TM to simulate a CFG?
- Must be certain CFG tries a finite number of
steps! - Solution Use Chomsky normal form
12Chomsky Normal Form Review
- All rules are of the form
- A ?BC
- A ?a
- Where A, B, and C are any variables (B and C
cannot be the start variable) - S ?eis the only erule, where S is the start
variable
13How Many Steps to Generate w?
- If w 0
- 1 step
- If w n gt 0?
- 2n 1 steps
14TM Simulating ACFG
- On input ltGgt, where G is a CFG
- Convert G into Chomsky normal form
- If w 0
- If there is an S ? e rule, accept
- Otherwise, reject
- List all derivations with 2w-1 steps
- If any generate w, accept
- Otherwise, reject
15Empty CFGs
- Consider the following language
- ECFG ltGgt G is a CFG and L(G) ?
- Theorem ECFG is decidable
- Can we use the TM in ACFG to prove this?
- No. There are infinitely many possible strings
in S - We need to check if there is any way to get from
the start variable to some string of terminals
16Work Backwards
- On input ltGgt, where G is a CFG
- Mark all terminals
- Repeat until no new variables are marked
- Mark any variable A if G has a rule A?U1U2Uk
where U1, U2, , Uk are all marked - If S is marked, reject Otherwise, accept
17What About EQCFG?
- Recall for EQDFA, we considered
- (L(A) ? L(B)) ? (L(A) ? L(B))
- Will this work for CFGs?
- No. CFGs are not closed under complementation or
intersection - EQCFG is not a decidable language!
- We will show this later
18Decidability of CFLs
- Theorem Every context-free language L is
decidable - Can we make a TM that simulates a PDA?
- No. May run into infinite loop.
- Proof idea For each w, we need to decide
whether or not w is in L. Let G be a CFG for L.
This problem boils down to ACFG, which we showed
is decidable.
19Summary of Decidable Languages
20Turing Machine Acceptance Problem
- Consider the following language
- ATMltM,wgt M is a TM that accepts w
- Theorem ATM is Turing-recognizable
- Theorem ATM is undecidable
- Proof idea Construct a universal Turing machine
recognizes, but does not decide, ATM
21The Universal Turing Machine
- U On input ltM, wgt, where M is a TM and w is a
string - Simulate M on input w
- If M ever enters its accept state, accept
- If M ever enters its reject state, reject
22Why Cant U Decide ATM?
- Intuitively, if M never halts on w, then U never
halts on ltM,wgt - Given a TM M and a string w, does M halt on input
w? - This is also known as the halting problem
- It is undecidable
- We will prove this more rigorously later
23Comparing Sizes of Infinite Sets
- Given two infinite sets A and B, is there a way
to determine whether AB or if AgtB? - Functional correspondence can show two infinite
sets have the same number of elements - Diagonalization can show one infinite set has
more elements than another
24Functional Correspondence
- Let f be a function from A to B
- f is called injective (one-to-one) if
- f(a1) ? f(a2) whenever a1 ? a2
- f is called surjective (onto) if
- For every b ? B, there is some a ? A such that
f(a) b - f is called a correspondence if it is injective
and surjective - A correspondence is a way to pair elements of the
two sets
25Example Correspondence
- Consider fZ ? P, where Z 0,1,2, and P
positive squares - P 1, 4, 9, 16, 25,
- f(x) (x1)2
- Is f one-to-one?
- Yes
- Is f onto?
- Yes
- Therefore Z P
26Countable Sets
- Let N 1, 2, 3, be the set of natural
numbers - The set A is countable if
- A is finite, or
- A N
- Some example of countable sets
- Integers
- x x ? Z and x 1 (mod 3)
27The Positive Rational Numbers
- Is Q m/n m,n ? N countable?
- Yes!
- Construct a one-to-one mapping
28The Real Numbers
- Is R (set of positive real numbers) countable?
- No!
X 4.1337 Diagonalization
29The Set of All Infinite Binary Strings
- Is the set of all infinite binary strings
countable? - No
- Diagonalization also works to prove this is not
countable - On the other hand, the set of finite length
binary strings is countable! - Let xb be the binary representation of x
- f(x) xb is 1-to-1 and onto function from N to
the set of finite binary strings
30Languages in S
- Is the set of all languages in S countable?
- No
- It has the same cardinality as the set of binary
strings - S e, a, b, aa, ab, ba, bb, aaa, aab,
- A a, ab, aaa,
- ?A 0 1 0 0 1 0 0 1
31S vs. Languages in S
- The set S is countable
- Let S n
- Every string in S can be associated with a
unique number, y, in base-(n1) - E.g., if S a, b, c, we can associate the
string acba with the value 143342241140
121 - Let f(x) be the string associated with x
- The set of all languages in Sis the power set of
S
32Turing Machines
- Is the set of all TMs countable?
- Yes
- Since all Turing machines can be represented by a
string of finite length, the set of all Turing
machines are countable - Theorem Some languages are not
Turing-recognizable - Proof idea There are more languages than there
are Turing machines
33Undecidability of ATM
- Theorem ATM is undecidable
- Proof (By contradiction) Assume ATM is
decidable and let H be a decider for ATM - H(ltM,wgt)
accept if M accepts w reject if M does not
accept w
34Proof (cont.)
- Consider the TM D that submits the string ltMgt as
input to the TM M - D On input ltMgt, where M is a TM
- Run H on input ltM,ltMgtgt
- If H accepts ltM,ltMgtgt, reject
- If H rejects ltM,ltMgtgt, accept
- Since H is a decider, it must accept or reject
- Therefore, D is a decider as well
35Proof (cont.)
- What happens if Ds input is ltDgt?
- D(ltDgt)
- D cannot exist!
- Therefore, H cannot exist i.e., ATM is
undecidable
reject if D accepts ltDgt accept if D does not
accept ltDgt
36Undecidable languages
Turing recognizable
Co-Turing recognizable
Decidable