Quick Review (?) of Sets A set is a collection of elements: – the set of students in this class CPSC 121: Models of Computation – the set of lowercase letters in English 2017S – the set of natural numbers ( N ) – the set of all left-handed students in this class Describing the World with Predicate Logic An element is either in the set ( x S ) or not Meghan Allen based on notes by Steve Wolfman, Patrice Belleville and others ( x S ). 1 2 What is a Set? Describing Sets (1/4) Some sets… A = {1, 3, 9} A set is an unordered collection of objects. B = {1, 3, 9, 27, snow} C = {1, 1, 3, 3, 9, 9} (the same as A!) The objects in a set are called members. D = {A, B} ( a S indicates a is a member of S ; a S indicates a is not a member of S ) D = { {1, 3, 9}, {1, 3, 9, 27, snow} } E = { } (the empty set, with nothing in it) A set contains its members. 3 4 Describing Sets (2/4) Describing Sets (3/4) Some sets… Some sets, using set builder notation: A = {x N | y N , x = 5 y } A = {1, 5, 25, 125, …} B = {…, -2, - 1, 0, 1, 2, …} B = {2 i - 1 | i is a prime} C = {n Z | 0 < n 100} C = {1, 2, 3, …, 98, 99, 100} To read, start with “the set of all”. Read “ | ” as “such that”. (The set of powers of 5, the set of integers, and the set of integers between 1 and 100.) A : “ the set of all natural numbers x such that x is a power of 5 ” B : “ the set of all numbers of the form 2 i -1 such that i is a prime” C : “ the set of all integers n such that 0 < n 100 ” “…” is an ellipsis 5 6 1
Describing Sets (4/4) Outline Graphical depiction of sets: Venn diagrams. • Prereqs, Learning Goals, and Quiz Notes Draw the set of all five-letter things. • Prelude: Scope and Predicate Definition All red things? • Problems and Discussion – Lists U is the U Texas universal – Sorted Lists snows seven set of – Comparing Algorithms everything. happiness • Next Lecture Notes books fire truck heart 7 8 Learning Goals: Pre-Class Learning Goals: In-Class By the start of class, you should be able to: By the end of this unit, you should be able to: – Evaluate the truth of predicates applied to particular – Build statements about the relationships between values. properties of various objects — which may be real- – Show predicate logic statements are true by world like “every candidate got votes from at least enumerating examples (i.e., all examples in the two people in every province” or computing domain for a universal or one for an existential). related like “on the i th repetition of this algorithm, – Show predicate logic statements are false by the variable min contains the smallest element in enumerating counterexamples (i.e., one counterexample for universals or all in the domain for the list between element 0 and element i ”)— using existentials). predicate logic. – 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). 9 10 Where We Are in Outline The Big Stories • Prereqs, Learning Goals, and Quiz Notes Theory Hardware • Prelude: Motivation, Scope & Defining Predicates How do we model How do we build devices to computational systems? compute? • Problems and Discussion – Lists Now : Finally getting a tool that Now : Still taking a bit of a we can use to model the vacation in lecture! – Sorted Lists complex systems – Comparing Algorithms we really want to reason about! • Next Lecture Notes 11 15 2
Limitations of Propositional Logic What Does Predicate Logic Model? as a Model Which of the following can propositional logic model • Relationships among real-world objects effectively? • Generalizations about patterns a. Relationships among factory production lines like • Infinite (or even just big ) domains “wheel assembly and frame welding both connect to the undercarriage line”. 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. Prop logic can model all of these effectively. e. Prop logic cannot model any of these effectively. Problems where the properties of different concepts, ideas, parts, or entities depend on each other. 16 17 But... Would You Ever Really Quantifier Syntax Use Predicate Logic? • Data Structures Example: “...every key is less than A quantifier in CPSC 121 is always of the form: or equal to all of its children’s keys...” • AI example: “...let h' be a ‘heuristic’ function _____ _____ ______, _______________ evaluating game states and h be the true value of the state. For all nodes n, h'(n) h(n)...” or variable set subexpression that can • Java example: “...there is no path via references mention the variable from any variable in scope to any memory location available for garbage collection...” Together, this forms a single subexpression. • Economics/elections example: “...for any distinct For example, x N , (x > 3) (x + 4 < 12). pair of candidates c 1 and c 2 , if all voters prefer c 1 to c 2 , then society must rank c 1 above c 2 ...” 18 19 Quantifier Syntax Quantifier Scope You cannot treat any part of this (like x Z or x) as a A quantifier applies to everything to its right subexpression. It just isn’t. until a closing parenthesis stops it. So, no saying: ( x Z) p. 20 21 3
Quantifier Scope Quantifier Scope A quantifier applies to everything to its right A quantifier applies to everything to its right until a closing parenthesis stops it. until a closing parenthesis stops it. x D, ( y E, Q(x,y) z F, R(y,z)) P(x). x D, ( y E, Q(x,y) z F, R(y,z)) P(x). one subexpression (all under the universal) a smaller subexpression 22 23 Quantifier Scope Quantifier Scope A quantifier applies to everything to its right A quantifier applies to everything to its right until a closing parenthesis stops it. until a closing parenthesis stops it. x D, ( y E, Q(x,y) z F, R(y,z)) P(x). x D, ( y E, Q(x,y) z F, R(y,z)) P(x). another smaller subexpression (all under the existential) another smaller subexpression 24 25 A Bit of Syntax: Aside: Where Can You “Cut” a Quantifier Scope Propositional Logic Statement? This doesn’t make sense: (x w) ( y). Which of the following placements of Why not? parentheses yields the same meaning as: x Z, y Z, x < y Even(y). Every use of looks just like every other use. a. ( )x Z, y Z, x < y Even(y). They all look like p q. b. ( x) Z, y Z, x < y Even(y). The left side must make sense as an equivalent to p: c. ( x Z), y Z, x < y Even(y). p x w here. d. ( x Z, y Z, x < y) Even(y). The right side must make sense as an equivalent to q. Does q y make sense? e. ( x Z, y Z, x < y Even(y)). Reminder: Z is the set of integers. 26 27 4
Aside: Where Can You “Cut” a Predicate Aside: Where Can You “Cut” a Predicate Logic Statement? Logic Statement? So does this make sense: x Z, Costs(y, x) Tasty(y)? This doesn’t make sense: x Z Tasty(y). Why not? Does it look like P(x, y, …) Q(x, y, …) ? P(y) x Z, Costs(y, x)? Every use of looks just like every other use. Q(y) Tasty(y)? They all look like P(x, y, …) Q(x, y, …) . No! The is inside the universal quantifier. It applies to Costs(y, x) The RIGHT side must make sense as an equivalent to Q( … ). and Tasty(y). Q(y) Tasty(y) here. P(x, y) Costs(y, x). The left side must make sense as an equivalent to P( … ): Q(y) Tasty(y). Does P(x) x Z make sense? x Z, P(x, y) Q(y). 28 29 A Bit of Syntax: Aside: Where Can You “Cut” a Predicate Logic Statement? Negation Scope How about: ( x Z, Costs(y, x)) ( w F, Salty(w))? Which of the following placements of parentheses yields the same meaning as: P(y) x Z, Costs(y, x). ~ x Z + , y Z + , x < y Even(y). q w F, Salty(w). a. (~ )x Z + , y Z + , x < y Even(y). b. (~( x)) Z + , y Z + , x < y Even(y). Note: q alone is essentially a predicate Q() with no arguments. c. (~( 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))). 30 31 A Bit of Semantics: Defining a Predicate Using Expressions with Unbound Variables “Unbound” Variables What is the truth value of the following formula? A pred. logic formula with only bound variables is a proposition , x Z, x*x = y . something that is either true or false: (Warning: a bit of a trick question.) a. True, because (for example) 5*5=25. b. True, because every y = (sqrt y)*(sqrt y) x Z, x*x = 25. true c. False, because of counterexamples like no integer x Z, x*x = 3. false multiplied by itself equals 3. 5 x Z, x*x = robson. false (malformed?) d. It depends on y, but given a value for y, we could 5 y Z, x Z, x*x = y. false calculate a truth value. e. None of the above. 5 5 32 33 5
Recommend
More recommend