CPS 352/543, 430/542 Lecture notes: Overview of first-order predicate logic



Coverage:
    (CPS 352/543) [COPL] §§16.1-16.3 (pp. 617-624), [PLPP] §§12.1-12.3 (pp. 539-552), and
    (CPS 430/542) [FCDB] §§10.1-10.3 (pp. 463-492)


What types of logics are there?

  • propositional logic, a proposition logical statement which is either true or false (e.g., Socrates is a man).
  • predicate logic (also called quantified logic) (e.g., Man(Socrates))


Logic programming

  • re-curring theme: mismatch between formal systems and computer systems
  • logic programming is based on formal logic
  • `formal logic was developed to provide a method for describing propositions, with the goal of allowing those formally stated propositions to be checked for validity' [COPL]
  • `symbolic logic can be used for the three basic needs of formal logic: to
    • express propositions,
    • express relationships between propositions, and
    • to describe how new propositions can be inferred from other propositions which are assumed to be true' [COPL]
  • the form of symbolic logic relevant to logic programming is called first-order predicate calculus



  • essence of logic programming: `a collection of propositions are assumed to be axioms (i.e., universal truths) and from these axioms, a desired fact is proved by applying the rules of inference in some automated way' [PLPP].


Propositions

Propositional Logic (courtesy Randal Nelson and Tom LeBlanc, Predicate Logic (courtesy Randal Nelson and Tom LeBlanc, University of Rochester)
  • atomic propositions:
    • examples:
        man(socrates).
        friend(larry, sallie).
    • man is called the functor
    • larry, sallie is the ordered list of parameters
    • when the functor and the ordered list of parameters are written together in the form of a function as one element of a relation, the result is called a compound term
    • no intrinsic semantics (they can mean whatever you want them to mean)
    • man(socrates). can be a fact or query

  • compound propositions: two or more atomic propositions connected by the following logical connectors, or operators:

      Concept Symbol Example Meaning
      negation ¬ ¬anot a
      conjunction aba and b
      disjunction aba or b
      equivalence aba is equivalent to b
      implication ab a implies b
      implication ab b implies a
      (precedence proceeds top-down)

      examples:
        abc

        a ∨ ¬bd ⇔ (a ∨ (¬b)) ⊃ d

        ab ⇔ ¬ ab

  • entailment (semantic consequence):
    • P |= Q
      • read left to right says: `P entails Q'
      • read right to left says: `Q follows from P' or `Q is a semantic consequence of P'
    • means that all of the models (i.e., true rows in the truth table) on the left hand side must also be models on the right hand side
    • for instance, ab |= ab
    • entailment (|=) is not implication (⊃)
    • implication is a statment, entailment is a meta-statement

  • quantifiers (introduce variables):

      QuantifierExampleMeaning
      universalX.P X, P is true
      existential X.P ∃ a value of X such that P is true

    • examples:
        X.(USpresident(X) ⊃ UScitizen(X)).
        X.(USpresident(X) ∧ servedmorethan2terms(X)).
        X.(hascar(larry, X) ∧ sportscar(X)).

    • scope is attached to atomic proposition
    • use parentheses to indicate scope
    • quantifiers have highest precedence

  • great deal of redundancy in predicate calculus
    • one proposition can be stated several different ways
    • fine for logicians, but poses a problem if we are to implement symbolic logic in a computer system


Clausal form

  • a standard (simplified) form for propositions: B1B2 ∨ ... ∨ BnA1A2 ∧ ... ∧ Am.
    • A's and B's are terms
    • left hand side is consequent
    • right hand side is antecedent
    • interpretation: if all of the A's are true, then at least one of the B's must be true

  • examples (courtesy [COPL]):
      likes(bob, trout) ⊂ likes(bob, fish) ∧ fish(trout).
      father(louis, al) ∨ father(louis, violet) ⊂ father(al, bob) ∧ mother(violet, bob) ∧ grandfather(louis, bob).

  • advantages
    • existential quantifiers are unnecessary
    • universal quantifiers are implicit in the use of variables in the atomic propositions
    • no operators other than conjunction and disjunction are required
    • all predicate calculus propositions can be converted to clausal form


