Lecture 13: Abstract Logic Programming

Abstract Logic Programming: Proof theory formulations (corresponds to chapter 5 in Dave Miller’s lecture notes)

Theory – Design – Examples/Applications – Implementation

Most of the theorems we’re about to see are here to justify the design aspect

Main theorems:

  • Cut-elimination (to prove consistency, etc…)
  • Completeness of

    • uniform proofs
    • focusal proofs

    for first-order vs. higher-order logic


\underbrace{P}_{\text{theory or assumption}} \overset{?}{⊢} \quad G

where

  • $P$ stands for Program/Database with rules
  • $G$ stands for Goal/Query

Prolog example:

z: nat
s: nat -> nat
plus: nat -> nat -> o
plus z N N
plus (s N) M (s P) :- plus N M P

Capital letters (N, M, …) means it’s implicitely universally quantified.

Translation:

∀ x, \quad plus \; z \; z \; x\\ ∀ n, m, p. \quad plus \; n \; m \; p ⇒ plus \; (s \, n) \; m \; (s \, p)

so that

plus \; n_1 \; n_2 \; n_3 \quad \text{ iff } \quad \overline{n_1} + \overline{n_2} = \overline{n_3}

Types of questions you can ask:

P ⊢ plus \; (s z) \; (s z) \; (s (s z))\\ P \overset{?}{⊢} ∃ x \; (plus \; (s z) \; (s z) \; x)\\ P \overset{?}{⊢} ∃ x, y \; (plus \; x \; y \; (s (s z)))\\ \vdots

Graphs:

  digraph {
    rankdir=LR;
    a -> b -> a;
    b -> c;
    d;
  }
adj a b.
adj b a.
adj b c.
path x y :- adj x y.
path x y :- adj x z, path z y.

⟹ Brute-force search when it comes to answering, for instance, if there exists a path from $x$ to $y$

Logical connectives: $∀, ⇒, ∧, ∃, ∨, …$ Non-logical symbols: adj, path, plus: nat -> nat -> o, ...

In $P ⊢ G$:

When there’s a toplevel logical connective in $G$, then $P$ is not relevant.

⟹ Fixed meaning of goal connective is right introduction rule

P ⊢ G_1 ∧ G_2 \quad \text{ if } \quad P ⊢ G_1 \text{ and } P ⊢ G_2\\ P ⊢ G_1 ∨ G_2 \quad \text{ if } \quad P ⊢ G_1 \text{ or } P ⊢ G_2\\ P ⊢ D ⇒ G \quad \text{ if } \quad P, D ⊢ G\\ \text{ if } Σ: P ⊢ ∀ x_τ. G(x) \text{ then } Σ : P, \underbrace{y: τ}_{\text{eigenvariable: it must be "fresh"}}: P ⊢ G(y)\\ \text{ if } Σ: P ⊢ ∃ x_τ. G(x) \text{ then there exists a } Σ \text{-term } t \text{ of type } τ \text{ st } Σ: P ⊢ G(t)\\

NB: the proof ought to be constructive. Recall the example (r \, a ∧ r \, b ⇒ q) ⊢_C ∃ x. \; (r \, x ⇒ q)

But completeness holds for some fragment of linear logic as well.

Uniform proofs

A sequent calculus $I$-proof $Ξ$ is uniform:

if every sequent in $Ξ$ that has a non-atomic rhs is the conclusion of a right introduction rule.

In other words, as soon as $G$ is not atomic in

Σ: P ⊢ G

we know which introduction rule must be applied (if you can do a right rule, you must do it).

Uniform proofs are not complete: p ∨ q ⊢ q ∨ p is not provable with a unfiform proof.


Atomic goals (atoms) are treated with backchaining.

Horn Clauses (Pre-logic)

Clause/Resolution refutation:

of the form ∀ x_1, …, x_n \; [ ¬ A_1 ∨ ⋯ ∨ ¬ A_n ∨ B_1 ∨ ⋯ ∨ B_m ] where the $A_i$’s and $B_i$’s are atoms

Horn clause:

a clause ∀ x_1, …, x_n \; [ ¬ A_1 ∨ ⋯ ∨ ¬ A_n ∨ B_1 ∨ ⋯ ∨ B_m ] where $m ≤ 1$

NB: they’re related to some sort of “pre-logic”, because it’s independent of intuitionistic or linear logic.

Three different definitions of Horn clauses:

  • Def 1:

    G \; ≝ \; A \; \mid \; G_1 ∧ G_2\\ D \; ≝ \; A \; \mid \; G ⇒ A \; \mid \; ∀x. D

    $G$-formulas (on the rhs of the sequent) are conjunctions, and $D$-formulas (on the lhs) are Horn clauses ($A_1 ∧ ⋯ ∧ A_n ⇒ B$).

  • Def 2:

    G \; ≝ \; ⊤ \; \mid \; A \; \mid \; G ∧ G \; \mid \; G ∨ G \; \mid \; ∃ x \; G\\ D \; ≝ \; A \; \mid \; G ⇒ D \; \mid \; D ∧ D \; \mid \; ∀ x \; D
  • Def 3:

    G \; ≝ \; A\\ D \; ≝ \; A \; \mid \; A ⇒ D \; \mid \; ∀ x \; D

