Presentation is loading. Please wait.

Presentation is loading. Please wait.

Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Describing the World with Predicate Logic Steve Wolfman, based on notes by Patrice Belleville.

Similar presentations


Presentation on theme: "Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Describing the World with Predicate Logic Steve Wolfman, based on notes by Patrice Belleville."— Presentation transcript:

1 snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Describing the World with Predicate Logic Steve Wolfman, based on notes by Patrice Belleville and others

2 Quiz 5 Notes Predicate translation went great! A few other problems caused trouble... Consider all variables in this problem to be drawn from the domain of 8-bit signed ints, not mathematical integers. Is the following statement true?

3 Quiz 5 Notes A few other problems caused trouble... Let P(x) be the predicate statement “x is prime” and O(x) be “x is odd”. Is P(10)  O(2) true?

4 Quiz 5 Notes A few other problems caused trouble...

5 Quiz 5 Notes: Sorting My wording focused many on “corresponding”, not “sorted”! What is “corresponding”? Unchanged contents: –everything in the first list is in the second –in one if and only if it's in the other –only order (indexes) changes, not values What is sorted? –need a definition for order (alphabetical?) –each element is >= the previous and <= the next –first element higher than all other elements; second is higher than all but one;... Lastly, a notion that “sorted” should mean “more organized” somehow.

6 Lecture Prerequisites Review Chapter 1 and be able to solve any Chapter 1 exercise. Read Sections 2.1 and 2.3 (skipping the “Negation” sections in 2.3 on pages 102-104) Solve problems like Exercise Set 2.1 #1-24 and Set 2.3 #1-12, part (a) of 14-19, 21-22, 30-31, part (a) of 32-38, 39, parts (a) and (b) of 45- 52, and 53-56. You should have completed the open-book, untimed quiz on Vista that was due before this class.

7 Learning Goals: Pre-Class By the start of class, you should be able to: –Evaluate the truth of predicates applied to particular values. –Show predicate logic statements are true by enumerating examples (i.e., all examples in the domain for a universal or one for an existential). –Show predicate logic statements are false by enumerating counterexamples (i.e., one counterexample for universals or all in the domain for existentials). –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).

8 Learning Goals: In-Class By the end of this unit, you should be able to: –Build statements about the relationships between properties of various objects—which may be real-world like “every candidate got votes from at least two people in every province” or computing related like “on the ith repetition of this algorithm, the variable min contains the smallest element in the list between element 0 and element i”)—using predicate logic.

9 What Does Predicate Logic Model? Propositional logic is a good (but not perfect) model of combinational circuits. What is predicate logic good for modeling? Relationships among real-world objects Programming constraints Properties of computing systems Generally, problems where the properties of different concepts, ideas, parts, or entities depend on each other.

10 Problem: Lists (aka Arrays) Let Elt(a, i, v) be a predicate indicating that list a has the integer value v at index i, where indexes must be  0. Problem: write a statement that means that some arrays contain duplicate values.

11 Problem: Lists (aka Arrays) Let’s assume that for any given list: (1)The list has a length. (We’ll call it len here for simplicity.) (2)The list has exactly one value for every index < len. (3)The list has no values for indexes >= len. Problem: Write logical statements that express these constraints. You may need to invent a new predicate. Predicates are clumsy for expressing these common ideas. Later, we’ll use functions to do a better job.

12 Problem: Sorted Lists Problem: Give a definition for the predicate Sorted(a) in terms of Elt(a, i, v).

13 Problem: Voting Database Consider a database that tracks the votes in an election. In the database, the predicate Tally(d, c, n) means that district d reported that candidate c received n votes, where n is an integer  0. Problem: Define a predicate GotVote(c) in terms of Tally whose truth set is the set of all candidates who received at least one vote.

14 Problem: Voting Database Problem: Define a predicate whose truth set is the set of all candidates who won at least one district. Why work so hard on defining predicates? This is essentially how we query databases.

15 Problem: Voting Database Let’s assume that every candidate has exactly one vote total for every district. That is, there’s no missing and no duplicate data. Problem: Write a logical statement that describes this constraint. Predicates are clumsy for expressing this common idea. Later, we’ll use functions to do a better job.

16 Problem: Voting Database Let Winner(c) indicate that candidate c is the winner of the election. Problem: Write a logical statement that means that the winner of the election must have received at least one vote.

17 Problem: Voting Database Let D be the set of all districts and C be the set of all candidates. Problem: Determine what the following statement means, whether it is necessarily true (no matter what the actual vote tallies are), and justify your stance:  c 1  C,  d  D,  c 2  C, Winner(c 1 )  c 1  c 2   n 1  Z,  n 2  Z, Tally(d,n 1,c 1 )  Tally(d,n 2,c 2 )  n 1 >n 2

18 Problem: Efficiency of Algorithms (1 of 3) Let’s say each student is in a “MUG” (1st year orientation group). For each of their MUG-mates, each student has a list of all of their classes. For simplicity, we’ll assume each MUG has 13 students and each student is taking 5 classes. I want to determine how many students in my class have a MUG-mate in my class.

19 Problem: Efficiency of Algorithms (2 of 3) I consider the following two algorithms: –MUG-lists algorithm: For each student, ask the student for the list of their MUG-mates’ classes, and check for each class whether it is CPSC 121. If the answer is ever yes, include the student in my count. Let’s this takes one second for each class I check. –Pairwise recognition algorithm: For each student s 1 in the class, ask the student for each other student s 2 in the class whether s 2 is a MUG-mate. If the answer is ever yes, include s 1 in my count. Let’s say a student takes one second to determine whether another student is a MUG-mate.

