Lecture 16 CS 1813 – Discrete Mathematics

Slides:



Advertisements
Similar presentations
Functional Programming Lecture 13 - induction on lists.
Advertisements

Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
13.4 Mathematical Induction. Mathematical Induction is a common method of proving that each statement of an infinite sequence of mathematical statements.
Induction and recursion
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 Lecture 3 CS 1813 – Discrete Mathematics Truth Inference and the Logical Way.
EE1J2 - Slide 1 EE1J2 – Discrete Maths Lecture 12 Number theory Mathematical induction Proof by induction Examples.
1 Section 3.3 Mathematical Induction. 2 Technique used extensively to prove results about large variety of discrete objects Can only be used to prove.
Mathematical Induction Readings on induction. (a) Weiss, Sec. 7.2, page 233 (b) Course slides for lecture and notes recitation. Every criticism from a.
Induction and recursion
Reading and Writing Mathematical Proofs
CSNB143 – Discrete Structure Topic 5 – Induction Part I.
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 Lecture 18 CS 1813 – Discrete Mathematics Loops Without Invariants Are Like.
Copyright © Peter Cappello Mathematical Induction Goals Explain & illustrate construction of proofs of a variety of theorems using mathematical induction.
CSE 311 Foundations of Computing I Lecture 15 Recursive Definitions and Structural Induction Autumn 2011 CSE 3111.
CSE 311 Foundations of Computing I Lecture 16 Recursively Defined Sets and Structural Induction Spring
1 CMSC 250 Chapter 4, con't., Inductive Proofs. 2 CMSC 250 Description l Inductive proofs must have: –Base case: where you prove that what it is you are.
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 Lecture 10 CS 1813 – Discrete Mathematics Quantify What? Reasoning with Predicates.
9.4 Mathematical Induction
Reading and Writing Mathematical Proofs Spring 2015 Lecture 4: Beyond Basic Induction.
Induction Proof. Well-ordering A set S is well ordered if every subset has a least element. [0, 1] is not well ordered since (0,1] has no least element.
Lecture 4,5 Mathematical Induction and Fibonacci Sequences.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
CompSci 102 Discrete Math for Computer Science March 1, 2012 Prof. Rodger Slides modified from Rosen.
CS 103 Discrete Structures Lecture 13 Induction and Recursion (1)
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 Lecture 19 CS 1813 – Discrete Mathematics Trees and Inductive Definitions.
Mathematical Induction
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
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.
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 Lecture 14 CS 1813 – Discrete Mathematics A Little Bit of Set Theory.
1 Discrete Mathematical Mathematical Induction ( الاستقراء الرياضي )
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 Lecture 17 CS 1813 – Discrete Mathematics How Does It Work in the Real World?
6/12/2016 Prepared by Dr.Saad Alabbad1 CS100 : Discrete Structures Proof Techniques(2) Mathematical Induction & Recursion Dr.Saad Alabbad Department of.
CSE 311 Foundations of Computing I Lecture 15 Strong Induction and Recursive Definitions Spring
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 CS 1813 – Discrete Mathematics Review of Predicate Calculus Set Theory Inductive.
(Proof By) Induction Recursion
MATH 224 – Discrete Mathematics
CPSC 121: Models of Computation 2008/9 Winter Term 2
COT 3100, Spring 2001 Applications of Discrete Structures
Mathematical Induction II
PROGRAMMING IN HASKELL
PROGRAMMING IN HASKELL
Methods of Proof A mathematical theorem is usually of the form pq
Chapter 5 Induction and Recursion
Lecture 4 CS 1813 – Discrete Mathematics
Lecture 15 CS 1813 – Discrete Mathematics
CS 1813 – Discrete Mathematics
Lecture 12 CS 1813 – Discrete Mathematics
Lecture 6 CS 1813 – Discrete Mathematics
Lecture 13 CS 1813 – Discrete Mathematics
CS 1813 – Discrete Mathematics
The Foundations: Logic and Proofs
Discrete Mathematics and its Applications
Quizzes CS 1813 – Discrete Mathematics
Induction and recursion
Lecture 9 CS 1813 – Discrete Mathematics
CS200: Algorithm Analysis
Lecture 11 CS 1813 – Discrete Mathematics
PROGRAMMING IN HASKELL
Predicate Transformers
Rosen 5th ed., §§ ~18 slides, ~1 lecture
Follow me for a walk through...
Trevor Brown CS 341: Algorithms Trevor Brown
CSCE 314: Programming Languages Dr. Dylan Shell
Advanced Analysis of Algorithms
Mathematical Induction
Mathematical Induction
Follow me for a walk through...
Discrete Mathematics and its Applications
Discrete Mathematics and its Applications
Discrete Mathematics and its Applications
Presentation transcript:

