The decision problem (entscheidungsproblem), halting problem, & Turing machines. CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/

Similar documents
Introduction to Turing Machines. Reading: Chapters 8 & 9

Turing Machines (TM) Deterministic Turing Machine (DTM) Nondeterministic Turing Machine (NDTM)

CSCE 551: Chin-Tser Huang. University of South Carolina

1 Showing Recognizability

CSE355 SUMMER 2018 LECTURES TURING MACHINES AND (UN)DECIDABILITY

CSE 105 THEORY OF COMPUTATION

Computability Theory. CS215, Lecture 6,

Decidability. Human-aware Robotics. 2017/10/31 Chapter 4.1 in Sipser Ø Announcement:

TURING MAHINES

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

CSE 105 THEORY OF COMPUTATION

Midterm Exam 2 CS 341: Foundations of Computer Science II Fall 2018, face-to-face day section Prof. Marvin K. Nakayama

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

Decidability (What, stuff is unsolvable?)

Turing Machine Recap

CSE 105 THEORY OF COMPUTATION

COMP/MATH 300 Topics for Spring 2017 June 5, Review and Regular Languages

Theory of Computation (IX) Yijia Chen Fudan University

CPSC 421: Tutorial #1

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

CS 301. Lecture 17 Church Turing thesis. Stephen Checkoway. March 19, 2018

Most General computer?

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

Midterm Exam 2 CS 341: Foundations of Computer Science II Fall 2016, face-to-face day section Prof. Marvin K. Nakayama

Turing Machines Part III

Computability and Complexity Theory

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) October,

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

CP405 Theory of Computation

CS5371 Theory of Computation. Lecture 12: Computability III (Decidable Languages relating to DFA, NFA, and CFG)

Undecidability COMS Ashley Montanaro 4 April Department of Computer Science, University of Bristol Bristol, UK

Undecidable Problems. Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, / 65

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Turing Machines (TM) The Turing machine is the ultimate model of computation.

Computational Models Lecture 8 1

Decidable Languages - relationship with other classes.

Decision Problems with TM s. Lecture 31: Halting Problem. Universe of discourse. Semi-decidable. Look at following sets: CSCI 81 Spring, 2012

CS4026 Formal Models of Computation

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CSCE 551 Final Exam, Spring 2004 Answer Key

CS154, Lecture 10: Rice s Theorem, Oracle Machines

UNIT-VIII COMPUTABILITY THEORY

CS20a: Turing Machines (Oct 29, 2002)

CSE 105 THEORY OF COMPUTATION

Computational Models Lecture 8 1

Turing Machines A Turing Machine is a 7-tuple, (Q, Σ, Γ, δ, q0, qaccept, qreject), where Q, Σ, Γ are all finite

Theory of Computation CS3102 Spring 2014 A tale of computers, math, problem solving, life, love and tragic death

Chomsky Normal Form and TURING MACHINES. TUESDAY Feb 4

CSE 2001: Introduction to Theory of Computation Fall Suprakash Datta

Turing Machines. Lecture 8

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

Turing Machines Decidability

V Honors Theory of Computation

CpSc 421 Final Exam December 15, 2006

Theory of Computation p.1/?? Theory of Computation p.2/?? We develop examples of languages that are decidable

Turing Machines Part II

The Church-Turing Thesis

The Turing Machine. CSE 211 (Theory of Computation) The Turing Machine continued. Turing Machines

Decidability: Church-Turing Thesis

CSci 311, Models of Computation Chapter 9 Turing Machines

Problems, and How Computer Scientists Solve Them Manas Thakur

Computational Models Lecture 8 1

Decidability and Undecidability

Introduction to Turing Machines

Final exam study sheet for CS3719 Turing machines and decidability.

Complexity Theory Part I

Turing s thesis: (1930) Any computation carried out by mechanical means can be performed by a Turing Machine

Limits of Computability

CSE 105 Theory of Computation

Exam Computability and Complexity

Computability Crib Sheet

An example of a decidable language that is not a CFL Implementation-level description of a TM State diagram of TM

