PROPOSITIONAL CALCULUS ====================== Definition ---------- Propositional Calculus (PC) is the simplest logic system we shall consider. PC uses (a) an (infinite) set of atoms, such as p, r17, foo, and john-likes-theakstons-old-peculier, (b) the logical relations v (inclusive OR) and ~ (NOT), (c) the parentheses ( and ). v and ~ are defined by the following truth tables: A B A v B A ~ A ----- ----- ----- --- --- FALSE FALSE FALSE FALSE TRUE FALSE TRUE TRUE TRUE FALSE TRUE FALSE TRUE TRUE TRUE TRUE The symbols (b) can all be defined in terms of the primitives NAND (NOT AND) or NOR (NOT OR). However, NAND does not correspond to any English word, and neither NAND nor NOR is associative, e.g. (a NAND b) NAND c is not, in general, equal to a NAND (b NAND c). A combinations of atoms, logical relations and parentheses is called a WELL-FORMED-FORMULA (wff) if it can be parsed by the following grammar: wff --> atom | ~ wff | wff v wff | (wff) It is possible to define other logical relations in terms of v and ~: [Def ^] (A ^ B) =Df ~(~A v ~B) [Def ->] (A -> B) =Df (~A v B) [Def <->] (A <-> B) =Df ((A -> B) ^ (B -> A)) where A and B can be any wff. ^ is usually called AND, -> IMPLIES and <-> EQUIVALENT-TO. The grammar for wff's can now be extended to incude ^, -> and <->: wff --> wff ^ wff | wff -> wff | wff <-> wff ---------- Rewrite Rules ------------- It is possible, in some cases, to simplify or rewrite wff using the following rewrite rules (in what follows, A, B and C can be any wff): Double Negation Law: ~~A <--> A de Morgan's Laws: ~(A v B) <--> ~A ^ ~B ~(A ^ B) <--> ~A v ~B Distributive Laws: A ^ (B v C) <--> (A ^ B) v (A ^ C) A v (B ^ C) <--> (A v B) ^ (A v C) Contrapositive Law: A -> B <--> ~B -> ~A ^ and v are associative and commutative, and <-> is commutative. ---------- Resolution ---------- It is possible to prove theorems in PC using a technique called Resolution. Supposing we have as axioms, the following wff: a [1] ~b [2] b v c [3] b v e [4] (c ^ a) -> d [5] It is possible to prove (that the theorem) d (is TRUE), as follows: we negate d and try to prove that the negation is inconsistent with our axioms. ~d ^ [5] produces the resolvent ~(c ^ a), which is (~c v ~a) by de Morgan's Laws; (~c v ~a) ^ [1] produces the resolvent ~c; ~c ^ [3] produces the resolvent b; b ^ [2] produces the resolvent FALSE. Thus, ~d is FALSE, and so d is TRUE. It is worth mentioning two important rules of inference, which can be used in the resolution process: Modus Ponens (MP) and Modus Tollens (MT): MP: A and A -> B produces the resolvent B MT: ~B and A -> B produces the resolvent ~A where A and B are any wff. ---------- FIRST ORDER PREDICATE CALCULUS ============================== Definition ---------- First Order Predicate Calculus (FOPC) is a generalization of PC, in that it contains PC as a special case. FOPC uses (a) a set of atomic formulae, of the form predicate( -- term -- ), where predicates are constant and terms are either constants, variables or atomic formulae. -- term -- means any number of terms (incl. zero). We shall follow the convention of Prolog and start variables with capital letters. Examples of atomic formulae are sunshine(), typhoon-signal(X) yuppy(nigel) and gave(john, Something, mary). Here, sunshine, typhoon-signal, yuppy and gave are predicates, X and Something are variables and nigel, john and mary are constants. In the case of zero-term predicates, a convenient notation is to omit the parentheses altogether, thus: sunshine. A more complex atomic formula is the following: sentence(subject(S), predicate(verb(V), object(O))), (b) and (c) as in PC, (d) the quantifier V (FOR ALL). In FOPC, wff's have the following grammar: wff --> atomic-formula | ~ wff | wff v wff | wff ^ wff | wff -> wff | wff <-> wff | (wff) | (V variable)wff It is possible to define another quantifier, E (THERE EXISTS): [Def E] (EX)A =Df ~(VX)~A (where X is any variable and A is any (FOPC) wff), after which the following addition to the grammar can be made: wff --> (E variable)wff. ---------- Unification ----------- In FOPC, variables are bound to constants or other variables by means of a pattern-matching operation known as unification. Two atomic formulae unify if their predicates are equal, and all of their terms unify. A variable can unify with anything, and a constant can unify either with another identical constant or a variable. During the unification process, a list of substitutions is built up. Any variables which have already unified with constants behave as if they were those constants. Examples: p(a, b) fails to unify with q(a, b) p(a, b) unifies with p(a, b) giving () p(X, Y) unifies with p(a, b) giving X/a, Y/b p(X, X) fails to unify with p(a, b) p(X, X) unifies with p(a, a) giving X/a p(X, Y) unifies with p(A, B) giving X/A, Y/B p(X, q(X, Y)) unifies with p(g(Z), q(g(Z), Z)) giving X/g(Z), Y/Z Here is the unification algorithm used in Prolog interpreters. Atomic formulae are represented as lists, e.g. p(X, q(X, Y)) is represented as (p X (q X Y)) The predicate is, then, treated as just another term. unify x with y in env = if x_val is a copy of y_val then env elseif x_val is a variable then add make_binding(x_val, y_val) to env elseif y_val is a variable then add make_binding(y_val, x_val) to env elseif neither x_val is an atom nor y_val is an atom then if new_env = FAIL then FAIL else unify rest of x_val with rest of y_val in new_env endif where new_env = unify first of x_val with first of y_val in env else FAIL endif where x_val = value of x in env, y_val = value of y in env; ---------- Resolution ---------- The method used in the example on resolution in PC was somewhat ad-hoc. Before performing the resolution process, it is desirable to ensure that all the wff's are in a standard form. This can be done using the following algorithm. (1) Eliminate ->. For example, (VX)[p(X) -> r(X)] becomes (VX)[~p(X) v q(X)] (2) Reduce scope of ~. For example, (VX)~(p(X) v q(X)) becomes (VX)[~p(X) ^ ~q(X)] (3) Standardize variables. For example, (VX)p(X) ^ (VX)q(X) becomes (VX)p(X) ^ (VY)q(Y) (4) Move all quantifiers (E and V) to the left and eliminate E. (VX)[p(X) ^ (VY)[q(Y) v (EZ)r(Y, Z)]] becomes (VX)(VY)[p(X) ^ [q(Y) v r(Y, g(Y))]] Note that Z has been replaced by a function, g(Y). (VY)(EZ)r(Y, Z) means that for for any given Y, there exists a Z, i.e. the value of Z is a function of Y. Such a function is called a Skolem function. (5) Put matrix in conjunctive normal form (cnf) and eliminate V. cnf means that the wff is a conjunction of several disjunctions possibly containing some negations -- ~ inside v inside ^. (VX)(VY)[p(X) v [q(X, Y) ^ ~r(Y)] becomes [p(X) v q(X, Y)] ^ [p(X) v ~r(Y)] (6) Eliminate ^ symbols. [p(X) v q(X, Y)] ^ [p(X) v ~r(Y)] becomes p(X) v q(X, Y) p(X) v ~r(Y) (7) Rename variables, so that each variable symbol only appears in one clause. p(X) v q(X, Y) becomes p(X1) v q(X1, Y1) p(X) v ~r(Y) becomes p(X2) v ~r(Y2) Suppose our database contains the following axioms: [1] p(X1) v q(X1, Y1) [2] ~p(X2) v ~r(Y2) [3] r(X3) Suppose we wish to prove q(a, b). First, we negate it: ~q(a, b), and then repeatedly unify it with a selected clause until either unification fails or we get an empty resolvent. If we get the empty resolvent, the threorem is proven. ~q(a, b) ^ [1] produces p(a) with Y1=b, X1=a p(a) ^ [2] produces ~r(Y2) with X2=a ~r(Y2) ^ [3] produces the empty resolvent with X3=Y2 ----------