Lecture 16 CS 1813 – Discrete Mathematics Lecture 17 - CS 1813 Discrete Math, University of Oklahoma 11/28/2018 Lecture 16 CS 1813 – Discrete Mathematics Strong Induction Induction at a Discount or Bringing in the Cavalry to Prove P(n) CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

deal — a way to split a sequence in half deal :: [a] -> ( [a], [a] ) Examples deal [1, 2, 3, 4, 5, 6] = ( [1, 3, 5], [2, 4, 6] ) deal [1, 2, 3, 4, 5, 6, 7] = ( [1, 3, 5, 7], [2, 4, 6] ) Pattern of computation deal [x1, x2, … x2n] = ( [x1, x3, … x2n-1], [x2, x4, … x2n] ) Definition deal (x1: (x2: xs)) = ( x1: ys, x2: zs ) where (ys, zs) = deal xs deal [x] = ( [x], [ ] ) deal [ ] = ( [ ], [ ] ) What equation changes if we want the extra element (if there is one) to go into the list in the second component? CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Termination Is deal a Finite Computation? Equations for deal deal :: [a] -> ( [a], [a] ) deal (x1: (x2: xs)) = ( x1: ys, x2: zs ) where (ys, zs) = deal xs deal [x] = ( [x], [ ] ) deal [ ] = ( [ ], [ ] ) Question of termination Given: a computer system that can interpret the deal equations Question: What conditions imply termination? Given a sequence xs::[a], under what conditions will the computer system be able to deliver, in a finite amount of time, a value of the form (ys, zs) = deal xs Answer When xs has a finite number of elements, (deal xs) terminates Proof … need to know a few things about basic operations CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

CS 1813 Discrete Mathematics, Univ Oklahoma Basic Operations deal :: [a] -> ( [a], [a] ) deal (x1: (x2: xs)) = ( x1: ys, x2: zs ) where (ys, zs) = deal xs deal [x] = ( [x], [ ] ) deal [ ] = ( [ ], [ ] ) Matching For any sequence xs::[a], computer system can determine, in a finite amount of time, which deal-equation matches xs Pairing For any sequences xs, ys::[a], computer system can build, in a finite amount of time, the pair (xs, ys) Insertion For any sequence xs::[a] and any value x::a, computer system can build, in a finite amount of time, the sequence (x: xs) Empty System can build, in a finite amount of time, the sequence [ ] CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

CS 1813 Discrete Mathematics, Univ Oklahoma Induction with a Twist n.(mn.P(m))P(n) {StrInd} n.P(n) Basic Principle of Induction Prove P(0) is true Prove P(n+1) is true, nN arbitrary Proof of P(n+1) may assume P(n) is true Conclude nN. P(n) What if proof of P(n+1) does not make use of P(n)? Conclusion nN. P(n) is still valid This would be a direct proof using the {I} inference rule The principle of induction is a lever that makes the proof easier Another Principle of Induction Prove P(n) for arbitrary n  N Twist: Can assume kDn.P(k), where Dn= {kN | k  n} Getting Started: D0 = { } So, must prove P(0) from scratch (as with old principle of induction) Strong Induction Pretty good deal, eh? CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

deal Terminates (deal xs) delivers (ys, zs) in a finite amount of time deal :: [a] -> ( [a], [a] ) deal (x1: (x2: xs)) = ( x1: ys, x2: zs ) where (ys, zs) = deal xs deal [x] = ( [x], [ ] ) deal [ ] = ( [ ], [ ] ) P(n)  length xs = n  (deal xs) terminates Proof of P(0) deal xs = deal [ ] (matching) xs has 0 elements = ( [ ], [ ] ) (pairing, empty ) (deal).[] Each step takes a finite amount of time, so (deal xs) terminates Proof of P(1) = deal [x] (matching) xs has 1 element = ( [x], [ ] ) (pairing, empty) (deal).[x] Again, each step takes a finite amount of time, so (deal xs) terminates CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

deal Terminates — inductive case deal :: [a] -> ( [a], [a] ) deal (x1: (x2: xs)) = ( x1: ys, x2: zs ) where (ys, zs) = deal xs P(n)  length xs = n  (deal xs) terminates Proof of P(n) for arbitrary n  {2, 3, 4, …} deal xs = deal (x1: (x2: ws)) (matching) xs has 2 or more elements = (x1: ys, x2: zs) where (ys, zs) = deal ws (deal).:: Two insertions Pair construction Terminates because ws has n-2 elements P(n-2) assumed true Each step finite, so (deal xs) terminates Summary P(0) proved (direct proof) P(1) proved (direct proof) P(n) proved for arbitrary n  {2, 3, 4, …} (inductive proof) Conclude nN. P(n) (strong induction) qed CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

