theory of computation (ix)basics.sjtu.edu.cn/~chen/teaching/toc/sip9.pdf · the theory of...

37
Theory of Computation (IX) Yijia Chen Fudan University

Upload: others

Post on 15-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Theory of Computation (IX)

Yijia ChenFudan University

Page 2: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Review

Page 3: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

The Definition of Algorithm

Page 4: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Polynomials and their roots

A polynomial is a sum of terms, where each term is a product of certainvariables and a constant, i.e., coefficient. For example,

6 · x · x · x · y · z · z = 6x3yz2

is a term with coefficient 6, and

6x3yz2 + 3xy 2 − x3 − 10

is a polynomial with four terms, over the variables x , y , and z .

A root of a polynomial is an assignment of values to its variables so that thevalue of the polynomial is 0. This root is an integral root because all thevariables are assigned integer values. Some polynomials have an integral rootand some do not.

Page 5: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Hilbert’s Problems

Hilbert’s tenth problem was to devise an algorithm that tests whether apolynomial has an integral root. He did not use the term algorithm but rather

a process according to which it can be determined by a finite numberof operations.

Page 6: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Church-Turing Thesis

In 1936 to formalize the definition of an algorithm:

1. Alonzo Church proposed λ-calculus;

2. Alan Turing proposed Turing machines,

which were shown to be equivalent.

So we have the Church-Turing Thesis:

Intuitive notion of algorithms = Turing machine algorithms.

Page 7: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Hilbert’s Tenth Problem

D ={

p∣∣ p is a polynomial with integer coefficients

and with an integral root}.

Theorem (Yuri Matijasevic, Martin Davis, Hilary Putnam, and JuliaRobinson, 1970)

D is not decidable.

Page 8: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

A simple variant

D1 ={

p∣∣ p is a polynomial on a single variable x with

integer coefficients and with an integral root}.

LemmaBoth D and D1 are Turing-recognizable.

Proof.On input p(x)

evaluate p with x set successively to the values 0, 1, −1, 2, −2, 3,−3, . . . . If at any point the polynomial evaluates to 0, then accept.

Page 9: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

A simple variant (con’d)

LemmaLet

p(x) = c1xn + c2xn−1 + · · ·+ cnx + cn+1

with c1 6= 0 and p(x0) = 0. Define

cmax = max{|ci |

}i∈[n+1]

.

Then

|x0| <cmax · (n + 1)

|c1|.

Corollary

D1 is decidable.

Page 10: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Decidability

Page 11: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Decidable Languages

Page 12: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Decidable problems concerning regular languages

ADFA ={〈B,w〉

∣∣ B is a DFA that accepts input string w}.

That is, for every w ∈ Σ∗ and DFA B,

w ∈ L(B) ⇐⇒ 〈B, x〉 ∈ ADFA.

TheoremADFA is a decidable language.

Page 13: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Proof (1)

M on 〈B,w〉:

1. Simulate B on input w .

2. If the simulation ends in an accepting state, then accept. If it ends in anonaccepting state, then reject.

Page 14: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Proof (2)

Some implementation details:

I The representation of B is a list of Q, Σ, δ, q0, and F .

I When M receives its input, M first determines whether it properlyrepresents a DFA B and a string w . If not, M rejects.

I Then M carries out the simulation directly.1. It keeps track of B’s current state and position in w by writing this

information down on its tape.

2. Initially, B’s current state is q0 and current input position is the leftmostsymbol of w .

3. The states and position are updated according to the specified transitionfunction δ.

4. When M finishes processing the last symbol of w, M accepts the input if Bis in an accepting state; M rejects the input if B is in a nonaccepting state.

Page 15: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

ANFA ={〈B,w〉

∣∣ B is an NFA that accepts input string w}.

That is, for every w ∈ Σ∗ and NFA B,

w ∈ L(B) ⇐⇒ 〈B, x〉 ∈ ANFA.

TheoremANFA is a decidable language.

Page 16: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Proof (1)

The simplest proof is to simulate an NFA using nondeterministic Turingmachine, as we used the (deterministic) Turing machine M to simulate a DFA.

Instead we design a (deterministic) Turing machine N which uses M as asubroutine.

Page 17: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Proof (2)

N on 〈B,w〉:

1. Convert NFA B to an equivalent DFA C using the subset construction.

2. Run TM M from the previous Theorem on input 〈C ,w〉.

3. If M accepts, then accept; otherwise reject.

Page 18: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

AREX ={〈R,w〉

∣∣ R is a regular expression that generates w}.

TheoremAREX is a decidable language.

Page 19: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Proof

P on 〈R,w〉:

1. Convert R to an equivalent NFA A.

2. Run TM N from the previous Theorem on input 〈A,w〉.

3. If N accepts, then accept; otherwise reject.

Page 20: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Testing the emptiness

EDFA ={〈A〉

∣∣ A is a DFA and L(A) = ∅}.

TheoremEDFA is a decidable language.

Page 21: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Proof

A DFA accepts some string if and only if reaching an accept state from thestart state by traveling along the arrows of the DFA is possible.

T on 〈A〉:

1. Mark the start state of A.

2. Repeat until no new states get marked:

3. Mark any state that has a transition coming into it from any statethat is already marked.

4. If no accept state is marked, then accept; otherwise, reject.

Page 22: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Testing equality

