First-Order Theories

CS 475 March 1, 2001

1 Preliminary

A first-order theory consists of an alphabet, a first order language, a set of axioms and a set of inference rules. Definition 1 An alphabet consists of the following sets:

1. variables

2. constants

3. function symbols

4. predicate symbols

5. connectives: {∧, ∨, ¬, ↔, →}

6. quantifiers:∀, ∃

7. punctuation symbols: ′(′,′)′,′ ,′ ,′ .′ NOTE: • The last three sets are the same for every alphabet.

• For an alphabet, only the set of constants or the set of function symbols may be empty.

• Notation convention: Variables: u, v, w, x, y, and z (possibly with indexes); constants: a, b, and c (possibly with indexes); function symbols of arities > 0: f, g, and h (possibly with indexes); and predicate symbols of arities ≥ 0: p, q, and r (possibly with indexes). The precedence among the connectives: ¬, ∀, ∃, ∧, ∨, →, ↔ Given an alphabet, a first order language is defined by the set of well-formed formula(wff or sentences) of the theory. Definition 2 A term is either

1. a variable, 2. a constant, or

3. f(t_{1}, …, t_{n}) where f is an n-ary function symbol and t_{1}, …, t_{n} are terms. Definition 3 A (well-formed) formula is defined inductively as follows.

1. p(t_{1}, …, t_{n}) where p is an n-ary predicate symbol and t_{1}, …, t_{n} are terms,

2. if P and Q are formulas then (¬P), (P ∧Q), (P ∨Q), (P → Q), (P ↔ Q) are formulas

3. if P is a formula and x is a variable then (∀x P) and (∃x P) are formulas. Definition 4 A first order language given by an alphabet consists of the set of all formulas constructed from the symbols of the alphabet. Example 1 (∀x(∃y(p(x, y) → q(x)))) and (¬∃x((p(x, a)∧q(f(x))))) are formulas. We can simplify them to ∀x∃y(p(x, y) → q(x)) and ¬∃x(p(x, a) ∧ q(f(x))). Definition 5 The scope of ∀x (resp. ∃x) in ∀xF (resp. ∃xF) is F. A bound occurrence of a variable in a formula is an occurrence immediately following a quantifier or an occurrence within the scope of the quantifier, which has the same variable immediately after the quantifier. Any other occurrence of a variable is free. Example 2 ∃xp(x, y) → q(x) – the first two occurrences of x are bound but the third one is free. ∃x(p(x, y) → q(x)) – all occurrences of x are bound. Definition 6 A closed formula is a formula with no free occurrences of any variable. Example 3 ∃xp(x, y) → q(x) is not a closed formula. ∃x(p(x, y) → q(x)) is a closed formula. Definition 7 A grounded term is a term not containing a variable. A grounded atom is an atom not containing a variable.

2 Interpretation

NOTE: When we say ‘a first order language L’ we understand that the alphabet of L is given. Definition 8 Let L be a first order language. An interpretation I of L consists of

1. a non-empty set D, called the domain of I, 2. for each constant in L, the assignment of an element of D, (i.e., a constant

c is mapped into an element I(c) ∈ D),

3. for each n-ary function symbol in L, the assignment of a mapping from D^{n} to D, (i.e., a function symbol f is mapped into a function f^{I})

4. for each n-ary predicate symbol in L, the assignment of a mapping from D^{n} to into {true, false}, (i.e., a predicate symbol p is mapped into a relation p^{I}).

Let I be an interpretation. A variable assignment (wrt. I) is an assignment to each variable in L of an element in D.

Let I be an interpretation and V be a variable assignment (wrt. I). The term assignment (wrt. I and V) of the terms in L is defined as follows.

1. Each variable is given its assignment according to V,

2. Each constant is given its assignment according to I,

3. If t′_{1}, …, t′_{n} are the term assignments of t_{1}, …, t_{n} and f′ is the assignment of the n-ary function symbol f, then f′(t′_{1}, …, t′_{n}) is the term assignment of f(t_{1}, …, t_{n}).

Let I be an interpretation and V be a variable assignment (wrt. I). Then, a formula L can be given a truth value, true or false, (wrt. I and V) as follows:

