Section 3.1: Proof Strategy Now that we have a fair amount of experience with proofs, we will start to prove more difficult theorems. Our experience so.

Slides:



Advertisements
Similar presentations
With examples from Number Theory
Advertisements

Introduction to Proofs
Lecture 19. Reduction: More Undecidable problems
Reasoning About Code; Hoare Logic, continued
Mutual Exclusion By Shiran Mizrahi. Critical Section class Counter { private int value = 1; //counter starts at one public Counter(int c) { //constructor.
Copyright © Cengage Learning. All rights reserved.
Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
The Big Picture Chapter 3. We want to examine a given computational problem and see how difficult it is. Then we need to compare problems Problems appear.
Ch. 10: What is a number?. MAIN DEFINITION OF THE COURSE: A symmetry of an object (in the plane or space) means a rigid motion (of the plane or space)
Prove the Impossible Sep 28 No program can check whether another program will run into infinite loop. x=0.
Section 7.4: Closures of Relations Let R be a relation on a set A. We have talked about 6 properties that a relation on a set may or may not possess: reflexive,
CSE115/ENGR160 Discrete Mathematics 02/28/12
Progressively Finite Games
1 Introduction to Computability Theory Lecture15: Reductions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
INFINITE SEQUENCES AND SERIES
Lecture 9 Recursive and r.e. language classes
1 Module 9 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.
1 Undecidability Andreas Klappenecker [based on slides by Prof. Welch]
1 Module 7 Halting Problem –Fundamental program behavior problem –A specific unsolvable problem –Diagonalization technique revisited Proof more complex.
CSE115/ENGR160 Discrete Mathematics 03/03/11 Ming-Hsuan Yang UC Merced 1.
CSE115/ENGR160 Discrete Mathematics 02/07/12
Recursion. Objectives At the conclusion of this lesson, students should be able to Explain what recursion is Design and write functions that use recursion.
CSE115/ENGR160 Discrete Mathematics 01/31/12 Ming-Hsuan Yang UC Merced 1.
CHAPTER 4 Decidability Contents Decidable Languages
Using Decision Procedures for Program Verification Christopher Lynch Clarkson University.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 16: Recursion.
DAST 2005 Tirgul 6 Heaps Induction. DAST 2005 Heaps A binary heap is a nearly complete binary tree stored in an array object In a max heap, the value.
Halting Problem. Background - Halting Problem Common error: Program goes into an infinite loop. Wouldn’t it be nice to have a tool that would warn us.
Induction and recursion
Great Theoretical Ideas in Computer Science.
Proof Methods.
Methods of Proof & Proof Strategies
Difficult Problems. Polynomial-time algorithms A polynomial-time algorithm is an algorithm whose running time is O(f(n)), where f(n) is a polynomial A.
Reading and Writing Mathematical Proofs
MATH 224 – Discrete Mathematics
Section 1.8. Section Summary Proof by Cases Existence Proofs Constructive Nonconstructive Disproof by Counterexample Nonexistence Proofs Uniqueness Proofs.
CS 173, Lecture B August 27, 2015 Tandy Warnow. Proofs You want to prove that some statement A is true. You can try to prove it directly, or you can prove.
MA/CSSE 474 Theory of Computation More Reduction Examples Non-SD Reductions.
1 Sections 1.5 & 3.1 Methods of Proof / Proof Strategy.
1 Proof Strategies CS/APMA 202 Rosen section 3.1 Aaron Bloomfield.
MA/CSSE 474 Theory of Computation Enumerability Reduction.
In section 11.9, we were able to find power series representations for a certain restricted class of functions. Here, we investigate more general problems.
Backtracking and Games Eric Roberts CS 106B January 28, 2013.
1 Computability CS 101E Spring 2007 Michele Co. 2 So Far In Class We’ve seen the following programming constructs –if, if-else, if-else-if –switch –for.
Section 3.3: Mathematical Induction Mathematical induction is a proof technique that can be used to prove theorems of the form:  n  Z +,P(n) We have.
Halting Problem and TSP Wednesday, Week 8. Background - Halting Problem Common error: Program goes into an infinite loop. Wouldn’t it be nice to have.
Theorem The square of any odd integer has the form 8m + 1 for some integer m.
Copyright © Curt Hill Proofs An Introduction.
Computation Motivating questions: What does “computation” mean? What are the similarities and differences between computation in computers and in natural.
CSE 311 Foundations of Computing I Lecture 28 Computability: Other Undecidable Problems Autumn 2011 CSE 3111.
Section 3.2: Sequences and Summations. Def: A sequence is a function from a subset of the set of integers (usually the set of natural numbers) to a set.
CS104:Discrete Structures Chapter 2: Proof Techniques.
5.1 Indirect Proof Objective: After studying this section, you will be able to write indirect proofs.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 09a: PROOF STRATEGIES Section 3.1 Jarek Rossignac CS1050:
Recursion. Objectives At the conclusion of this lesson, students should be able to Explain what recursion is Design and write functions that use recursion.
CS 173, Lecture B August 27, 2015 Tandy Warnow. Proofs You want to prove that some statement A is true. You can try to prove it directly, or you can prove.
The Church-Turing Thesis Chapter Are We Done? FSM  PDA  Turing machine Is this the end of the line? There are still problems we cannot solve:
Let’s try it one more time!. Allan Technique Programming Recursively 1.Decide that the problem needs a recursive solution. 2.Decide specifically what.
Module 7 Halting Problem –Fundamental program behavior problem –A specific unsolvable problem –Diagonalization technique revisited Proof more complex 1.
CSE15 Discrete Mathematics 03/06/17
Recursion Version 1.0.
Chapter 2 Sets and Functions.
The Acceptance Problem for TMs
CSE15 Discrete Mathematics 02/08/17
HIERARCHY THEOREMS Hu Rui Prof. Takahashi laboratory
ELEMENTARY NUMBER THEORY AND METHODS OF PROOF
Halting Problem.
5.1 Indirect Proof Let’s take a Given: Prove: Proof: Either or
Algorithms CSCI 235, Spring 2019 Lecture 37 The Halting Problem
Presentation transcript:

Section 3.1: Proof Strategy Now that we have a fair amount of experience with proofs, we will start to prove more difficult theorems. Our experience so far has been with theorems that require us only to apply the definitions and fit them together to reach the desired conclusion. Such proofs are definitional in nature and require little extra insight into the problem. Some of the more interesting theorems that we turn to now will require a bit more insight and often some less obvious way of combining our hypotheses to reach the desired conclusions. In the text, many of the tricks and general techniques that we will apply to prove more complicated theorems are discussed. I will point out such techniques during the course of proofs but discuss them less.

Ex: Consider a game played between two people. At the beginning of the game, there is a pile of 9 stones. The players take turns removing stones from the pile. On each turn a player can remove 1, 2, or 3 stones from the pile. The player who takes the last of the stones from the pile wins. Prove that the first player can always win this game. Proof: For the first player to win, he must be left with 1, 2, or 3 stones in the pile on one of his turns (then he would just grab the rest of them). He could achieve this by leaving his opponent with 4 stones in the pile. To be able to leave his opponent with 4 stones in the pile, the first player needs to be left with 5, 6, or 7 stones when his turn comes. He could force his opponent to leave him with 5, 6, or 7 stones if he leaves his opponent with 8 stones to choose from. To leave his opponent with 8 stones to choose from, the first player simply takes 1 stone on his first move of the game. So the first player can always win by following the strategy: take 1 stone, take enough to get down to 4, then take the remaining stones. 

Ex: What if the person who takes the last stone loses? Follow the same sort of reasoning. What we did in the last proof is called backward reasoning. Instead of starting at the beginning and moving forward to our goal, we started with the goal and moved backward to see how to derive it. Let’s use the same strategy. For a player to win, he must leave his opponent with 1 stone in the pile. To be able to leave his opponent with 1 stone in the pile, the player needs to be left with 2, 3, or 4 stones when his turn comes. He could force his opponent to leave him with 2, 3, or 4 stones if he leaves his opponent with 5 stones to choose from. To be able to leave his opponent with 5 stones to choose from, the player needs to be left with 6, 7, or 8 stones when his turn comes. But the first players move will leave the second player with 6, 7, or 8 stones to choose from. So in this case the second player has a winning strategy: After player 1 moves, take enough stones to get down to 5, then take all but the last stone.

Ex: Prove that n 3 - n is divisible by 3 for all integers n. Proof: Let n be an integer. Consider n 3 - n = n(n 2 - 1) = n(n - 1)(n + 1). Now n - 1, n, and n + 1 are three consecutive integers. If we could show that 3 divides one of these integers then we can conclude that 3 divides n 3 - n (because it is a multiple of each of these integers). So what we really want to prove is that 3 divides at least one of any three consecutive integers. Then 3 | n 3 - n is just a corollary of this. Lemma: Let n be an integer. Then 3 divides n - 1, n, or n + 1. Proof: Let n be an integer. Then by the FTOA when n is divided by 3 it leaves a remainder of 0, 1 or 2. Case 1: If n leaves a remainder of 0 when divided by 3, then 3 | n. Case 2: If n leaves a remainder of 1 when divided by 3, then n = 3q + 1 for some integer q. So n + 2 = 3q + 3 = 3(q + 1). So 3 | n + 2. Case 3: If n leaves a remainder of 2 when divided by 3, then n = 3r + 2 for some integer r. So n + 1 = 3r + 3 = 3(r + 1). So 3 | n + 1. 

The Halting Problem int factorial(int n) { int result = 1; for( int i = n; i != 0; i-- ) result = result * i; return result; } factorial(0) = 1 = 0!factorial(1) = 1 = 1!factorial(2) = 2 = 2! factorial(3) = 6 = 3!factorial(4) = 24 = 4!factorial(5) = 120 = 5! factorial(-1) = ???

It would be nice if we had a function bool Halts( program P, input I ); such that when we call this function Halts giving it a program P and an input to the program I, the function will return true if program P would halt when run with input I and will return false if program P would enter an infinite loop and never halt when run with input I. The question immediately arises, “Will the program Halt always terminate?”. Well, clearly, for Halt to be useful to us, we must be ensured that no matter what input we give to Halt (program and input for the program), Halt is always guaranteed to halt and give us an answer. That is, part of the design criteria for Halt is that it would never enter an infinite loop. Surely we would also like to impose some time constraint on Halt such as it can only take up to 10 minutes, but before we even consider this further improvement, we can rule out the possibility of Halt altogether.

Theorem (The Halting Problem): There does not exist a program which given an arbitrary program P and arbitrary input to the program I, will always halt and tell you correctly whether program P would halt or not when run with input I. First let’s consider the obvious attempt at Halt. What if we just had Halt simulate program P when run with input I. That is, all Halt does is to run the program you give it on the input you give it and then tell you the results of whether P terminated when run with input I. This implementation of Halt violates the criterion that Halt must always terminate. Surely if you give Halt a program and input that will terminate then Halt will finish simulating the program and tell you true. But if the input to Halt is a program and input that would not ever terminate, then Halt will never finish simulating the program. We don’t have the machinery to formally prove the halting problem, but we can discuss the proof in informal terms.

Let’s assume to the contrary that there does exist a program H(P, I) which solves the halting problem. (We will derive a contradiction). Then H(P, I) takes two inputs, P which is a program, and I which is an input to the program. And H always halts in a finite amount of time and tells us whether the program P when run with input I would have halted or not. Consider that a program P is simply the text of the source code. And the input to a program is also simply some text. Since the input is arbitrary, we could consider what a program P would do when we give it as input its own source code P. That is, what happens when we make the call H(P, P) for a program P. We are asking whether the program P halts when given its own source code as input. Since we have assumed the existence of the procedure H(P, I) we can use it as a subprocedure whenever we wish. Let us construct a new procedure K which will take advantage of the existence of H.

We construct the procedure K(P) which takes a program as input. K(P) works as follows: bool K(program P) { bool result = H(P, P);// run H with program P given input P if( result == false )// if P would loop forever on input P return true;// then K halts else// if P would halt on input P while(1){};// then K loops forever } So K(P) calls H(P, P) to see what P would do when given its own source code as input. Then K(P) does the opposite of what H(P, P) said P would do on its own input. K(P) loops forever if P would halt.

Now we ask the (extremely convoluted) question: “Would K halt if it were run with its own source as input?” That is, we what would happen if we run H(K, K)? There are two possibilities, K would halt when given input K or not. Case 1: What if the truth of the matter is that K would indeed halt when run with its own source code as input. That is K(K) halts. Then since H(K, K) always tells us the truth about whether K would halt given input K, then we would expect H(K, K) to tell us true. But if H(K, K) tells us true, then by the definition of procedure K, K(K) would loop forever. That is, when we run K with its own source as input it would not halt! This is a contradiction because we were considering the case that K halted when run with its own source as input. So Case 1 cannot be!

Case 2: We are left with the alternative that the truth of the matter is that K would loop forever when run with its own source code as input. That is K(K) does not halt. Then since H(K, K) always tells us the truth about whether K would halt given input K, then we would expect H(K, K) to tell us false. But if H(K, K) tells us false, then by the definition of procedure K, K(K) would halt. That is, when we run K with its own source as input it would halt! This is a contradiction because we were considering the case that K looped forever when run with its own source as input. So Case 2 cannot be! So in either case we run into a contradiction. K does not halt when run with its own source as input, nor does K loop forever. But it must do one of the two. So we conclude that K can not exist. But K was a perfectly legitimate procedure that only used procedure H. So the conclusion must be that H can’t exist. That is, we could never construct a procedure that solves the halting problem because the very existence of H allows us to construct a procedure K which can’t exist.