--------------- Predicate Logic (cont'd) --------------- Satisfiability and validity: - The truth-value of a formula F under an interpretation I=(S,v) is defined as follows: . if F is an atomic formula P(t_1,...,t_m), where each t_i is a term (either a variable or a constant), then F is true iff the relation A^S is satisfied by the values of t_1,...,t_m under I; For example, the formula L(x,O) is true for the interpretation (Z,v) where v(x)=-5, but false for the interpretation (Z,v) where v(x)=2. The same formula is false for the interpretation (N,v) for every possible valuation v. . if F consists of subformulas joined by a connective, then the value of F is obtained from the truth table for that connective, applied to the values of each subformula; . if F is of the form (forall x E), then F is true iff E is true for every value of x in the domain D (other variables keep their value under valuation v), i.e., F is true iff E is true under every interpretation (S,v') where v'=v except possibly for v'(x); For example, forall x (L(O,x) \/ ==(O,x)) is true under interpretation (N,v) for every valuation v, but the same formula is false under interpretation (Z,v) for every valuation v (the valuation is irrelevant in this case). . if F is of the form (exists x E), then F is true iff E is true for some value of x in the domain D (other variables keep their value under valuation v), i.e., F is true iff E is true under some interpretation (S,v') where v'=v except possibly for v'(x). For example, exists y L(y,O) is false under interpretation (N,v) for every valuation v, but the same formula is true under interpretation (Z,v) for every valuation v (the valuation is irrelevant in this case). - A formula is "satisfiable" if some interpretation satisfies it (i.e., makes it true). - A formula is "unsatisfiable" if no interpretation satisfies it. - A formula is "valid" if every interpretation satisfies it. - Example 1: forall x (L(x,O) \/ ==(x,O) \/ L(O,x)) is satisfiable but not valid (try to think of different interpretations to make it true or false). - Example 2: forall x P(x,y,I) -> exists x P(x,y,I) is valid: consider an arbitrary interpretation (S,v); if it falsifies forall x P(x,y,I), then the entire formula is true by the truth table for ->; if it satisfies forall x P(x,y,I), then P(x,y,I) is true for all values of x in the domain, which means that it is true for at least one value of x in the domain, so exists x P(x,y,I) is true. Logical equivalences: - Formula F "logically implies" formula E if and only if every interpretation that satisfies F also satisfies E. Example: forall x(A(x) -> B(x)) and A(c) logically implies B(c). - Formulas F and E are "logically equivalent" if every interpretation gives both formulas the same value. - Basic quantifier equivalences (we use "Q" to stand for either 'forall' or 'exists' quantifier and, as before, ~ to stand for negation): . ~ forall x E <=> exists x ~ E; ~ exists x E <=> forall x ~ E . A /\ Q x B <=> Q x (A /\ B) [if x is **not free** in A] . A \/ Q x B <=> Q x (A \/ B) [if x is **not free** in A] . Q x F <=> Q y F[y/x] (if y does not appear in F, and where F[y/x] is obtained from F by replacing every free occurrence of x with y) Example: exists x(P(u,v,w), /\ S(x,w) -> exists x P(u,v,x)) LEQV exists y(P(u,v,w) /\ S(y,w) -> exists x P(u,v,x)) . If P and Q are propositional formulas with variables x_1...x_n such that P LEQV Q and F_1...F_n are first order formulas, then P' and Q' that are obtained from P and Q by replacing x_i by F_i are logically equivalent. Example: forall x L(x,y) -> exists z M(z) LEQV ~forall x L(x,y) \/ exists z M(z) . We can replace a piece of a formula by a logically equivalent expression. Example: ~forall x L(x,y) \/ exists z M(z) LEQV exists x ~L(x,y) \/ exists z M(z) . forall x A -> B LEQV exists x (A -> B) [if x is not free in B] . exists x A -> B LEQV forall x (A -> B) [if x is not free in B] . See notes (page 186-189) for further details. - A set of formulas H logically implies a formula F if and only if every interpretation that satisfies all formulas in H also satisfies F. Example: Let L be a first-order language with binary predicate symbol L. F1: forall x ~L(x,y) F2: forall x forall y forall z (L(x,y) /\ L(y,z) -> L(x,z) F3: forall x forall y (L(x,y) -> ~L(y,x)) if H={F1,F2} then H logically imples F3, because: By contradiction, assume that there is a structure S that satisfies F1 and F2 but falsifes F3. It means that exists a exists b such that (a,b) and (b,a) are in L^S. Since S satisfes F2 it follows that (a,a) is in L^S, contradicting the assumption that S satisfies F1. Predicate Logic and relational databases - First order forumals can be used to express queries about relational databases. - Consider the database of a library, with information about books, subscribers, and books that have been borrowed. . Each book is a relation Book(b,t,n) where b is the id, t is the title and n is the name. . Each subscriber is defined by his/her SIN #, name, and address with a triple Subscriber(s, n, a). . For each book that is borrowed we store the name of the person who has borrowed, book id, and the due date: Borrowed(s,b,d) . These relations are stored as two dimentional arrays. Columns of the array correspond to the attributes of the relationand (such as id, name, etc) and rows contain the elements of the relation. . To find the titles of all the books written by "Knuth" we can write: exists b Book(b, t, "Knuth") where t is a free variable and can range over all possible names. This means: find the set of all values u for t, so that for some book c, the triple (c, u, "Knuth") is in the relation Book. . To find the names and addresses of all subscribers that have borrowed books that are due Nov 4, 2002: exists s (Subscriber(s, n, a) /\ exists b Borrowed(s,b,2002/11/04)) . The attributes we are interested in finding are the free variables of the formula. . Logically equivalent formulas represnet the same queries: exists s exists b (Subscriber(s, n, a) /\ Borrowed(s, b, 2002/11/04)) . To find the address of all people who have borrowed a book with title "The art of computer programming": exists s exists n exists b exists n' exists d (Borrowed(s, b, d) /\ Book(b, "The art of computer programming", n) /\ Subscriber (s, n', a)) - Can we express all queries using first-order formulas? . No! for example, we cannot write a predicate formula for find the subscribers who have borrowed a majority of the books owned by the library. . However, for any *constant* k, we can write a first-order formula that represents: find the subscribers who have borrowed at least k books owned by the library. . There is a non-trivial mathematical proof for these facts. Prenex normal form - A first-order formula is in Prenex Normal Form (PNF) iff all its quantifiers appear at the begining of it: Q1 x1 Q2 x2 .. Qk xk E (each Qi is either forall or exits and E is a quantifier-free first-order formula) Example: forall x exists y (P(x,y,z) /\ ~M(x) -> S(x,z)) is a formula in PNF form. - For any first-order formula we can move the quantifiers outwards and get a formula that is logically equivalent to the original one and is in PNF form. We can do this using "factoring" and "substitution" rules: Example: (forall x A(x) \/ B(y)) -> forall x C(x) LEQV (forall x A(x) \/ B(y)) -> forall z C(z) LEQV (rule III) forall x (A(x) \/ B(y)) -> forall z C(z) LEQV (rule IId) forall z (forall x (A(x) \/ B(y)) -> C(z)) (rule IIf) forall z exists x (A(x) \/ B(y) -> C(z)) (rule IIe) - If we have "forall x forall y E" does it matter which "forall" comes first? The order of same quantifiers is not important, BUT the order of *different* quantifiers IS very important: Example: "forall x exists y L(x,y)" is NOT the same as "exists y forall x L(x,y)" - Generally, "exists y forall x E" logically implies "forall x exists y E" for any formula E, but the converse is not necessarily true. - We have seen formulas that involve several quantifiers over the same variable. In these cases, every occurences of that variable is bound by the *closest* quantifier. |------------------------------------| Example: forall x (S(x,y) -> exists u (exists v P(u,v,y) /\ exists v P(v,u,x))) |----| |-------------| |---| |-----| - The meaning of a formula is very dependent on binding of variables to quantifiers. For example, forall x(M(x) \/ F(x)) is totally different from forall x M(x) \/ forall x F(x). - The requirement in rule III (rename a varible x in a formula F to y, if y does NOT occure in F) is to ensure that binding of quantifiers are unchanged. However this requirement is stronger than necessary. We can achieve the same goal by ensuring that: (a) there is no free variable y in F, and (b) there is no free occurence of x in E that is within the scope of a y-quantifier. Example: exists x (M(x) /\ forall y (S(x,y) -> F(y))) if we change x to y, since x occures free within the scope of the y-quantifier we get exists y (M(y) /\ forall y (S(y,y) -> F(y))) which is *different* from the original one. However, we can rename x to z without any problems. - Note that if x is a free variable in a formula we *CANNOT* simply rename it to a variable that does not occure in the formula. The resulting formula is NOT logically equivalent to the original one.