CS 1813 – Discrete Mathematics

Slides:



Advertisements
Similar presentations
Discrete Mathematics Lecture 5 Alexander Bukharovich New York University.
Advertisements

Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Instructor: Hayk Melikya
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 Lecture 3 CS 1813 – Discrete Mathematics Truth Inference and the Logical Way.
Discrete Mathematics Lecture 4 Harper Langston New York University.
EE1J2 - Slide 1 EE1J2 – Discrete Maths Lecture 12 Number theory Mathematical induction Proof by induction Examples.
Relations Chapter 9.
Course Outline Book: Discrete Mathematics by K. P. Bogart Topics:
A Brief Summary for Exam 1 Subject Topics Propositional Logic (sections 1.1, 1.2) –Propositions Statement, Truth value, Proposition, Propositional symbol,
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 Lecture 18 CS 1813 – Discrete Mathematics Loops Without Invariants Are Like.
MATH 224 – Discrete Mathematics
INTRODUCTION TO THE THEORY OF COMPUTATION INTRODUCTION MICHAEL SIPSER, SECOND EDITION 1.
Week 15 - Wednesday.  What did we talk about last time?  Review first third of course.
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
Mathematical Preliminaries (Hein 1.1 and 1.2) Sets are collections in which order of elements and duplication of elements do not matter. – {1,a,1,1} =
CS 103 Discrete Structures Lecture 10 Basic Structures: Sets (1)
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 Lecture 10 CS 1813 – Discrete Mathematics Quantify What? Reasoning with Predicates.
Sets Define sets in 2 ways  Enumeration  Set comprehension (predicate on membership), e.g., {n | n  N   k  k  N  n = 10  k  0  n  50} the set.
Reading and Writing Mathematical Proofs Spring 2015 Lecture 4: Beyond Basic Induction.
Hazırlayan DISCRETE COMPUTATIONAL STRUCTURES Propositional Logic PROF. DR. YUSUF OYSAL.
CompSci 102 Discrete Math for Computer Science
Mathematical Preliminaries
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
Review 2 Basic Definitions Set - Collection of objects, usually denoted by capital letter Member, element - Object in a set, usually denoted by lower.
2007 D iscrete The foundations C ounting theory N umber theory G raphs & trees structure s
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 Lecture 19 CS 1813 – Discrete Mathematics Trees and Inductive Definitions.
1 Topic Sets (5.1, 5.2, 5.3). 2 Original author of the slides: Vadim Bulitko University of Alberta Modified by.
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 Lecture 14 CS 1813 – Discrete Mathematics A Little Bit of Set Theory.
Week 15 - Wednesday.  What did we talk about last time?  Review first third of course.
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?
Chapter 2 1. Chapter Summary Sets (This Slide) The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions.
Week 8 - Wednesday.  What did we talk about last time?  Relations  Properties of relations  Reflexive  Symmetric  Transitive.
Introduction to Set Theory (§1.6) A set is a new type of structure, representing an unordered collection (group, plurality) of zero or more distinct (different)
CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page 1 CS 1813 – Discrete Mathematics Review of Predicate Calculus Set Theory Inductive.
CSCE 355 Foundations of Computation
Types CSCE 314 Spring 2016.
Equivalence Relations
Relations Chapter 9.
Formal Modeling Concepts
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 2 Sets Slides are adopted from “Discrete.
Computer Science Department
Lecture 15 CS 1813 – Discrete Mathematics
CSCE 355 Foundations of Computation
Jaya Krishna, M.Tech, Assistant Professor
Lecture 12 CS 1813 – Discrete Mathematics
PROGRAMMING IN HASKELL
Propositional Calculus: Boolean Algebra and Simplification
Lecture 6 CS 1813 – Discrete Mathematics
Lecture 13 CS 1813 – Discrete Mathematics
CS 1813 – Discrete Mathematics
Lecture 16 CS 1813 – Discrete Mathematics
CSE 311 Foundations of Computing I
CS201: Data Structures and Discrete Mathematics I
Quizzes CS 1813 – Discrete Mathematics
INTRODUCTION TO THE THEORY OF COMPUTATION
Lecture 9 CS 1813 – Discrete Mathematics
Lecture 1 CS 1813 – Discrete Mathematics
Lecture 11 CS 1813 – Discrete Mathematics
A Brief Summary for Exam 1
Back to “Serious” Topics…
MA/CSSE 474 More Math Review Theory of Computation
Computer Security: Art and Science, 2nd Edition
Lecture 5 CS 1813 – Discrete Mathematics
MCS680: Foundations Of Computer Science
Lecture 8 CS 1813 – Discrete Mathematics
This Lecture Substitution model
Chapter 1 Introduction to the Theory of Computation
Logic Logic is a discipline that studies the principles and methods used to construct valid arguments. An argument is a related sequence of statements.
CS201: Data Structures and Discrete Mathematics I
Presentation transcript:

CS 1813 – Discrete Mathematics Lecture 27 - CS 1813 Discrete Math, University of Oklahoma 9/21/2018 CS 1813 – Discrete Mathematics Discrete Mathematics Review or Yes, the Final Will Be Comprehensive CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Truth Tables for Logical Operators P Q P  Q False False False False True False True False False True True True P  Q False True P  Q PQ PQ  P CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Predicates and Quantifiers Parameterized collection of propositions P(x) Typically a different proposition for each x Universe of discourse Values that x may take Quantifiers x.P(x) True iff the proposition P(x) is True for every x in the universe of discourse x.P(x) True iff there is at least one x in the universe of discourse for which the proposition P(x) is True CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Rules of Inference Propositional Calculus Lecture 27 - CS 1813 Discrete Math, University of Oklahoma 9/21/2018 Rules of Inference Propositional Calculus Discrete Mathematics with a Computer Springer, 2000 Fig 2.1, Hall/O’Donnell After presenting this slide, put up a copy on the overhead projector to refer to in upcoming proofs. CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Inference Rules of Predicate Calculus Lecture 27 - CS 1813 Discrete Math, University of Oklahoma 9/21/2018 Inference Rules of Predicate Calculus x. F(x) {y not in F(x)} {R} y. F(y) Renaming Variables F(x) {x arbitrary, y not in F(x)} {R} F(y) x. F(x) {y not in F(x)} {R} y. F(y) Introducing/Eliminating Quantifiers F(x) {x arbitrary} {I} x. F(x) x. F(x) {universe is not empty} {E} F(x) {E} rule triggers discharge F(x) {I} x. F(x) x. F(x) F(x) |– A {x not free in A} {E} A ...plus the inference rules of propositional calculus CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Induction Rules of Inference P(0) n.(P(n)P(n+1)) {Ind} n.P(n) Induction n.((mn.P(m))P(n)) {StrInd} n.P(n) Strong Induction t. ((s  t. P(s))  P(t)) {TrInd} t.P(t) Tree Induction s  t means s is a proper subtree of t {P(v)  B(v)} s {P(v)} {LInd} {P(v)} (while B(v) do s) {P(v)B(v)} Loop Induction v is a set v of variables P(v) and B(v) are predicates cannot alter values in v s is a command s may alter values in v CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Some Theorems in Rule Form a  b {Comm} b  a Or Commutes a  b {Comm} b  a And Commutes ab bc {Chain} ac Implication Chain Rule (a  b) {()Comm} (b  a) Not Or Commutes a  b b {modTol} a Modus Tollens a  b {conPosF} (b)(a) Contrapositive Fwd {noMiddle} a  (a) Law of Excluded Middle a a { +&- } False NeverBoth a  b {F} (a)  b Implication Fwd CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

More Theorems in Rule Form (a  b) {DeMF} (a)(b) DeMorgan Or Fwd (a)(b) {DeMB} (a  b) DeMorgan Or Bkw (a  b) {DeMF} (a)(b) DeMorgan And Fwd (a)(b) {DeMB} (a  b) DeMorgan And Bkw a  b a {disjSyll} b Disjunctive Syllogism (a) { F} a Double Negation Fwd a { B} (a) Double Negation Bkw CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Some Laws of Boolean Algebra From Fig 2.1, Hall & O’Donnell, Discrete Math with a Computer, Springer, 2000 CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

More Laws of Boolean Algebra From Fig 2.1, Hall & O’Donnell, Discrete Math with a Computer, Springer, 2000 (a  b)  b = b { absorption} (a  b)  b = b { absorption} (a  b)  c = (a  c)  (b  c) { imp} ((a  b)  (a  c)  (b  c))  c { Elim} CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Algebraic Laws of Predicate Calculus Lecture 27 - CS 1813 Discrete Math, University of Oklahoma 9/21/2018 Algebraic Laws of Predicate Calculus x not free in q (x. P(x))  (y. Q(y)) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) y not in f(x) (x. f(x)) = (y. f(y)) {R} (x. f(x)) = (y. f(y)) {R} CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

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 CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Some Algebraic Laws of Software Algebraic law of sequence construction x : [x1, x2, …, xn] = [x, x1, x2, …, xn] -- (:) Algebraic laws of concatenation [ ] ++ ys = ys -- (++).[] (x : xs) ++ ys = x : (xs ++ ys) -- (++).: What is the type of (++) ? (++) :: [a] -> [a] -> [a] Algebraic laws of foldr foldr () z [ ] = z -- (foldr).[] foldr () z (x : xs) = x  (foldr () z xs) -- (foldr).: What is the type of foldr ? foldr :: (a -> b -> b) -> b -> [a] -> b The big or (\/) :: Bool -> Bool -> Bool -- “little or” – satisfies Boolean laws for  or = foldr (\/) False -- “big or” What is the type of or ? or :: [Bool] -> Bool CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