Advanced topic: Space complexity

Introduction to Languages and Computation

Decidability (intro.)

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

UNRESTRICTED GRAMMARS

Harvard CS 121 and CSCI E-121 Lecture 14: Turing Machines and the Church Turing Thesis

CpSc 421 Homework 9 Solution

CS6901: review of Theory of Computation and Algorithms

CSE 105 Theory of Computation

Recap DFA,NFA, DTM. Slides by Prof. Debasis Mitra, FIT.

Turing Machines. 22c:135 Theory of Computation. Tape of a Turing Machine (TM) TM versus FA, PDA

Reducability. Sipser, pages

Undecidable Problems and Reducibility

Finish K-Complexity, Start Time Complexity

CS151 Complexity Theory. Lecture 1 April 3, 2017

CSCE 551: Chin-Tser Huang. University of South Carolina

CS3719 Theory of Computation and Algorithms

The Unsolvability of the Halting Problem. Chapter 19

Turing Machines Part II

ON COMPUTAMBLE NUMBERS, WITH AN APPLICATION TO THE ENTSCHENIDUGSPROBLEM. Turing 1936

CSE 105 Theory of Computation

1 Unrestricted Computation

What languages are Turing-decidable? What languages are not Turing-decidable? Is there a language that isn t even Turingrecognizable?

CSE 105 THEORY OF COMPUTATION

Part I: Definitions and Properties

Opleiding Informatica

Q = Set of states, IE661: Scheduling Theory (Fall 2003) Primer to Complexity Theory Satyaki Ghosh Dastidar

} Some languages are Turing-decidable A Turing Machine will halt on all inputs (either accepting or rejecting). No infinite loops.

Transcription:

The decision problem (entscheidungsproblem), halting problem, & Turing machines CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/ 1

We must not believe those, who today, with philosophical bearing and deliberative tone, prophesy the fall of culture and accept the ignorabimus [i.e., that fundamental ignorance and limitation underly reason, science, logic]. For us there is no ignorabimus, and in my opinion none whatever in natural science. In opposition to the foolish ignorabimus our slogan shall be: Wir müssen wissen; wir werden wissen! We must know; we will know! David Hilbert 2

Hilbert s entscheidungsproblem (decision problem): What general process (i.e., algorithm) will decide if a given proposition (in standard firstorder logic, or a similar system) is provable/deducible, or not? (Surely such a process exists!) David Hilbert 3 1928 (generalizes Hilbert s 10th problem from his famous 23 problems for the turn of the century in 1900)

But, there are undecidable problems Alan Turing Alonzo Church 4

Decision procedures A decision procedure is some algorithm resulting in a Yes or No decision True or False. A decision procedure corresponds to determining if a string is a member of a formal language, or, equivalently, if a proposition holds: is some statement true. The entscheidungsproblem asks specifically for a decision procedure for all statements written in first-order logic. Other examples of decision procedures: Is the string w accepted by the given NFA? Is the string w accepted by the given PDA? Is the string w generated by the given CFG? Is the string w in the language L? 5

Undecidable problems Some problems are decidable, there exists a decision procedure that always correctly yields True or False (e.g., a string s membership in a regular language), but some are not. E.g. Is the string w in the language L? is undecidable when L is the language of all C programs without buff. overflow. L is the language of all valid and true english statements. L is the language of all (textually encoded) Conway s game of life states following a particular setup. 6

Conway s game of life At each iteration: cells with three living neighbors are alive; cells with two remain as they were; all other cells die. 7

Undecidable problems Some problems are decidable, there exists a decision procedure that always correctly yields True or False (e.g., a string s membership in a regular language), but some are not. E.g. Is the string w in the language L? is undecidable when L is the language of all C programs without buff. overflow. L is the language of all valid and true english statements. L is the language of all (textually encoded) Conway s game of life states following a particular setup. L is the language of Python programs that halt. 8

