Presentation is loading. Please wait.

# Mathematics for Computing Science

## Presentation on theme: "Mathematics for Computing Science"— Presentation transcript:

Mathematics for Computing Science
Fall 2013 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 (5th Edition) by Kenneth H. Rosen (c) , Frank, van Deemter, and Wyner

Mathematics for Computing Science
Fall 2013 Predicate Logic III (c) , Frank, van Deemter, and Wyner

Frank / van Deemter / Wyner
Agenda Formal Evaluation Nested Quantifiers Quantifier equivalences Defining (or not) other quantifiers Fall 2013 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 iff bill  {bill, jill} is T in M1. Work from bottom to top. Fall 2013 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. Fall 2013 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. Fall 2013 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? Fall 2013 Frank / van Deemter / Wyner

Mathematics for Computing Science
Fall 2013 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 x likes" = "x likes someone". (A predicate with 1 free variable, x) x (y L(x,y)) = "Everyone has someone whom they like" = "everyone likes someone". (A real proposition; no free variables left) Fall 2013 Frank / van Deemter / Wyner (c) , Frank, van Deemter, and Wyner

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." Fall 2013 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 iff there is some b where I(b)  D such that A(x,y)) (x:=a) (x:=b) is T in M1. Fall 2013 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? Fall 2013 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? Fall 2013 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? Fall 2013 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?" Fall 2013 Frank / van Deemter / Wyner