Horn clauses

  • `when propositions are used for resolution, only a restricted kind of clausal form called a Horn clause can be used, which further simplifies the resolutions process' [COPL]

  • Horn clause: a proposition with 0 or 1 terms in the consequent
    • headless Horn clause: a proposition with 0 terms in the consequent (e.g., {} ⊂ man(jake). (or false ⊂ man(jake).) (called a goal or query in PROLOG))
    • headed Horn clause: a proposition with 1 atomic term in the consequent (e.g.,
      • likes(bob, trout) ⊂ {}. (or likes(bob, trout) ⊂ true.) (called a fact in PROLOG)
      • likes(bob, trout) ⊂ like(bob, fish) ∧ fish(trout). (called a rule in PROLOG)
      )

  • `most, but not all, propositions can be stated as Horn clauses' [COPL] (e.g., p(a) and (∃x, not(p(x))) [PLPP], pp. 565-566)

  • logicPROLOG
    headless Horn clausegoal/query
    headed Horn clausefact/rule


Conversion examples

(courtesy [PLPP])


  • basic idea: `remove or (∨) connectives by writing separate clauses and treat the lack of quantifiers by assuming that variables appearing in the head are universally quantified, while variables appearing in the body (not also in the head) are existentially quantified' [PLPP]

  • greatest common divisor:
    • specification of GCD (proposition):
        the gcd of u and 0 is u
        the gcd of u and v, if v is not 0, is the same as the gcd of v and the remainder of dividing v into u
    • FOPL:
        u, gcd(u, 0, u).
        u, ∀ v, ∀ w, gcd(u, v, w) ⊂ ∼ zero(v) ∧ gcd(v, u mod v, w).
    • Horn clauses:
        gcd(u, 0, u).
        gcd(u, v, w) ⊂ ¬ zero(v) ∧ gcd(v, u mod v, w).

  • grandparent:
    • specification of grandparent (proposition):
        x is a grandparent of y if x is the parent of someone who is the parent of y
    • FOPL:
        x, ∀ y, (∃ z, grandparent(x,y) ⊂ parent(x,z) ∧ parent(z,y)).
    • Horn clause:
        grandparent(x,y) ⊂ parent(x,z) ∧ parent(z,y).

  • remember, universal quantifier is implicit and existential quantifier is not required:
    all variables on lhs of ⊂ are universally quantified and those on rhs (which do not appear on the lhs) are existentially quantified

  • mammal:
    • specification of mammal (proposition):
        x, if x is a mammal, then x has two or four legs
    • FOPL:
        x, legs(x,2) ∨ legs(x,4) ⊂ mammal(x).
    • Horn clauses:
        legs(x,2) ⊂ mammal(x) ∧ ¬ legs(x,4).
        legs(x,4) ⊂ mammal(x) ∧ ¬ legs(x,2).

  • `in general the more connectives which appear on the lhs of the ⊂, the harder to translate into a set of Horn clauses' [PLPP]
  • skolemization: a technique to eliminate existential quantifiers (courtesy Thoralf Skolem) involving Skolem constants and functions


Use of all of this: proving theorems (P |= ?)

  • what can we infer from known axioms and theorems?
  • need a deductive apparatus known as rules of inference