The Collatz ( 3n+1 ) conjecture Start with any positive integer, n. If even, the number is modified by dividing it in half to obtain n/2; or, if odd, the number is modified by multiplying it by three and adding one to obtain 3n+1. Repeat. Eventually, n will become 1. E.g., 8, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, E.g., 9, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5,16, 8, 4, 2, 1, 4, 2, 1, 4, 2, 1, 4, 2, 1, 9

Collatz and the halting problem def collatz(n): while n!= 1: if n%2 == 0: n = n/2 else: n = 3*n+1 Would this definition for collatz(n) be in the language of Python programs that must halt? Intuitively: the halting problem must be at least as hard as Collatz! 10

Collatz and the halting problem: Another kind of reduction If we can solve the halting problem for all programs, then we can prove the Collatz conjecture. Contrapositive: If the Collatz conjecture is unproven, then the halting problem must also be unsolved. Contrapositive: If the Collatz conjecture is too hard to solve, then the halting problem must also be too hard to solve. 11

The halting problem def halt(prog, input):... # Assume: logic to detect halting... return True else: return False 12

The halting problem: an informal proof First assume we have a program which will determine if a program P halts on input I, or not. We assume this exists and treat it as a black box. Program P halt() predicate True / False P s input I 13

The halting problem: an informal proof First assume we have a program which will determine if a program P halts on input I, or not. E.g., collatz(n) halt() predicate True 9 14

The halting problem: an informal proof def P(prog): if halt(prog,prog): while True: pass P(P) # What happens here? 15

The halting problem: an informal proof Paradox! P halts if it doesn t halt and doesn t halt if it does! def P(prog): if halt(prog,prog): while True: pass P(P) # What happens here? Thus P cannot exist, and neither can halt. 16

The printing problem Now assume we have a program which will determine if a program P prints any output to STDOUT on a given input I, or not. def f(n): if n == 3: print hello E.g., prints() predicate True 3 17

Try an example. Design a paradoxical program P which shows that decision procedure prints cannot exist. 18

Try an example. Design a paradoxical program P which shows that decision procedure prints cannot exist. def P(prog): if not prints(prog,prog): print Oh, but it does though P(P) # Paradox! 19

Reductions for decision procedures If we can reduce solving decision procedure d1 to one of solving d0, then d1 s undecidability implies d0 s. d1() predicate Do some preprocessing to turn an input to d1 to an input for d0 such that the decision for d0 is guaranteed to also be correct for d1. d0() predicate 20

Turing machines A model of universal computation. 21

Informally, a Turing machine (TM) pairs a deterministic finite automaton (a set of states, alphabet, transition edges, a start state, final states) with an unbounded bi-directional tape of memory. There is no distinguished input source; the input starts out loaded into memory. deterministic finite control Edges of the TM s finite control can read from the tape at the current position, write to the tape at the current position, and move the tape head (current position on the tape) left or right. q0 q1???? E A C A A 22

A set of final states Formally, each TM is a 7-tuple: (Q, Σ, Γ, δ, q 0, B, F) A finite set of states {q } A finite input alphabet A finite set of tape symbols A deterministic transition function A designated blank symbol. A designated starting state!23

Formally, each TM is a 7-tuple: (Q, Σ, Γ, δ, q 0, B, F) δ (Q Γ Q Γ {L, R}) q 0 Q F Q Σ Γ B Γ B Σ!24

An example of an edge: At state q0, if the symbol read at the current position on the tape is X: transition to q1, clear the tape at current location, and move left. (q 0, X, (q 1, B, L)) δ Recall delta s signature: δ (Q Γ Q Γ {L, R})!25

Try an example. Give tuple(s) for the edge(s) matching the description: At state q0, stay at q0 and either read an X and move right on the memory tape, or read a Y and move left, changing Y to X. 26

Try an example. Give tuple(s) for the edge(s) matching the description: At state q0, stay at q0 and either read an X and move right on the memory tape, or read a Y and move left, changing Y to X. (q 0, X, (q 0, X, R)) δ (q 0, Y, (q 0, X, L)) δ 27

Diagramming TMs, notational conventions E.g., If X is read, transition from q0 to q1, clearing the current memory location and moving left. (q 1, B, L) = δ(q 0, X) Y/Y X/B q0 q1 q2 B/X 28

