Lecture 13 CS 1813 – Discrete Mathematics

Slides:



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

Mathematical Induction
Lecture 11 Mathematical Induction CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 Lecture 3 CS 1813 – Discrete Mathematics Truth Inference and the Logical Way.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
CSE115/ENGR160 Discrete Mathematics 04/03/12 Ming-Hsuan Yang UC Merced 1.
1 Mathematical Induction. 2 Mathematical Induction: Example  Show that any postage of ≥ 8¢ can be obtained using 3¢ and 5¢ stamps.  First check for.
CSE115/ENGR160 Discrete Mathematics 03/31/11
EE1J2 - Slide 1 EE1J2 – Discrete Maths Lecture 12 Number theory Mathematical induction Proof by induction Examples.
Discrete Structures Chapter 5: Sequences, Mathematical Induction, and Recursion 5.2 Mathematical Induction I [Mathematical induction is] the standard proof.
Chapter 10 Sequences, Induction, and Probability Copyright © 2014, 2010, 2007 Pearson Education, Inc Mathematical Induction.
1 Section 3.4 Recursive Definitions. 2 Recursion Recursion is the process of defining an object in terms of itself Technique can be used to define sequences,
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.
Lecture 9. Arithmetic and geometric series and mathematical induction
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!
Lecture 3.1: Mathematical Induction CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren, Zeph Grunschlag.
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.
March 3, 2015Applied Discrete Mathematics Week 5: Mathematical Reasoning 1Arguments Just like a rule of inference, an argument consists of one or more.
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.
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 Lecture 7 CS 1813 – Discrete Mathematics Equational Reasoning Back to the Future:
Methods of Proof Dr. Yasir Ali. Proof A (logical) proof of a statement is a finite sequence of statements (called the steps of the proof) leading from.
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 Lecture 2 CS 1813 – Discrete Mathematics Proofs Propositions and Calculuses.
(CSC 102) Lecture 23 Discrete Structures. Previous Lecture Summery  Sequences  Alternating Sequence  Summation Notation  Product Notation  Properties.
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 Lecture 19 CS 1813 – Discrete Mathematics Trees and Inductive Definitions.
1 2/21/2016 MATH 224 – Discrete Mathematics Sequences and Sums A sequence of the form ar 0, ar 1, ar 2, ar 3, ar 4, …, ar n, is called a geometric sequence.
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 Lecture 14 CS 1813 – Discrete Mathematics A Little Bit of Set Theory.
Mathematical Induction Thinking Skill: Develop Confidence in Reason Warm Up: Find the k+1 term (P k+1 ) 1) 2)
Mathematical Induction 1. 2 Suppose we have a sequence of propositions which we would like to prove: P (0), P (1), P (2), P (3), P (4), … P (n), … We.
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.
9/27/2011 Lecture Mathematical Induction1 Lecture 3.1: Mathematical Induction* CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
1 Section 4.4 Inductive Proof What do we believe about nonempty subsets of N? Since  N, <  is well-founded, and in fact it is linear, it follows that.
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 CS 1813 – Discrete Mathematics Review of Predicate Calculus Set Theory Inductive.
MATH 224 – Discrete Mathematics
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett
Chapter 3 The Real Numbers.
Mathematical Induction 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
CS 1813 – Discrete Mathematics
Lecture 16 CS 1813 – Discrete Mathematics
Quizzes CS 1813 – Discrete Mathematics
Lecture 9 CS 1813 – Discrete Mathematics
Lecture 11 CS 1813 – Discrete Mathematics
Mathematical Induction I
Applied Discrete Mathematics Week 9: Integer Properties
Lecture 5 CS 1813 – Discrete Mathematics
Lecture 18 Section 4.1 Thu, Feb 10, 2005
PROGRAMMING IN HASKELL
Lecture 3.1: Mathematical Induction
Induction (Section 3.3).
Follow me for a walk through...
Lecture 8 CS 1813 – Discrete Mathematics
CSCE 314: Programming Languages Dr. Dylan Shell
Advanced Analysis of Algorithms
Miniconference on the Mathematics of Computation
Mathematical Induction
Mathematical Induction
Follow me for a walk through...
CS344 : Introduction to Artificial Intelligence
Copyright © Cengage Learning. All rights reserved.
Lecture 3.1: Mathematical Induction
Presentation transcript:

Lecture 13 CS 1813 – Discrete Mathematics Lecture 16 - CS 1813 Discrete Math, University of Oklahoma 11/18/2018 Lecture 13 CS 1813 – Discrete Mathematics Induction Induction … CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Concatenating Sequences Lecture 16 - CS 1813 Discrete Math, University of Oklahoma 11/18/2018 Concatenating Sequences (++) :: [a] -> [a] -> [a] (x: xs) ++ ys = x: (xs ++ ys) (++).: [ ] ++ ys = ys (++).[] Proposition P(n) (universe of discourse: n N ) length xs = n  length(xs ++ ys) = length xs + length ys P(0): length xs = 0  length(xs++ys) = length xs + length ys length(xs ++ ys) = length([ ] ++ ys) len 0  [ ] = length ys (++).[] = 0 + length ys 2nd-grade arithmetic = length xs + length ys hypothesis of implication Next, prove P(n)  P(n+1) … next slide CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Concatenating Sequences the inductive case Lecture 16 - CS 1813 Discrete Math, University of Oklahoma 11/18/2018 Concatenating Sequences the inductive case P(n+1): length xs = n+1  length(xs++ys) = (length xs) + (length ys) length(xs++ys) = length((z:zs) ++ ys) xs = (z: zs) {see note} = length(z: (zs ++ ys)) (++).: = 1 + length(zs ++ ys) (length).: = 1 + length zs + length ys P(n), since length zs = n = 1 + n + length ys (length zs) = n {see note} = n + 1 + length ys + comm = length xs + length ys hypothesis in P(n+1) Note: z. zs. (xs = (z: zs))  ((length zs) = n) (:len) corollary CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Concatenating Sequences applying the principle of induction Lecture 16 - CS 1813 Discrete Math, University of Oklahoma 11/18/2018 Concatenating Sequences applying the principle of induction Proved: P(0) Proved: P(n)  P(n+1) Conclude nN. P(n) — by the principle of induction P(n): length xs = n  length(xs ++ ys) = length xs + length ys qed CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Concatenating a List of Sequences the big ++ Lecture 16 - CS 1813 Discrete Math, University of Oklahoma 11/18/2018 Concatenating a List of Sequences the big ++ concat :: [[a]] -> [a] concat(xs: xss) = xs ++ concat xss (concat).: concat[ ] = [ ] (concat).[] Theorem: n N. P(n) where P(n) is defined as follows: P(n)  (k{1, 2, … n}. length(xsk)N)  length(concat [xs1, xs2, … xsn]) = sum[length xs1, length xs2, … length xsn] List Comprehension — like set comprehension, but for sequences [sequence-element | generator, optional-constraint] [x - 2 | x <- [12, 9, 27, 19, 13]] = [10, 7, 25, 17, 11] [x | x <- [12, 9, 27, 19, 13], x < 15] = [12, 9, 13] [x + 3 | x <- [12, 9, 27, 19, 13], x < 15] = [15, 12, 16] Proof Induction on n All this stuff is starting to look alike, isn’t it? CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Lecture 16 - CS 1813 Discrete Math, University of Oklahoma 11/18/2018 shuffle shuffle :: [a] -> [a] -> [a] Examples shuffle [1, 2, 3, 4, 5] [6, 7, 8, 9, 10] = [1, 6, 2, 7, 3, 8, 4, 9, 5, 10] shuffle [1, 2, 3, 4, 5] [6, 7, 8] = [1, 6, 2, 7, 3, 8, 4, 5] shuffle [1, 2, 3, 4] [6, 7, 8, 9, 10] = [1, 6, 2, 7, 3, 8, 4, 9, 10] Pattern of computation shuffle [x1, x2, … xn] [y1, y2, … yn] = [x1, y1, x2 , y2, … xn , yn] Note: extra elements in either sequence appended to the end Definition shuffle (x: xs) (y: ys) = [x, y] ++ shuffle xs ys shuffle [ ] ys = ys shuffle xs [ ] = xs CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Lecture 16 - CS 1813 Discrete Math, University of Oklahoma 11/18/2018 shuffle Works shuffle :: [a] -> [a] -> [a] shuffle (x: xs) (y: ys) = [x, y] ++ shuffle xs ys (shf).: shuffle [ ] ys = ys (shf).[]L shuffle xs [ ] = xs (shf).[]R Theorem (shuffle works) nN. P(n) where P(n)  shuffle [x1, x2, … xn] [y1, y2, … yn] = [x1, y1, x2 , y2, … xn , yn] P(0) = shuffle [ ] [ ] = [ ] — Why? Because (shf).[]L That’s why! P(n+1)  shuffle [x1, x2, … xn+1] [y1, y2, … yn+1]=[x1, y1, x2 , y2, … xn+1 , yn+1] Proof of P(n+1) shuffle [x1, x2, … xn+1] [y1, y2, … yn+1] = shuffle (x1 : [x2, x3, … xn+1] ) (y1 : [y2, y3, … yn+1] ) (: …) (twice) = [x1, y1] ++ shuffle [x2, x3, … xn+1] [y2, y3, … yn+1] (shf).: = [x1, y1] ++ [x2, y2, x3 , y3, … xn+1 , yn+1] P(n) = x1: (y1: [x2, y2, x3 , y3, … xn+1 , yn+1] ) (++).: (twice) = [x1, y1, x2 , y2, … xn+1 , yn+1] (: …) (twice) CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Lecture 16 - CS 1813 Discrete Math, University of Oklahoma 11/18/2018 Indexing (!!) (!!):: [a] -> Int -> a (x: xs) !! 0 = x (!!).0 (x: xs) !! (n+1) = xs !! n (!!).n+1 Note: n N N = {0, 1, 2, …} Pattern of computation [x0, x1, x2, …] !! k = xk What do the (!!)-equations say about the following formula? [ ] !! 0 How about this formula? [ ] !! k How about these? (x: xs) !! (-1) xs !! (-1) CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