1. If L = p(t_{1}, …, t_{n}) and t′_{1}, …, t′_{n} are the term assignments of t_{1}, …, t_{n} (wrt. I and V), and p′ be the mapping assigned to the n-ary predicate symbol p by I, then the truth value of L is obtained by calculating the truth value of p′(t_{1}, …, t′_{n}),

2. If the formula has the form (¬P), (P ∧ Q), (P ∨ Q), (P → Q), (P ↔ Q) then the truth value of the formula is given by the following table

F G ¬ P P ∧ Q P ∨ Q P → Q P ↔ Q
t t  f  t  t  t  t
t f  f  f  t  f  f
f t  t  f  t  f  f
f f  t  f  t  f  t

3. if the formula has the form ∃xF, then the truth value of the formula is true if there exists d ∈ D such that F has the truth value wrt. I and the variable assignment V in which x is assigned to d; Otherwise, its truth value is false.

4. if the formula has the form ∀xF, then the truth value of the formula is true if for all d ∈ D, F has the truth value wrt. I and the variable assignment V in which x is assigned to d; Otherwise, its truth value is false.

From the above, the truth value of a closed formula does not depend on the variable assignment. Thus, we can speak about the truth value of a closed formula wrt. to an interpretation (without mentioning the variable assignment).

Definition 9 Let I be an interpretation of a first order language L and let F be a closed formula of L. Then, I is a model of F if F is true wrt. I.

Definition 10 Let T be a first order theory and L be its first order language L and let F be a closed formula of L. Then, I is a model of F if F is true wrt. I.

Let S be a closed formulas of a first order language L and I be an interpretation of L. I is a model of S if every formula F ∈ S is true wrt. I.

Definition 11 Let S be a closed formulas of a first order language L. We say

1. S is satisfiable if L has an interpretation which is a model of S,

2. S is valid if every interpretation of L is a model of S,

3. S is unsatisfiable if no interpretation of L is a model of S,

4. S is nonvalid if L has an interpretation which is not a model of S.

Definition 12 Let S be a closed formulas of a first order language L and F a formula in L. S entails F, denoted by S ⊧ F, if F is true wrt. to every model of S.

3 Unification

Definition 13 A substitution η us a finite set of the form {v_{1}/t_{1}, …, v_{n}/t_{n}} where each v_{i} is a variable, each t_{i} is a term distinct from v_{i} and the variables v_{1}, …, v_{n} are distinct.

Each v_{i}/t_{i} is called a binding for v_{i};

η is called a grounded substitution if the t_{i} are all ground terms.

Definition 14 Let η = {v_{1}/t_{1}, …, v_{n}/t_{n}} be a substitution and E be an expression (term, literal, conjunction of literals, or disjunction of literals). Then, Eη, the instance of E by η, is the expression obtained from E by simultaneously replacing each occurrence of the variables v_{i} in E by the term t_{i}.

If Eη is ground, then it is called a ground instance of E.

Example 4 Let E = p(x, y, f(a)) and η = {x/b, y/x} then Eη = p(b, x, f(a)).

Definition 15 Let σ = {v_{1}/t_{1}, …, v_{n}/t_{n}} and η = {u_{1}/s_{1}, …, u_{m}/s_{n}} be two substitutions. Then the composition ησ of η and σ is the substitution obtained from the set {u_{1}/s_{1}σ, …, u_{m}/s_{n}σ, v_{1}/t_{1}, …, v_{n}/t_{n}} by deleting any binding v_{j}/t_{j} for which v_{j} ∈ {u_{1}, …, u_{m}}.

Example 5 Let σ = {x/a, y/b, z/y} and η = {x/f(y), y/z} then ησ = {x/f(b), z/y} since X = {x/f(y)σ, y/zσ} = {x/f(b), y/y, x/a, y/b, z/y} and ησ is obtained from X by deleting y/y, x/a, y/b because x and y are variables occurring in η.

Two expressions E and F are called variants if there exists a substitution η such that E = F η and F = Eη. (We also say that E is a variant of F and vice versa!)

A set of expressions S = {E_{1}, …, E_{n}} is unifiable if there exists a substitution η such that E_{1}η = E_{2}η = … = E_{n}η. In that case, η is a unifier of S.

