<<

Resolution for First Order Logic

Meghdad Ghari

Institute for Research in Fundamental Sciences (IPM) School of Mathematics-Isfahan Branch Logic Group http://math.ipm.ac.ir/Isfahan/Logic-Group.htm

Logic Short Course II, Computational Predicate Logic March 9, 2017

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 1 / 82 Outline

1 Propositional Logic Propositional Resolution

2 First Order Logic Syntax Semantics Resolution for FOL

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 2 / 82 Language

Atom = {p1, p2, p3,...}, A (finite or infinite) set of atomic propositions (or propositional variables). L = Atom ∪ {(, ), ¬, ∧, ∨, →} Formulas of propositional logic are defined by the following grammar in Backus Naur form (BNF):

φ ::= p | (¬φ) | (φ ∧ φ) | (φ ∨ φ) | (φ → φ), p ∈ Atom

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 3 / 82 Semantics: principle of compositionality

The meaning of a complex expression is determined by the meanings of its constituent expressions and the rules used to combine them. Valuations: v : Atom → {T, F} Valuations can be extended to the set of all formulas as follows:

v(¬φ) = 1 − v(φ) v(φ ∧ ψ) = min(v(φ), v(ψ)) v(φ ∨ ψ) = max(v(φ), v(ψ)) v(φ → ψ) = min(1, 1 − v(φ) + v(ψ))

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 4 / 82 Decideability

Definition A logical system is decidable if there is an effective method (or algorithm) for determining whether arbitrary formulas are theorems of the logical system.

Truth tables provide a decision procedure for propositional logic.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 5 / 82 and satisfiability

Theorem Let φ be a formula of propositional logic. Then

φ is satisfiable iff ¬φ is not valid.

Theorem

Given formulas φ1, φ2, . . . , φn and ψ of propositional logic,

φ1, φ2, . . . , φn |= ψ iff |= φ1 ∧ φ2 ∧ ... ∧ φn → ψ

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 6 / 82 Validity and satisfiability

Theorem Let φ be a formula of propositional logic. Then

φ is satisfiable iff ¬φ is not valid.

Theorem

Given formulas φ1, φ2, . . . , φn and ψ of propositional logic,

φ1, φ2, . . . , φn |= ψ iff |= φ1 ∧ φ2 ∧ ... ∧ φn → ψ

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 6 / 82 Conjunctive Normal Form (CNF)

L ::= p | ¬p, p ∈ Atom Literal D ::= L | L ∨ D Clause C ::= D | D ∧ C Conjunctive normal form

Example (Set representation)

CNF Clausal form (¬q ∨ p ∨ r) ∧ (¬p ∨ r) ∧ q ∧ (r ∨ ¬p) {{¬q, p, r}, {¬p, r}, {q}}

Facts The empty clsuse  is always false and unsatisfiable. The empty clause form ∅ is valid. A clause form that has  is a contradiction, and hence unsatisfiable.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 7 / 82 Converting formulas to CNF Theorem Every formula in propositional logic can be transformed into an equivalent formula in CNF

Step 1. Elimination of → and ↔: φ → ψ ≡ ¬φ ∨ ψ φ ↔ ψ ≡ (¬φ ∨ ψ) ∧ (φ ∨ ¬ψ) Step 2. Converting to negation normal forms (NNF): ¬¬φ ≡ φ ¬(φ ∧ ψ) ≡ ¬φ ∨ ¬ψ ¬(φ ∨ ψ) ≡ ¬φ ∧ ¬ψ Step 3. Distributivity rules: φ ∧ (ψ ∨ σ) ≡ (φ ∧ ψ) ∨ (φ ∧ σ) φ ∨ (ψ ∧ σ) ≡ (φ ∨ ψ) ∧ (φ ∨ σ)

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 8 / 82 Resolution

John Alan Robinson, A Machine-Oriented Logic Based on the Resolution Principle J. ACM. 12 (1): 23-41, 1965.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 9 / 82 Propositional Resolution

Resolution is a refutation procedure used to check if a formula in clausal form is unsatisfiable.

The resolution procedure consists of a sequence of applications of the resolution rule to a set of clauses.

The rule maintains satisfiability: if a set of clauses is satisfiable, so is the set of clauses produced by an application of the rule.

Therefore, if the (unsatisfiable) empty clause is ever obtained, the original set of clauses must have been unsatisfiable.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 10 / 82 Propositional Resolution Rule

Resolution: ¬φ ∨ ψ φ ∨ χ ψ ∨ χ Resolution is sound (preserves validity).

Modus Ponens: φ → ψ φ ψ ¬φ ∨ ψ φ ∨ > ψ ∨ χ is a special case of resolution.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 11 / 82 Propositional Resolution Rule

Resolution: ¬φ ∨ ψ φ ∨ χ ψ ∨ χ Resolution is sound (preserves validity).

Modus Ponens: φ → ψ φ ψ ¬φ ∨ ψ φ ∨ > ψ ∨ χ Modus Ponens is a special case of resolution.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 11 / 82 Propositional Resolution Rule

Propositional Resolution Rule:

C t {p} D t {¬p} C ∪ D where C and D are clauses and t denotes disjoint union.

C ∪ D is called the resolvent of C t {p} and D t {¬p}:

C ∪ D = Res(C t {p}, D t {¬p})

Resolution on clause forms:

{C1,..., C t {p}, D t {¬p},..., Cn} {C1,..., C ∪ D,..., Cn} Resolution on clause forms preserves satisfiability.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 12 / 82 Proof by resolution

Definition A resolution refutation of S is a resolution proof of empty clause  from S.