CS 1813 Discrete Mathematics, Univ Oklahoma merge merge :: Ord a => [a] -> [a] -> [a] Desired outcome Sequence in increasing order (if both arguments are) All (and only) elements from both sequences included in result Examples merge [1, 3, 4, 7, 10] [2, 5, 8, 9] = [1, 2, 3, 4, 5, 7, 8, 9, 10] merge [“if”, “it”, “were”] [“ain’t”, “is”, “it”] = [“ain’t”, “if”, “is”, “it”, “it”, “were”] Preconditions x1  x2  …  xn and y1  y2  …  ym Postconditions (zs = [z1, z2, … zn+m] = merge xs ys)  (z1  z2  …  zn+m )  (xs  zs)(ys  zs)(length(xs ++ ys)= length zs) where vs  ws means vs is a subsequence of ws Any cases not covered? merge (x: xs) (y: ys) = if y  x then y : (merge (x: xs) ys) else x : (merge xs (y: ys)) merge [ ] ys = ys merge (x: xs) [ ] = (x: xs) CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page merge (x: xs) [ ]

Making a Sequence Ordered — Sorting msort :: Ord a => [a] -> [a] Desired outcome Sequence containing same elements as input … … but arranged in order Preconditions Ord a, xs::[a], xs has finite number of elements Postconditions (ys = [y1, y2, … , yn] = msort xs)  y1  y2  …  yn  ((x  xs)  (x  ys))  length xs = length(msort xs) where “” means “element of” All cases covered? msort (x1: x2: xs) = merge (msort ys) (msort zs) where (ys, zs) = deal(x1: x2: xs) merge-sort msort [ ] = [ ] msort [x] = [x] Theorem: msort = qsort Definition qsort (x: xs) = qsort[y | y <- xs, y  x] ++ [x] ++ qsort[y | y<- xs, y = x] qsort [ ] = [ ] Proof: major project quicksort (Antony Hoare) CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

CS 1813 Discrete Mathematics, Univ Oklahoma msort Terminates Theorem (mT): (merge xs ys) terminates  length(merge xs ys) = (length xs) + (length ys) Proof — induction on n = (length xs) + (length ys) Need finite time for two additional operations Comparing: Ord a, x, y::a, system computes (x  y) in finite time Selecting: b::Bool, x, y::a, system computes (if b then x else y) in finite time Theorem (dS): n. (length xs = n)  (ys, zs) = deal xs  (deal xs) terminates  (length xs) = (length ys) + (length zs) Proof — induction on n = (length xs) Corollary (dR): (length xs)  2  (ys, zs) = deal xs  length ys  (length xs)  (length zs)  (length xs) Theorem(msT): (length xs) = n  (msort xs) terminates  length(msort xs) = n Proof — next slide CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Termination Proof — msort msort (x1: x2: xs) = merge (msort ys) (msort zs) where (ys, zs) = deal(x1: x2: xs) msort [ ] = [ ] msort [x] = [x] P(n)  (length xs) = n  (msort xs) terminates  length(msort xs) = n Proof of P(0) msort xs = msort [ ] (pattern matching) (length xs) = 0 = [ ] (build empty sequence) (msort).[] Each step takes a finite amount of time, so (msort xs) terminates Proof of P(1) = msort [x] (matching) (length xs) = 1 = [x] (no operation) (msort).[x] CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

msort Termination Proof — inductive case msort (x1: x2: xs) = merge (msort ys) (msort zs) where (ys, zs) = deal(x1: x2: xs) P(n)  (length xs) = n  (msort xs) terminates  length(msort xs) = n Proof of P(n) for arbitrary n  {2, 3, 4, …} msort xs = msort(x1: x2: ws) (pattern matching) (length xs)  2 = merge (msort ys) (msort zs) (no operation) (msort).:: where (ys, zs) = deal(x1: x2: ws) merge terminates (mT) (msort ys) terminates – Why? (msort zs) terminates (similar argument) deal terminates (dS) length ys  length xs (dR) Ind Hyp implies P(length ys) is True Each step (matching, deal, msort twice, merge) takes a finite amount of time, so (msort xs) terminates length xs = length ys + length zs (dS) = length(msort ys) + length(msort zs) P(length ys), P(length zs) = length(merge (msort ys) (msort zs)) (mT) = length(msort xs) (msort).:: – as in above proof CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page qed (strong induction)

Lecture 17 - CS 1813 Discrete Math, University of Oklahoma 11/28/2018 End of Lecture CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page