Resolution

  • there are many rules of inference in formal systems
  • resolution (courtesy Alan Robinson) is the primary rule of inference used in logic programming
  • resolution is a rule of inference which allows new propositions to be inferred from given propositions
  • resolution was devised to be used with propositions in clausal form

  •   (a ⊃ b) ∧ (b ⊃ c)

            a ⊃ c

  • how do we apply resolution? (example)
      ba.
      cb.

      bcab.
      ca.

  • or more generally (assume bi matches a):

                      aa1 ∧ ... ∧ an
                      bb1 ∧ ... ∧ bm
      bb1 ∧ ... ∧ bi-1 a1 ∧ ... ∧ anbi+1 ∧ ... ∧ bm

  • example (courtesy [COPL]):

      older(joanne, jake) ⊂ mother(joanne, jake).
      wiser(joanne, jake) ⊂ older(joanne, jake).
      older(joanne, jake) ∧ wiser(joanne, jake) ⊂ mother(joanne, jake) ∧ older(joanne, jake).
      wiser(joanne, jake) ⊂ mother(joanne, jake).

  • example (courtesy [COPL]):

      father(bob, jake) ∨ mother(bob, jake) ⊂ parent(bob, jake).
      grandfather(bob, fred) ⊂ father(bob, jake) ∧ father(jake, fred).

      (father(bob, jake) ∨ mother(bob, jake)) ∧ grandfather(bob, fred) ⊂ parent(bob, jake) ∧ father(bob, jake) ∧ father(jake, fred).

      mother(bob, jake) ∨ grandfather(bob, fred) ⊂ parent(bob, jake) ∧ father(jake, fred).

  • backward chaining systems (PROLOG) vs. forward chaining systems (CLIPS)

  • hypothesis vs. goal

  • fact vs. goal
      mammal(human) ⊂ {}. (a fact)
      {} ⊂ mammal(human). (a goal)
      {} ⊂ mammal(human) ∧ legs(x,2). (a goal; each term on rhs is called a sub-goal)

  • proof by contradiction:
    goodday(thu).
    
    ?- goodday(thu).
    
    goodday(thu) ⊂ true.
    false ⊂ goodday(thu).

    false ⊂ true (a contradiction)

  • resolution algorithm ([PLPP]):

      goal: {} ⊂ a
      rule: aa1 ∧ ... ∧ an

      match goal with head of one of the known clauses, and replace the matched goal with the body of the clause, creating a new list of sub-goals

      therefore, the original goal is replaced with subgoals: {} ⊂ a1 ∧ ... ∧ an

      if, after multiple iterations of this process, we end up with the empty Horn clause {} ⊂ {}, then the proposition has been proved (i.e., it is a theorem)

  • resolution can be slow on a large database

  • the presence of variables in propositions makes the process of resolution more complex than this
    • requires temporary assignment of values to variables called instantiation
    • the process of determining useful values for variables is called unification
    • unification often involves backtracking

  • logic programming = resolution + unification


Resolution examples

  • example (courtesy [PLPP]):

      mammal(human) ⊂ {}.

      {} ⊂ mammal(human).

      mammal(human) ⊂ mammal(human).

      {} ⊂ {} (proved!)

  • another example (courtesy [PLPP]):

      legs(x,2) ⊂ mammal(x) ∧ arms(x, 2).
      legs(x,4) ⊂ mammal(x) ∧ arms(x, 0).
      mammal(horse) ⊂ {}.
      arms(horse,0) ⊂ {}.

      {} ⊂ legs(horse, 4).

      legs(x,4) ⊂ mammal(x) ∧ arms(x,0) ∧ legs(horse, 4). (using the second rule above)

      now to cancel out, we need unification (bind x to horse)

      legs(horse,4) ⊂ mammal(x) ∧ arms(x,0) ∧ legs(horse, 4).
      {} ⊂ mammal(x) ∧ arms(x,0).

      mammal(horse) ⊂ mammal(horse) ∧ arms(horse,0). (using the third rule above)
      {} ⊂ arms(horse,0).

      arms(horse,0) ⊂ arms(horse,0). (using the fourth rule above)
      {} ⊂ {}. (proved!)


References

    [COPL] R.W. Sebesta. Concepts of Programming Languages. Addison-Wesley, Boston, MA, Sixth edition, 2003.
    [FCDB] J.D. Ullman and J. Widom. A First Course in Database Systems. Prentice Hall, Upper Saddle River, NJ, Second edition, 2002.
    [PLPP] K.C. Louden. Programming Languages: Principles and Practice. Brooks/Cole, Pacific Grove, CA, Second edition, 2002.