Theorem S is unsatisfiable iff there is a resolution refutation of S.

Checking validity φ is valid, if ¬φ is unsatisfiable or there is a resolution refutation of ¬φ.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 13 / 82 Proof by resolution

In order to show that φ1, φ2, . . . , φn |= ψ,

we show that φ1 ∧ φ2 ∧ ... ∧ φn ∧ ¬ψ is unsatisfiable.

1 First, φ1 ∧ φ2 ∧ ... ∧ φn ∧ ¬ψ is converted into CNF. 2 Then, the resolution rule is applied to the resulting clauses. 3 The process continues until one of two things happens:

I two clauses resolve to yield the empty clause , in which case φ1, φ2, . . . , φn |= ψ. I there are no new clauses that can be added, in which case φ1, φ2, . . . , φn 6|= ψ;

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 14 / 82 Resolution algorithm

/* Input: A set of clauses S */ /* Output: S is satisfiable or unsatisfiable */

while there are clauses C1, C2 ∈ S and C := Res(C1, C2) such that C 6∈ S do S := S ∪ {C} If  ∈ S then return unsatisfiable else (i.e. if  6∈ S) return satisfiable.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 15 / 82 Example I We prove that |= ¬(p ∨ q) → (¬p ∧ ¬q). To this end, we show that

¬[¬(p ∨ q) → (¬p ∧ ¬q)] (1)

is unsatisfiable. The CNF of (1) is:

¬p ∧ ¬q ∧ (p ∨ q),

and in clausal form: {{¬p}, {¬q}, {p, q}}. The following is a resolution refutation of it:

{¬p}{p, q} {q} {¬q} 

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 16 / 82 Example II We show that p 6|= p ∧ q. To this end, we show that p ∧ ¬(p ∧ q) (2) is satisfiable. The CNF of (2) is: p ∧ (¬p ∨ ¬q), and in clausal form: S = {{p}, {¬p, ¬q}}. Using resolution algorithm we update S as follows: 1 {p} a clause of S 2 {¬p, ¬q} a clause of S 3 {¬q} resolvent of clauses 1 and 2 S is satisfiable, since there are no new resolvents that can be added and  6∈ S. Meghdad Ghari (IPM) Resolution Logic Short Course 2017 17 / 82 Resolution refutation as a In order to prove that (p → (q → r)) → ((p → q) → (p → r)) is valid, we show that its negation is unsatisfiable. The following is a resolution refutation tree of its negation: ¨H ¨ H ¨¨ HH ¨¨ HH p¯ p @ @ @ @ p¯q¯ pq¯ ¡A ¡ A ¡ A ¡ A p¯qr¯ ¯r

p¯ denotes ¬p. pq¯ denotes the clause {¬p, q}.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 18 / 82 Exercise

By the resolution algorithm show that: 1 ¬(p → ¬q) |= p. Counterexample in natural language: it is not the case that if it is raining then the ground is not wet |= it is raining. 2 p → q 6|= ¬(p → ¬q). Counterexample in natural language: if it is raining then the ground is wet |= it is not the case that if it is raining then the ground is not wet.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 19 / 82 Ontological commitment

Ontological commitment: what the logic assumes about the nature of reality: propositional logic assumes that there are facts that either hold or do not hold in the world. First-order logic assumes that the world consists of objects with certain relations among them that do or do not hold.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 20 / 82 Language

Objects: people, houses, numbers, theories, Ronald McDonald, colors, baseball games, wars, centuries . . . Relations: these can be unary relations or properties such as red, round, prime, . . ., or more general n-ary relations such as brother of, bigger than, inside, part of, has color, occurred after, owns, comes between, . . . Functions: father of, best friend, one more than, beginning of . . .

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 21 / 82 Language

Variables: V = {x1, x2, x3,...} Logical operators:

L = {⊥, ¬, ∨, ∧, →, ∀x, ∃x, =}x∈V for x ∈ V

First order language:

L(R, F, C) = L ∪ R ∪ F ∪ C

R is a finite or countable set of relation symbols (or predicate symbols) of any arity. F is a finite or countable set of function symbols of any arity. C is a finite or countable set of constant symbols.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 22 / 82 Language

Terms (Tm): t ::= x | c | f (t, t,..., t), where x ∈ V, c ∈ C, f ∈ F. Formulas (Fml):

φ ::= P(t, t,..., t) | t = t | (¬φ) | (φ ∧ φ) | (φ ∨ φ) | (φ → φ) | (∀x)φ | ∃xφ,

where P ∈ R, t ∈ Tm, x ∈ V

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 23 / 82 Examples

Natural language Logical formula John walks W (j) John sees Mary S(j, m) John gives Mary the book G(j, m, b) He walks W (x) John sees her S(j, x) Someone walks ∃xW (x) Some boy walks ∃x(B(x) ∧ W (x)) Everyone walks ∀xW (x) Every girl sees Mary ∀x(G(x) → S(x, m)) Someone creates everythings ∃x∀yC(x, y)

Natural language processing Computers translate

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 24 / 82 First Order Theories

First order logic is a framework to formalize mathematical theories. It is a universal language for talking about structures.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 25 / 82 Axioms of FOL

Axioms: 1 A finite complete set of axioms of propositional logic, 2 ∀xA → A{t/x}, where t is free for x in A, 3 ∀x(A → B) → (A → ∀xB), where x 6∈ FV (A), 4 A{t/x} → ∃xA, where t is free for x in A, 5 ∀x(A → B) → (∃xA → B), where x 6∈ FV (B), 6 ∀x(x = x),