A unifier η of S is called a most general unifier (or mgu) of S if for each unifier σ of S there exists a substitution γ such that σ = ηγ.

Example 6 The set S = {p(f(x), a), p(y, f(w))} is not unifiable because we can not unify the constant a with f(w).

The set S = {p(f(x, y), g(z), a), p(f(y, x), g(u), a)} is unifiable since for η = {x/y, y/x, z/u}, Sη = {p(f(x, x), g(u), a)}. Here, η is a mgu of S.

Definition 16 Let S be a set of simple expressions (a simple expression is a term or an atom). The disagreement set of S is defined as follows. Locate the leftmost symbol position at which not all expressions in S have the same symbol and extract from each expression expression in S the subexpression beginning at that symbol position. The set of all such subexpressions is the disagreement set.

Example 7 Let S = {p(f(x), h(y), a), p(f(x), z, a), p(f(x), h(y), b)}. Then the disagreement set is {h(y), z)}.

Example 8 Let S = {p(f(x), h(y), a), p(f(x), z, a), p(f(x), w, b)}. Then the disagreement set is ?.

4 Unification Algorithm

Let S = {P_{1}, …, P_{m}} be a set of simple expressions.

S1 Put k = 0 and σ_{0} = {}.

S2 If Sσ_{k} is a singleton (P_{i}σ_{k} = P_{j}σ_{k} for every i ≠ j), then stop; σ_{k} is an mgu (most general unifier) of S; Otherwise, find the disagreement set D_{k} of Sσ_{k}.

S3 If there exist v and t in D_{k} such that v is a variable that does not occur in t, then put σ_{k+1} = σ_{k}{v/t}, increment k and go to S2. Otherwise, stop; S is not unifiable.

Example 9 Let S = {p(f(a), g(x)), p(y, y)}.

S1 Put k = 0 and σ_{0} = {}.

S2 Sσ_{0} = S is not a singleton. So, we need to find the disagreement set D_{0} of Sσ_{0} = S. We have: D_{0} = {f(a), y}.

S3 Here, y is a variable which does not occur in f(a). So, we let σ_{1} = σ_{0}{y/f(a)} = {y/f(a)} and go to S2.

S2 Sσ_{1} = {p(f(a), g(x)), p(f(a), f(a))} is not a singleton. So, we need to find the disagreement set D_{1} of Sσ_{1} = S. We have: D_{1} = {g(x), f(a)}.

S3 Here, there is no variable in D_{1}. So, we stop; S is not unifiable.

Example 10 Let S = {p(a, x, h(g(z))), p(z, h(y), h(y))}.

S1 Put k = 0 and σ_{0} = {}.

S2 Sσ_{0} = S is not a singleton. So, we need to find the disagreement set D_{0} of Sσ_{0} = S. We have: D_{0} = {a, z}.

S3 Here, z is a variable which does not occur in a. So, we let σ_{1} = σ_{0}{z/a} = {z/a} and go to S2.

S2 Sσ_{1} = {p(a, x, h(g(a))), p(a, h(y), h(y))} is not a singleton. So, we need to the disagreement set D_{1} of Sσ_{1}. We have: D_{1} = {x, h(y)}.

S3 Here, x is a variable which does not occur in h(y). So, we let σ_{2} = σ_{1}{x/h(y)} = {z/a, x/h(y)} and go to S2.

S2 Sσ_{2} = {p(a, h(y), h(g(a))), p(a, h(y), h(y))} is not a singleton. So, we need to the disagreement set D_{2} of Sσ_{2}. We have: D_{1} = {y, g(a)}.

S3 Here, y is a variable which does not occur in g(a). So, we let σ_{3} = σ_{2}{y/g(a)} = {z/a, x/h(g(a)), y/g(a)} and go to S2.

S2 Sσ_{3} = {p(a, h(g(a)), h(g(a)))} is a singleton. So we stop and one mgu of S is σ_{3} = {z/a, x/h(g(a)), y/g(a)}.

Theorem 1 Let S be a finite of simple expressions. If S is unifiable then the algorithm terminates and gives an mgu for S. If S is not unifiable then the algorithm terminates and reports this fact.