Transition table for TMs Y/Y X/B q0 q1 q2 B/X δ X Y B q0 (q1, B, L) q1 (q1, Y, R) (q2, X, L) q2 29

Evaluating TMs Q, Σ, Γ, δ, q 0, B, F Given a TM called M,, we can define a step- wise evaluation relation ( ) and its transitive/reflexive closure ( * ). x * x x y * z x * z Evaluation can be described in terms of sequences (inst. descriptions) in Γ*QΓ* starting with: q 0 w 0 w k (w i Σ) The input is not read separately but is loaded onto the memory tape up front, the read/write head positioned on the first input token.!30

Evaluating TMs Iff P contains an edge (p, Y, L) = δ(q, X), then: def X 0 X i 1 qxx i+1 X k X 0 X i 2 px i 1 Y X k and moving left (or right) off the end of previously-utilized memory uncovers more implicit B symbols which can then be overwritten: def qxx 1 X i 1 X k pbyx 1 X i 1 X k!31

Try an example. Let s design a TM for the language: L = {xy, xx} 32

Try an example. Let s design a TM for the language: L = {xy, xx} x/b x/b y/b q0 q1 q2 33

Try an example. Show the evaluation of this TM on string xy. x/b x/b y/b q0 q1 q2 34

Try an example. Show the evaluation of this TM on string xy. x/b x/b y/b q0 q1 q2 q 0 xy Bq 1 y q 2 BB Accepts upon reaching state q2 35

Try an example. Let s design a TM for the language: L = {x n y n N} 36

Try an example. Let s design a TM for the language: L = {x n y n N} y/y B/B q0 q1 q2 x/x Note that if we replace edges a in a DFA with a/a, and add a check for a blank at the end, we get a TM! 37

Try an example. Let s design a TM for the language: L = L(10 * 01 * ) 38

Try an example. Let s design a TM for the language: L = L(10 * 01 * ) 1/1 0/0 q1, 0 B/B q0, B q1, B 1/1 q1, 1 B/B 0/0 39

Tricks for programming TMs Just as we saw with DFAs, the finite state component can also encode arbitrary information (that is perhaps inconvenient to store on the tape) so long as this information is drawn from a finite domain; e.g., Q = {q 0, q 1 } {0, 1, B} A finite domain of additional info. A TM with multiple tracks can be encoded by using a tape alphabet that is the product of multiple tape alphabets (although often the same). E.g., a tape with three synchronized tracks on the left; or two, on the right. Γ = Γ 1 Γ 2 Γ 3 Γ 2 The alphabet for track 1, track 2, track 3. Alphabet for a machine with two tracks over the same tape tokens.!40

Try an example. Let s design a TM for the language: L = {x0 n x n N x {0, 1}} 41

Try an example. Let s design a TM for the language: L = {x0 n x n N x {0, 1}} 0/0 B/B 0/1 q2, 0 q1, 0 0/0 q0 q3, 1 1/1 q1, 1 q2, 1 B/B 1/1 0/0 42

Try an example. Let s design a TM for the language: L = {x n y n n N} 43

Try an example. Let s design a TM for the language: L = {x n y n n N} x/x q0 B/B 44

Try an example. Let s design a TM for the language: L = {x n y n n N} x/x y/y q0 q1 B/B x/x 45

Try an example. Let s design a TM for the language: L = {x n y n n N} x/x Y/Y x/x y/y q0 q1 q2 B/B x/x 46

Try an example. Let s design a TM for the language: L = {x n y n n N} x/x Y/Y x/x y/y q0 q1 q2 B/B x/x X/X 47

Try an example. Let s design a TM for the language: L = {x n y n n N} x/x Y/Y x/x y/y q0 q1 q2 B/B x/x Y/Y X/X 48

Try an example. Let s design a TM for the language: L = {x n y n n N} x/x Y/Y x/x y/y q0 q1 q2 B/B Y/Y x/x Y/Y X/X q3 Y/Y B/B q4 49