A formula in the style of def 2 is equivalent to a set of formulas in the style of def 1 or def 3 (similar to CNF form):

G_1 ⇒ (G_2 ⇒ D) \quad ≡ \quad (G_1 ∧ G_2) ⇒ D\\ (G_1 ⇒ D) ∧ (G_2 ⇒ D) \quad ≡ \quad (G_1 ∨ G_2) ⇒ D\\ ∀x \; (G(x) ⇒ D) \quad ≡ \quad (∃ x \; G (x)) ⇒ D \qquad \text{(holds intuitionistically)}

But: this tranformation (from 2 to 1 or 3) is exponential (cf. the middle case).

order(G) = 0\\ order(D) = 0 \text{ or } 1

From now on, we’ll use the second definition.

Prop (5.6): Let $𝒫$ be a set of Horn clauses and let $𝒢$ be a set of goal formulas.

If

Σ: 𝒫 ⊢_C 𝒢

then there is a $G ∈ 𝒢$ such that Σ: 𝒫 ⊢_I G

Proof: By induction on the height of $C$-proof of $Σ: 𝒫 ⊢ 𝒢$.

  • height $= 1$: for initial and $⊤$-right rule: trivial, just pick the relevant formula ($A$ for initial, $⊤$ for $⊤$-right) on the right.

  • height $> 1$:

    \cfrac{𝒫_1 ⊢ G, Δ_1 \qquad 𝒫_2, D ⊢ Δ_2}{G ⇒ D, 𝒫_1, 𝒫_2 ⊢ Δ_1, Δ_2}⇒ \text{-L}

    By IH, there exist

    H_1 ∈ \lbrace G \rbrace ∪ Δ_1 \qquad H_2 ∈ Δ_2

    st

    𝒫_i ⊢_I H_i \qquad i=1, 2
    • If $H_1 ∈ Δ_1$, then pick it: G ⇒ D, 𝒫_1, 𝒫_2 ⊢_I H_1 is provable

    • If $H_1 = G$, then $𝒫_1 ⊢_I G$ and $𝒫_2, D ⊢_I H_2$, so:

    \cfrac{𝒫_1 ⊢_I G \qquad 𝒫_2, D ⊢_I H_2}{G ⇒ D, 𝒫_1, 𝒫_2 ⊢_I H_2}⇒ \text{-R}

NB: the only reason Horn clauses are relevant is because it throws away the problematic cases, such as:

\cfrac{B_1, 𝒫 ⊢_C 𝒢 \ni B_1 \qquad B_2, 𝒫 ⊢_C 𝒢 \ni B_2}{B_1 ∨ B_2, 𝒫 ⊢_C 𝒢 \ni B_1, B_2}

Horn clauses are consistent: it’s impossible to prove $𝒫 ⊢_C$, since there’s no element in the empty set.

Hereditary Harrop formulas

  • Def 1:

    G \; ≝ \; A \; \mid \; G_1 ∧ G_2 \; \mid \; D ⇒ G \; \mid \; ∀ x \; G\\ D \; ≝ \; A \; \mid \; G ⇒ A \; \mid \; ∀x. D

    $G$-formulas (on the rhs of the sequent) are conjunctions, and $D$-formulas (on the lhs) are Horn clauses ($A_1 ∧ ⋯ ∧ A_n ⇒ B$).

  • Def 2:

    G \; ≝ \; ⊤ \; \mid \; A \; \mid \; G ∧ G \; \mid \; G ∨ G \; \mid \; ∃ x \; G \; \mid \; D ⇒ G \; \mid \; ∀ x \; G\\ D \; ≝ \; A \; \mid \; G ⇒ D \; \mid \; D ∧ D \; \mid \; ∀ x \; D
  • Def 3:

    G \; ≝ \; A \; \mid \; D ⇒ G \; \mid \; ∀ x \; G \; \mid \; G ∧ G\\ D \; ≝ \; A \; \mid \; G ⇒ D \; \mid \; ∀ x \; D \; \mid \; D ∧ D

Even with that restricited logic, uniform proofs are not complete. Example, Pierce formula:

((p ⇒ q) ⇒ p) ⇒ p

(or even $p ∨ (p ⇒ q)$) is classically provable but not uniformly.

So

⊢_C G \text{ provable } \quad \not ⟹ \quad ⊢ G \quad \text{ has a uniform proof}

But we do have

⊢_I G \text{ provable } \quad ⟹ \quad ⊢ G \text{ has a uniform proof}

NB: $order (G)$ and $order (D)$ are not bounded.

The only difference with the comprehensive system is that you dont allow yourself to use $∃$ or $∨$

Higher-order versions (in Prolog) of $∨$ and $∃$:

or P Q :- P
or P Q :- Q
B: i -> o
T: i
exists B :- B T

Abstract Logic Programming

Abstract Logic Programming Language is a triple $⟨𝒟, 𝒢, ⊢⟩$ such that