20 Problem: Efficiency of Algorithms (3 of 3) Problem: How long does each of these algorithms take in terms of the number of students?

21 Problem: Detailed Efficiency of Algorithms Let the predicate Faster(a 1, a 2, n) mean algorithm a 1 is faster than algorithm a 2 on a problem of size n, where n is a positive integer. Problem: for which n s is Faster(MUG- list, pairwise, n) true?

22 Problem: General Efficiency of Algorithms Let the predicate Faster(a 1, a 2, n) mean algorithm a 1 is faster than algorithm a 2 on a problem of size n, where n is a positive integer. Problem: create a definition of GenerallyFaster(a 1, a 2 ) in terms of Faster(a 1, a 2, n) that you can live with.

23 Learning Goals: In-Class By the start of class, you should be able to: –Build statements about the relationships between properties of various objects—which may be real-world like “every candidate got votes from at least two people in every province” or computing related like “on the ith repetition of this algorithm, the variable min contains the smallest element in the list between element 0 and element i”) using predicate logic.

24 Next Lecture Learning Goals: Pre-Class By the start of class, you should be able to: –Determine the negation of any quantified statement. –Given a quantified statement and an equivalence rule, apply the rule to create an equivalent statement (particularly the De Morgan’s and contrapositive rules). –Prove and disprove quantified statements using the “challenge” method (Epp, 3 d edition, page 99). –Apply universal instantiation, universal modus ponens, and universal modus tollens to predicate logic statements that correspond to the rules’ premises to infer statements implied by the premises.

25 Next Lecture Prerequisites Reread Sections 2.1 and 2.3 (including the negation part that we skipped previously). Read Sections 2.2 and 2.4. Solve problems like Exercise Set 2.1 #25-28 and 30- 31; Set 2.2 #1-25 and 27-36; Set 2.3 #13-20, 23- 29, 40-42, and 45-52; and Set 2.4 #2-19, and 28- 34. (You needn’t learn the “diagram” technique, but it may make more sense than other explanations!) Complete the open-book, untimed quiz on Vista that’s due before the next class.

26 Problem: Java Collections Problem: Translate the following text from the Java 1.6.0 API page for the Collection interface into predicate logic. [T]he specification for the contains(Object o) method says: "returns true if and only if this collection contains at least one element e such that (o==null ? e==null : o.equals(e))." contains(Object o) c ? a : b acts essentially like a multiplexer. If c is true, it evaluates to a; otherwise, it evaluates to b.

27 Problem: Java Collections Problem: The API goes on to say: This specification should not be construed to imply that invoking Collection.contains with a non-null argument o will cause o.equals(e) to be invoked for any element e. Explain whether and how this is consistent with your definition.

28 More Quantifier Examples Someone is in charge. Everyone except the person in charge reports to someone else.

29 More Quantifier Examples n is a prime number. Note: we use x|y as a predicate meaning x divides y (i.e., x “goes into” y with no remainder).

30 More Quantifier Examples n is a prime number. Let’s define a new predicate P(x) in terms of this “clause”. Then, let’s express… There’s some prime number larger than 10. There’s some prime number larger than every natural number.

31 Yet More Examples Eating food causes Alice to grow or shrink. F = set of all foods E(x) : Alice eats x g : Alice grows s : Alice shrinks

32 Yet More Examples Alice shrank when she ate some food. F = set of all foods E(x) : Alice eats x g : Alice grows s : Alice shrinks

33 Yet More Examples All lions are fierce. F(x) : x is a fierce creature L(x) : x is a lion C(x) : x drinks coffee Domain for all is the set of all creatures.

34 Yet More Examples Some lions do not drink coffee. F(x) : x is a fierce creature L(x) : x is a lion C(x) : x drinks coffee Domain for all is the set of all creatures.

35 Yet More Examples All fierce creatures are not lions. F(x) : x is a fierce creature L(x) : x is a lion C(x) : x drinks coffee Domain for all is the set of all creatures. Is that English sentence ambiguous?

36 Yet More Examples Is  x, K(x, y) a proposition? Why or why not? F(x) : x is a fierce creature L(x) : x is a lion C(x) : x drinks coffee K(x, y) : x has been in y ’s kitchen Domain for all is the set of all creatures (with kitchens?).

37 Yet More Examples Every creature has been in its own kitchen. Some creature has not been in its own kitchen. F(x) : x is a fierce creature L(x) : x is a lion C(x) : x drinks coffee K(x, y) : x has been in y ’s kitchen Domain for all is the set of all creatures (with kitchens?).

38 Yet More Examples There is a creature that has been in every creature’s kitchen. Every creature’s kitchen has had some creature in it. F(x) : x is a fierce creature L(x) : x is a lion C(x) : x drinks coffee K(x, y) : x has been in y ’s kitchen Domain for all is the set of all creatures (with kitchens?). Are these the same?

39 Yet More Examples Every creature has been in every other creature’s kitchen. Every creature’s kitchen has had every creature in it. F(x) : x is a fierce creature L(x) : x is a lion C(x) : x drinks coffee K(x, y) : x has been in y ’s kitchen Domain for all is the set of all creatures (with kitchens?). Are these the same? What if we removed the word “other”?


Download ppt "Snick  snack CPSC 121: Models of Computation 2008/9 Winter Term 2 Describing the World with Predicate Logic Steve Wolfman, based on notes by Patrice Belleville."

Similar presentations


Ads by Google