Theory of Computation
Lec-36-39: Decidability & Undecidability
Dr. Ramesh K. Jallu
Introduction
• We have seen that Turing machines form a model for “everything that
is intuitively computable”
• Now, we will explore the limitations of Turing machines
• We demonstrate certain problems that can be solved algorithmically
and others that cannot
• In fact, we will even see that “most” problems are not solvable by
Turing machines and, therefore, not solvable by computers/TMs
Algorithms as TMs
• We continue to speak of Turing machines, but our real focus from now
on is on algorithms
• That is, the Turing machine merely serves as a precise model for the
definition of algorithm
• We skip over the extensive theory of Turing machines themselves and
do not spend much time on the low-level programming/transactions of
Turing machines
• We need only to be comfortable enough with Turing machines to
believe that they capture all algorithms
Decidable languages (Recap)
• We say that a language L is decidable, if there exists a Turing machine
M, such that for every string w ∈ Σ∗, the following holds:
1. If w ∈ L, then the computation of the Turing machine M, on the input string
w, terminates in the accept state.
2. If w ∉ L, then the computation of the Turing machine M, on the input string
w, terminates in the reject state.
• A language L that is not decidable is called undecidable
• For such a language, there does not exist an algorithm that satisfies (1)
and (2) above
Some decidable problems related to FA
• We give algorithms for testing
• Whether a finite automaton accepts a string
• Whether the language of a finite automaton is empty
• Whether two finite automata are equivalent, etc.
• We represent computational problems in the form of languages
• The elements of the language are pairs of the form ⟨C, w⟩, where C is some
computation model and w is a string over the alphabet
• That is L = {⟨C, w⟩ | w ∈ L(C)}
• The pair ⟨C, w⟩ is in the language L if and only if the string w is in the
language of the computation model C
• We formulated computational problems in terms of testing
membership in a language
The language ADFA
• The acceptance problem for DFAs of testing whether a particular
deterministic finite automaton accepts a given string can be expressed as a
language ADFA
• This language contains the encodings of all DFAs together with strings
that the DFAs accept
• Define ADFA = {⟨M, w⟩| M is a DFA that accepts input string w}
• The problem of testing whether a DFA M accepts an input w is the
same as the problem of testing whether ⟨M, w⟩ is a member of the
language ADFA
• Showing that a language is decidable is the same as showing that the
computational problem is decidable
Encoding finite automata as strings
• Let M = (Q, Σ, δ, q0, F) be a DFA
• We try to encode M as a unary string
• Encoding Q
• For Q = {q0, q1, . . ., qn−1}, encode qi using i + 1 0’s, i.e., using the string 0i + 1
• Encoding Σ
• For Σ = {a1, a2, . . . am}, encode ai using i 0’s, i.e., using the string 0i
• Encoding δ
• Each entry of δ, e.g., δ(qi , aj) = qk is encoded as
• The whole δ can be encoded as
Cont...
• Encoding F
• F can be encoded just as a list of the encodings of all the final states
• For example, if states 2 and 4 are the final states, F could be encoded as
• The whole DFA M would be encoded by
⟨M ⟩ =
• Similarly strings over Σ can be encoded with (the same convention)
• ⟨M, w⟩ represents the encoding of a machine followed by an input string, in
the manner above with a suitable separator between ⟨M ⟩, ⟨w⟩
Theorem 1
• We will show that ADFA is decidable: As a result the problem of testing
whether a given finite automaton accepts a given string is decidable
• Theorem: The language ADFA is decidable
• Proof: We will try to design a TM M1 that decides ADFA
• M1 = “On input ⟨M, w⟩, where M is a DFA and w is a string:
• Simulate M on input w
• If the simulation ends in an accept state, accept. If it ends in a nonaccepting
state, reject .”
• We can prove a similar theorem for nondeterministic finite automata
• Let ANFA = {⟨M, w⟩| M is an NFA that accepts input string w}
Theorem 2: ANFA is decidable
• M2 = “On input ⟨M, w⟩, where M is an NFA and w is a string:
1. If input ⟨M, w⟩ is not proper encoding of NFA M and
string w, reject
1. Convert NFA M to an equivalent DFA N
2. Run TM M1 on input ⟨N, w⟩
3. If M1 accepts, accept; otherwise, reject.”
• We can determine whether a regular expression generates a
given string
• Let AREX = {⟨R, w⟩ | R is a regular expression that generates string w}
Theorem 3: AREX is a decidable language
• M3= “On input ⟨R, w⟩, where R is a regular expression and w is a
string:
1. Convert regular expression R to an equivalent NFA A
2. Run TM M2 on input ⟨A, w⟩
3. If M2 accepts, accept; if M2 rejects, reject.”
• How do we decide if L(M) is empty or not for a given DFA M?
• Let EDFA = {⟨M⟩| M is a DFA and L(M) = ∅}
Theorem 4: EDFA is a decidable language
• Determining whether two DFAs recognize the same language is
decidable
• Let EQDFA = {⟨A, B⟩ | A and B are DFAs and L(A) = L(B)}
Theorem 5: EQDFA is a decidable language
A few decidable properties of CFL (PDA)
• We describe algorithms to determine whether a CFG generates a
particular string and to determine whether the language of a CFG is
empty
• Let ACFG = {⟨G, w⟩| G is a CFG that generates string w}
• Theorem 6: ACFG is a decidable language
ECFG is a decidable language
• The emptiness testing problem for the language of a CFG is decidable
• As we did for DFAs, we can show that the problem of determining
whether a CFG generates any strings at all is decidable
• Let ECFG = {⟨G⟩| G is a CFG and L(G) = ∅}
• Theorem 7: ECFG is a decidable language
Relationship among languages
Undecidability
• Computers (TMs) are powerful, yet has some limitations
• There are problems that are algorithmically unsolvable
• We will study several computationally unsolvable problems
• In one type of unsolvable problem, we are given a computer program
and a precise specification of what that program is supposed to do
• If we need to verify that the program performs as specified (i.e., that it
is correct)
• Because both the program and the specification are mathematically
precise objects, we expect to automate the process of verification by
feeding these objects into a suitably programmed computer
Not always possible!
ATM is undecidable
• The problem of determining whether a Turing machine accepts a given
input string or not is undecidable
• Let ATM = {⟨M, w⟩| M is a TM and M accepts w}
• Observe that ATM is Turing recognizable
• The machine U recognizes ATM but cannot decide it as it loops on
input ⟨M, w⟩ if M loops on w
• If there is a way to determine that M was not halting on w, it could
reject in this case
The diagonalization method
• The proof of the undecidability of ATM uses a technique called
diagonalization, discovered by mathematician Georg Cantor in 1873
• The technique was invented to measure the sizes of infinite sets
• The set of real numbers and the set of integers
• What about the set of even integers and the set of all strings over {0,1}?
• Both sets are infinite and thus larger than any finite set, but is one of
the two larger than the other? How can we compare their relative size?
• Cantor observed that two finite sets have the same size if the elements
of one set can be paired with the elements of the other set
• We can extend this idea to infinite sets
Ex. N vs Q
Doesn't work for real numbers
Implication of diagonalization to RELs
• For any finite alphabet Σ, the set of all strings in Σ* is countable
• The set of all Turing machines is countable because each Turing
machine M has an encoding into a string ⟨M⟩
• Theorem: The set L of all languages over an alphabet Σ is
uncountable
• To prove the theorem, we will first prove that the set of all infinite
binary sequences is uncountable
• Let B be the set of all infinite binary sequences.
• We can show that B is uncountable by using a proof by
diagonalization
Proof (Cont..)
• To show that L is uncountable, we will give a correspondence with B
• That is each language in L has a unique sequence in B
• Let Σ* = {s1, s2, s3, . . .} and A ∈ L
• The ith bit of that sequence is a 1 if si ∈ A and is a 0 if si ∉ A
• Therefore, the set of languages cannot be countable
• As a result, there are some languages are not recognized by any TM
Theorem 8: ATM is undecidable
• Proof by contradiction
• Suppose that H is a decider for ATM
• Now we construct a new Turing machine D with H as a subroutine
• This new TM calls H to determine what M does when the input to M is
its own description ⟨M⟩
• Once D has determined this information, it does the opposite to H
Proof (Cont...)
• In summary
• What happens if we feed D with its own description ⟨D⟩?
Review of the proof
1. The decider H accepts ⟨M, w⟩ exactly when M accepts w
2. D rejects ⟨M⟩ exactly when M accepts ⟨M⟩
3. D rejects ⟨D⟩ exactly when D accepts ⟨D⟩
• Where did we use the diagonalization method?
• It becomes apparent when you examine tables of behavior for TMs H
and D
• In these tables we list all TMs down the rows, M1, M2, . . . , and all
their descriptions across the columns, ⟨M1⟩, ⟨M2⟩, . . . .
Cont...
Cont...
Turing unrecognizable language
• We say that a language is co-Turing-recognizable if it is the
complement of a Turing-recognizable language
• WKT a language is decidable if and only if it is Turing-recognizable
and co-Turing-recognizable
• The language
Thank you!