700 likes | 886 Views
University of Aberdeen, Computing Science CS2013 Mathematics for Computing Science Adam Wyner. Slides adapted from Michael P. Frank ' s course based on the text Discrete Mathematics & Its Applications (5 th Edition) by Kenneth H. Rosen. Predicate Logic Continued. Agenda. Formal Evaluation
E N D
University of Aberdeen, Computing ScienceCS2013Mathematics for Computing ScienceAdam Wyner Slides adapted from Michael P. Frank's course based on the textDiscrete Mathematics & Its Applications(5th Edition)by Kenneth H. Rosen
Agenda • Formal Evaluation • Nested Quantifiers • Quantifier equivalences • Defining (or not) other quantifiers • Applications – Prolog and Oracle Policy Automation Frank / van Deemter / Wyner
Formal Evaluation - B(bill') • Suppose M1 = (D,I) where D={bill, jill, mary} I(jill') = jill, I(mary') = mary, I(bill') = bill, I(B)={bill, jill}I(G)={jill},I(A)={(bill, jill), (mary,bill), (jill, jill)} • B(bill') is T in M1 iff I(bill') I(B) is T in M1 iffbill {bill, jill} is T in M1. • Work from bottom to top. Frank / van Deemter / Wyner
Formal Evaluation - x B(x) • Suppose M1 = (D,I) where D={bill, jill, mary} I(jill') = jill, I(mary') = mary, I(bill') = bill, I(B)={bill, jill}I(G)={jill},I(A)={(bill, jill), (mary,bill), (jill, jill)} • x B(x) is T in M1 iff there is an a where I(a) D such that B(x)(x := a) is T in M1 • where (x := bill'), B(x) is B(bill'). B(bill') is T in M1 iff.... • where (x := jill'), B(x) is B(jill'). B(jill') is T in M1 iff.... • where (x := mary'), B(x) is B(mary'). B(mary') is T in M1 iff.... • Look in the 'where' clauses. Is there some a that makes B(x)(x := a) is T in M1? • Work from bottom to top. Frank / van Deemter / Wyner
Formal Evaluation - x B(x) • Suppose M1 = (D,I) where D={bill, jill, mary} I(jill') = jill, I(mary') = mary, I(bill') = bill, I(B)={bill, jill}I(G)={jill},I(A)={(bill, jill), (mary,bill), (jill, jill)} • x B(x) is T in M1 iff for every a where I(a) D, B(x)(x := a) is T in M1 • where (x := bill'), B(x) is B(bill'). B(bill') is T in M1 iff.... • where (x := jill'), B(x) is B(jill'). B(jill') is T in M1 iff.... • where (x := mary'), B(x) is B(mary'). B(mary') is T in M1 iff.... • Look in the 'where' clauses. Is it so that for every a, B(x)(x := a) is T in M1? • Work from bottom to top. Frank / van Deemter / Wyner
Formal Evaluation - x (G(x) B(x)) • Suppose M1 = (D,I) where D={bill, jill, mary} I(jill') = jill, I(mary') = mary, I(bill') = bill, I(B)={bill, jill}I(G)={jill},I(A)={(bill, jill), (mary,bill), (jill, jill)} • x (G(x) B(x)) is T in M1 iff for every a where I(a) D, (G(x) B(x))(x := a) is T in M1 • where (x:=bill'), (G(x) B(x)) is (G(bill') B(bill')); (G(bill') B(bill')) is T in M1 iff G(bill') is F in M1 or B(bill') is T in M1. • where (x:=jill'), (G(x) B(x)) is (G(jill') B(jill')); (G(jill') B(jill')) is T in M1 iff G(jill') is F in M1 or B(jill') is T in M1. • where (x:=mary'), (G(x) B(x)) is (G(jill') B(jill')); (G(jill') B(jill')) is T in M1 iff G(jill') is F in M1 or B(jill') is T in M1. • Are all true? Frank / van Deemter / Wyner
Nested Quantifiers Example: Let D for x and y be people. Let L(x,y) = x likes y(a predicate with 2 free variables) y L(x,y) = "There is someone whom xlikes" = "x likes someone". (A predicate with 1 free variable, x) x (y L(x,y)) = "Everyone has someone whom they like" = "everyone likes someone".(Areal proposition; no free variables left) Frank / van Deemter / Wyner
Nested Quantifiers Assume S(x,y) means “x sees y” D = {bill, phil, jill, mell} What does xS(x,bill') mean? "For every x, x sees bill'" In other words, "Everyone sees Bill." Frank / van Deemter / Wyner
Formal Evaluation - x y A(x,y) • Suppose M1 = (D,I) where D={bill, jill, mary} I(jill') = jill, I(mary') = mary, I(bill') = bill, I(B)={bill, jill}I(G)={jill},I(A)={(bill, jill), (mary,bill), (jill, jill)} • x y A(x,y) is T in M1 iff for every a where I(a) D, y A(x,y))(x:=a) is T in M1; • y A(x,y))(x:=a) is T in M1 iffthere is some b where I(b) D such that A(x,y))(x:=a)(x:=b) is T in M1. Frank / van Deemter / Wyner
Formal Evaluation - x y A(x,y) • Suppose M1 = (D,I) where D={bill, jill, mary} I(jill') = jill, I(mary') = mary, I(bill') = bill, I(B)={bill, jill}I(G)={jill}, I(A)={(bill, jill), (mary,bill), (jill, jill)} • A(x,y) is true where (x:=bill') and y is some constant? • where (x:=bill')(y:=bill'), A(x,y)is A(bill',bill'); A(bill',bill')is T in M1 iff(bill, bill) I(A). • where (x:=bill') (y:=jill'), A(x,y) is A(bill',jill'); A(bill',jill') is T in M1 iff (bill, jill) I(A). • where (x:=bill') (y:=mary'), A(x,y) is A(bill',mary'); A(bill',mary') is T in M1 iff (bill, mary) I(A). • Is one of these true? Frank / van Deemter / Wyner
Formal Evaluation - x y A(x,y) • Suppose M1 = (D,I) where D={bill, jill, mary} I(jill') = jill, I(mary') = mary, I(bill') = bill, I(B)={bill, jill}I(G)={jill}, I(A)={(bill, jill), (mary,bill), (jill, jill)} • A(x,y) is true where (x:=jill') and y is some constant? • where (x:=jill')(y:=bill'), A(x,y)is A(jill',bill'); A(jill',bill')is T in M1 iff(jill, bill) I(A). • where (x:=jill') (y:=jill'), A(x,y) is A(jill',jill'); A(jill',jill') is T in M1 iff(jill, jill) I(A). • where (x:=jill') (y:=mary'), A(x,y) is A(jill',mary'); A(jill',mary') is T in M1 iff(jill, mary) I(A). • Is one of these true? Frank / van Deemter / Wyner
Formal Evaluation - x y A(x,y) • Suppose M1 = (D,I) where D={bill, jill, mary} I(jill') = jill, I(mary') = mary, I(bill') = bill, I(B)={bill, jill}I(G)={jill}, I(A)={(bill, jill), (mary,bill), (jill, jill)} • A(x,y) is true where (x:=mary') and y is some constant? • where (x:=mary')(y:=bill'), A(x,y)is A(mary',bill'); A(mary',bill')is T in M1 iff(mary, bill) I(A). • where (x:=mary') (y:=jill'), A(x,y) is A(mary',jill'); A(mary',jill') is T in M1 iff(mary, jill) I(A). • where (x:=mary') (y:=mary'), A(x,y) is A(mary',mary'); A(mary',mary') is T in M1 iff(mary, mary) I(A). • Is one of these true? Frank / van Deemter / Wyner
Formal Evaluation - x y A(x,y) • Suppose M1 = (D,I) where D={bill, jill, mary} I(jill') = jill, I(mary') = mary, I(bill') = bill, I(B)={bill, jill}I(G)={jill}, I(A)={(bill, jill), (mary,bill), (jill, jill)} • x y A(x,y) is true in M1 so long as we can answer T to each of the preceding questions "Is one of these true?" Frank / van Deemter / Wyner
Quantifier Exercise If R(x,y)="xrelies on y" express the following: x(y R(x,y)) = Everyone has someone to rely on. y(xR(x,y)) = There is someone whom everyone relies on. x(y R(x,y)) = There is someone who relies on everyone. y(x R(x,y)) = Everyone has someone who relies on them. x(y R(x,y)) = Everyone relies on everyone. Frank / van Deemter / Wyner
Quantifier Exercise R(x,y) = "xrelies on y" where D is not empty. • x(y R(x,y)) • y(xR(x,y)) • x(y R(x,y)) Which of them is most informative? Which of them is least informative? Frank / van Deemter / Wyner
Quantifier Exercise • x(y R(x,y)) Least informative • y(xR(x,y)) • x(y R(x,y)) Most informative If 3 is true then 2 must also be true. If 2 is true then 1 must also be true. We say: 3 is logically stronger than 2 than 1 Frank / van Deemter / Wyner
Natural language is ambiguous • "Everybody likes somebody." • Can mean: • For everybody, there is somebody they like, • x yLikes(x,y) • Each to a different person • There is somebody whom everyone likes? • y xLikes(x,y) • Each to the same person Frank / van Deemter / Wyner
Quantifier Equivalences • Expanding quantifiers: If D = {a,b,c,…}x P(x) P(a) P(b) P(c) … x P(x) P(a) P(b) P(c) … • From those, we can “prove” the laws:x P(x) x P(x)x P(x) x P(x) • Which propositional equivalence laws can be used to prove this? Frank / van Deemter / Wyner
More Equivalences • x y P(x,y) y x P(x,y)x y P(x,y) y x P(x,y) • x (P(x) Q(x)) (x P(x)) (x Q(x))x (P(x) Q(x)) (x P(x)) (x Q(x)) • Let’s prove the last of these equivalences using the definition of the truth of a formula of the form xφ Frank / van Deemter / Wyner
Proving a Quantifier Equivalence • x (P(x) Q(x)) (x P(x)) (x Q(x))Proof: Suppose x (P(x) Q(x)) is true. So, there is a constant a such that (P(x) Q(x)) (x:=a) is true. So, for that a, the formula P(a) Q(a) is true. One possibility is that P(a) is true. In this case, P(x)(x:=a) is true. So, x P(x)is true, so (x P(x)) (x Q(x)) is true. The other possibility is that Q(a) is true. In this case, Q(x)(x:=a) is true. So, x Q(x)is true, so (x P(x)) (x Q(x))is true. disjunction introduction Frank / van Deemter / Wyner
Proving a Quantifier Equivalence • x (P(x) Q(x)) (x P(x)) (x Q(x))Proof: Suppose (x P(x)) (x Q(x))is true. One possibility is that x P(x) is true. This would mean that there is an a such that P(x) (x:=a) is true. So, for that constant a, P(a)is true.Therefore, P(a) Q(a) would also be true. Hence, (P(x) Q(x))(x:=a) would be true. Hence, x (P(x) Q(x)) would be true. The other possibility is that x Q(x). From this, x (P(x) Q(x)) is proven in the same way QED Frank / van Deemter / Wyner
Another Equivalence Law? • How about this one? x (P(x) Q(x)) (x P(x))(x Q(x))? Frank / van Deemter / Wyner
Not an Equivalence Law • x (P(x) Q(x)) (x P(x))(x Q(x)) ? • This equivalence statement is false. Counterexample (i.e. model making this false): • P(x): x’s birthday is on 30 AprilQ(x): x’s birthday is on 20 December • We can pick different people for x on the right since x in P(x) and x in Q(x) are not both bound to the same quantifier. Frank / van Deemter / Wyner
Some consequences of these definitions • Sometimes, predicate logic is taught very informally • This makes it easy to understand simple formulas • But each more complex case has to be explained separately, as if it was an exception • By defining things properly once, complex formulas fall out as special cases • One example: quantifier nesting Frank / van Deemter / Wyner
Theorems about logic • We are studying logical languages/calculi to allow you to use them (better). • Logicians study logical languages/calculi to understand their limitations. • Meta-theorems can say things about what can and cannot be expressed in predicate logic. Frank / van Deemter / Wyner
Theorems about logic • About propositional logic, we asked “What types of things can we express?” How many connectives do we need? • About predicate logic, logicians ask similar questions. For example, are these two quantifiers enough to be able to ‘say everything’? • This is a question about the expressive power of predicate logic. Frank / van Deemter / Wyner
Defining Other Quantifiers • one • at most one • at least two • exactly two • infinitely many • finitely many Frank / van Deemter / Wyner
Example: one • As per their name, quantifiers can be used to express that a predicate is true of a given quantity (number) of objects. • Example:Can predicate logic say “there exists at most one object with property P”? Frank / van Deemter / Wyner
Example: at mostone • Example:Can predicate logic say “there exists at most one object with property P”? Yes (provided we have equality): xy((P(x) P(y)) x = y) Frank / van Deemter / Wyner
Example: one • Can predicate logic say “there exists exactly one object with property P”? Frank / van Deemter / Wyner
Example: one • Can predicate logic say “there exists exactly one object with property P”? xP(x) xy((P(x) P(y)) x= y) • “There exist x such that P(x)” and“There exists at most one x such that P(x)” • Abbreviation: !xP(x)(“there exists exactly one x such that P(x)”) Frank / van Deemter / Wyner
Example: one • Another way to write this: • x (P(x) y (P(y) y x))“There is an x such that P(x), such that there is no y such that P(y) and y x.” • x binds x throughout the conjunction:x(P(x) y (P(y) y x)) Frank / van Deemter / Wyner
At least two • Can predicate logic say “there exist at least two objects with property P”? Frank / van Deemter / Wyner
At least two • Can predicate logic say “there exist at least two objects with property P”? • Yes:xy ((P(x) P(y)) x y) • Incorrect would bexP(x) y(P(y) x y),(where x occurs free, and whichtherefore does not express a proposition) Frank / van Deemter / Wyner
Exactly two • Can predicate logic say “there exist exactly two objects with property P”? Frank / van Deemter / Wyner
Exactly two • Can predicate logic say “there exist exactly two objects with property P”? • Yes: • x y (P(x) P(y) x y z (P(z) (z = x z = y))) Frank / van Deemter / Wyner
What’s wrong with • x y (P(x) P(y) x y) z (P(z) (z= x z= y ))as a formalisation of ‘exactly two’? Frank / van Deemter / Wyner
What’s wrong with • x y (P(x) P(y) x y) z (P(z) (z= x z= y ))as a formalisation of ‘exactly two’? • This is a conjunction of two separate propositions. As a result, x and y are not bound, so this is not even a proposition Frank / van Deemter / Wyner
What Cannot be Expressed in Predicate Logic: InfinitelyMany • Can predicate logic say “there exist infinitely many objects with property P”? • No! [This follows from the so-called Compactness Theorem: “An infinite set S of formulas has a model iff every finite subset of S has a model”] • How aboutfinitely many? Frank / van Deemter / Wyner
What Cannot be Expressed in Predicate Logic: FinitelyMany • How aboutfinitely many? • Suppose there existed a formula = “there exist only finitely many x such that so and so” • Then = “there exist infinitely many x such that so and so” • We know that such a formula does not exist • So, also does not exist Frank / van Deemter / Wyner
Another Way to Infinity If we allow infinitely long disjunctions then all this can be expressed: !xP(x) 2!xP(x) 3!xP(x) … Frank / van Deemter / Wyner
Remember • In propositional logic, we can strictly speaking only build formulas of finite size. • E.g., we can write P(a) P(b) P(a) P(b) P(c) P(a) P(b) P(c) P(d) , etc up to some finite length. • But this way, we could never say that all natural numbers have P Frank / van Deemter / Wyner
What Cannot be Expressed in Predicate Logic: Most, Many • Can predicate logic say “most objects have property P”? • No! [This follows from the Compactness Theorem as well. Again, this is unless we allow infinitely long disjunctions.] • Can predicate logic say “many objects have property P”? • No, only precisely defined quantities Frank / van Deemter / Wyner
Formulas of Infinite Length? • In predicate logic, you can say this easily:xP(x) • It’s sometimes useful to pretend that propositional logic allows infinitely long formulas, but in the “official” version this is not possible. Frank / van Deemter / Wyner
Decidability • We’ve shown you two ways of checking propositional logic equivalencies: • Checking truth tables • Using equivalence laws • You’ve seen how (1) can be done algorithmically (consider the T-tables and semantic evaluation). • This shows that checking propositional logic equivalence is decidable • But, predicate logic has variables over (potentially) infinite domains and combinations of quantifiers, so checking predicate logic equivalence is not decidable Frank / van Deemter / Wyner
Decidability • Checking proplog equivalence is decidable • Checking predlog equivalence is not decidable.Therefore, theorem proving will always remain an art (for both computers and humans) • Some “fragments” of predlog are decidable. One application: PROLOG Frank / van Deemter / Wyner
Bonus Topic: Logic Programming • Some programming languages are based entirely on (a part of) predicate logic • The most famous one is called Prolog. • A Prolog program is a set of propositions (“facts”) and (“rules”) in predicate logic. • The input to the program is a “query” proposition. • Want to know if it is true or false. • The Prolog interpreter does some automated deduction to determine whether the query follows from the facts. Frank / van Deemter / Wyner
Facts in Prolog • A fact in Prolog represents a simple, non-compound proposition in predicate logic. • E.g., likes(john,mary) • Lowercase symbols are used for constants and predicates, uppercase is used for variables. Frank / van Deemter / Wyner
Rules in Prolog • A rule in Prolog represents a universally quantified proposition of the general form xy (P(x,y) → Q(x)),where x and y are variables, P a possibly compound predicate, and Q an atomic proposition. • In Prolog: q(X) :- p(X,Y). i.e., the , quantifiers are implicit. • Example: likable(X) :- likes(Y,X). Frank / van Deemter / Wyner