7 t1 = t2 ∧ A{t1/x} → A{t2/x}. Rules: ` A → B ` A ` A MP Gen ` B ` ∀xA

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 26 / 82 Graph Theory

L = {R}, R is a predicate symbol with two arguments.

Proper axioms: 1 ∀x¬R(x, x), 2 ∀x∀y(R(x, y) → R(y, x)).

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 27 / 82 Group Theory

L = {∗, e}, ∗ is a binary function symbol and e is a constant symbol.

Proper axioms: 1 ∀x(e ∗ x = x ∗ e = x), 2 ∀x∀y∀z(x ∗ (y ∗ z) = (x ∗ y) ∗ z), 3 ∀x∃y(x ∗ y = y ∗ x = e).

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 28 / 82 Set Theory

L = {∈}, ∈ is a predicate symbol with two arguments.

Proper axioms: 1 ∀z(z ∈ x ↔ z ∈ y) → x = y, 2 ∀x(ϕ(x) → x ∈ y) → ∃w∀x(x ∈ w ↔ ϕ(x)), 3 ∃w∀z(z ∈ w ↔ ∃y ∈ x(z ∈ y)), 4 ∃w∀x(x ∈ w ↔ x ⊆ y), 5 ∃w∀x(x ∈ w ↔ ∃y ∈ z(x = F(y)), where F is a unary operation, 6 ∃x(∃y ∈ x∀z(z 6∈ y) ∧ ∀y ∈ x∃z ∈ x∀w(w ∈ z ↔ w ∈ y ∨ w = y)), 7 ∃y(y ∈ x) → ∃y ∈ x∀z ∈ y(z 6∈ x).

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 29 / 82 Peano Arithmetic PA

L = {0¯, s, ⊕, }, 0¯ is a constant symbol, s is a unary function symbol and ⊕, are binary function symbol.

Proper axioms: 1 ∀x(s(x) 6= 0¯), 2 ∀x(x 6= 0¯ → (∃y)s(y) = x), 3 ∀x(x ⊕ 0¯ = x), 4 ∀x∀y(x ⊕ s(y) = s(x ⊕ y)), 5 ∀x(x 0¯ = 0¯), 6 ∀x∀y(x s(y) = (x y) ⊕ x). 7 ∀y[ϕ(0¯, y) ∧ ∀x(ϕ(x, y) → ϕ(s(x), y)) → ∀xϕ(x, y)].

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 30 / 82 Semantics of FOL

semantics Syntactic expressions of language 99K Real situations

Example M(x) x is a man B(y) y is a bicycle R(x, y) x rides y

∃x∃y(M(x) ∧ B(y) ∧ R(x, y))

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 31 / 82 Models

Definition A model for the first-order language L(R, F, C) is a pair M = (D, I) such that Domain: D is a non-empty set of individual objects. Interpretation: I is a function mapping relation symbols, function symbols, and constant symbols to relations on D, functions on D, and objects in D. n n n I I(P ) ⊆ D , for P ∈ R. n n n I I(f ): D → D, for f ∈ F. I I(c) ∈ D, for c ∈ C.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 32 / 82 Example

Let L = {0¯, s, ⊕, } be the language of PA.

The standard model N = (N, I) of PA is defined as follows: I(0¯) = 0. I(s) = suc, where suc : N → N is suc(n) = n + 1. I(⊕) = +, where + : N × N → N is +(n, m) = n + m. I( ) = ·, where · : N × N → N is ·(n, m) = n · m.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 33 / 82 Variable assignment

Is φ(x) true in natural numbers?

φ(x) ≡ ∃y(x = y ⊕ y)

Variable assignment in a model M = (D, I):

s : V → D

Example Let N = (N, I) be the standard model of PA.

0 s : V → N s : V → N s(x) = 6 s0(x) = 7 φ(x) is true under s φ(x) is false under s0

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 34 / 82 Variable assignment

Is φ(x) true in natural numbers?

φ(x) ≡ ∃y(x = y ⊕ y)

Variable assignment in a model M = (D, I):

s : V → D

Example Let N = (N, I) be the standard model of PA.

0 s : V → N s : V → N s(x) = 6 s0(x) = 7 φ(x) is true under s φ(x) is false under s0

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 34 / 82 A variable assignment models a memory state of a computer, where the variables are “addresses" that store “current values".

A computer typically works by successively replacing values in addresses by new values. s[x := a] is the variable assignment that is completely like σ except that x now gets the value a (where σ might have assigned a different value).

Example Let D = {1, 2, 3} and V = {x, y, z}.

s s[x := 2]

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 35 / 82 Values of terms

Given a model M = (D, I) and variable assignment s in M, we define the value (or interpretation) of terms as follows:

xI,s := s(x), for x ∈ V cI,s := I(c), for c ∈ C I,s I,s I,s [f (t1,..., tn)] := I(f )(t1 ,..., tn ) for f ∈ F

Example Let L = {0¯, s, ⊕, } be the language of PA, N = (N, I) be the standard model of PA, and s0 is an assignment s.t. s0(x) = 3.

0 [s(0¯) ⊕ x]I,s = 4

0 [s(s(0¯)) s(x)]I,s = 8

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 36 / 82 Tarski’s theory of truth Notation:

M |=s φ φ is ture in M under assignment s

Definition Let M = (D, I) be a model and s be an assignment in M: I,s I,s M |=s P(t1,..., tn) iff (t1 ,..., tn ) ∈ I(P). M |=s ¬φ iff M 6|=s φ.

M |=s φ ∧ ψ iff M |=s φ and M |=s ψ.

M |=s φ → ψ iff M |=s φ implies M |=s ψ.

M |=s ∀xφ iff M |=s[x:=a] φ for all a ∈ D.

M |=s ∃xφ iff M |=s[x:=a] φ for some a ∈ D.

Definition

φ is (logically) valid if M |=s φ for every model M and every assignment s in M. Notation: |= φ.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 37 / 82 Example

Let φ(x) ≡ ∃y(x = y ⊕ y)

Let N = (N, I) be the standard model of PA.

0 s : V → N s : V → N s(x) = 6 s0(x) = 7

N |=s φ(x) N 6|=s0 φ(x)

In fact,

N |=s φ(x) iff s(x) is an even number.

Exercise Show that 6|= ∀y∃x p(x, y) → ∃x∀y p(x, y).

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 38 / 82 Semantics

Valuations: v : Formulas → {T, F}

v(¬φ) = 1 − v(φ) v(φ ∧ ψ) = min(v(φ), v(ψ)) v(φ ∨ ψ) = max(v(φ), v(ψ)) v(φ → ψ) = min(1, 1 − v(φ) + v(ψ)) v(∀xφ) = min{v(φ[a¯/x]) | a ∈ D} v(∃xφ) = max{v(φ[a¯/x]) | a ∈ D}

∀ is a generalization of ∧, and ∃ is a generalization of ∨.

Semantics of FOL does not provide a decision procedure for FOL.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 39 / 82

Theorem FOL is sound and complete:

` φ iff |= φ