shuffle Works – more formally Lecture 16 - CS 1813 Discrete Math, University of Oklahoma 11/18/2018 shuffle Works – more formally shuffle (x: xs) (y: ys) = [x, y] ++ shuffle xs ys (shf).: Theorem (shuffle works) nN. P(n) where P(n)  ( ((length xs) > n)  ((length ys) > n) )  (k, 0  k  n. (((shuffle xs ys) !! (2*k)) = (xs !! k))  (((shuffle xs ys) !! (2*k + 1)) = (ys !! k)) ) P(0)  ( ((length xs) > 0)  ((length ys) > 0) )  (k, 0  k  0. (((shuffle xs ys) !! (2*k)) = (xs !! k))  (((shuffle xs ys) !! (2*k + 1)) = (ys !! k)) ) = ( ((length xs) > 0)  ((length ys) > 0) )  ( (((shuffle xs ys) !! 0) = (xs !! 0))  (((shuffle xs ys) !! 1) = (ys !! 0)) ) {finite -universe} = ( (x. ws. xs = (x: ws))  (y. zs. ys = (y: zs)) )  ( (((shuffle (x: ws) (y: zs)) !! 0) = ((x: ws) !! 0))  (((shuffle (x: ws) (y: zs)) !! 1) = ((y: zs) !! 0)) ) {(:), len 0  [ ], arith} = ( (x. ws. xs = (x: ws))  (y. zs. ys = (y: zs)) )  ( ((([x, y] ++ shuffle ws zs) !! 0) = ((x: ws) !! 0))  ((([x, y] ++ shuffle ws zs) !! 1) = ((y: zs) !! 0)) ) {(shf).:} = ( (x. ws. xs = (x: ws))  (y. zs. ys = (y: zs)) )  ( (x = x )  (y = y) ) { (++).:, , (!!).n+1, (!!).0} = True {= reflexive,  id, Thm: (a  True) = True } CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page end of base case

shuffle Works – more formally inductive case Lecture 16 - CS 1813 Discrete Math, University of Oklahoma 11/18/2018 shuffle Works – more formally inductive case P(n+1)  ( ((length xs) > n+1)  ((length ys) > n+1) )  (k, 0  k  n+1. (((shuffle xs ys) !! (2*k)) = (xs !! k))  (((shuffle xs ys) !! (2*k + 1)) = (ys !! k)) ) = ( (x.ws.xs=(x:ws)((length ws) > n) )(y.zs.ys=(y:zs)((length zs) > n)) )  (k, 0  k  n+1. (((shuffle xs ys) !! (2*k)) = (xs !! k))  (((shuffle xs ys) !! (2*k + 1)) = (ys !! k)) ) {len 0  [ ], } = ( (x.ws.xs=(x:ws)((length ws) > n) )(y.zs.ys=(y:zs)((length zs) > n)) )  ((k, 0  k  n.( (((shuffle xs ys) !! (2*k)) = (xs !! k))  (((shuffle xs ys) !! (2*k + 1)) = (ys !! k)) )  (((shuffle (x:ws) (y:zs))!!(2*(n+1))) = ((x:ws)!!(n+1)))  (((shuffle (x:ws) (y:zs))!!(2*(n+1)+1)) = ((y:zs)!!(n+1))) ) {subst, finite -univ} = ( (x.ws.xs=(x: ws)((length ws) > n))  (y.zs.ys=(y: zs) ((length zs) > n)))  (k, 0  k  n.( (((shuffle xs ys) !! (2*k)) = (xs !! k))  (((shuffle xs ys) !! (2*k + 1)) = (ys !! k)) )  (((shuffle ws zs)!!(2*n)) = (ws!!n))  (((shuffle ws zs)!!(2*n+1)) = (zs!!n)) ) {(shf).:, (++).:, , (!!).n+1} = ( (x.ws.xs=(x: ws)((length ws) > n))  (y.zs.ys=(y: zs)  ((length zs) > n)))  (True  True  True) {P(n)} = True { id, Thm: (a  True) = True} CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page qed

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