Logic programming

`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].

`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)

logic

PROLOG

headless Horn clause

goal/query

headed Horn clause

fact/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

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