There exists a proof for φ iff φ is true in all models.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 40 / 82 Completeness

Theorem FOL is sound and complete:

` φ iff |= φ

There exists a proof for φ iff φ is true in all models.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 40 / 82 Undecidability

Theorem Validity in first order logic is undecidable.

Proof. The proof that there is no decision procedure for validity describes an algorithm that takes an arbitrary Turing machine T and generates a formula ST in first-order logic, such that

|= ST iff T halts.

If there were a decision procedure for validity, this construction would give us an decision procedure for the halting problem.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 41 / 82

All A are B ∀x(A(x) → B(x)) No A are B ¬∃x(A(x) ∧ B(x)) or ∀x(A(x) → ¬B(x)) Some A are B ∃x(A(x) ∧ B(x)) Not all A are B ¬∀x(A(x) → B(x)) or ∃x(A(x) ∧ ¬B(x))

The language of Syllogism is a small fragment of predicate logic: monadic predicate logic, which has unary predicates only. Theorem Validity in monadic predicate logic is decidable.

Johan van Benthem, Hans van Ditmarsch, Jan van Eijck, Jan Jaspars, Logic in Action New Edition, November 23, 2016

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 42 / 82 CNF in Predicate Logic In propositional logic, every formula is equivalent to one in CNF, but this is not true in first-order logic. However, a formula in first-order logic can be transformed into an equisatisfiable formula in CNF.

Arbitrary formulas in predicate logic

Formulas in prenex normal form (PNF)

Skolemization

Formulas in clausal form or CNF

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 43 / 82 Prenex Normal Form (PNF)

Theorem For every formula A there is an equivalent formula A0 (prenex normal form of A) with the same free variables in which all quantifiers appear at the begining.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 44 / 82 ` ¬∀xA ↔ ∃x¬A. ` ¬∃xA ↔ ∀x¬A. ` (∀xA ∗ B) ↔ ∀y(A[y/x] ∗ B). ` (A ∗ ∀xB) ↔ ∀y(A ∗ B[y/x]). ` (∃xA ∗ B) ↔ ∃y(A[y/x] ∗ B). ` (A ∗ ∃xB) ↔ ∃y(A ∗ B[y/x]). ` (∀xA → B) ↔ ∃y(A[y/x] → B). ` (A → ∀xB) ↔ ∀y(A → B[y/x]). ` (∃xA → B) ↔ ∀y(A[y/x] → B). ` (A → ∃xB) ↔ ∃y(A → B[y/x]). where ∗ ∈ {∧, ∨}, and y does not occur in A, B.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 45 / 82 A decidable fragment

Theorem There are decision procedures for the validity of PNF formulas without constant and function symbols whose prefixes are of one of the forms (where m, n ≥ 0): ∀x1 ... ∀xn∃y1 ... ∃ym

∀x1 ... ∀xn∃y∀z1 ... ∀zm

∀x1 ... ∀xn∃y1∃y2∀z1 ... ∀zm These classes are conveniently abbreviated ∀∗∃∗, ∀∗∃∀∗, ∀∗∃∃∀∗.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 46 / 82 Skolemization

Theorem For every sentence A in a given language L there is an equisatisfiable universal formula A0 (Skolemization of A) in an expanded language L0 gotten by the addition of new function symbols.

Lemma

For any sentence A = ∀x1 ... ∀xn∃yB of a language L, A and 0 A = ∀x1 ... ∀xnB[f (x1,..., xn)/y] are equisatisfiable, where f is a function symbol not in L.

Example

∃x∀yP(x, y) ∀yP(c, y) ∀x∃yP(x, y) ∀xP(x, f (x))

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 47 / 82 Example

∀x∀y[∃z(P(x, z) ∧ P(y, z)) → ∃uQ(x, y, u)] ↓ ∀x∀y∀w[P(x, w) ∧ P(y, w) → ∃uQ(x, y, u)] ↓ ∀x∀y∀w∃v[P(x, w) ∧ P(y, w) → Q(x, y, v)] ↓ ∀x∀y∀w[P(x, w) ∧ P(y, w) → Q(x, y, f (x, y, w))] L0 = L ∪ {f } ↓ P(x, w) ∧ P(y, w) → Q(x, y, f (x, y, w)) ↓ ¬P(x, w) ∨ ¬P(y, w) ∨ Q(x, y, f (x, y, w)) Clausal form (CNF)

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 48 / 82 Herbrand Theorem Reduction of first-order logic to propositional logic. Theorem

Let φ = (∃y1,..., yn)F(y1,..., yn) and F is quantifier-free. Then φ is valid if and only if there exists a finite sequence of terms tij , possibly in an expansion of the language, with 1 ≤ i ≤ k and 1 ≤ j ≤ n, such that F(t11,..., t1n) ∨ ... ∨ F(tk1,..., tkn) is a of propositional logic.

Theorem Let A be a sentence in PNF in a language L, B a prenex equivalent of ¬A, and C(~x) a quantifier-free Skolemization of B in the expanded languge L0. ~ ~ 0 Then A is valid iff there are terms t1,..., tn of L such that ~ ~ ¬C(t1) ∨ ... ∨ ¬C(tn) is a tautology of propositional logic.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 49 / 82 and unifier

Definition An expression is any or literal. A substitution is a mapping θ : V → Tm, denoted by {t1/x1,..., tn/xn}. The result of applying θ on expression E is denoted by Eθ.

A set of expressions S = {E1,..., En} is unifiable if there is a substitution θ, called a unifier for S, such that E1θ = ... = Enθ. A unifier θ for S is a most general unifier (mgu) for S if for every unifier σ for S there is a substitution λ such that σ = θλ.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 50 / 82 Substitution and unifier

Definition An expression is any term or literal. A substitution is a mapping θ : V → Tm, denoted by {t1/x1,..., tn/xn}. The result of applying θ on expression E is denoted by Eθ.

A set of expressions S = {E1,..., En} is unifiable if there is a substitution θ, called a unifier for S, such that E1θ = ... = Enθ. A unifier θ for S is a most general unifier (mgu) for S if for every unifier σ for S there is a substitution λ such that σ = θλ.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 50 / 82 Substitution and unifier

Definition An expression is any term or literal. A substitution is a mapping θ : V → Tm, denoted by {t1/x1,..., tn/xn}. The result of applying θ on expression E is denoted by Eθ.

A set of expressions S = {E1,..., En} is unifiable if there is a substitution θ, called a unifier for S, such that E1θ = ... = Enθ. A unifier θ for S is a most general unifier (mgu) for S if for every unifier σ for S there is a substitution λ such that σ = θλ.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 50 / 82 Substitution and unifier

Definition An expression is any term or literal. A substitution is a mapping θ : V → Tm, denoted by {t1/x1,..., tn/xn}. The result of applying θ on expression E is denoted by Eθ.

A set of expressions S = {E1,..., En} is unifiable if there is a substitution θ, called a unifier for S, such that E1θ = ... = Enθ. A unifier θ for S is a most general unifier (mgu) for S if for every unifier σ for S there is a substitution λ such that σ = θλ.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 50 / 82 Meghdad Ghari (IPM) Resolution Logic Short Course 2017 51 / 82 Disagreement set

Definition For a finite nonempty set of expressions S, the disagreement set D(S) is the set of subexpressions of S that begin at the leftmost position at which elements of S differ.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 52 / 82 Unification Algorithm

/*Input: A set S 6= ∅ of literals */ /* Output: A most general unifier for S or report not unifiable */

σ :=  (the empty substitution) while S is not a singleton do choose a disagreement pair x ∈ V, t ∈ Tm in D(S) s.t. x 6∈ t if there is no such disagreement pair then return “non-unifiable" else σ := σ{t/x} and S := Sσ return σ

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 53 / 82 Unification Algorithm

/*Input: A set S 6= ∅ of literals */ /* Output: A most general unifier for S or report not unifiable */

σ :=  (the empty substitution) while S is not a singleton do choose a disagreement pair x ∈ V, t ∈ Tm in D(S) s.t. x 6∈ t if there is no such disagreement pair then return “non-unifiable" else σ := σ{t/x} and S := Sσ return σ

Example We find a mgu for S = {P(x, g(b)), P(h(y, a), z)} by the unification algorithm.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 54 / 82 Unification Algorithm

/*Input: A set S 6= ∅ of literals */ /* Output: A most general unifier for S or report not unifiable */

σ :=  (the empty substitution) while S is not a singleton do choose a disagreement pair x ∈ V, t ∈ Tm in D(S) s.t. x 6∈ t if there is no such disagreement pair then return “non-unifiable" else σ := σ{t/x} and S := Sσ return σ

Example (Step 1) σ :=  S = {P(x, g(b)), P(h(y, a), z)}

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 55 / 82 Unification Algorithm

/*Input: A set S 6= ∅ of literals */ /* Output: A most general unifier for S or report not unifiable */

σ :=  (the empty substitution) while S is not a singleton do choose a disagreement pair x ∈ V, t ∈ Tm in D(S) s.t. x 6∈ t if there is no such disagreement pair then return “non-unifiable" else σ := σ{t/x} and S := Sσ return σ

Example (Step 2) D(S) = {x, h(y, a)} σ := {h(y, a)/x} = {h(y, a)/x} S := Sσ = {P(h(y, a), g(b)), P(h(y, a), z)}

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 56 / 82 Unification Algorithm

/*Input: A set S 6= ∅ of literals */ /* Output: A most general unifier for S or report not unifiable */

σ :=  (the empty substitution) while S is not a singleton do choose a disagreement pair x ∈ V, t ∈ Tm in D(S) s.t. x 6∈ t if there is no such disagreement pair then return “non-unifiable" else σ := σ{t/x} and S := Sσ return σ

Example (Step 3) D(S) = {g(b), z} σ := {h(y, a)/x}{g(b)/z} = {h(y, a)/x, g(b)/z} S := Sσ = {P(h(y, a), g(b)), P(h(y, a), g(b))} = {P(h(y, a), g(b))}

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 57 / 82 Unification Algorithm

/*Input: A set S 6= ∅ of literals */ /* Output: A most general unifier for S or report not unifiable */

σ :=  (the empty substitution) while S is not a singleton do choose a disagreement pair x ∈ V, t ∈ Tm in D(S) s.t. x 6∈ t if there is no such disagreement pair then return “non-unifiable" else σ := σ{t/x} and S := Sσ return σ

Example Thus the mgu for S = {P(x, g(b)), P(h(y, a), z)} is σ = {h(y, a)/x, g(b)/z}.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 58 / 82 Unification Algorithm

/*Input: A set S 6= ∅ of literals */ /* Output: A most general unifier for S or report not unifiable */

σ :=  (the empty substitution) while S is not a singleton do choose a disagreement pair x ∈ V, t ∈ Tm in D(S) s.t. x 6∈ t if there is no such disagreement pair then return “non-unifiable" else σ := σ{t/x} and S := Sσ return σ

Exercise Apply the unification algorithm to the following sets: 1 {P(a, y, f (y)), P(z, z, u)}, where a ∈ C, y, z, u ∈ V, f ∈ F. 2 {P(g(x), y), P(y, y), P(y, f (u))}, where x, y, u ∈ V, f ∈ F.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 59 / 82 Resolution Rule

~ ~ Let C t {Pt1,..., Ptn} and D t {¬P~s1,..., ¬P~sm} be clauses which by renaming of variables have no variables in common.

Resolution Rule: ~ ~ C t {Pt1,..., Ptn} D t {¬P~s1,..., ¬P~sm} Cσ ∪ Dσ ~ ~ where σ is an mgu for {Pt1,..., Ptn, P~s1,..., P~sm}. Cσ ∪ Dσ is the resolvent of the parent clauses.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 60 / 82 Definition A resolution proof of C from a given formula S is a finite sequence C1, C2,..., Cn such that each Ci is either a clause in S or obtained by renamig variables of a clause in S or is inferred from earlier member of the sequence by the resolution rule and Cn = C. In this case we write S `R C. A resolution refutation of S is a resolution proof of empty clause  from S.

