the church-turing thesis encoding of tms universal turing...

64
Computational Models Lecture 7, Spring 2011 The Church-Turing Thesis Encoding of TMs Universal Turing Machines The Halting/Acceptance problem The Halting/Acceptance problems are undecidable Diagonalization Sipser’s book, 3.2, 3.3, 4.1, 4.2 Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 1

Upload: others

Post on 07-Apr-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Computational Models Lecture 7, Spring 2011

The Church-Turing Thesis

Encoding of TMs

Universal Turing Machines

The Halting/Acceptance problem

The Halting/Acceptance problems are undecidable

Diagonalization

Sipser’s book, 3.2, 3.3, 4.1, 4.2

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 1

Page 2: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Decidability vs. Enumerability (reminder)

Decidability is a stronger notion than enumerability.

If a language L is decidable then clearly it isenumerable (the other dirction does not hold, as we’llshow in a couple of lectures).

It is also clear that if L is decidable then so is L, andthus L is also enumerable.

Let RE denote the class of enumerable languages, andlet coRE denote the class of languages whosecomplement is enumerable.

Let R denote the class of decidable languages. We sawin lecture 6 that R=RE ∩ coRE .

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 2

Page 3: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Revised View of the World of Languages

We’ll see later today (or next week) that R ( RE

context free

regular

decidable

enumerable

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 3

Page 4: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Enumerators

We said a language is enumerable if it is accepted by someTuring machine.But why enumerable?

1 010

aaabba

Definition: An enumerator is a TM with a printer.

TM sends strings to printer

may create infinite list of strings

TM enumerates a language – all the strings produced.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 4

Page 5: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Theorem

Theorem: A language is accepted by some Turing machineif and only if some enumerator enumerates it.

Will show

If E enumerates language A, then some TM M acceptsA.

If M accepts A, then some enumerator E enumerates it.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 5

Page 6: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Theorem

Claim: If E enumerates language A, then some TM Maccepts A.

On input w, TM M

Runs E. Every time E outputs a string v, M compares itto w.

If v = w, M accept.

If v 6= w, M continues running E.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 6

Page 7: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Theorem

Claim: If M accepts A, then some enumerator Eenumerates it.

Let s1, s2, s3, . . . is a list of all strings in Σ∗ (e.g. strings inlexicographic order).The enumerator, E

repeat the following for i = 1, 2, 3, . . .

run M for i steps on each input s1, s2, . . . , si.

if any computation accepts, print out the correspondings. ♣

Note that with this procedure, each output is duplicatedinfinitely often.How can this duplication be avoided?

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 7

Page 8: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Theorem

Claim: A language L is decidable if and only if there is someenumerator E that enumerates L in lexicographic order.

Proof: Left as an exercise.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 8

Page 9: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

What is an Algorithm???????

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 9

Page 10: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Indeed, What is an Algorithm?

Informally

a recipe

a procedure

a computer program

who cares? I know it when I see it :-(

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 10

Page 11: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Indeed, What is an Algorithm?

Historically,

notion has long history in Mathematics (starting withEuclid’s gcd algorithm), but

not precisely defined until 20th century

informal notions rarely questioned,

still, they were insufficient

Euclid of Alexandria, circa 300BC

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 11

Page 12: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Remarks

Many models have been proposed for general-purposecomputation.

Remarkably, all “reasonable” models were shown to beequivalent to Turing machines.

All “reasonable” programming languages (e.g. Java,Pascal, C, Python, Scheme, Mathematica, Maple,Cobol,. . . ) are equivalent.

The notion of an algorithm is model-independent!

We don’t really care about Turing machines per se.

We do care about understanding computation, andbecause of their simplicity, Turing machines are a goodmodel to use.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 12

Page 13: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Church-Turing Thesis

Formal notions appeared, starting in 1936:

λ-calculus of Alonzo Church

Turing machines of Alan Turing

Recursive functions of Godel and Kleene

Counter machines of Minsky

Normal algorithms of Markov

Unrestricted grammars

Two stack automata

Random access machines (RAMs)...These definitions look very different, but are provablyequivalent.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 13

Page 14: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Church-Turing Thesis

These definitions look very different, but are provablyequivalent.

The Church-Turing Thesis:

“The intuitive notion of reasonable models ofcomputation equals Turing machine algorithms”.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 14

Page 15: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Wild Models

What about “wild” models of computation?Consider MUntel’s ℵ-AXP10 c© processor (to be released...).

Like a Turing machine, except

Takes first step in 1 second.

Takes second step in 1/2 second.

Takes i-th step in 2−i seconds . . .

After 2 seconds, the ℵ-AXP c© decides any enumerablelanguage!

Question: Does the ℵ-AXP c© invalidate the Church-TuringThesis?

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 15

Page 16: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Encodings

Input to a Turing machine is a string of symbols.

But we want algorithms that work on graphs, matrices,polynomials, Turing machines, etc.

Need to choose an encoding for objects.

Can often be done in many reasonable ways.

Sometimes it is helpful to distinguish between X, theobject, and 〈X〉, its encoding.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 16

Page 17: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Standard Encoding of Turing Machines

Just like any piece of code in any programming language,Turing machines can be encoded as strings. We will nowdescribe a possible such encoding. This will enable us

To check (by an algorithm) that a given string is a legalencoding of a TM.

To build a universal machine that can read suchencoding and simulate the encoded TM on any inputstring.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 17

Page 18: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Standard Encoding of Turing Machines

The encoding 〈M〉 of a TM, M , will use a binary alphabet.

Blocks of 0’s will be used as delimiters.

A set Q with m states will be indicated by m in unary.

By conventions states will be 1 through m.

By convention, q0 is indicated by state 1.

Indicate the accept and the reject states i and j (& delimiters!).

Indicate the sizes of Σ, ℓ, and of Γ, k, (again in unary, plus

delimiters). ℓ < k. Letters in Σ encoded by 1 . . . ℓ (in unary),

while letters in Γ encoded by ℓ+ 1 . . . k (in unary). By

convention, blank is encoded by k.

Finally, the transition function δ is encoded as a list of 5-tuples

with correct size and no duplications in q, γ entries.

Important and Easy: An algorithm (TM) can check that a given

string is legal encoding of a TM.Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 18

Page 19: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

The Universal Turing Machine

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 19

Page 20: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Universal Turing Machines

We now define the universal Turing machine, U .On input 〈M,w〉, where M is a TM and w a string

1. Checks that 〈M,w〉 is a proper encoding of a TM,followed by a string from Σ∗.

2. Simulates M on input w (HOW???)

3. If M on input w enters its accept state, U accept, and ifM on input w ever enters its reject state, U reject.

Notice that as a consequence, if M on input w enters aninfinite loop, so does U on input 〈M,w〉.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 20

Page 21: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Universal Turing Machines (2)

The universal machine U obviously has a fixed numberof states (100 should do) .

Despite this, it can simulate machines M with manymore states.

Universal machines inspired the development ofstored-program computers in the 40s and 50s.

Most of you have seen a universal machine, and haveeven used one!

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 21

Page 22: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Universal Turing Machines (3)

For example, Dr. Scheme (interpreter) is a universalScheme machine.

It accepts a two part input: “Above the line” – theprogram (corresponding to 〈M〉), and “below the line”the input to run it on (corresponding to w).

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 22

Page 23: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

The Halting Problem

One of the most philosophically important theorems of thetheory of computation.

Computers (and computation) are not omnipotent – theyare limited in a very fundamental way.

Many common problems are unsolvable, e.g.

Does a program sort an array of integers?

Note that this problem is well defined: Both programand specification are precise mathematical objects.

Hey, proving program ∼= specification should be just likeproving that triangle 1 ∼= triangle 2 . . .

Well, this is not the case!

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 23

Page 24: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

CFG, NFA, DFA Reminders

Let ECFG = {〈G〉 | G is a CFG and L(G) = ∅}We saw that ECFG is a decidable language.

ACFG = {〈M,w〉 | M is a PDA accepting the string w}.Saw that the language ACFG is decidable.

ANFA = {〈M,w〉 | M is an NFA accepting the string w}.

ADFA = {〈M,w〉 | M is a DFA ,accepting the string w}.

Saw both ANFA and ADFA are also decidable.

What would happen with Turing Machines?

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 24

Page 25: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Acceptance Problem

Does a Turing machine accept a string?

ATM = {〈M,w〉|M is a TM that accepts w}

Theorem: ATM is undecidable.

Recall that the corresponding languages forDFAs, NFAs, and CFGs, namelyADFA, ANFA, and ACFG, are decidable.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 25

Page 26: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

The Acceptance Problem

ATM = {〈M,w〉|M is a TM that accepts w}

Before approaching the proof of undecidability, we firstprove

Theorem: ATM is recursively enumerable (namely in RE).

Proof: The universal machine accepts ATM . ♣

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 26

Page 27: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Acceptance, Again

We are now able to prove the undecidability of

ATM = {〈M,w〉|M is a TM that accepts w} .

Proof: By contradiction. Suppose a TM, H, is a decider forATM .

On input 〈M,w〉, where M is a TM and w is a string, H haltsand accepts if and only if M accepts w. Furthermore, Hhalts and rejects if M fails to accept w.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 27

Page 28: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Acceptance (2)

On input 〈M,w〉, where M is a TM and w is a string, H haltsand accepts if and only if M accepts w. Furthermore, Hhalts and rejects if M fails to accept w.

H(〈M,w〉) ={

accept if M accepts w

reject if M does not accept w

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 28

Page 29: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Acceptance (3)

Now we construct a new TM, D, with H as a subroutine.

D does the following

Calls H to determine what TM, M , does when the inputto M is its own description, 〈M〉.When D determines this, it does the opposite.

So D rejects if M accepts 〈M〉, and accepts if M doesnot accept 〈M〉.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 29

Page 30: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Acceptance (4)

More precisely, D does the following:

Run H on input 〈M, 〈M〉〉.Output the opposite of what H outputs:

If H accepts, reject, andIf H rejects, accept.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 30

Page 31: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Self Reference (4)

Don’t be confused by the notion of running a machine on itsown description!

Actually, you should get used to it.

Notion of self-reference comes up again and again indiverse areas.

Read “Gödel, Escher, Bach, an Eternal Golden Braid”,by Douglas Hofstadter.

This notion of self-reference is the basic idea behindGödel’s revolutionary result.

Compilers do this all the time . . . .

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 31

Page 32: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

The Punch Line

So far we have,

D(〈M〉) ={

reject if M accepts 〈M〉accept if M does not accept 〈M〉

What happens if we run D on its own description?

D(〈D〉) ={

reject if D accepts 〈D〉accept if D does not accept 〈D〉

Oh, oh...Or, more accurately, a contradiction (to what?) ♣

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 32

Page 33: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Once Again

Assume that TM H decides ATM .

Then use H to build a TM, D, that when given 〈M〉,accepts exactly when M does not accept.

Run D on its own description.

D does:H accepts 〈M,w〉 when M accepts w.D rejects 〈M〉 exactly when M accepts 〈M〉.D rejects 〈D〉 exactly when D accepts 〈D〉.

Last step leads to contradiction.

Therefore neither TM D nor H can exist.

So ATM is undecidable!

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 33

Page 34: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

A Non-enumerable Language

We already saw a non-decidable language: ATM .

Can we do better (i.e., worse)?

Mais, oui!

We now display a language that isn’t even recursivelyenumerable . . . .

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 34

Page 35: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

A Non-enumerable Language

Earlier we saw

Theorem: If L and L are both enumerable, then L isdecidable.

orollary: If L is not decidable, then either L or L is notenumerable.

Definition: A language is co-enumerable if it is thecomplement of an enumerable language.

Reformulating theorem Theorem: A language is decidable ifand only if it is both enumerable and co-enumerable.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 35

Page 36: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

ATM is not Enumerable

Theorem: If L and L are both enumerable, then L isdecidable.

We proved that ATM is undecidable.

On the other hand, we saw that the universal TM, U ,accepts ATM .

Therefore ATM is enumerable.

If ATM were also enumerable, then by theorem ATM

was decidable.

Therefore ATM is not enumerable. ♣

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 36

Page 37: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Languages

enumerableco-enumerable decidable

ATMADFAATM

???

Question: Are there any languages in the area marked ????

Answer: Yes, heaps (why?)

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 37

Page 38: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

The Acceptance Problem (again)

We saw

ATM = {〈M,w〉|M is a TM that accepts w}

Our proof that ATM is undecidable was actually adiagonalization proof.

To see this, we start with a short “diagonalization reminder”.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 38

Page 39: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Comparing Sizes of Sets

Suppose A and B are two sets, and we wish to comparetheir sizes.

If both A and B are finite, we can count how many elementseach of them has, and compare the numbers.

This method does not generalize to infinite sets.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 39

Page 40: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Comparing Sizes of Sets (2)

Alternatively, we can pair the elements of A and B. If theypair perfectly, they have equal sizes.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 40

Page 41: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Correspondence

Question: What does it mean to say that two infinite setsare the same size?

Answered by Georg Cantor in 1873: Pair them off.

A map f : A → B is a correspondence if f satisfies

f one-to-one: if a1 6= a2 then f(a1) 6= f(a2).

f onto: for every b ∈ B, there is an a ∈ A such thatf(a) = b.

Question: What does it mean to say that sets A and B arethe same size?

Answer: A and B are the same size if there is acorrespondence from A to B.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 41

Page 42: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Correspondence (2)

Question: In a crowded room, how can we tell if there aremore people than chairs, or more chairs than people?

Answer Establish a correspondence: ask everyone to sitdown.

(c.f., Mathematician’s trick for counting a herd of cows . . . )

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 42

Page 43: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Correspondence

Claim: The set N of natural numbers has thesame size as the set E of even numbers

Proof: Let f(i) = 2i.

Remark: The set E is a proper subset of the set N ,yet they are the same size!

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 43

Page 44: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Countable Sets

Definition A set A is countable if

either A is finite, or

A has the same size as N , the natural numbers.

We have just seen that E is countable.

A countable set is sometimes said to have size ℵ0.

Claim: The set Z of integers is countable.

Proof: Define f : N → Z by

f(i) =

{

i/2 if i is even−(⌊i/2⌋+ 1) if i is odd

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 44

Page 45: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Pop Quiz

In Heaven, there is a hotel with a countable number ofrooms.

One day, the society of Prophets, Oracles, and AIResearchers holds a 3-day convention that books everyroom in the hotel.

Then one more guest arrives, claiming he invented Lisp,and angrily demanding a room.

You are the manager. What do you do?

Answer: Ask the guest in room i to move to room i+ 1, andput the newcomer in room 1.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 45

Page 46: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Pop Quiz #2

Then a countable number of guests arrive, all angrilydemanding rooms. (What a noise!)

Now what do you do?

Answer: Ask the guest in room i to move to room 2i, andput the newcomers in the odd-numbered rooms.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 46

Page 47: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Rational Numbers

Let

Q ={m

n| m,n ∈ N

}

Theorem: Q is countable.

This claim may seem counterintuitive.

Idea

list Q as 2-dim array

begin counting with the first row . . .

Why doesn’t this work?

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 47

Page 48: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Rational Numbers (2)

1/2 1/3 1/4 1/51/1

2/1

3/1

4/1

5/1

2/2 2/3 2/4 2/5

1/2 3/3 3/4 3/5

4/2 4/3 4/4

5/35/2

Enumerate numbers along northeast and diagonals,skipping duplicates.

Does this mean that every infinite set is countable?

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 48

Page 49: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

The Real Numbers

Every real number has a decimal representation.

For example, π = 3.1415926 . . .,√2 = 1.4142136 . . ., and

0 = 0.0000000 . . ..

Let R be the set of real numbers.

Theorem: R is uncountable.

R is sometimes said to have size ℵ1.

This is Cantor’s historic proof, which

introduced the diagonalization method.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 49

Page 50: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

The Real Numbers

Assume there is a correspondence between N and R.Write it down:

n f(n)

1 3.14159. . .2 55.55555. . .3 40.18642. . .4 15.20601. . .

We now show that there is a number x not in this list.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 50

Page 51: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Diagonalization

Pick 0 ≤ x ≤ 1, so its significant digits follow decimal point.Will ensure x 6= f(n) for all n.

n f(n)

1 3.14159. . .2 55.55555. . .3 40.18643. . .4 15.20607. . .

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 51

Page 52: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Diagonalization n f(n)

1 3.14159. . .

2 55.55555. . .

3 40.18643. . .

4 15.20607. . .

First fractional digit of f(1) is 1, so pick first fractionaldigit of x to be something else (say, 2).

Second fractional digit of f(2) is 5, so pick secondfractional digit of x to be something else (say, 6).

and so on . . .

x = 0.2691 . . .

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 52

Page 53: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Diagonalization

A similar proof shows there are languages that are notenumerable.

the set of Turing machines is countable, butthe set of languages is uncountable!

Ergo,there exist languages that are not enumerable(why?)indeed, “most” languages are not enumerable(explain)

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 53

Page 54: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

∃ Countably Many Turing Machines

Claim: The set of strings, Σ∗, is countable.

Proof: List strings of length 0, then length 1, then 2, and soon. This exhausts all of Σ∗.The union of countably many finite sets is countable.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 54

Page 55: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

∃ Countably Many Turing Machines (2)

Claim: The set of all Turing machines is countable.

Proof: Each TM M has an encoding as a string 〈M〉.Therefore there is a one-to-one mapping from the set of allTMs into (but not onto) Σ∗.

Since Σ∗ is countable, so is the set of all TMs.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 55

Page 56: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

The Set of All Languages is Uncountable

Let B be the set of of infinite binary sequences.

Claim B is uncountable.

Proof Diagonalization argument, essentially identical to theproof that R is uncountable.

(additional helpful clue: think of binary sequence as binaryexpansion!)

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 56

Page 57: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

The Set of Languages is Uncountable (2)

Let L be the set of all languages over alphabet Σ.Recall B is the set of of infinite binary sequences.We give a correspondence

χ : L → B

called the language’s characteristic sequence.

Let Σ∗ = {s1, s2, s3, . . .} (in lexicographic order).

Each language L ∈ L is associated with a uniquesequence χ(L) ∈ B:

the i-th bit of χ(L) is 1 if and only if si ∈ L.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 57

Page 58: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

The Set of Languages is Uncountable (3)

Each language L ∈ L has a unique sequence χ(L) ∈ B:the i-th bit of χ(L) is 1 if and only if si ∈ L.

Example:Σ∗ {ε, 0, 1, 00, 01, 10, 11, 000 . . .}A { 0, 00, 01, 000 . . .}χ(A) {0, 1, 0 1, 1, 0, 0, 1 . . .}

The map χ : L → Bis one-to-one and onto (why?),

and is hence a correspondence.

It follows that L is uncountable.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 58

Page 59: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

TMs vs. Languages

We saw that the set of all Turing machines is countable.

We saw that the set L of all languages over alphabet Σ isuncountable.

Therefore there are languages that are not accepted by anyTM.

This is an existential proof – it does not explicitly show anysuch language.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 59

Page 60: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Reflections on Diagonalization

This proof that the acceptance problem is undecidable isactually diagonalization in transparent disguise.To unveil this, let’s start by making a table.

〈M1〉 〈M2〉 〈M3〉 〈M4〉 . . .M1 accept acceptM2 accept accept accept acceptM3

M4 accept accept...

Entry (i, j) is accept if Mi accepts 〈Mj〉, andblank if Mi rejects or loops on 〈Mj〉.

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 60

Page 61: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Diagonalization (2)

〈M1〉 〈M2〉 〈M3〉 〈M4〉 . . .

M1 accept acceptM2 accept accept accept acceptM3

M4 accept accept...

Run H on on corresponding inputs. In new table,entry (i, j) states whether H accepts 〈Mi, 〈Mj〉〉.

〈M1〉 〈M2〉 〈M3〉 〈M4〉 . . .M1 accept reject accept rejectM2 accept accept accept acceptM3 reject reject reject rejectM4 accept accept reject reject...

......

...

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 61

Page 62: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Diagonalization (3)

Now we add D to the table.

By assumption, H is a TM, and therefore so is D.D occurs on the list M1,M2, . . . of all TMs.D computes the opposite of the diagonal entries.

At diagonal entry, D computes its own opposite!

〈M1〉 〈M2〉 〈M3〉 . . . 〈D〉M1 accept reject acceptM2 accept accept acceptM3 reject reject rejectM4 accept accept reject...

... . . .D reject reject accept ???...

... . . .♣

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 62

Page 63: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Halting vs Acceptance Problem

We have already established that ATM is undecidable.

Here is a closely related problem.

HTM = {〈M,w〉|M is a TM and M halts on input w}

Clarification: How does HTM differ from ATM?

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 63

Page 64: The Church-Turing Thesis Encoding of TMs Universal Turing ...tau-cm.wdfiles.com/local--files/course-schedule/L7_M_2011.pdf · Turing machines can be encoded as strings. We will now

Undecidable Problems

HTM = {〈M,w〉|M is a TM and M halts on input w}

Theorem: HTM is undecidable.

Proof idea:

Similar to ATM .

Again, proof by diagonalization.

Soon (lecture or recitation) we will prove this differently,by a reduction from ATM .

Slides modified by Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p. 64