Mathematics for Computing Science
Fall 2013 Quantifier Exercise If R(x,y)="x relies on y" express the following: x(y R(x,y)) = Everyone has someone to rely on. y(x R(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. Fall 2013 Frank / van Deemter / Wyner (c) , Frank, van Deemter, and Wyner

Mathematics for Computing Science
Fall 2013 Quantifier Exercise R(x,y) = "x relies on y" where D is not empty. x(y R(x,y)) y(x R(x,y)) x(y R(x,y)) Which of them is most informative? Which of them is least informative? Fall 2013 Frank / van Deemter / Wyner (c) , Frank, van Deemter, and Wyner

Mathematics for Computing Science
Fall 2013 Quantifier Exercise x(y R(x,y)) Least informative y(x R(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 Fall 2013 Frank / van Deemter / Wyner (c) , Frank, van Deemter, and Wyner

Natural language is ambiguous
Mathematics for Computing Science Fall 2013 Natural language is ambiguous "Everybody likes somebody." Can mean: For everybody, there is somebody they like, x y Likes(x,y) Each to a different person There is somebody whom everyone likes? y x Likes(x,y) Each to the same person Fall 2013 Frank / van Deemter / Wyner (c) , Frank, van Deemter, and Wyner

Quantifier Equivalences
Mathematics for Computing Science Fall 2013 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? (Chalkboard.) Another way to see why the order of quantifiers matters is to expand out the definitions of FORALL and EXISTS in terms of AND and OR. For example, suppose the universe of discourse just consists of two objects a and b. Now, consider some predicate P(x,y). Then, FORALL x EXISTS y P(x,y)  (EXISTS y P(a,y)) /\ (EXISTS y P(b,y))  (P(a,a) \/ P(a,b)) /\ (P(b,a) \/ P(b,b)). In contrast, EXISTS y FORALL x P(x,y)  (FORALL x P(x,a)) \/ (FORALL x P(x,b))  (P(a,a) /\ P(b,a)) \/ (P(a,b) /\ P(b,b)). To see that these two are inequivalent, suppose only P(a,a) and P(b,b) are true. Then, the first proposition (with the FORALL first) is true, but, the second proposition (with the EXISTS first) is true. Students can come up with this counterexample in-class as an exercise. Fall 2013 Frank / van Deemter / Wyner (c) , Frank, van Deemter, and Wyner

Mathematics for Computing Science
Fall 2013 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φ Fall 2013 Frank / van Deemter / Wyner (c) , Frank, van Deemter, and Wyner

Proving a Quantifier Equivalence
Mathematics for Computing Science Fall 2013 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. Fall 2013 Frank / van Deemter / Wyner (c) , Frank, van Deemter, and Wyner

Proving a Quantifier Equivalence
Mathematics for Computing Science Fall 2013 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 Fall 2013 Frank / van Deemter / Wyner (c) , Frank, van Deemter, and Wyner

Another Equivalence Law?
Mathematics for Computing Science Fall 2013 Another Equivalence Law? How about this one? x (P(x)  Q(x))  (x P(x))  (x Q(x))? Fall 2013 Frank / van Deemter / Wyner (c) , Frank, van Deemter, and Wyner

Mathematics for Computing Science
Fall 2013 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 April Q(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. Fall 2013 Frank / van Deemter / Wyner (c) , Frank, van Deemter, and 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 Fall 2013 Frank / van Deemter / Wyner

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. Fall 2013 Frank / van Deemter / Wyner

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. Fall 2013 Frank / van Deemter / Wyner

Defining Other Quantifiers
one at most one at least two exactly two infinitely many finitely many Fall 2013 Frank / van Deemter / Wyner

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”? Fall 2013 Frank / van Deemter / Wyner

Frank / van Deemter / Wyner
Example: at most one Example: Can predicate logic say “there exists at most one object with property P”? Yes (provided we have equality): xy ((P(x)  P(y))  x = y) Fall 2013 Frank / van Deemter / Wyner

Frank / van Deemter / Wyner
Example: one Can predicate logic say “there exists exactly one object with property P”? Fall 2013 Frank / van Deemter / Wyner

Frank / van Deemter / Wyner
Example: one Can predicate logic say “there exists exactly one object with property P”? xP(x)  xy((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: !x P(x) (“there exists exactly one x such that P(x)”) Fall 2013 Frank / van Deemter / Wyner

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)) Fall 2013 Frank / van Deemter / Wyner

Frank / van Deemter / Wyner
At least two Can predicate logic say “there exist at least two objects with property P”? Fall 2013 Frank / van Deemter / Wyner

Frank / van Deemter / Wyner
At least two Can predicate logic say “there exist at least two objects with property P”? Yes: x y ((P(x)  P(y))  x y) Incorrect would be xP(x)  y(P(y)  x y), (where x occurs free, and which therefore does not express a proposition) Fall 2013 Frank / van Deemter / Wyner

Frank / van Deemter / Wyner
Exactly two Can predicate logic say “there exist exactly two objects with property P”? Fall 2013 Frank / van Deemter / Wyner

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) )) Fall 2013 Frank / van Deemter / Wyner

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’? Fall 2013 Frank / van Deemter / Wyner

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 Fall 2013 Frank / van Deemter / Wyner

What Cannot be Expressed in Predicate Logic: Infinitely Many
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 about finitely many? Fall 2013 Frank / van Deemter / Wyner

What Cannot be Expressed in Predicate Logic: Finitely Many
How about finitely 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 Fall 2013 Frank / van Deemter / Wyner

Another Way to Infinity
If we allow infinitely long disjunctions then all this can be expressed: !x P(x)  2!x P(x)  3!x P(x)  … Fall 2013 Frank / van Deemter / Wyner

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 Fall 2013 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 Fall 2013 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. Fall 2013 Frank / van Deemter / Wyner

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 Fall 2013 Frank / van Deemter / Wyner

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 Fall 2013 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. Fall 2013 Frank / van Deemter / Wyner

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. Fall 2013 Frank / van Deemter / Wyner

Frank / van Deemter / Wyner
Rules in Prolog A rule in Prolog represents a universally quantified proposition of the general form xy (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). Fall 2013 Frank / van Deemter / Wyner

Frank / van Deemter / Wyner
Rules in Prolog Note that xy (P(x,y)→Q(x)) is equivalent to x((y P(x,y)→Q(x)) In other words, Q(x) holds if you can find a y such that P(x,y) Fall 2013 Frank / van Deemter / Wyner

Conjunction and Disjunction
Logical conjunction is encoded using multiple comma-separated terms in a rule. Logical disjunction is encoded using multiple rules. E.g., x ((P(x)Q(x))R(x))→S(x) can be rendered in Prolog as: s(X) :- p(X),q(X) s(X) :- r(X) Fall 2013 Frank / van Deemter / Wyner

Frank / van Deemter / Wyner
Deduction in Prolog When a query is input to the Prolog interpreter, it searches its database to determine if the query can be proven true from the available facts. if so, it returns “yes”, if not, “no” (! Called Negation-as-failure) If the query contains any variables, all values that make the query true are printed. Fall 2013 Frank / van Deemter / Wyner

Frank / van Deemter / Wyner
Simple Prolog Example An example input program: likes(john,mary). likes(mary,fred). likes(fred,mary). likable(X) :- likes(Y,X). An example query: ? likable(Z) returns: ... Fall 2013 Frank / van Deemter / Wyner

Frank / van Deemter / Wyner
Simple Prolog Example An example input program: likes(john,mary). likes(mary,fred). likes(fred,mary). likable(X) :- likes(Y,X). An example query: ? likable(Z) returns: mary fred Fall 2013 Frank / van Deemter / Wyner

Relation between PROLOG and Predicate Logic
PROLOG cannot use all predicate logic formulas. (It covers a decidable “fragment” of predicate logic.) It uses ‘negation as failure’ Based on these limitations, PROLOG-based deduction is decidable. PROLOG is more than just logic (I/O, cut!), but logic is its hard core. Fall 2013 Frank / van Deemter / Wyner

Relation between PROLOG and Predicate Logic
PROLOG cannot use all predicate logic formulas. (It covers a decidable “fragment” of predicate logic.) It uses ‘negation as failure’ Based on these limitations, PROLOG-based deduction is decidable. PROLOG is more than just logic (I/O, cut!), but logic is its hard core. Fall 2013 Frank / van Deemter / Wyner

Download ppt "Mathematics for Computing Science"

Similar presentations

Ads by Google