Theorem S is unsatisfiable iff there is a resolution refutation of S.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 61 / 82 Resolution algorithm

/* Input: A set of clauses S */ /* Output: S is satisfiable or unsatisfiable */ S0 := S Loop do Choose a new pair of clauses C1, C2 ∈ Si C := Res(C1, C2) If C =  then return unsatisfiable else Si+1 := Si ∪ {C} If Si+1 := Si for all pairs of clauses then return satisfiable.

While an unsatisfiable set of clauses will eventually produce  under a suitable systematic execution of the procedure, the existence of infinite models means that the resolution procedure on a satisfiable set of clauses may never terminate, so resolution is not a decision procedure for first order logic.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 62 / 82 Example We want to show that A1, A2 `R A3,

A1 := ∀x∀y∀z[P(x, y) ∧ P(y, z) → P(x, z)] (transitivity)

A2 := ∀x∀y[P(x, y) → P(y, x)] (symmetry)

A3 := ∀x∀y∀z[P(x, y) ∧ P(x, z) → P(y, z)] (Euclideanness) Note that

¬A3 := ∃x∃y∃z[P(x, y) ∧ P(x, z) ∧ ¬P(y, z)]

The clausal form of A1, A2, ¬A3 are

{{¬P(x, y), ¬P(y, z), P(x, z)}}

{{¬P(u, v), P(v, u)}} {{P(a, b)}, {P(a, c)}, {¬P(b, c)}}

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 63 / 82 Example We want to show that A1, A2 `R A3,