5 Resolution

Definition 17 A literal is either an atom P or its negation ¬P.

A clause is a disjunction of literals. (sometime it is written as P_{1} ∨ … ∨ P_{n} or {P_{1}, …, P_{n}})

A formula Q is said to be in conjunctive normal form (or CNF) if Q is a conjunction of clauses.

A formula Q is said to be in implicative normal form if Q is a conjunction of implication of the form P_{1} ∧ … ∧ P_{n} → Q_{1} ∨ … ∨ Q_{m} where each P_{i}, Q_{j} is an atom.

(P ∨ Q ∨ ¬S) ∧ (¬P ∨ Q ∨ S) ∧ (¬P ∨ ¬R ∨ ¬S) ∧ (P ∨ T ∨ ¬S) is a CNF.

Theorem 2 For every formula ϕ there exists a formula ψ in CNF form such that ϕ and ψ is equivalent, i.e., ∀(ϕ ↔ ψ) is a valid formula.

Algorithm to convert a formula into CNF form.

1. Eliminate implications: Replace p → q with ¬p ∨ q

2. Move ¬ inward: do the following

(a) ¬(p ∨ q) is replaced by ¬p ∧ ¬q

(b) ¬(p ∧ q) is replaced by ¬p ∨ ¬q

(c) ¬∀xp is replaced by ∃xp

(d) ¬∃xp is replaced by ∀x¬p

(e) ¬¬p is replaced by p

3. Standardize variable: For sentences like (∀xP (x)) ∨ (∃xQ(x)) that use the same variable name twice, change the name of one of the variable.

4. Move quantifier left: Move all quantifiers in the formula to the left, for example, p ∨ ∀xq is equivalent to ∀xq ∨ p etc.

5. Skolemize: Remove the existential quantifier by elimination – this includes: (1) defines a Skolem function, one for a variable occurred immediately after an existential quantification, (2) introduces a new constant, one for a variable occurred immediately after an existential quantification,

(3) removes the existential quantification and substitutes x for F^{x}(A^{x}) in the formula.

6. Distribute ∧ over ∨: (a ∧ b) ∨ c becomes (a ∨ c) ∧ (b ∨ c).

7. Flatten nested conjunction and disjunction: (a ∧ b) ∧ c becomes (a ∧ b ∧ c) and (a ∨ b) ∨ c becomes (a ∨ b ∨ c).

Example 11 Convert ((¬∀xA(x)) ∨ (∀yB(y))) → (¬(∀zQ(z, f(z)))) to CNF.

1. ¬((¬∀xA(x)) ∨ (∀yB(y))) ∨ (¬(∀zQ(z, f(z)))) (Eliminate implication)

2. ((¬¬∀xA(x)) ∧ (¬∀yB(y))) ∨ (¬(∀zQ(z, f(z)))) (Move ¬ ...)

3. (∀xA(x) ∧ ∃y¬B(y)) ∨ ((∃z¬Q(z, f(z)))) (Move ¬ ...)

4. ∀x∃y∃z((A(x) ∧ ¬B(y)) ∨ ¬Q(z, f(z))) (Move quantifier left)

5. ∀x((A(x) ∧ ¬B(F y(Cy))) ∨ ¬Q(Cz, f(F z(Cz)))) (Removing existential quantifier - F y, F z are two new functions and Cy, Cz are two new constants, correspond to the variable y and z respectively)

6. (A(x) ∧ ¬B(F y(Cy))) ∨ ¬Q(Cz, f(F z(Cz))) (Drop universal quantifier)

7. (A(x) ∨ ¬Q(Cz, f(F z(Cz)))) ∧ (¬B(F y(Cy)) ∨ ¬Q(Cz, f(F z(Cz)))) (Distribute ∧ over ∨)

NOTE: Implicative normal form is often used to. A formula of the form ¬P_{1} ∨ ¬P_{2} ∨ … ∨ ¬P_{n} ∨ Q_{1} ∨ Q_{2} … ∨ Q_{m} is equivalent to P_{1} ∧ P_{2} … ∧ P_{n} → Q_{1} ∨ Q_{2} … ∨ Q_{m}

