cpsc 121 models of computation
play

CPSC 121: Models of Computation Evaluate the truth of predicates - PowerPoint PPT Presentation

Before-Class Learning Goals By the start of class, you should be able to CPSC 121: Models of Computation Evaluate the truth of predicates applied to particular values. Show a predicate logic statement is true by enumerating examples


  1. Before-Class Learning Goals  By the start of class, you should be able to CPSC 121: Models of Computation  Evaluate the truth of predicates applied to particular values.  Show a predicate logic statement is true by enumerating examples (i.e., all in the domain/one for a universal/existential quantifier). Unit 5  Show a predicate logic statement is false by enumerating counterexamples (i.e., one/all in the domain for a Predicate Logic universal/existential 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). Based on slides by Patrice Belleville and Steve Wolfman Unit 5 - Predicate Logic 2 Quiz 5 Feedback In-Class Learning Goals  Overall:  By the end of this unit, you should be able to:  Build statements about the relationships between properties  Specific Issues: of various objects using predicate logic.  These may be o real- world like “every candidate got votes from at least two people in every province” or o 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”.  We will discuss the open-ended question on what it means for an algorithm to be faster/slower than another one next week. Unit 5 - Predicate Logic Unit 5 - Predicate Logic 3 4 1

  2. ? ? Related to CPSC 121 Big Questions Unit Outline  How can we convince ourselves that an algorithm  Predicates vs Propositions does what it's supposed to do?  Examples  We need to prove that it works.  Now we will learn how to model suck problems in predicate  More examples: sorted lists logic using predicates and variables.  How do we determine whether or not one algorithm is  Algorithm efficiency revisited. better than another one?  Additional examples to consider.  We can finally model and answer that question! Unit 5 - Predicate Logic Unit 5 - Predicate Logic 5 6 What Predicate Logic is Good for Is Propositional Logic a complete model?  Which of the following can propositional logic model  Predicate logic is good for modeling: effectively?  Relationships among real-world objects A. Relationships among factory production lines (e.g., “wheel  Generalizations about patterns assembly” and “frame welding” both feed the undercarriage  Infinite domains line).  Generally, problems where the properties of the B. Defining what it means for a number to be prime. different concepts, or parts, depend on each other C. Generalizing from examples to abstract patterns like “everyone takes off their shoes at airport security”.  and more…. D. It can model all of these effectively. E. It can not model any of these effectively. Unit 5 - Predicate Logic Unit 5 - Predicate Logic 7 8 2

  3. Predicate Logic in Computer Science Quantifier Scope  Examples of predicate logic use in CS:  A quantifier applies to everything to its right, up to the closing parenthesis of the () pair that “contains” it.  Data structures: Every key stored in the left subtree of a node N is smaller than the key stored at N (CPSC 221).  Example:  Language definition: No path via references exists from any variable in scope to any memory location available for ∀ x ∈ D, ( ∃ y ∈ E, Q(x, y) → ∀ z ∈ F, R(x, z)) ∧ P(x) garbage collection... (CPSC 312)  Databases: the relational model is based on predicate logic (CPSC 304).  Algorithms: in the worst case, every comparison sort requires at least c*n*log 2 n comparisons to sort n values, for some constant c > 0 (CPSC 320). Unit 5 - Predicate Logic Unit 5 - Predicate Logic 9 10 Quantifier Scope (cont') Negation Scope:  Which of the following placements of parentheses  Which of the following placements of parentheses yields the same meaning as: yields the same meaning as: ∀ x ∈ Z, ∃ y ∈ Z, x < y ∧ Even(y) ? ~ ∃ x ∈ Z+, ∀ y ∈ Z+, x < y ∧ Even(y) ? A. ( ~ ∃ ) 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) B. ( ∀ x) ∈ Z, ∃ y ∈ Z, x < y ∧ Even(y) C. ( ~ ( ∃ x ∈ Z+ )) , ∀ y ∈ Z+, x < y ∧ Even(y) C. ( ∀ x ∈ Z), ∃ y ∈ Z, x < y ∧ Even(y) D. ( ~ ( ∃ x ∈ Z+, ∀ y ∈ Z+, x < y )) ∧ Even(y) D. ( ∀ x ∈ Z, ∃ y ∈ Z, x < y) ∧ Even(y) E. ( ~ ( ∃ x ∈ Z+, ∀ y ∈ Z+, x < y ∧ Even(y) )) E. ( ∀ x ∈ Z, ∃ y ∈ Z, x < y ∧ Even(y)) Unit 5 - Predicate Logic Unit 5 - Predicate Logic 11 12 3

  4. Predicates vs. Propositions Unbound Variables  What is the difference between a proposition and a  What is the truth value of the following formula?  x  Z, x*x = y . predicate? A. A predicate may contain one or more quantifiers, but a A. True, because (for example) 5*5=25. proposition never does. B. A proposition's name is a lowercase letter, whereas a B. True, because every y = (sqrt y)*(sqrt y) predicate's name is an uppercase letter. C. False, because of counterexamples like no integer C. A predicate may contain unbound variables, but a proposition does not. multiplied by itself equals 3. D. They are the same thing, using different names. D. It depends on y, but given a value for y, we could calculate E. None of the above. a truth value. E. None of the above. Unit 5 - Predicate Logic Unit 5 - Predicate Logic 13 14 Unbound Variables Defining Predicates  Which variables does this formula's truth depend on?  A predicate is a predicate logic formula with ∀ i ∈ Z+, (i ≥ n) → ~ ∃ v ∈ Z+, HasValue(a, i, v) unbound variables PerfectSquare(y):  x  Z, x*x = y A. i and v where y  Z B. a and n  Then  PerfectSquare(25) C. n and v is ________  PerfectSquare(3) is ________ D. i and n   y  Z, PerfectSquare(y) is ________ E. None of these are correct.   y  Z, PerfectSquare(y) is ________ Unit 5 - Predicate Logic Unit 5 - Predicate Logic 15 16 4

  5. Unit Outline Example 1  Given the definitions:  Predicates vs Propositions  F: the set of foods.  Examples  E(x): Alice eats food x.  g: Alice grows.  More examples: sorted lists (c) Walt Disney Co.  s: Alice shrinks.  Express these statements using predicate logic:  Algorithm efficiency revisited.  Eating food causes Alice to grow or shrink.  Additional examples to consider.  Alice shrank when she ate some food. Unit 5 - Predicate Logic Unit 5 - Predicate Logic 17 18 Example 2 Restricting the Domain of an Existential  Given the definitions: Compare and contrast the following:  D: the set of all creatures.  Some creature drinks coffee:  F(x): x is a fierce creature. (c) animal.discovery.com  L(x): x is a lion  C(x): x drinks coffee  T(x,y): creature x has “tasted” creature y.  Some lion drinks coffee:  Express these statements using predicate logic:  All lions are fierce.  Some fierce lion drinks coffee:  Some lions do not drink coffee. Unit 5 - Predicate Logic Unit 5 - Predicate Logic 19 20 5

  6. Restricting the Domain of a Universal Ambiguity with Negation  Consider the statements Compare and contrast the following:  All creatures drink coffee: 1. All fierce creatures are not lions 2. Not all fierce creatures are lions  Their translations into predicate logic are:  All lions drink coffee: 1. 2.  All fierce lions drink coffee:  Do we often mean (2) when we say (1)? Unit 5 - Predicate Logic Unit 5 - Predicate Logic 21 22 Order of Quantifiers Unit Outline  Express these two propositions in English:  Predicates vs Propositions  ∀ x ∈ D, ∃ y ∈ D, T(x,y)  Examples  ∃ x ∈ D, ∀ y ∈ D, T(x,y)  More examples: sorted lists  Algorithm efficiency revisited.  Give an example where one of the propositions is true,  Additional examples to consider. and the other proposition is false. Unit 5 - Predicate Logic Unit 5 - Predicate Logic 23 24 6

Recommend


More recommend