Skip to main content

Lecture 6: Unification and Lifting

Laura Kovács

First-Order Logic: Exercises

Which of the following statements are true?

  1. First-order logic is an extension of propositional logic.
  2. First-order logic is NP-complete.
  3. In first-order logic you can use quantifiers over sets.
  4. First-order logic is decidable.
  5. One can axiomatise naturals in first-order logic.
  6. Having proofs is good.

Substitution

  • A substitution θ\theta is a mapping from variables to terms such that the set {xθ(x)x}\{x \mid \theta(x) \neq x\} is finite.
  • This set is the domain of θ\theta.
  • Notation: {x1t1,,xntn}\{\,x_1 \mapsto t_1,\ldots,x_n \mapsto t_n\,\}, where x1,,xnx_1,\ldots,x_n are pairwise different variables, denotes the substitution θ\theta with θ(x)={tiif x=xi,xif x{x1,,xn}.\theta(x) = \begin{cases} t_i & \text{if } x = x_i,\\ x & \text{if } x \notin \{x_1,\ldots,x_n\}. \end{cases}
  • Applying a substitution θ\theta to an expression EE means replacing each xix_i by tit_i simultaneously; we denote the result by EθE\theta.
  • Substitutions are functions, so we can compose them. We write στ\sigma\tau (rather than τσ\tau \circ \sigma), and we always have E(στ)=(Eσ)τE(\sigma\tau) = (E\sigma)\tau.

Example

Consider the expression E=p(x,y,f(a))E = p(x,y,f(a)) and the substitution θ={xb,  yx}\theta = \{x \mapsto b,\; y \mapsto x\}.
What is EθE\theta?

Substitution Composition

Suppose we have two substitutions

θ1={x1s1,,xmsm},θ2={y1t1,,yntn}.\begin{aligned} \theta_1 &= \{x_1 \mapsto s_1,\ldots,x_m \mapsto s_m\},\\ \theta_2 &= \{y_1 \mapsto t_1,\ldots,y_n \mapsto t_n\}. \end{aligned}

How can we compute their composition θ1θ2\theta_1\theta_2?

The substitution θ1θ2\theta_1\theta_2 is obtained from

{x1s1θ2,,xmsmθ2,  y1t1,,yntn}\{x_1 \mapsto s_1\theta_2,\ldots,x_m \mapsto s_m\theta_2,\; y_1 \mapsto t_1,\ldots,y_n \mapsto t_n\}

by deleting

  1. all yitiy_i \mapsto t_i such that yi{x1,,xm}y_i \in \{x_1,\ldots,x_m\};
  2. all xisiθ2x_i \mapsto s_i\theta_2 such that xi=siθ2x_i = s_i\theta_2.

The remaining bindings constitute θ1θ2\theta_1\theta_2.

Example

Let

θ1={xf(y),  yz},θ2={xa,  yb,  zy}.\theta_1 = \{x \mapsto f(y),\; y \mapsto z\}, \qquad \theta_2 = \{x \mapsto a,\; y \mapsto b,\; z \mapsto y\}.

What is θ1θ2\theta_1\theta_2?

Instances and Ground Instances

An instance of an expression EE (term, atom, literal, or clause) is obtained by applying a substitution to EE.

  • Some instances of the term f(x,a,g(x))f(x,a,g(x)) are f(x,a,g(x))f(x,a,g(x)), f(y,a,g(y))f(y,a,g(y)), f(a,a,g(a))f(a,a,g(a)), and f(g(b),a,g(g(b)))f(g(b),a,g(g(b))).
  • The term f(b,a,g(c))f(b,a,g(c)) is not an instance of f(x,a,g(x))f(x,a,g(x)).
  • A ground instance is an instance that contains no variables.

Herbrand's Theorem

For a set of clauses SS, let SS^* denote the set of ground instances of clauses in SS.

Theorem. Let Σ\Sigma be a signature with at least one constant symbol and let SS be a set of universal clauses over Σ\Sigma. The following are equivalent:

  1. SS is unsatisfiable.
  2. SS^* is unsatisfiable.

By compactness of first-order logic, this is equivalent to:

  1. There exists a finite unsatisfiable set of ground instances of clauses in SS.

Thus the theorem reduces checking unsatisfiability of arbitrary clause sets to checking unsatisfiability of sets of ground clauses, even though SS^* can be infinite.

Lifting

Lifting is a technique for proving completeness theorems:

  1. Prove completeness of the inference system for sets of ground clauses.
  2. Lift the proof to the non-ground case.

Lifting Example

Consider the non-ground clauses p(x,a)q1(x)p(x,a) \lor q_1(x) and ¬p(y,z)q2(y,z)\neg p(y,z) \lor q_2(y,z). When the signature contains function symbols, both clauses have infinitely many ground instances:

{p(r,a)q1(r)r is ground},{¬p(s,t)q2(s,t)s,t are ground}.\{\,p(r,a) \lor q_1(r) \mid r \text{ is ground}\,\}, \qquad \{\,\neg p(s,t) \lor q_2(s,t) \mid s,t \text{ are ground}\,\}.

We can resolve ground instances iff r=sr=s and t=at=a, yielding inferences such as

p(s,a)q1(s)¬p(s,a)q2(s,a)q1(s)q2(s,a)(BR),\frac{p(s,a) \lor q_1(s) \qquad \neg p(s,a) \lor q_2(s,a)}{q_1(s) \lor q_2(s,a)}(\text{BR}),

but there are infinitely many such inferences.

Lifting Idea

Represent an infinite number of ground inferences of the form:

p(s,a)q1(s)¬p(s,a)q2(s,a)q1(s)q2(s,a)(BR),\frac{p(s,a) \lor q_1(s) \qquad \neg p(s,a) \lor q_2(s,a)}{q_1(s) \lor q_2(s,a)}(\text{BR}),

with a single non-ground inference:

p(x,a)q1(x)¬p(y,z)q2(y,z)q1(y)q2(y,a)(BR).\frac{p(x,a) \lor q_1(x) \qquad \neg p(y,z) \lor q_2(y,z)}{q_1(y) \lor q_2(y,a)}(\text{BR}). Is this always possible?

Yes!

For the inference

p(x,a)q1(x)¬p(y,z)q2(y,z)q1(y)q2(y,a)(BR),\frac{p(x,a) \lor q_1(x) \qquad \neg p(y,z) \lor q_2(y,z)}{q_1(y) \lor q_2(y,a)}(\text{BR}),

the substitution {xy,  za}\{x \mapsto y,\; z \mapsto a\} solves the “equation” p(x,a)=p(y,z)p(x,a) = p(y,z), so the lifted inference represents all its ground instances.

Lifting Lemma for BR\mathbb{BR} (Robinson 1965)

Idea. Represent infinitely many ground inferences by a single non-ground inference.

For binary resolution BR\mathbb{BR} with selection:

  • Work with non-ground clauses.
  • Generalize the notion of “same” ground atoms to unifiability of non-ground atoms.
  • Compute most general unifiers (mgu) only.

Lifting Lemma. Let CC and DD be clauses that share no variables. If a ground binary resolution inference

Cσ1Dσ2C(ground BR)\frac{C\sigma_1 \qquad D\sigma_2}{C'}(\text{ground BR})

exists, then there is a substitution σ\sigma such that a non-ground inference

CDC(BR)\frac{C \qquad D}{C''}(\text{BR})

and C=CσC' = C''\sigma.

Similar lifting lemmas exist for each inference of BR\mathbb{BR} and of the superposition system Sup\mathbb{S}\mathrm{up}.

What Should We Lift?

  • The ordering \succ.
  • The selection function σ\sigma.
  • The calculus Supsat\mathbb{S}\mathrm{up}^{\mathrm{sat}}.

Most importantly, lifting requires solving equations s=ts = t between terms and between atoms, which we do using most general unifiers.

Unifier

A unifier of expressions s1s_1 and s2s_2 is a substitution θ\theta with s1θ=s2θs_1\theta = s_2\theta.
Equivalently, it is a solution of the “equation” s1=s2s_1 = s_2. For systems of equations s1=s1,,sn=sns_1 = s'_1,\ldots,s_n = s'_n, a substitution that satisfies all equations simultaneously is a simultaneous unifier.

Most General Unifiers

A solution θ\theta to a set of equations EE is most general if, for every other solution σ\sigma, there exists a substitution τ\tau with θτ=σ\theta\tau = \sigma. In a similar way, we can define a most general unifier.

Consider the terms f(x1,g(x1),x2)f(x_1,g(x_1),x_2) and f(y1,y2,y2)f(y_1,y_2,y_2). Two unifiers are

θ1={y1x1,  y2g(x1),  x2g(x1)},θ2={y1a,  y2g(a),  x2g(a),  x1a}.\theta_1 = \{y_1 \mapsto x_1,\; y_2 \mapsto g(x_1),\; x_2 \mapsto g(x_1)\}, \qquad \theta_2 = \{y_1 \mapsto a,\; y_2 \mapsto g(a),\; x_2 \mapsto g(a),\; x_1 \mapsto a\}.

Both substitutions make the terms equal, but only θ1\theta_1 is an mgu; θ2\theta_2 is obtained from it by instantiating x1x_1 with aa.

Unification Algorithm

Let EE be a set of equations. An isolated equation in EE is any equation x=tx = t in EE such that xx has exactly one occurrence in EE.

Input. A finite set of equations EE (here s,ts,t denote terms, c,dc,d constants, f,gf,g function symbols, and xx a variable).

Output. A solution to EE or failure.

  1. While there exists a non-isolated equation (s=t)E(s = t) \in E:
    • Consider the pair (s,t)(s,t).
      • (t,t)(t,t) \Rightarrow remove this equation from EE.
      • (x,t)(x,t) \Rightarrow
        • if xx occurs in tt, halt with failure;
        • otherwise, replace every other occurrence of xx in EE by tt.
      • (t,x)(t,x) \Rightarrow replace this equation by x=tx = t and proceed as in (x,t)(x,t).
      • (c,d)(c,d) \Rightarrow halt with failure.
      • (c,f(t1,,tn))(c,f(t_1,\ldots,t_n)) \Rightarrow halt with failure.
      • (f(t1,,tn),c)(f(t_1,\ldots,t_n),c) \Rightarrow halt with failure.
      • (f(s1,,sm),g(t1,,tn))(f(s_1,\ldots,s_m),g(t_1,\ldots,t_n)) with fgf \neq g \Rightarrow halt with failure.
      • (f(s1,,sn),f(t1,,tn))(f(s_1,\ldots,s_n),f(t_1,\ldots,t_n)) \Rightarrow replace this equation by the set {s1=t1,,sn=tn}\{\,s_1 = t_1,\ldots,s_n = t_n\,\}.
  2. Once E={x1=r1,,x=r}E = \{x_1 = r_1,\ldots,x_\ell = r_\ell\} and every equation in it is isolated, return the substitution {x1r1,,xr}\{\,x_1 \mapsto r_1,\ldots,x_\ell \mapsto r_\ell\,\}.

Examples

Try running the algorithm on:

  • {h(g(f(x),a))=h(g(y,y))}\{\,h\big(g(f(x),a)\big) = h\big(g(y,y)\big)\,\}
  • {h(f(y),y,f(z))=h(z,f(x),x)}\{\,h(f(y),y,f(z)) = h(z,f(x),x)\,\}
  • {h(g(f(x),z))=h(g(y,y))}\{\,h\big(g(f(x),z)\big) = h\big(g(y,y)\big)\,\}

Properties

Theorem. Suppose we run the algorithm on s=ts = t.

  • If ss and tt are unifiable, the algorithm terminates and outputs a most general unifier of ss and tt.
  • If ss and tt are not unifiable, the algorithm terminates with failure.

We often write mgu(s,t)\operatorname{mgu}(s,t) for a most general unifier and mgs(E)\operatorname{mgs}(E) for a most general solution of the equation set EE.

Exercise

Consider the trivial systems of equations \varnothing and {a=a}\{a = a\}.

  • What is the set of all solutions?
  • What is the set of most general solutions?

Revisiting the Ingredients of Lifting

  • Lift the ordering \succ.
  • Lift the selection function σ\sigma.
  • Lift the calculus Supsat\mathbb{S}\mathrm{up}^{\mathrm{sat}} (thanks to the lifting lemmas).

Most importantly, lifting works because we use most general unifiers.