A1 := ∀x∀y∀z[P(x, y) ∧ P(y, z) → P(x, z)] (transitivity)

A2 := ∀x∀y[P(x, y) → P(y, x)] (symmetry)

A3 := ∀x∀y∀z[P(x, y) ∧ P(x, z) → P(y, z)] (Euclideanness) Note that

¬A3 := ∃x∃y∃z[P(x, y) ∧ P(x, z) ∧ ¬P(y, z)]

The clausal form of A1, A2, ¬A3 are

{{¬P(x, y), ¬P(y, z), P(x, z)}}

{{¬P(u, v), P(v, u)}} {{P(a, b)}, {P(a, c)}, {¬P(b, c)}}

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 63 / 82 Example We want to show that A1, A2 `R A3,

A1 := ∀x∀y∀z[P(x, y) ∧ P(y, z) → P(x, z)] (transitivity)

A2 := ∀x∀y[P(x, y) → P(y, x)] (symmetry)

A3 := ∀x∀y∀z[P(x, y) ∧ P(x, z) → P(y, z)] (Euclideanness) Note that

¬A3 := ∃x∃y∃z[P(x, y) ∧ P(x, z) ∧ ¬P(y, z)]

The clausal form of A1, A2, ¬A3 are

{{¬P(x, y), ¬P(y, z), P(x, z)}}

{{¬P(u, v), P(v, u)}} {{P(a, b)}, {P(a, c)}, {¬P(b, c)}}

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 63 / 82 Example

Resolution proof: 1 {¬P(x, y), ¬P(y, z), P(x, z)} 2 {¬P(u, v), P(v, u)} 3 {P(a, b)} 4 {P(a, c)} 5 {¬P(b, c)} 6 {P(b, a)} Res(2,3), {a/u, b/v} 7 {¬P(a, z), P(b, z)} Res(1,6), {b/x, a/y} 8 {¬P(a, c)} Res(5,7), {c/z} 9  Res(4,8)

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 64 / 82 Exercise

Using resolution prove that

father(y, x) ∧ male(x) → son(x, y), father(jim, tim), male(tim)

` son(tim, jim) I.e. show that the clause