More Algebraic Laws of Software sum(x: xs) = x + sum xs (sum).: sum[ ] = 0 (sum).[] Theorem: sum = foldr (+) 0 Type: sum :: Num n => [n] -> n length(x: xs) = 1 + length xs (length).: length[ ] = 0 (length).[] Theorem: length = foldr oneMore 0 where oneMore x n = 1 + n Type: length :: [a] -> Int (x: xs) ++ ys = x: (xs ++ ys) (++).: [ ] ++ ys = ys (++).[] Theorem: xs ++ ys = foldr (:) ys xs Type: (++) :: [a] -> [a] -> [a] concat(xs: xss) = xs ++ concat xss (concat).: concat[ ] = [ ] (concat).[] Theorem: concat = foldr (++) [ ] Type: concat :: [[a]] -> [a] CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Still More Algebraic Laws of Software Pattern: foldr () z [x1, x2, …, xn-1, xn ] = x1  ( x2  … (xn-1  ( xn  z)) … ) foldr () z (x: xs) = x  foldr () z xs (foldr).: foldr () z [ ] = z (foldr).[] Type: foldr :: (a -> b -> b) -> b -> [a] -> b Pattern: map f [x1, x2, … xn] = [f x1, f x2, … f xn] map f (x : xs) = (f x) : map f xs (map).: map f [ ] = [ ] (map).[] Type: map :: (a -> b) -> [a] -> [b] Pattern: zipWith b [x1, x2, … xn] [y1, y2, … yn] = [b x1 y1, b x2 y2, … b xn yn] Note: extra elements in either sequence are dropped zipWith b (x:xs) (y:ys) = (b x y): (zipWith xs ys) (zipW).: zipWith b [ ] ys = [ ] (zipW).[]-1 zipWith b xs [ ] = [ ] (zipW).[]-2 Type: zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

CS 1813 Discrete Mathematics, Univ Oklahoma 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 CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Loop Induction for verifying properties of loops Loop precondition: P(x1, x2, … xx) proved True while B(x1, x2, … xx) … body of loop … Loop invariant: P(x1, x2, … xx) proved True P(x1, x2, … xx)  B(x1, x2, … xx) is True Loop Induction Proof by Loop Induction Prove: P(x1, x2, … xx) is true when a loop begins Prove: same P(x1, x2, … xx) is true at end of each iteration Proof may assume P(x1, x2, … xx) was true on previous iterations Conclude: P(x1, x2, … xx) is True and B(x1, x2, … xx) is False if and when the loop terminates Requirement Computing B(x1, x2, … xx) does not affect values of x1, x2, … xx CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

sum = foldr (+) 0 — as a loop Function precondition: a[1..n] defined integer sum(integer a[ ]) integer n = length(a[ ]) integer k, s s = 0 k = 0 while (k < n) k = k+1 s = s + a[k] return s Conclude at return (by loop induction) s = a[i] i=1 k Loop precondition: s = a[i] i=1 k But what is k at return? Loop invariant: s = a[i] i=1 k Loop terminates with k = n by counting-loop theorem (coming up) Loop precondition True Subscript set for  is empty and empty sums are 0, by convention Loop invariant True at end of loop if True at beginning a[i] = i=1 k+1 a[i] where k denotes top-of-loop value of k k a[k+1] + CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

The Counting-Loop Theorem A type, c, is a “counting type” if c includes operations suc::c -> c and (<), (=)::c -> c -> bool (suc m)  n whenever (m < n) {Note: x  y means (x < y)(x = y)} (m < n)  (n  iterate suc m) iterate f x = x : (iterate f (f x)) Computation pattern: iterate f x = [x, f x, f(f x), f(f(f x), … ] Theorem (counting loop) If k, m, n :: c, and m  n, and If neither cmd1 nor cmd2 affects the values of k, m, or n Then the following loop terminates and when it does, k = n k = m while (k < n) cmd1 k = suc k cmd2 CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

CS 1813 Discrete Mathematics, Univ Oklahoma What Is a Tree? Tree a diagram or graph that branches usually from a simple stem without forming loops or polygons Merriam-Webster a type of data structure in which each element is attached to one or more elements directly beneath it — Webopedia a node, together with a sequence of trees inductive definition Tree terminology subtree — a node in a tree, together with its sequence of trees root — the node that, with its subtrees, comprises the entire tree interior node — a node with a nonempty sequence of subtrees leaf — a tree with an empty sequence of subtrees branch — a line connecting a node to its subtrees (in tree diagram) binary tree — a tree with no nodes having more than 2 subtrees CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Binary Search Tree a formal representation Nub – leaf constructor data SearchTree key dat = Nub | Cel key dat (SearchTree key dat) (SearchTree key dat) Cel – constructor, non-empty trees Key goes here Node data Left subtree (smaller keys) Right subtree (larger keys) Type parameters — key, dat key — might be Int, for example (datatype with an ordering) dat — could be any type, typically a tuple Example s :: SearchTree Int (String, Float, [String] ) s is a SearchTree key type – Int (maybe a catalog order number) dat type – tuple storing a String (product description), a Float (price), and a sequence of strings (inventory records) CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Big O Notation and Computation Time Bounding the rate of growth Given: functions f and g f is big-O of g, written f = O(g), means c, s. x  s. |f(x)|  c|g(x)| deal (x1: (x2: xs)) = ( x1: ys, x2: zs ) where (ys, zs) = deal xs deal [x] = ( [x], [ ] ) deal [ ] = ( [ ], [ ] ) Computation time for deal Tn = time required for to compute deal[x1, x2, … xn] Recurrence equations T0 = T1 = 3 3 ops: matching, []-build, pair-build Tn = Tn-2 + 4 4 ops: matching, 2 insertions, pair-build plus deal sequence that is shorter by 2 Tn  4n, n  0 that is, Tn = O(n) — prove by induction CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

What a Relation Is as a mathematical object Relation — a definition A binary relation () :: A  B is a subset of the Cartesian product of A (the domain) and B (the codomain)   A  B = {(a, b) | aA, bB} a  b means (a, b) Reflexive ::AA, aA. a  a Irreflexive ::AA, aA. (a, a) Symmetric ::AA, a, bA. ab  ba Antisymmetric ::AA, a, bA. ab  ba  a = b Transitive ::AA, a, b, c A. ab  bc  ac Closure wrt P ::AA, {S | S  S has property P} CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

CS 1813 Discrete Mathematics, Univ Oklahoma Classes of Relations Partial Order  :: AA, reflexive, antisymmetric, transitive Total Order  :: AA, partial order a, bA. (a, b)  (b, a) Well Order  :: AA, total order B, BA, B. bB. aA. (b, a) Equivalence Relation  :: A  A reflexive, symmetric, and transitive CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

CS 1813 Discrete Mathematics, Univ Oklahoma What It All Means Completeness in Formal Systems If a |= b, then a |– b (a, b arbitrary WFFs) If b is true whenever a is, there is a proof of a |– b Notions of Consistency in Formal Systems If a |– b, then a |= b (a, b arbitrary WFFs) No WFF a such that both |– a and |– a Predicate Logic Consistent Inference preserves tautologies Inconsistency would make all WFFs tautologies Some WFFs aren’t tautologies — QED (consistency) Complete There is a proof for every tautology in predicate calculus More powerful formal systems (such as arithmetic or Haskell) are not complete CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Lecture 27 - CS 1813 Discrete Math, University of Oklahoma 9/21/2018 Why Bother with Proofs? 100s of inputs > 2100s of possibilities input signals software output signals Key presses Mouse gestures Files Databases … computation Images Sounds Software translates input signals to output signals A program is a constructive proof of a translation Responsible software developers are obligated specify what properties their software is guaranteed to have. Proofs play a big role in this. Other methods of confirming software properties, especially testing, leave software riddled with errors. Most systems have hundreds of input signals. Since each input signal must have at least two possible values, the number of different input states that must be checked to verify the operation of the software through testing is at least 2 to the power 100. If you can generate, run, and examine one test case every minute, round the clock, you will not finish testing before you die. Not even before the sun runs out of fuel. Not even if you do one test case every nanosecond. Forget it. Testing can work only on very small pieces of software. But what translation? Proofs can confirm that software works correctly Testing cannot confirm software correctness Practice with proofs improves software thinking CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

CS 1813 Discrete Mathematics Learning Goals Lecture 27 - CS 1813 Discrete Math, University of Oklahoma 9/21/2018 CS 1813 Discrete Mathematics Learning Goals Apply mathematical logic to prove software properties Predicate calculus and natural deduction Boolean algebra and equational reasoning Mathematical induction Understand fundamental data structures Sets Trees Functions and relations Additional topics Graphs Counting Algorithm Complexity proofs galore! CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page

Lecture 27 - CS 1813 Discrete Math, University of Oklahoma 9/21/2018 End of Lecture CS 1813 Discrete Mathematics, Univ Oklahoma Copyright © 2000 by Rex Page