EQDFA ={〈A,B〉

∣∣ A are B are DFAs and L(A) = L(B)}.

TheoremEQDFA is a decidable language.

Page 23: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Proof (1)

From A and B we construct a DFA C such that

L(C) =(

L(A) ∩ L(B))∪(

L(A) ∩ L(B)),

i.e., the symmetric difference between L(A) and L(B).

Then

L(A) = L(B) ⇐⇒ L(C) = ∅.

Page 24: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Proof (2)

F on 〈A,B〉:

1. Construct DFA C from A and B.

2. Run TM T from the previous Theorem on input 〈C〉.

3. If T accepts, then accept; otherwise reject.

Page 25: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Decidable problems concerning context-free languages

ACFG ={〈G ,w〉

∣∣ G is a CFG that generates w}.

TheoremACFG is a decidable language.

Page 26: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Proof (1)

For CFG G and string w , we want to determine whether G generates w .

One idea is to use G to go through all derivations to determine whether any isa derivation of w . Then if G does not generate w , this algorithm would neverhalt. It gives a Turing machine that is a recognizer, but not a decider.

Page 27: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Recall:

DefinitionA context-free grammar is in Chomsky normal form if every rule is of the form

A→ BC and A→ a

where a is a terminal, and A, B, and C are variables – except that B and Cmay be not the start variable. In addition, we permit the rule S → ε, where Sis the start variable.

TheoremAny context-free language is generated by a context-free grammar in Chomskynormal form.

TheoremLet G be CFG in Chomsky normal form, and G generates w with w 6= ε. Thenany derivation of w has 2|w | − 1 steps.

Page 28: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Proof (2)

S on 〈G ,w〉:

1. Convert G to an equivalent grammar in Chomsky normal form.

2. List all derivations with 2|w | − 1 steps; except if |w | = 0, then insteadcheck whether there is a rule S → ε.

3. If any of these derivations generates w , then accept; otherwise reject.

Page 29: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Testing the emptiness

ECFG ={〈G〉

∣∣ G is a CFG and L(G) = ∅}.

TheoremECFG is a decidable language.

Page 30: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Proof (1)

To determine whether L(G) = ∅, the algorithm might try going through allpossible w ’s, one by one. But there are infinitely many w ’s to try, so thismethod could end up running forever.

Instead, the algorithm solves a more general problem: determine for eachvariable whether that variable is capable of generating a string of terminals.

I First, the algorithm marks all the terminal symbols in the grammar.

I It scans all the rules of the grammar. If it finds a rule that permits somevariable to be replaced by some string of symbols, all of which are alreadymarked, then it marks this variable.

Page 31: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Proof (2)

R on 〈G〉:

1. Mark all terminal symbols in G .

2. Repeat until no new variables get marked:

3. Mark any variable A where G contains a rule A→ U1 · · ·Uk and all Ui ’shave already been marked.

4. If the start variable is not marked, then accept; otherwise, reject.

Page 32: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Testing equality

EQCFG ={〈G ,H〉

∣∣ G are H are CFGs and L(G) = L(H)}.

TheoremEQCFG is not decidable.

Page 33: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

TheoremEvery context-free language is decidable.

Recall using Chomsky normal form, we have shown:

TheoremACFG =

{〈G ,w〉

∣∣ G is a CFG that generates w}

is a decidable language.

Page 34: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Relationship among classes of languages

4.2 UNDECIDABILITY 201

FIGURE 4.10

The relationship among classes of languages

4.2UNDECIDABILITY

In this section, we prove one of the most philosophically important theorems ofthe theory of computation: There is a specific problem that is algorithmicallyunsolvable. Computers appear to be so powerful that you may believe that allproblems will eventually yield to them. The theorem presented here demon-strates that computers are limited in a fundamental way.

What sorts of problems are unsolvable by computer? Are they esoteric,dwelling only in the minds of theoreticians? No! Even some ordinary prob-lems that people want to solve turn out to be computationally unsolvable.

In one type of unsolvable problem, you are given a computer program anda precise specification of what that program is supposed to do (e.g., sort a listof numbers). You need to verify that the program performs as specified (i.e.,that it is correct). Because both the program and the specification are mathe-matically precise objects, you hope to automate the process of verification byfeeding these objects into a suitably programmed computer. However, you willbe disappointed. The general problem of software verification is not solvable bycomputer.

In this section and in Chapter 5, you will encounter several computationallyunsolvable problems. We aim to help you develop a feeling for the types ofproblems that are unsolvable and to learn techniques for proving unsolvability.

Now we turn to our first theorem that establishes the undecidability of a spe-cific language: the problem of determining whether a Turing machine accepts a

Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional

content at any time if subsequent rights restrictions require it.

Page 35: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Undecidability

Page 36: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

Testing membership

ATM ={〈M,w〉

∣∣ M is a TM and M accepts w}.

TheoremATM is not decidable.

Page 37: Theory of Computation (IX)basics.sjtu.edu.cn/~chen/teaching/TOC/sip9.pdf · the theory of computation: There is a specic problem that is algorithmically unsolvable. Computers appear

TheoremATM is Turing-recognizable.

Proof.U on 〈M,w〉:

1. Simulate M on w .

2. If M enters its accept state, then accept; if it enters its reject state, reject.

U is a universal Turing machine first proposed by Alan Turing in 1936. Thismachine is called universal because it is capable of simulating any other Turingmachine from the description of that machine.