It is easy to see that if Q is in CNF then we can convert it into implicative normal form using the above conversion.

The resolution inference rule If β_{1} and β_{2} are unifiable and η is a mgu of β_{1} and β_{2}, then

\frac{α ∨ β_{1}, ¬β_{2} ∨ γ}{αη ∨ γη}  (1)

or

\frac{¬α → β_{1}, β_{2} → γ}{¬αη → γη}  (2)

We can Given a set of formulas S and a formula Q, we would like to determines if S ⊧ Q.

We can use (1) (or (2)) to determine whether S ⊢ Q holds or not.

We make the following assumptions:

1. Each formula in S is a clause (why?)

2. Q is a literal (why?)

Example 12 Let Δ be the set consisting of the following clauses:

1. ¬P (w) ∨ Q(w),

2. P (x) ∨ R(x),

3. ¬Q(y) ∨ S(y), and

4. ¬R(z) ∨ S(z).

Question: Δ ⊢ S(A)?

Proof.

1. \frac{¬P (w)∨Q(w),P (x)∨R(x)}{¬P (w)∨S(w)} where η = \{y/w\}

2. \frac{¬P (w)∨S(w),P (x)∨R(x)}{S(x)∨R(x)} with \{w/x\}

3. \frac{S(x)∨R(x),¬R(z)∨S(z)}{S(A)} with \{x/A, z/A\}! DONE!

Refutation proof procedure. Given a set of clauses S and a literal Q. The refutation proof procedure uses resolution to determine whether S ⊧ Q holds or not.

1. Idea: If S ⊧ Q then S ∪ {¬Q} is unsatisfiable, i.e., there is no model for S ∪ {¬Q}. So, we will assume that ¬Q holds and try to derive a contradiction out of S ∪ {¬Q}.

2. Algorithm: We try to derive a proof that derives a contradiction from S ∪ {¬Q}. The algorithm can be described as follows.

A1 Let k = 0, G_{k} = ¬Q.

A2 If G_{k} = false then step and answer ’yes’; Otherwise, find a clause C in S that contains a literal L which is contradictory with some L′ of G_{k} and η is a mgu of L and L′. Go to step [A3]!

A3 Let G_{k+1} = ((C \ {L}) ∪ (G_{k} \ {L′}))η, k = k + 1, and go to step [A2]!

Example 13

Dog(D)  (3)
Owns(Jack, D)  (4)
Dog(y) ∧ Owns(x, y) → AnimalLover(x)  (5)
AnimalLover(x) ∧ Animal(y) ∧ Kills(x, y) → F alse  (6)
Kills(Jack, T una) ∨ Kills(Curiosity, T una)  (7)
Cat(T una)  (8)
Cat(x) → Animal(x)  (9)

Convert to clausal form

Dog(D)  (10)
Owns(Jack, D)  (11)
¬Dog(y) ∨ ¬Owns(x, y) ∨ AnimalLover(x)  (12)
¬AnimalLover(x) ∨ ¬Animal(y) ∨ ¬Kills(x, y)  (13)
Kills(Jack, T una) ∨ Kills(Curiosity, T una)  (14)
Cat(T una)  (15)
¬Cat(x) ∨ Animal(x)  (16)

Proving Kills(Curiosity, T una)

G_{0} = ¬Kills(Curiosity, T una), η = {}, Clause (14)

G_{1} = Kills(Jack, T una), η = {x/Jack, y/T una}, Clause (13)

G_{2} = ¬AnimalLover(Jack) ∨ ¬Animal(T una), η = {x/T una}, Clause (16)

G_{3} = ¬AnimalLover(Jack) ∨ ¬Cat(T una), η = {x/T una}, Clause (16) G_{4} = ¬AnimalLover(Jack), η = {}, Clause (15) G_{5} = ¬Dog(y) ∨ ¬Owns(Jack, y), η = {x/Jack}, Clause (12) G_{6} = ¬Dog(D), η = {y/D}, η = {}, Clause (11) G_{7} = □ (or G_{7} = false), η = {}, Clause (10)! DONE Remark. The steps can be drawn into a refutation tree as follows: