Gray Code Can you find an ordering of all the n-bit strings in such a way that two consecutive n-bit strings differed by only one bit? This is called the.

Slides:



Advertisements
Similar presentations
Mathematical Induction
Advertisements

Mathematical Induction II Lecture 14: Nov
Prove the Impossible Sep 28 No program can check whether another program will run into infinite loop. x=0.
Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
Week 5 - Friday.  What did we talk about last time?  Sequences  Summation and production notation  Proof by induction.
Induction and Recursion. Odd Powers Are Odd Fact: If m is odd and n is odd, then nm is odd. Proposition: for an odd number m, m k is odd for all non-negative.
Basic properties of the integers
Induction Lecture 5: Sep 21 (chapter of the book and chapter of the notes)
Induction and recursion
Elementary Number Theory and Methods of Proof. Basic Definitions An integer n is an even number if there exists an integer k such that n = 2k. An integer.
1 Intro to Induction Supplementary Notes Prepared by Raymond Wong Presented by Raymond Wong.
Invariant Method Lecture 6: Sep
Strong Induction, WOP and Invariant Method Leo Cheung.
Methods of Proof Lecture 4: Sep 16 (chapter 3 of the book)
Invariant Method Lecture
Prove the Impossible Lecture 6: Sep 19 (based on slides in MIT 6.042)
Induction (chapter of the book and chapter of the notes)
Induction and recursion
Methods of Proof & Proof Strategies
Mathematical Maxims and Minims, 1988
Invariant Method
Induction and recursion
The Pigeonhole (Dirichlet’s box) Principle
Introduction to Proofs
Reading and Writing Mathematical Proofs
Mathematical Induction. F(1) = 1; F(n+1) = F(n) + (2n+1) for n≥ F(n) n F(n) =n 2 for all n ≥ 1 Prove it!
1 Introduction to Abstract Mathematics Chapter 4: Sequences and Mathematical Induction Instructor: Hayk Melikya 4.1- Sequences. 4.2,
Methods of Proof. This Lecture Now we have learnt the basics in logic. We are going to apply the logical rules in proving mathematical theorems. Direct.
Section 1.8. Section Summary Proof by Cases Existence Proofs Constructive Nonconstructive Disproof by Counterexample Nonexistence Proofs Uniqueness Proofs.
Discrete Mathematics Tutorial 11 Chin
Methods of Proof Lecture 3: Sep 9. This Lecture Now we have learnt the basics in logic. We are going to apply the logical rules in proving mathematical.
Mathematical Induction I Lecture 4: Sep 16. This Lecture Last time we have discussed different proof techniques. This time we will focus on probably the.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
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.
Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.
CompSci 102 Discrete Math for Computer Science March 1, 2012 Prof. Rodger Slides modified from Rosen.
1 INFO 2950 Prof. Carla Gomes Module Induction Rosen, Chapter 4.
Mathematical Induction Section 5.1. Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If.
Mathematical Induction
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
CS104:Discrete Structures Chapter 2: Proof Techniques.
Chapter 5. Section 5.1 Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If we can reach.
Mathematical Induction I Lecture 5: Sep 20 (chapter of the textbook and chapter of the course notes)
Section 1.7. Definitions A theorem is a statement that can be shown to be true using: definitions other theorems axioms (statements which are given as.
Methods of Proof Lecture 4: Sep 20 (chapter 3 of the book, except 3.5 and 3.8)
3.3 Mathematical Induction 1 Follow me for a walk through...
Chapter 5 1. Chapter Summary  Mathematical Induction  Strong Induction  Recursive Definitions  Structural Induction  Recursive Algorithms.
Fifteen Puzzle Move: can move a square adjacent to the empty square to the empty square.
Induction (chapter of the book and chapter of the notes)
Hubert Chan (Chapters 1.6, 1.7, 4.1)
The Foundations: Logic and Proofs
Chapter 3 The Real Numbers.
CSE15 Discrete Mathematics 02/08/17
Advanced Algorithms Analysis and Design
Mathematical Induction II
Chapter 3 The Real Numbers.
Induction and recursion
Predicate Calculus Validity
Hubert Chan (Chapters 1.6, 1.7, 4.1)
Chapter 5 Induction and Recursion
The Foundations: Logic and Proofs
Induction and recursion
Methods of Proof Rosen 1.7, 1.8 Lecture 4: Sept 24, 25.
Induction Chapter
Advanced Analysis of Algorithms
Foundations of Discrete Mathematics
Induction Rosen 5 Lecture 8: Oct 29, 30.
Copyright © Cengage Learning. All rights reserved.
Agenda Proofs (Konsep Pembuktian) Direct Proofs & Counterexamples
Methods of Proof Rosen 1.7, 1.8 Lecture 4: Sept, 2019.
Presentation transcript:

Gray Code Can you find an ordering of all the n-bit strings in such a way that two consecutive n-bit strings differed by only one bit? This is called the Gray code and has many applications. How to construct them? Think inductively! (or recursively!) 2 bit 00 01 11 10 3 bit 000 001 011 010 110 111 101 100 Can you see the pattern? How to construct 4-bit gray code?

Gray Code 4 bit 3 bit 000 001 011 010 110 111 101 100 3 bit (reversed) 1 000 001 011 010 110 111 101 100 differed by 1 bit by induction differed by 1 bit by construction 100 101 111 110 010 011 001 000 Every 4-bit string appears exactly once. differed by 1 bit by induction

Gray Code n+1 bit n bit 000…0 … 100…0 n bit (reversed) 100…0 … 000…0 1 1 000…0 … 100…0 differed by 1 bit by induction differed by 1 bit by construction 100…0 … 000…0 Every (n+1)-bit string appears exactly once. differed by 1 bit by induction So, by induction, Gray code exists for any n.

P(n) ::= any set of n horses have the same color Paradox Theorem: All horses are the same color. Proof: (by induction on n) Induction hypothesis: P(n) ::= any set of n horses have the same color Base case (n=0): No horses so obviously true! …

… n+1 Paradox (Inductive case) Assume any n horses have the same color. Prove that any n+1 horses have the same color. … n+1

Paradox (Inductive case) Assume any n horses have the same color. Prove that any n+1 horses have the same color. Second set of n horses have the same color … First set of n horses have the same color

Paradox (Inductive case) Assume any n horses have the same color. Prove that any n+1 horses have the same color. … Therefore the set of n+1 have the same color!

Paradox What is wrong? n =1 Proof that P(n) → P(n+1) is false if n = 1, because the two horse groups do not overlap. Second set of n=1 horses First set of n=1 horses (But proof works for all n ≠ 1)

Unstacking Game a b a+b Start: a stack of boxes Move: split any stack into two stacks of sizes a,b>0 Scoring: ab points Keep moving: until stuck Overall score: sum of move scores a b a+b

Unstacking Game n n-1 1 What is the best way to play this game? Suppose there are n boxes. What is the score if we just take the box one at a time? n n-1 1

Not better than the first strategy! Unstacking Game What is the best way to play this game? n 2n Suppose there are n boxes. What is the score if we cut the stack into half each time? Not better than the first strategy! Say n=8, then the score is 1x4x4 + 2x2x2 + 4x1 = 28 first round second third Say n=16, then the score is 8x8 + 2x28 = 120

Unstacking Game Base case n = 0: Claim: Every way of unstacking gives the same score. Claim: Starting with size n stack, final score will be Proof: by Induction with Claim(n) as hypothesis Base case n = 0: score = 0 Claim(0) is okay.

Unstacking Game Inductive step. assume for n-stack, and then prove C(n+1): (n+1)-stack score = Case n+1 = 1. verify for 1-stack: score = 0 C(1) is okay.

Unstacking Game Case n+1 > 1. So split into an a-stack and b-stack, where a + b = n +1. (a + b)-stack score = ab + a-stack score + b-stack score by induction: a-stack score = b-stack score =

Unstacking Game (a + b)-stack score = ab + a-stack score + b-stack score so C(n+1) is okay. We’re done!

Induction Hypothesis Wait: we assumed C(a) and C(b) where 1  a, b  n. But by induction can only assume C(n) the fix: revise the induction hypothesis to In words, it says that we assume the claim is true for all numbers up to n. Proof goes through fine using Q(n) instead of C(n). So it’s OK to assume C(m) for all m  n to prove C(n+1).

Strong Induction Prove P(0). Strong induction Then prove P(n+1) assuming all of P(0), P(1), …, P(n) (instead of just P(n)). Conclude n.P(n) Strong induction equivalent Ordinary induction 0  1, 1  2, 2  3, …, n-1  n. So by the time we got to n+1, already know all of P(0), P(1), …, P(n) The point is: assuming P(0), P(1), up to P(n), it is often easier to prove P(n+1).

Divisibility by a Prime Theorem. Any integer n > 1 is divisible by a prime number. Let n be an integer. If n is a prime number, then we are done. Otherwise, n = ab, both are smaller than n. If a or b is a prime number, then we are done. Otherwise, a = cd, both are smaller than a. If c or d is a prime number, then we are done. Otherwise, repeat this argument, since the numbers are getting smaller and smaller, this will eventually stop and we have found a prime factor of n. Remember this slide? Now we can prove it by strong induction very easily. In fact we can prove a stronger theorem very easily. Idea of induction.

Prime Products Claim: Every integer > 1 is a product of primes. Proof: (by strong induction) Base case is easy. Suppose the claim is true for all 2 <= i < n. Consider an integer n. If n is prime, then we are done. So n = k·m for integers k, m where n > k,m >1. Since k,m smaller than n, By the induction hypothesis, both k and m are product of primes k = p1 p2   p94 m = q1 q2   q214

n = k m = p1 p2   p94 q1 q2   q214 Prime Products Claim: Every integer > 1 is a product of primes. …So n = k m = p1 p2   p94 q1 q2   q214 is a prime product.  This completes the proof of the induction step.

Well Ordering Principle Every nonempty set ofnonnegative integers has a least element. Axiom This is an axiom equivalent to the principle of mathematical induction. Note that some similar looking statements are not true: Every nonempty set of nonnegative rationals has a least element. NO! Every nonempty set of nonnegative integers has a least element. NO!

Well Ordering Principle Thm: is irrational Proof: suppose …can always find such m, n without common factors… why always? By WOP,  minimum |m| s.t. so where |m0| is minimum.

Well Ordering Principle but if m0, n0 had common factor c > 1, then and contradicting minimality of |m0| The well ordering principle is usually used in “proof by contradiction”. Assume the statement is not true, so there is a counterexample. Choose the “smallest” counterexample, and find a even smaller counterexample. Conclude that a counterexample does not exist.

To prove ``for all n in a set N. P(n)’’ using WOP: Well Ordering Principle in Proofs To prove ``for all n in a set N. P(n)’’ using WOP: Define the set of counterexamples C ::= {n | ¬P(n)} 2. Assume C is not empty. 3. By WOP, have minimum element m0 in C. 4. Reach a contradiction (somehow) – usually by finding a member of C that is < m0 . 5. Conclude no counterexamples exist. QED

Non-Fermat Theorem It is difficult to prove there is no positive integer solutions for Fermat’s theorem But it is easy to prove there is no positive integer solutions for Non-Fermat’s theorem Hint: Prove by contradiction using well ordering principle…

Non-Fermat Theorem Suppose, by contradiction, there are integer solutions to this equation. By the well ordering principle, there is a solution with |a| smallest. In this solution, a,b,c do not have a common factor. Otherwise, if a=a’k, b=b’k, c=c’k, then a’,b’,c’ is another solution with |a’| < |a|, contradicting the choice of a,b,c. (*) There is a solution in which a,b,c do not have a common factor.

Non-Fermat Theorem On the other hand, we prove that every solution must have a,b,c even. This will contradict (*), and complete the proof. (because odd power is odd). First, since c3 is even, c must be even. Let c = 2c’, then

Non-Fermat Theorem Since b3 is even, b must be even. (because odd power is odd). Let b = 2b’, then Since a3 is even, a must be even. (because odd power is odd). There a,b,c are all even, contradicting (*)

Invariant Method 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 15 14

? A Chessboard Problem A Bishop can only move along a diagonal Can a bishop move from its current position to the question mark? ?

? A Chessboard Problem A bishop can only move along a diagonal Can a bishop move from its current position to the question mark? ? Impossible! Why?

? A Chessboard Problem Invariant! The bishop is in a red position. A red position can only move to a red position by diagonal moves. The question mark is in a white position. So it is impossible for the bishop to go there. This is a simple example of the invariant method.

Domino Puzzle An 8x8 chessboard, 32 pieces of dominos Can we fill the chessboard?

Domino Puzzle An 8x8 chessboard, 32 pieces of dominos Easy!

Domino Puzzle An 8x8 chessboard with two holes, 31 pieces of dominos Can we fill the chessboard? Easy!

Domino Puzzle An 8x8 chessboard with two holes, 31 pieces of dominos Can we fill the chessboard? Easy??

Domino Puzzle An 4x4 chessboard with two holes, 7 pieces of dominos Can we fill the chessboard? Impossible!

Domino Puzzle An 8x8 chessboard with two holes, 31 pieces of dominos Can we fill the chessboard? Then what??

Domino Puzzle An 8x8 chessboard with two holes, 31 pieces of dominos Can we fill the chessboard?

Domino Puzzle Invariant! Each domino will occupy one white square and one red square. There are 32 blue squares but only 30 white squares. So it is impossible to fill the chessboard using only 31 dominos. This is another example of the invariant method.

Invariant Method Find properties (the invariants) that are satisfied throughout the whole process. Show that the target do not satisfy the properties. Conclude that the target is not achievable. In the rook example, the invariant is the colour of the position of the rook. In the domino example, the invariant is that any placement of dominos will occupy the same number of blue positions and white positions.

The Possible We just proved that if we take out two squares of the same colour, then it is impossible to finish. What if we take out two squares of different colours? Would it be always possible to finish then? Yes??

Prove the Possible Yes??

Prove the Possible The secret.

Prove the Possible The secret.

Fifteen Puzzle 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Move: can move a square adjacent to the empty square to the empty square.

Fifteen Puzzle 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 15 14 Initial configuration Target configuration Is there a sequence of moves that allows you to start from the initial configuration to the target configuration?

Invariant Method Find properties (the invariants) that are satisfied throughout the whole process. Show that the target do not satisfy the properties. Conclude that the target is not achievable. What is an invariant in this game?? This is usually the hardest part of the proof.

Hint 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 15 14 Initial configuration Target configuration ((1,2,3,…,14,15),(4,4)) ((1,2,3,…,15,14),(4,4)) Hint: the two states have different parity.

row number of the empty square Parity Given a sequence, a pair is “out-of-order” if the first element is larger. More formally, given a sequence (a1,a2,…,an), a pair (i,j) is out-of-order if i<j but ai > aj. For example, the sequence (1,2,4,5,3) has two out-of-order pairs, (4,3) and (5,3). Given a state S = ((a1,a2,…,a15),(i,j)) Parity of S = (number of out-of-order pairs + row) mod 2 row number of the empty square