∀ 𝒫 ⊆ 𝒟, ∀ G ∈ 𝒢, \\ 𝒫 ⊢ G \quad ⟹ \quad \text{ the sequent } 𝒫 ⊢ 𝒢 \text{ has a uniform proof}
  • Let $𝒟_1 ⊢ 𝒢_1$ be Horn clauses.

    ⟨𝒟_1, 𝒢_1, ⊢_C⟩ \text{ and } ⟨𝒟_1, 𝒢_1, ⊢_I⟩ \text{ are ALPL}
  • Let $𝒟_2 ⊢ 𝒢_2$ be hereditary Harrop formulas. Then

    ⟨𝒟_2, 𝒢_2, ⊢_C⟩ \text{ is not an ALPL}\\ ⟨𝒟_1, 𝒢_1, ⊢_I⟩ \text{ is an ALPL}

Prop: Let $G$ be non-atomic. Assume $𝒫 ⊢ G$ has an $I$-proof in which the last rule is not a right introduction and the premises have uniform proofs.

For example, if

\cfrac{\overset{Ξ_1}{𝒫_1 ⊢ G} \qquad \cfrac{\overset{Ξ_2}{𝒫_2, D ⊢ G_1} \qquad \overset{Ξ_3}{𝒫_2, D ⊢ G_2}}{𝒫_2, D ⊢ G_1 ∧ G_2} } {G ⇒ D, 𝒫_1, 𝒫_2 ⊢ G_1 ∧ G_2}

is turned into

\infer[∧R]{G ⇒ D, 𝒫_1, 𝒫_2 ⊢ G_1 ∧ G_2}{ \infer{G ⇒ D, 𝒫_1, 𝒫_2 ⊢ G_1}{ \infer{𝒫_1 ⊢ G}{ Ξ_1 } & \infer{𝒫_2, D ⊢ G_1}{ Ξ_2 } } & \infer{G ⇒ D, 𝒫_1, 𝒫_2 ⊢ G_2}{ \infer{𝒫_1 ⊢ G}{ Ξ_1 } & \infer{𝒫_2, D ⊢ G_2}{ Ξ_3 } } }

But the $G_i$ may not be atomic, in which case: apply the process recursively on the premise proofs.


Harrop formulas:
D \; ≝ \; A \; \mid \; \underbrace{B}_{\text{arbitrary}} ⇒ D \; \mid \; ∀ x \; D \; \mid \; D ∧ D

Witness property: you don’t always keep Harrop formulas (cf. picture).

Focusing: Backchaining

Search mechanism: $⊢_o$ proofs

Define $⊢_o$ ($o$ stands for operational).

Take the usual Right Intro Rules, take the backchaining rules (cf. picture)

Thm: If $𝒫 ⊆ 𝒟_2, G ∈ 𝒢_2$

𝒫 ⊢_I G \quad \text{ iff } \quad 𝒫 ⊢_o G \text{ for hereditary Harrop formulas}

NB: Forward chaining is not used in proof search

Example: Let’s consider natural numbers $0, 1, …$ and $+$ (they can be formally defined as we did earlier).

D_0: fib 0 0
D_1: fib 1 1
D_2: fib N F :- fib (N-2) F1, fib (N-1) F2, plus F1 F2 F

How would we prove

𝒫 ⊢ fib \; 12 \; 144

?

\infer{𝒫 ⊢ fib \; 12 \; 144}{ \infer{𝒫 ⇓ D_2 ⊢ fib \; 12 \; 144}{ \infer{𝒫 ⇓ (fib \; 10 \; 55 ∧ fib \; 11 \; 89 ∧ plus \; 55 \; 89 \; 144) ⇒ fib \; 12 \; 144 ⊢ fib \; 12 \; 144}{ \infer{𝒫 ⊢ fib \; 10 \; 55 ∧ fib \; 11 \; 89 ∧ plus \; 55 \; 89 \; 144}{ \infer{𝒫 ⊢ fib \; 10 \; 55}{\vdots} & \infer{𝒫 ⊢ fib \; 11 \; 89}{\vdots} & \infer{𝒫 ⊢ plus \; 55 \; 89 \; 144}{} } & \infer{𝒫 ⇓ fib \; 12 \; 144 ⊢ fib \; 12 \; 144}{} } } }

But it’s terribly inefficient of course (exponential) ⟹ resort to forward-chaining to “emulate” the classic memoization solution for this problem.

Dynamics of proof search (using $⇓ ⊢$)

If you have, in $⊢_o$:

\cfrac{Ξ \ni Σ': 𝒫' ⊢ G', Σ': 𝒫' ⇓ D ⊢ G'}{Σ: 𝒫 ⊢ G}

how do $𝒫, Σ$ and $𝒫’, Σ’$ relate?

  • In Horn clauses: $𝒫 = 𝒫’, Σ = Σ’$
  • In hereditary Harrop formulas: $𝒫 ⊆ 𝒫’, Σ ⊆ Σ’$:

    \cfrac{𝒫, D ⊢ G}{𝒫 ⊢ D ⇒ G}

Leave a comment