Download presentation
Presentation is loading. Please wait.
Published byAngelina Horn Modified over 8 years ago
1
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 CS 1813 – Discrete Mathematics Review of Predicate Calculus Set Theory Inductive Definition Proof by Mathematical Induction
2
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 2 What is a Predicate? Predicate Parameterized collection of propositions P(x) Typically a different proposition for each x Universe of discourse –Values that x may take Universe of discourse Must be specified Otherwise, all bets off — muchas contradicciónes Non-empty Empty universe calls for special handling Default assumption: non-empty universe
3
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 3 — the Universal Quantifier, Forall x.P(x) This formula is a WFF of predicate calculus whenever P(x) is a WFF of predicate calculus True if the proposition P(x) is True for all x’s in the universe of discourse False if there is some x in the universe of discourse for which P(x) is False Equivalent to forming the Logical And of all P(x)’s Example – S predicate about sum S(n) sum[x 1, x 2, …, x n ] = x 1 + x 2 + … + x n n.S(n) Universe of discourse: natural numbers N = {0, 1, 2, … } n.S(n) means S(0) S(1) S(2) … So, “ ” provides a way to write formulas that would contain an infinite number of symbols if written in propositional calculus notation (but infinitely long formulas aren’t WFFs)
4
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 4 —the Existential Quantifier, There Exists x.P(x) This formula is a WFF of predicate calculus whenever P(x) is a WFF of predicate calculus True if there is at least one x in the universe of discourse for which the proposition P(x) is True False if x. P(x) is True Equivalent to forming the Logical Or of all P(x)’s Example – E predicate about maximum E(n, k) maximum[s 1, s 2, …, s n ] = s k k.E(23, k) Universe of discourse: U = {1, 2, …, 23} k.E(23, k) means E(23,1) E(23,2) … E(23,23) Note: When U is finite, quantifiers not required –Clumsy to write big formulas without quantifiers, though –Without quantifiers, reasoning can be more complex, too
5
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 5 Free Variables and Bound Variables Variables in WFFs of predicate calculus Denoted by lower-case letters Examples of predicate calculus WFFs with variables F(p, q) G(q, r)variables: p, q, r ( x.F(x)) (G(y) H(y))variables: x, y ( x.F(x, y) G(y)) (H(z) K(x))variables: x, y, z Free variables and bound variables Let e stand for a WFF of predicate calculus Bound variable x. ex is bound in the formula x. e x. ex is bound in the formula x. e Free variables are variables that are not bound Which variables are free?
6
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 6 Arbitrary Variables A variable is arbitrary in a proof if it does not occur free in any undischarged assumption of that proof Examples x. F(x) { E} F(x) G(x, y) { I} y. G(x, y) x arbitrary? P(x) Q { E L } P(x) { I} P(x) Q P(x) { I} x. P(x) Q P(x) x arbitrary? discharged Yes No Yes
7
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 7 x. F(x) F(x) |– A {x not free in A} { E} A Inference Rules of Predicate Calculus...plus the inference rules of propositional calculus x. F(x) {universe is not empty} { E} F(x) F(x) {x arbitrary} { I} x. F(x) F(x) { I} x. F(x) { E} rule triggers discharge x. F(x) {y not in F(x)} { R} y. F(y) x. F(x) {y not in F(x)} { R} y. F(y) F(x) {x, y arbitrary, y not in F(x)} {R} F(y) Renaming Variables Introducing/Eliminating Quantifiers
8
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 8 x. F(x) F(x) |– A {x not free in A} { E} A x. P(x) Q(x) { E} P(x) Q(x) Existential Elimination something like { E} Theorem 31 x. P(x), x. P(x) Q(x) |– x. Q(x) proof { E} Q(x) { E} x. Q(x) {x not free in x.Q(x)} x. P(x) discharge P(x) x. Q(x) x U. Q(x) plays role of A in { E} rule P plays role of F in { E} rule { I}
9
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 9 Existential Incrimination it’s not legal, really Theorem 9 from Planet X: x. P(x), x. P(x) Q(x) |– x. Q(x) Proof Why not? Suppose U, where U is the domain of discourse for x Is P( ) Q( ) True? Maybe so, maybe not “ x. P(x) Q(x)” means P( ) Q( ) is True for at least one value U There may be many values U where P( ) Q( ) is False Counter-example that disproves the theorem Universe of discourse = {0, 1} P(0) = True, P(1) = True Note: ( x. P(x)) = True Q(0) = True, Q(1) = FalseNote: ( x. P(x) Q(x)) = True But, ( x. (P(x) Q(x))) is also True Because P(1) Q(1) is False ( x. Q(x)) = False, because Q(1) = False QED
10
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 10 ( ) x not free in q Algebraic Laws of Predicate Calculus ( x. P(x)) ( y. Q(y)) ( x. f(x)) ( y. f(y)){ R} ( x. f(x)) ( y. f(y)){ R} y not in f(x)
11
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 11 Equational Reasoning with Predicates Theorem ( ( x. P(x)) ( x. Q(x)) ) = ( x. y. P(x) Q(y) ) Proof of Theorem ( x. P(x)) ( x. Q(x)) = ( ( x. P(x))) ( x. Q(x)) {implication} = ( x. P(x)) ( x. Q(x)) {3.6} = x. ( ( P(x)) ( x. Q(x)) ) {3.10} = x. ( ( x. Q(x)) ( P(x)) ) { comm} = x. ( ( y. Q(y)) ( P(x)) ) { R} = x. y. ( Q(y) ( P(x)) ) {3.10} = x. y. ( ( P(x)) Q(y) ) { comm} = x. y. ( P(x) Q(y) ) {implication} qed
12
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 12 Equational Reasoning about Software Algebraic law of sequence construction x : [x 1, x 2, …, x n ] = [x, x 1, x 2, …, x n ]-- (:) Algebraic laws of concatenation (++) :: [a] -> [a] -> [a] [ ] ++ ys = ys -- (++).[] (x : xs) ++ ys = x : (xs ++ ys) -- (++).: An equational argument [x] ++ xs = (x : [ ]) ++ xs (:) = x : ([ ] ++ xs) (++).: = x : xs (++).[] What did this prove? Theorem (++ 1 ) [x] ++ xs = x : xs ( )
13
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 13 More Software Equations The big or (\/) :: Bool -> Bool -> Bool -- “little or” – satisfies Boolean laws for or :: [Bool] -> Bool -- “big or” or = foldr (\/) False -- (or) Theorem (or null 1 ) — or null/first element or ([True] ++ xs) = True or ([True] ++ xs) = or (True : xs) (++ 1 ) = foldr (\/) False (True : xs) (or) = True \/ (foldr (\/) False xs) (foldr).: = True ( null) qed foldr (the big picture) foldr ( ) z [x 1, x 2, …, x n ] = x 1 (x 2 … (x n-1 (x n z)) … ) Algebraic laws of foldr foldr :: (a -> b -> b) -> b -> [a] -> b foldr ( ) z [ ] = z -- (foldr).[] foldr ( ) z (x : xs) = x (foldr ( ) z xs) -- (foldr).:
14
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 14 principleofinduction Universe of discourse: N = {0, 1, 2, …} Predicate P P(n) is a proposition whenever n N Want to prove: n N. P(n) That is, to prove that the proposition P(n) is True for all natural numbers n Principle of Induction Prove: P(0) Prove: n N. (P(n) P(n+1)) Conclude: n N. P(n) The Principle of Mathematical Induction A way to prove P(n) for all values of n, without proving any P(n) directly except P(0)
15
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 15 Theorem — or[x, y, …,True, …] = True Theorem (or T ) n N. length ys = n or (ys ++ ([True] ++ xs)) = True Proof P(n) length ys = n or (ys ++ ([True] ++ xs)) = True Base case: P(0) length ys = 0 or(ys ++ ([True] ++ xs)) = True length ys = 0 ys = [ ]zero len theorem or(ys ++ ([True] ++ xs)) = or([ ] ++ ([True] ++ xs)) substitution = or ([True] ++ xs) ++.[] = True or 1 T Inductive case: P(n) P(n+1) … next slide
16
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 16 Theorem — or[x, y, …,True, …] = True Inductive Case Predicate to prove for inductive case P(n+1) length ys = n+1 or (ys ++ ([True] ++ xs)) = True length ys = n+1 ys [ ]zero len theorem ys = y: zs length zs = n :len corollary or(ys ++ ([True] ++ xs)) = or((y:zs) ++ ([True] ++ xs)) subst length zs = n = or(y:(zs ++ ([True] ++ xs))) length zs = n (++).: = y \/ (or(zs ++ ([True] ++ xs)))) length zs = n (foldr).: = (y \/ True) length zs = n P(n) (y \/ True) (conj imp) = True null Conclude: n N. P(n) principle of induction induction hypothesis qed
17
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 17 Strong Induction 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 Principle of Strong Induction Prove P(n) for arbitrary n N Twist: Can assume k D n. P(k), where D n = {k N | k n} Conclude n N. P(n) Getting Started: D 0 = { } So, must prove P(0) from scratch (as with old principle of induction) Pretty good deal, eh? Strong Induction n.( m n.P(m)) P(n) {StrInd} n.P(n)
18
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 18 msort Termination Proof — inductive case 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 (msort ys) (msort zs) (msort).: msort (x1: x2: xs) = where (ys, zs) = deal(x1: x2: xs) 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 length ys length xs (dR) (msort ys) terminates – Why? (msort zs) terminates (similar argument) merge terminates (mT) qed (strong induction) Ind Hyp implies P(length ys) is True strong induction deal terminates (dS)
19
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 19 Haskell Type Specifications x, y, z :: Integer -- x, y, and z have type Integer xs, ys :: [Integer]-- sequences with Integer elements or :: [Bool] -> Bool -- function with one argument argument is sequence with Bool elems delivers value of type Bool (++) :: [e] -> [e] -> [e] -- generic function with two arguments args are sequences with elems of same type type is not constrained (can be any type) delivers sequence with elements of same type as those in arguments sum :: Num n => [n] -> n -- generic function with one argument argument is a sequence with elems of type n n must a type of class Num Num is a set of types with +, , … operations powerSet :: (Eq e, Show e) => Set e -> Set(Set e) -- generic function with one argument argument is a set with elements of type e delivers set with elements of type (Set e) type e must be both class Eq and class Show Class Eq has == operator, Show displayable
20
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 20 Inductive Definitions aka Recursive Equations sum :: Num n => [n] -> n sum(x: xs) = x + sum xs(sum).: sum[ ] = 0 (sum).[] Theorem: sum = foldr (+) 0 length :: [a] -> Int length(x: xs) = 1 + length xs (length).: length[ ] = 0(length).[] Theorem: length = foldr oneMore 0 where oneMore x n = 1 + n (++) :: [a] -> [a] -> [a] (x: xs) ++ ys = x: (xs ++ ys) (++).: [ ] ++ ys = ys(++).[] Theorem: xs ++ ys = foldr (:) ys xs concat :: [[a]] -> [a] concat(xs: xss) = xs ++ concat xss (concat).: concat[ ] = [ ](concat).[] Theorem: concat = foldr (++) [ ]
21
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 21 Patterns of Computation Pattern: foldr ( ) z [x 1, x 2, …, x n-1, x n ] = x 1 ( x 2 … (x n-1 ( x n z)) … ) foldr :: (a -> b -> b) -> b -> [a] -> b foldr ( ) z (x: xs) = x foldr ( ) z xs(foldr).: foldr ( ) z [ ] = z(foldr).[] Pattern: map f [x 1, x 2, … x n ] = [f x 1, f x 2, … f x n ] map :: (a -> b) -> [a] -> [b] map f (x : xs) = (f x) : map f xs(map).: map f [ ] = [ ](map).[] Pattern: zipWith b [x 1, x 2, … x n ] [y 1, y 2, … y n ] = [b x 1 y 1, b x 2 y 2, … b x n y n ] Note: extra elements in either sequence are dropped zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] zipWith b (x:xs) (y:ys) = (b x y): (zipWith b xs ys)(zipW).: zipWith b [ ] ys = [ ](zipW).[]-1 zipWith b xs [ ] = [ ] (zipW).[]-2
22
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 22 Sets {2, 3, 5, 7, 11} — explicit enumeration 2 {2, 3, 5, 7, 11} — stylized epsilon means “element of” = { } — stylized Greek letter phi denotes empty set {x | p x} — set comprehension Denotes set with elements x, where (p x) is True {f x | p x} — set comprehension Denotes set with elements of form (f x), where (p x) is True A B x. (x A x B) — subset A = B (A B) (B A) — set equality A B = {x | x A x B} — union S = {x | A S. x A} — big union A B = {x | x A x B} — intersection S = {x | A S. x A} — big intersection A – B = {x | x A x B} — set difference A’ = U – A — complement (U = universe) P(A) = {S | S A} — power set A B = {(a, b) | a A b B} — Cartesian product
23
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 23 End of Lecture
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.