S = {son(tim, jim)}

follows from the following clauses

1 C1 = {son(x, y), ¬father(y, x), ¬male(x)}.

2 C2 = {father(jim, tim)}.

3 C3 = {male(tim)}.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 65 / 82 Example 1 (Prover 9)

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 66 / 82 Example 2 (Prover 9)

` ∃x∀yp(x, y) → ∀y∃xp(x, y)

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 67 / 82 Example 3 (Prover 9)

6` ∀y∃xp(x, y) → ∃x∀yp(x, y)

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 68 / 82 Example 4 (Prover 9)

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 69 / 82 Other forms of resolution

Ground resolution Positive resolution Hyperresolution Semantic resolution Set-of-support resolution Unit resolution Input resolution Linear resolution SLD resolution ... Samuel R. Buss, An Introduction to Proof Theory, In Handbook of Proof Theory, Elsevier 1998

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 70 / 82 PROLOG Definition A T is a clause which contains at most one positive literal. A program clause P is a Horn clause which contains exactly one positive literal (PROLOG notation p : − p1,..., pn for C = {p, ¬p1,..., ¬pn}, read “to compute p (head), compute p1,..., pn (body)"). A rule is a program clause which contains some negative literals (i.e. p : − p1,..., pn with n > 0). A fact is a program clause which contains exactly one positive literal (i.e. p : − p1,..., pn with n = 0; PROLOG notation p.). A PROLOG program (or knowledge base or database) is a set of program clauses (rules or facts). A goal clause G is a Horn clause which contains no positive literals. (PROLOG notation ? − q1,..., qn for G = {¬q1,..., ¬qn}).

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 71 / 82 Logic Programming PROLOG Definition A Horn clause T is a clause which contains at most one positive literal. A program clause P is a Horn clause which contains exactly one positive literal (PROLOG notation p : − p1,..., pn for C = {p, ¬p1,..., ¬pn}, read “to compute p (head), compute p1,..., pn (body)"). A rule is a program clause which contains some negative literals (i.e. p : − p1,..., pn with n > 0). A fact is a program clause which contains exactly one positive literal (i.e. p : − p1,..., pn with n = 0; PROLOG notation p.). A PROLOG program (or knowledge base or database) is a set of program clauses (rules or facts). A goal clause G is a Horn clause which contains no positive literals. (PROLOG notation ? − q1,..., qn for G = {¬q1,..., ¬qn}).

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 71 / 82 Logic Programming PROLOG Definition A Horn clause T is a clause which contains at most one positive literal. A program clause P is a Horn clause which contains exactly one positive literal (PROLOG notation p : − p1,..., pn for C = {p, ¬p1,..., ¬pn}, read “to compute p (head), compute p1,..., pn (body)"). A rule is a program clause which contains some negative literals (i.e. p : − p1,..., pn with n > 0). A fact is a program clause which contains exactly one positive literal (i.e. p : − p1,..., pn with n = 0; PROLOG notation p.). A PROLOG program (or knowledge base or database) is a set of program clauses (rules or facts). A goal clause G is a Horn clause which contains no positive literals. (PROLOG notation ? − q1,..., qn for G = {¬q1,..., ¬qn}).

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 71 / 82 Logic Programming PROLOG Definition A Horn clause T is a clause which contains at most one positive literal. A program clause P is a Horn clause which contains exactly one positive literal (PROLOG notation p : − p1,..., pn for C = {p, ¬p1,..., ¬pn}, read “to compute p (head), compute p1,..., pn (body)"). A rule is a program clause which contains some negative literals (i.e. p : − p1,..., pn with n > 0). A fact is a program clause which contains exactly one positive literal (i.e. p : − p1,..., pn with n = 0; PROLOG notation p.). A PROLOG program (or knowledge base or database) is a set of program clauses (rules or facts). A goal clause G is a Horn clause which contains no positive literals. (PROLOG notation ? − q1,..., qn for G = {¬q1,..., ¬qn}).

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 71 / 82 Logic Programming PROLOG Definition A Horn clause T is a clause which contains at most one positive literal. A program clause P is a Horn clause which contains exactly one positive literal (PROLOG notation p : − p1,..., pn for C = {p, ¬p1,..., ¬pn}, read “to compute p (head), compute p1,..., pn (body)"). A rule is a program clause which contains some negative literals (i.e. p : − p1,..., pn with n > 0). A fact is a program clause which contains exactly one positive literal (i.e. p : − p1,..., pn with n = 0; PROLOG notation p.). A PROLOG program (or knowledge base or database) is a set of program clauses (rules or facts). A goal clause G is a Horn clause which contains no positive literals. (PROLOG notation ? − q1,..., qn for G = {¬q1,..., ¬qn}).

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 71 / 82 Logic Programming PROLOG Definition A Horn clause T is a clause which contains at most one positive literal. A program clause P is a Horn clause which contains exactly one positive literal (PROLOG notation p : − p1,..., pn for C = {p, ¬p1,..., ¬pn}, read “to compute p (head), compute p1,..., pn (body)"). A rule is a program clause which contains some negative literals (i.e. p : − p1,..., pn with n > 0). A fact is a program clause which contains exactly one positive literal (i.e. p : − p1,..., pn with n = 0; PROLOG notation p.). A PROLOG program (or knowledge base or database) is a set of program clauses (rules or facts). A goal clause G is a Horn clause which contains no positive literals. (PROLOG notation ? − q1,..., qn for G = {¬q1,..., ¬qn}).

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 71 / 82 Correct Answer Substitution

Definition

If P is a program and G = {¬q1,..., ¬qn} a goal clause, we say that the substitution θ is a correct answer substitution if P |= ∀(q1 ∧ ... ∧ qn)θ.

Theorem If P is a program and G = {¬R(~x)} a goal clause, P ∪ {G} is unsatisfiable iff P |= ∃~xR(~x) iff there are Herbrand terms ~t such that P |= R(~t) (i.e., there is a correct answer substitution).

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 72 / 82 Correct Answer Substitution

Definition

If P is a program and G = {¬q1,..., ¬qn} a goal clause, we say that the substitution θ is a correct answer substitution if P |= ∀(q1 ∧ ... ∧ qn)θ.

Theorem If P is a program and G = {¬R(~x)} a goal clause, P ∪ {G} is unsatisfiable iff P |= ∃~xR(~x) iff there are Herbrand terms ~t such that P |= R(~t) (i.e., there is a correct answer substitution).

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 72 / 82 Logic Programming PROLOG

"Programming in Logic" PROLOG are based on Horn clause logic. The general view of a PROLOG program is that we are given a PROLOG program P and wish to deduce consequences from them, or typically to know if the conjunction of some facts q1,..., qn follows from the program. We enter this as a question (query) ? − q1,..., qn at the PROLOG prompt.

PROLOG adds a goal clause G = {¬q1,..., ¬qn} to P and ask if P ∪ {G} of Horn clauses is unsatisfiable. If all attempts at finding a proof fail PROLOG answers “no". If a proof is found, PROLOG gives us an correct answer substitution. Theorem P ∪ {G} is unsatisfiable iff there is an SLD-resolution refutation of P ∪ {G}.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 73 / 82 Logic Programming PROLOG

"Programming in Logic" PROLOG are based on Horn clause logic. The general view of a PROLOG program is that we are given a PROLOG program P and wish to deduce consequences from them, or typically to know if the conjunction of some facts q1,..., qn follows from the program. We enter this as a question (query) ? − q1,..., qn at the PROLOG prompt.

PROLOG adds a goal clause G = {¬q1,..., ¬qn} to P and ask if P ∪ {G} of Horn clauses is unsatisfiable. If all attempts at finding a proof fail PROLOG answers “no". If a proof is found, PROLOG gives us an correct answer substitution. Theorem P ∪ {G} is unsatisfiable iff there is an SLD-resolution refutation of P ∪ {G}.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 73 / 82 Logic Programming PROLOG

"Programming in Logic" PROLOG are based on Horn clause logic. The general view of a PROLOG program is that we are given a PROLOG program P and wish to deduce consequences from them, or typically to know if the conjunction of some facts q1,..., qn follows from the program. We enter this as a question (query) ? − q1,..., qn at the PROLOG prompt.

PROLOG adds a goal clause G = {¬q1,..., ¬qn} to P and ask if P ∪ {G} of Horn clauses is unsatisfiable. If all attempts at finding a proof fail PROLOG answers “no". If a proof is found, PROLOG gives us an correct answer substitution. Theorem P ∪ {G} is unsatisfiable iff there is an SLD-resolution refutation of P ∪ {G}.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 73 / 82 SLD-resolution

Definition An SLD-resolution refutation of P ∪ {G} (as a set of ordered clauses) is a sequence < G0, C0 >, ..., < Gn, Cn > such that

G0 = G, Gn+1 = , each Gi is an ordered goal clause,

each Ci is an ordered program clause, and

for each i < n, the ordered clause Gi+1 is the resolvent of Gi and Ci (the topmost clause) by the following (sequence version) resolution: {¬q1,..., ¬qn}{p, ¬p1,..., ¬pm} {¬p1,..., ¬pm, ¬q2,..., ¬qn}

where the resolution rule resolve on the leftmost literal in Gi (i.e. p = q1).

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 74 / 82 G0 C0 |  G1 C1 |  . .

Gn Cn |  

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 75 / 82 Example

Consider the following program: p : −q, r. p : −s. q. r. Suppose G = {¬p}. An SLD-resolution refutation of P ∪ {G} is as follows:

{¬p}{p, ¬q, ¬r} {¬q, ¬r}{q} {¬r}{r} 

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 76 / 82 Meghdad Ghari (IPM) Resolution Logic Short Course 2017 77 / 82 Meghdad Ghari (IPM) Resolution Logic Short Course 2017 78 / 82 Meghdad Ghari (IPM) Resolution Logic Short Course 2017 79 / 82 References

M. Fitting, First-Order Logic and Automated Theorem Proving, Springer, 1996. J. H. Gallier, Logic for Computer Science Foundations of Automatic Theorem Proving, John Wiley, 1987.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 80 / 82 References

M. Ben Ari, for Computer Science, Springer, 2012. S. J. Russell and P. Norvig, Artificial Intelligence, A Modern Approach, Prentice Hall, 2010.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 81 / 82 References

A. Nerode and R. Shore, Logic for Applications, Springer, 1997.

Meghdad Ghari (IPM) Resolution Logic Short Course 2017 82 / 82