cpsc 121 models of computation
play

CPSC 121: Models of Computation Module 5: Predicate Logic Module 5: - PowerPoint PPT Presentation

CPSC 121: Models of Computation Module 5: Predicate Logic Module 5: Predicate Logic Midterm 1: Friday October 12 th , 17:30 to 18:45 A to G (by last name): room FSC 1005 H to O: room ESB 1013 P to Z: room CIRS 1250 Modules 1 to 5 (up to


  1. CPSC 121: Models of Computation Module 5: Predicate Logic

  2. Module 5: Predicate Logic Midterm 1: Friday October 12 th , 17:30 to 18:45 A to G (by last name): room FSC 1005 H to O: room ESB 1013 P to Z: room CIRS 1250 Modules 1 to 5 (up to about the end of next Tuesday’s class), plus Labs 1 to 3. You can bring Nothing but we will provide the parts of Dave’s excellent handout that you need. CPSC 121 – 2018W T1 2

  3. Module 5: Predicate Logic Assignment #2 is due Wednesday October 10 th at 19:00. Pre-class quiz #6 is due Monday October 15 th at 19:00 Assigned reading for the quiz: Epp, 4 th edition: 3.2, 3.4 Epp, 3 rd edition: 2.2, 2.4 Rosen, 6 th edition: 1.3, 1.4 Rosen, 7 th edition: 1.4, 1.5 CPSC 121 – 2018W T1 3

  4. Module 5: Predicate Logic Pre-class quiz #7 is tentatively due Wednesday October 24 th at 19:00. Assigned reading for the quiz: Epp, 4 th edition: 4.1, 4.6, Theorem 4.4.1 Epp, 3 rd edition: 3.1, 3.6, Theorem 3.4.1. Rosen, 6 th edition: 1.6, 1.7. 3.4 (theorem 2 only). Rosen 7 th edition: 1.7, 1.8, 4.1 (theorem 2 only). CPSC 121 – 2018W T1 4

  5. Module 5: Predicate Logic Quiz 5 feedback: Very well done; only one question below 90%: If D is the set of 8 bit signed integers, is ∀ x ∈ ∀ ∈ D, y D, ((x > 0) ^ (y > 0)) → (x + y) > 0 true? Answer: NO. For instance 100 + 100 = -56. As usual, we will discuss the open-ended question (what it means for an algorithm to be faster or slower than another one) in class. CPSC 121 – 2018W T1 5

  6. Module 5: Predicate Logic By the start of class, you should be able to Evaluate the truth of predicates applied to particular values. Show a predicate logic statement is true by enumerating examples, i.e. one (all) in the domain for an existential (universal) quantifier. Show a predicate logic statement is false by enumerating counterexamples, i.e. all (one) in the domain for an existential (universal) quantifier. Translate between statements in formal predicate logic notation and equivalent statements in closely matching informal language, i.e., informal statements with clear and explicitly stated quantifiers. CPSC 121 – 2018W T1 6

  7. Module 5: Predicate Logic CPSC 121: the BIG questions: ? ? ? How can we convince ourselves that an algorithm ? ? does what it's supposed to do? We need to prove that it works. ? ? We have done a few proofs in the last week or so. ? ? ? Many statements (that we need to prove) involve quantifiers. How do we determine whether or not one algorithm ? is better than another one? ? ? ? We can finally answer that question! ? ? ? CPSC 121 – 2018W T1 7

  8. Module 5: Predicate Logic By the end of this module, you should be able to: Build statements about the relationships between properties of various objects using predicate logic. These may be real-world like “every candidate got votes from at least two people in every province” or computing related like “on the i th repetition of this algorithm, the variable min contains the smallest element in the list between element 0 and element i” . CPSC 121 – 2018W T1 8

  9. Module 5: Predicate Logic Module Summary Predicates vs Propositions Examples More examples: sorted lists Algorithm efficiency revisited. Additional examples to consider. CPSC 121 – 2018W T1 9

  10. Module 5.1: Predicates vs Propositions Is Propositional Logic a complete model? Can it be used to model every real-world situation? Which of the following can it model effectively? a) Specializing abstract patterns to specific instances, like “... so Donald Trump was born in the United States of America”. b) Defining what it means for a number to be prime. c) Generalizing from examples to abstract patterns like “everyone takes off their shoes at airport security”. d) It can model all of these effectively. e) It can not model any of these effectively. ▷ CPSC 121 – 2018W T1 10

  11. Module 5.1: Predicates vs Propositions What is predicate logic good for modeling? Relationships among real-world objects. Generalizations about patterns Infinite domains Generally, problems where the properties of the different concepts, or parts, depend on each other. CPSC 121 – 2018W T1 12

  12. Module 5.1: Predicates vs Propositions Examples of predicate logic use: Data structures: Every key stored in the left subtree of a node N is smaller than the key stored at N. [CPSC 221] Language definition: No path via references exists from any variable in scope to any memory location available for garbage collection... [CPSC 311 or 312] Databases: the relational model is based on predicate logic. [CPSC 304] Algorithms: in the worst case, every comparison sort requires at least cnlog 2 n comparisons to sort n values, for some constant c > 0. [CPSC 320] CPSC 121 – 2018W T1 13

  13. Module 5.1: Predicates vs Propositions Quantifiers scope: A quantifier applies to everything to its right, up to the closing parenthesis of the () pair that “contains” it. Example: ∀ x ∈ D , ∃ y ∈ E ,Q  x , y  ∀ z ∈ F , R  y , z  ∧ P  x     CPSC 121 – 2018W T1 14

  14. Module 5.1: Predicates vs Propositions Quantifiers scope (continued) Which of the following placements of parentheses yields the same meaning as: ∀ x ∈ ∃ ∈ ∧ Z, y Z, x < y Even(y) ? ∀ ∈ ∃ ∈ ∧ a) ( x Z, y Z, x < y) Even(y) b) ∀ x ∈ ∃ ∈ ∧ Z, ( y Z, x < y Even(y)) c) ( x ∀ ∈ Z, y ∃ ∈ Z, x < y Even(y)) ∧ d) Both a and b. e) Both b and c. ▷ CPSC 121 – 2018W T1 15

  15. Module 5.1: Predicates vs Propositions Negation scope: Which of the following placements of parentheses yields the same meaning as: ∃ ∈ + , y ∀ ∈ + , x < y Even(y) ∧ ~ x Z Z ? ∃ ∈ + )), y ∀ ∈ + , x < y Even(y) ∧ a) (~( x Z Z ∃ ∈ + , y ∀ ∈ + , x < y)) Even(y) ∧ b) (~( x Z Z ∃ ∈ + , y ∀ ∈ + , x < y Even(y) ∧ c) (~( x Z Z )) d) None of the above. ▷ CPSC 121 – 2018W T1 17

  16. Module 5.1: Predicates vs Propositions What is the difference between a proposition and a predicate? a) A predicate may contain one or more quantifiers, but a proposition never does. b) A proposition's name is a lowercase letter, whereas a predicate's name is an uppercase letter. c) A predicate may contain unbound variables, but a proposition does not. d) They are the same thing, using different names. e) None of the above. ▷ CPSC 121 – 2018W T1 19

  17. Module 5.1: Predicates vs Propositions What is the truth value of the proposition: ∃ x ∈ Z, x*x = y ? a) True because (for example) 5 * 5 = 25 b) True because every y = √ y * √ y c) False, because of counterexamples like no integer multiplied by itself equals 3 d) It depends on y, but given a value for y, we could calculate a truth value. e) None of the above. ▷ CPSC 121 – 2018W T1 21

  18. Module 5.1: Predicates vs Propositions Which variables do we need values for in order to determine this formula's truth value? + , (i ≥ n) ↔ ~ v + , HasValue(l, i, v) ∀ i ∈ Z ∃ ∈ Z a) i and v b) l and n c) n and v d) i and n e) None of these are correct. ▷ CPSC 121 – 2018W T1 23

  19. Module 5.1: Predicates vs Propositions A predicate is a logic formula with unbound variables, such as Perfect Square(y): ∃ x ∈ Z, x*x = y Then PerfectSquare(25) is PerfectSquare(27) is ∃ y ∈ Z, PerfectSquare(y) is ∀ y ∈ Z, PerfectSquare(y) is CPSC 121 – 2018W T1 25

  20. Module 5: Predicate Logic Module Summary Predicates vs Propositions Examples More examples: sorted lists Algorithm efficiency revisited. Additional examples to consider. CPSC 121 – 2018W T1 26

  21. Module 5.2: Examples Given the definitions: F: the set of foods. E(x): Alice eats food x. g: Alice grows. s: Alice shrinks. (c) Walt Disney Co. CPSC 121 – 2018W T1 27

  22. Module 5.2: Examples Express these statements using predicate logic: Eating food causes Alice to grow or shrink. Alice shrank when she ate some food. CPSC 121 – 2018W T1 28

  23. Module 5.2: Examples Given the definitions: F(x): x is a fierce creature. L(x): x is a lion C(x): x drinks coffee (c) animal.discovery.com D: the set of all creatures. T(x,y): creature x has “tasted” creature y. CPSC 121 – 2018W T1 29

  24. Module 5.2: Examples Express these statements using predicate logic: All lions are fierce. Some lions do not drink coffee. CPSC 121 – 2018W T1 30

  25. Module 5.2: Examples Compare and contrast the following: Some creature drinks coffee Some lion drinks coffee Some fierce lion drinks coffee (restricting the domain of an existential stmt) CPSC 121 – 2018W T1 31

  26. Module 5.2: Examples Compare and contrast the following: Every creature drinks coffee Every lion drinks coffee Every fierce lion drinks coffee (restricting the domain of an universal stmt) CPSC 121 – 2018W T1 32

  27. Module 5.2: Examples Consider the statement All fierce creatures are not lions Give two different (not logically equivalent) translations into predicate logic. Why did we end up with two translations? CPSC 121 – 2018W T1 33

  28. Module 5.2: Examples Express these two propositions in English: ∀ x ∈ D, ∃ ∈ y D, T(x,y) ∃ y ∈ ∀ ∈ D, x D, T(x,y) Give an example where one of the propositions is true, and the other proposition is false. CPSC 121 – 2018W T1 34

Recommend


More recommend