Lecture 9 CS 1813 Discrete Mathematics Predicate Calculus

  • Slides: 10
Download presentation
Lecture 9 CS 1813 – Discrete Mathematics Predicate Calculus Propositions Plus 1

Lecture 9 CS 1813 – Discrete Mathematics Predicate Calculus Propositions Plus 1

What is a Predicate? q Predicate § Parameterized collection of propositions § P(x) ü

What is a Predicate? q Predicate § Parameterized collection of propositions § P(x) ü Typically a different proposition for each x ü Universe of discourse – Values that x may take q 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 CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 2

Predicate on a Program for Sums q sum: : [Rational] -> Rational function-type arrow,

Predicate on a Program for Sums q sum: : [Rational] -> Rational function-type arrow, not implication § Input (argument) ü Sequence of Rational values (ratios of whole numbers) ü Type: [Rational] — square brackets indicate sequence-type § Output (value delivered): Rational — not a sequence (so, no brackets) q Predicate § S(n) sum[x 1, x 2, …, xn] = x 1 + x 2 + … + xn ü S is a predicate — each equation S(n) is a different proposition ü Each S(n) is either True or False ü S(3) is the (atomic) proposition sum[x 1, x 2, x 3] = x 1 + x 2 + x 3 § Universe of discourse (collection of values that parameterize S) ü Natural numbers N = {0, 1, 2, … } — a collection of infinite size § Why not T([x 1, x 2, … xn]) instead of S(n)? ü Nothing wrong with T([x 1, x 2, … xn]) ü Universe of discourse for T: finite sequences of numbers ü Universe of discourse for S: counting numbers {0, 1, 2, …} CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 3

Predicate on a Program for Maximums q maximum : : [String] -> String §

Predicate on a Program for Maximums q maximum : : [String] -> String § Argument ü Sequence of strings (String means sequence of characters) ü Type: [String] — square brackets indicate sequence-type § Value: String — not a sequence of strings (so, no brackets) q Predicate § B(n, k) maximum[s 1, s 2, …, sn] sk ü B is a predicate — each B(n, k) is a proposition (True or False) ü B(4, 2) is the (atomic) proposition maximum[s 1, s 2, s 3 , s 4] s 2 § Universe of discourse (collection of values that parameterize B) ü Pairs of non-zero natural numbers {(1, 1), (2, 2), (3, 1), … } where second number in pair does not exceed first § Why not C([s 1, s 2, … sn], sk) instead of B(n, k)? ü C is ok, but depends on the strings si — not just on n and k – Proofs involving B must take care to encompass arbitrary si’s – Note: Proofs will work for any type of class Ord, not just String ü What is the universe of discourse for C([s 1, s 2, … sn], sk)? CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 4

Another Predicate about Maximums q maximum : : [String] -> String § Argument ü

Another Predicate about Maximums q maximum : : [String] -> String § Argument ü Sequence of strings (String means sequence of characters) ü Type: [String] — square brackets indicate sequence-type § Value: String — not a sequence of strings (so, no brackets) q Predicate § E(n, k) maximum[s 1, s 2, …, sn] = sk ü E is a predicate —each equation E(n, k) is an atomic proposition ü Each E(n, k) is either True or False ü E(4, 1) is the proposition maximum[s 1, s 2, s 3 , s 4] = s 1 § Universe of discourse (collection of values that parameterize E) ü Pairs of non-zero natural numbers {(1, 1), (2, 2), (3, 1), … } where second number in pair does not exceed first § Is E(n, k) usually True or usually False? ü Would you expect E(n, k) to be True for some pairs (n, k)? ü Given a sequence of strings [s 1, s 2, … sn], would you expect to be able to find any values of k for which E(n, k) is true? CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 5

Predicates about a Sorting Program q qsort : : Ord a => [a] ->

Predicates about a Sorting Program q qsort : : Ord a => [a] -> [a] § Argument ü Sequence of type [a] — where a is a type of class Ord § Value — Also a sequence of type [a] q Predicates § L(n) length(qsort[a 1, a 2, …, an] ) = n ü L is a predicate — each equation L(n) is a proposition ü Universe of discourse: Natural numbers N = {0, 1, 2, … } ü What does [a 1, a 2, …, an] mean when n = 0 ü Would you expect L(n) to be True, regardless of the ai’s? § I(n, k) (qsort[a 1, a 2, …, an] = [b 1, b 2, …, bn] ) (bk bk+1 ) ü I is a predicate — each I(n, k) is a proposition (non-atomic, btw) ü Universe of discourse: Pairs of non-zero natural numbers where first number exceeds second {(2, 1), (3, 2), (4, 1), … } ü For what pairs would you expect I(n, k) to be True? § R(n, j, k) (qsort[a 1, a 2, …, an] = [b 1, b 2, …, bn] ) (aj = bk) ü Universe of discourse? Places in universe where R(n, j, k) is True? CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 6

Predicates about Concatenation q (++) : : [a]-> [a] § Two arguments ü Sequences

Predicates about Concatenation q (++) : : [a]-> [a] § Two arguments ü Sequences of type [a] — where a can be any type § Value — Also a sequence of type [a] q Predicates § C(n, m) length( [a 1, a 2, …, an] ++ [b 1, b 2, …, bm] ) = n + m ü C is a predicate — each equation C(n, m) is a proposition ü Universe of discourse: Pairs of natural numbers {(0, 0), (1, 0), … } ü Would you expect C(n, m) to be True? § A(xs, ys, zs) xs ++ (ys ++ zs) = (xs ++ ys) ++ zs ü A is a predicate — each equation A(xs, ys, zs) is a proposition ü Universe of discourse: Triples of sequences of type [a] ü For what sequences would you expect A(xs, ys, zs) to be True? CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 7

 — the Universal Quantifier, Forall q x. P(x) § This formula is a

— the Universal Quantifier, Forall q 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 every value of x in the universe of discourse § False if there is some value x in the universe of discourse for which P(x) is False § Equivalent to forming the Logical And of all P(x)’s q Example – S predicate about sum § S(n) sum[x 1, x 2, …, xn] = x 1 + x 2 + … + xn § 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) CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 8

Another Example with Forall — the Universal Quantifier q B — predicate about maximum

Another Example with Forall — the Universal Quantifier q B — predicate about maximum § B(n, k) maximum[s 1, s 2, …, sn] sk § Universe of discourse ü Pairs of non-zero natural numbers where second number in pair does not exceed first ü U = {(n, k) N N | 0 k n} = {(1, 1), (2, 2), (3, 1), … } ü OK, so we haven’t gotten to set theory yet — Sabe, verdad? § (n, k). B(n, k) ü A predicate calculus formula because each B(n, k) is a proposition, which is a portion of predicate calculus U = N N s y, lue l l a a v c ü Do you expect (n, k). B(n, k) to be True? ut hni b c , he e e t s T e a is c outsid ial. § Other ways to write (n, k). B(n, k) h t in k) ter , a n ( m ü n N. k N. (0 k) (k n) B(n, k) of B are im U ü n N, n 0. k N, 0 k n. B(n, k) old ü Note nesting and direct specification of universe of discourse CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 9

End of Lecture 9 10

End of Lecture 9 10