Try an example. Show the evaluation of this TM on input xxyy. B/B Y/Y x/x y/y q0 q1 q2 x/x Y/Y x/x Y/Y q3 X/X Y/Y B/B q4 50

Try an example. Show the evaluation of this TM on input xxyy. q 0 xxyy Xq 1 xyy Xxq 1 yy Xq 2 xyy q 2 XxYy Xq 0 xyy XXq 1 Yy XXYq 1 y XXq 2 YY Xq 2 XYY XXq 0 YY XXYq 3 Y XXYYq 3 B XXYYBq 4 B B/B Y/Y x/x y/y q0 q1 q2 x/x Y/Y x/x Y/Y q3 X/X Y/Y B/B q4 51

Tricks for programming TMs A TM with multiple (synchronized) tracks can be encoded by using a tape alphabet that is the product of multiple tape alphabets (perhaps the same).? Finite control Γ = {A, B, C, D, E}? q0 q1 {T, F}?? E A C A A F F F T F!52

Tricks for programming TMs A TM with multiple (non-synchronized) tapes can be encoded by using multiple tracks where each tape is simulated by two tracks: one for its data, and one to store a mark saving the read/write head location on that tape.? Finite control Γ = {A, B, C, D, E}? q0 q1 {*, B}?? A D E!53 A C A * A *

Decidable, recognizable languages with TMs A language L (or decision problem) is decidable (also, recursive) iff there exists a TM that will always eventually halt, on any input, yielding true or false to correctly indicate the input string s existence in language L. A language L (or decision problem) is recognizable (also, recursively enumerable or RE) iff there exists a TM that, on any input, will always eventually accept when the input is in the language L, but will either eventually reject or will non-terminate (loop forever) when the input is not in L. If L s complement is RE, L is called co-recognizable. If a language is both recognizable and co-recognizable, then it is also decidable i.e., both positive and negative examples can be recognized finitely.!54

Decidable, recognizable languages with TMs Any decision problem may be encoded formally as a language; but non-decision problems can as-well if encoded as a decision problem over pairs of (Input, Output). A problem/language is decidable if there exists a TM decider; recognizable if there is a TM recognizer; etc. Decidable : TM correctly decides and always halts. Recognizable (recursively enumerable, RE) : TM correctly decides but is only guaranteed to halt on true-yielding inputs. Co-recognizable : TM correctly decides acceptance, but is only guaranteed to halt on false-yielding inputs.!55

Decidable, recognizable languages with TMs P-TIME Decidable problems Recognizable / RE problems Undecidable problems / languages!56

A textual-encoding for TMs First, observe that TMs are amenable to a binary encoding: States can be encoded as positive ints: q1, q2, q3, Likewise, the tape alphabet: X1, X2, X3, Left and right directions as: D1, D2 Each edge δ(q i, X j ) = (q k, X l, D m ) is encoded: 0 i 10 j 10 k 10 l 10 m Note that there are no sequential 1s within an edge. A TM is encoded as a sequence of its edges (in any order) separated by substring 11. A given TM can have many valid encodings.!57

An undecidable, unrecognizable language L D Enumerate all binary strings. M0 M1 M2 The characteristic vector for Mi M3 M4...... Mi 0 1 0 0 0 1 0 0!58

An undecidable, unrecognizable language L D Enumerate all binary strings. Note: Not all these machines need be valid; invalid TM encodings denote the empty lang. M0 M1 M2 The characteristic vector for Mi M3 M4 M1 is accepted by Mi...... Mi 0 1 0 0 0 1 0 0!59

An undecidable, unrecognizable language L D Language LD has a characteristic vector that is the complement of this diagonal. This means LD is the language of all binary strings encoding TMs that do not accept when given their own binary-string encodings. By diagonalization, LD is not RE. M0 M1 M2 M3 M4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 1 1 0 0 0 1 1 0 1 0 0 0...... Mi 0 1 0 0 0 1 0 0!60

A recognizable but undecidable language L U Language LU, called the universal language, is the language of all strings M111w such that M is an encoding of a TM that accepts on input string w. First, we observe it is recognizable because we can construct a TM M that simulates a binary-encoded TM on an input step-by-step if the encoded TM accepts, M accepts. M could use one tape for input, one for tracking finite state, one for the simulated TM s tape, etc. Second, we observe LU cannot be decidable because LD can be reduced its complement. If LD is not decidable, LU is not.!61

Reductions for decision procedures If we can reduce solving decision procedure d1 to one of solving d0, then d1 s undecidability implies d0 s. d1() predicate Do some preprocessing to turn an input to d1 into an input for d0 such that the decision for d0 is guaranteed to also be correct for d1. d0() predicate 62

A recognizable but undecidable language L U LD predicate Copy the input w to produce M111M. M M111M LU predicate!63

The language of halting TMs: L H Assume an LH that accepts on input M111w iff machine M halts on input w. LU predicate Construct a new TM M that goes into an infinite loop whenever M would become stuck. We just add missing edges to an explicit stuck state! M, w M, w LH predicate!64

Try the reverse reduction: can LH be reduced to LU? LH predicate? M, w? LU predicate!65

Try the reverse reduction: can LH be reduced to LU? LH predicate Construct a new TM M that accepts whenever M would get stuck (and also accepts if M accepts)! M, w M, M LU predicate!66

Intractable problems (more in 650/750!) Infeasible or impracticable problems with no solution that we can realistically compute. 67

Intractable problems The main class of tractable problems is P (P-TIME): the set of problems we can solve in polynomial-time w.r.t. input size. A time-bounded TM is a TM that can solve a problem in a given complexity class (e.g., P) but not others. EXPTIME problems (problems that are time-bounded by an exponential function in the input size) are considered to be intractable for any sufficiently large input. Problems in the class NP are verifiable in polynomial time, and therefore solvable in Nondeterministic-Polynomial-time. Whether class NP is distinct from P is a major open problem.!68

Complexity classes for intractable problems P NP-complete NP EXPTIME, etc!69

Intractable problems (NP-Hard, NP-complete) NP-Hard problems are those at least as hard as problems in NP. We can prove this using a reduction from a known NP-Hard problem. If an NP-Hard problem is also in P, then all NP must be! NP-Complete problems are those that are NP and NP-Hard. Classic NP-complete problems include SAT and TSP. SAT is the problem of finding an assignment to variables which shows that a given boolean formula (using and, or, not) is satisfiable. Traveling salesman problem (TSP) asks for a hamiltonian circuit (a circuit through each node of a weighted graph once) that minimizes distance (or is below a given threshold).!70

Polynomial-time reductions If we can reduce solving decision procedure d1 to one of solving d0 in P-TIME, then if d0 is polynomial time, so is d1. Put another way: if d1 is unsolvable in P-TIME, then d0 also cannot be! d1() predicate Some reduction that must be polynomial-time. d0() predicate 71

Chains of reductions are used to prove NP-Hardness CSAT Circuit-SAT SAT 3-SAT P0 P1 means that P0 reduces to P1.!72

Final announcements Final Exam: Thursday Dec 13, 10:45am 1:15pm There will be a modest curve for final letter grades. However, if your current grade is below the mid-60s %, then you will probably need to improve your grade to pass. However, the final is worth a full 20% of your grade and there will be opportunities to earn over 100% as usual. A set of new practice questions will be posted, but the final is comprehensive (roughly 2/3rds will be midterm review) so you should use all old problem sets and midterms to study! Jordan s final office hours on Tuesday will be a practice session.!73

Final announcements 401: λ-calculus, interpreters/mini-compilers, formal semantics, new paradigms (functional programming, logic programming)! IDEA survey: please fill out https://uab.campuslabs.com/courseeval This is primarily how the department gets feedback on courses and instructors. Let them know how it went. I ll be teaching 350 regularly each fall. Do you have ideas for improving future classes? Please let me know! Go ahead and fill out your survey now, in class. TM Videos: Paul Rendell s TM coded in Conway s game of life.!74