Foundations of AI
9. Predicate Logic
Syntax and Semantics, Normal Forms, Herbrand Expansion, Resolution
Wolfram Burgard & Luc De Raedt & Bernhard Nebel
Contents
• Motivation
• Syntax and Semantics
• Normal Forms
• Reduction to Propositional Logic:
Herbrand Expansion
• Resolution & Unification
• Closing Remarks
Motivation
We can already do a lot with propositional logic. It is,
however, annoying that there is no structure in the atomic propositions.
Example:
“All blocks are red”
“There is a block A”
It should follow that “A is red”
But propositional logic cannot handle this.
Idea: We introduce individual variables, predicates, functions, … .
First-Order Predicate Logic (PL1)
The Alphabet of First-Order Predicate Logic
Symbols:
• Operators: ¬, -, ., ∀, ∃, =
• Variables: x,x1,x2,…,x’,x’’,…,y,…,z,…
• Brackets: ( ) [ ] { }
• Function symbols (e.g. weight( ), color( ))
• Predicate symbols (e.g. block( ), red( ))
• Predicate and function symbols have an arity (number of arguments).
0-ary predicate: propositional logic atoms 0-ary function: constant
• We suppose a countable set of predicates and functions of any arity.
• “=“ is usually not considered a predicate, but a logical symbol
The Grammar of First-Order Predicate Logic (1)
Terms (represent objects):
1. Every variable is a term.
2. If t1,t2,…,tn are terms and f is an n-ary function, then f f
f f (t1,t2,…,tn) is also a term.
Terms without variables: ground terms.
Atomic Formulae (represent statements about objects) 1. If t1,t2,…,tn are terms and P is an n-ary predicate, then
P(t1,t2,…,tn) is an atomic formula.
2. If t1 and t2 are terms, then t1 = t2 is an atomic formula.
Atomic formulae without variables: ground atoms.
The Grammar of First-Order Predicate Logic (2)
Formulae:
1. Every atomic formula is a formula.
2. If ϕ and ψ are formulae and x is a variable, then
¬ϕ , ϕ . ψ , ϕ - ψ , ϕ ⇒ ψ , ϕ⇔ψ , ∃ x ϕ and ∀ x ϕ are also formulae.
∀ , ∃ are as strongly binding as ¬ .
Propositional logic is part of the PL1 language:
1. Atomic formulae: only 0-ary predicates
2. Neither variables nor quantifiers.
Alternative Notation
~ ϕ ϕ
ϕ & ψ ϕ • ψ ϕ , ψ ϕ | ψ ϕ ; ψ ϕ + ψ ϕ→ψ ϕ q ψ ϕ↔ψ ϕ≡ψ ( ∀ x ) ϕ . x ϕ ( ∃ x ) ϕ - x ϕ
¬ϕ ϕ . ψ ϕ - ψ ϕ ⇒ ψ ϕ⇔ψ
∀ x ϕ
∃ x ϕ
Elsewhere Here
–
Meaning of PL1-Formulae
Our example: ∀x[Block(x)⇒Red(x)],Block(a)
For all objects x: If x is a block, then x is red and a is a block.
Generally:
• Terms are interpreted as objects.
• Universally-quantified variables denote all objects in the universe.
• Existentially-quantified variables represent one of the objects in the universe (made true by the quantified expression).
• Predicates represent subsets of the universe.
Similar to propositional logic, we define interpretations, satisfiability, models, validity, …
9
Semantics of PL1-Logic
Interpretation: I = …D,
•I where D is an arbitrary, non- empty set and
•Iis a function that
• maps n-ary function symbols to functions over D:
f
I∈ [D
nD]
• maps individual constants to elements of D:
a
I∈ D
• maps n-ary predicate symbols to relations over D:
P
I` D
nInterpretation of ground terms:
(f f f f (t
1,…,t
n))
I= f f f f
I(t
1 I,…,t
n I) Satisfaction of ground atoms P(t
1,…,t
n):
I Ñ P(t
1,…,t
n) iff …t
1 I,…,t
n I ∈ P
IExample (1)
Block(b) U
U U I U
Red(b) Ñ
Ñ Ñ I Ñ
D
= Red
I{d
1}
= Block
I…
= c
Id
2= b
Id
1= a
I{d
1,…,d
n| n > 1}
=
D
Example 2
Even(succ(2)) U
U U I U
Even(2) Ñ
Ñ Ñ I Ñ
{( 1 2 ),( 2 3 ), …}
= succ
I{ 2, 4, 6, …}
= Even
I§
§
§
§
= 2 2
I= 1 1
I{ 1, 2, 3 , …}
=
D
Semantics of PL1:
Variable Assignment
Set of all variables V. Function α: VD
Notation: α[x/d] is the same as α up to point x. For x : α[x/d](x) = d.
Interpretation of terms under I, α:
f f
f f
I(t
1 I,α,…,t
n I,α) (f f f f (t
1,…,t
n))
I,α=
a
Ia
I,α=
α (x ) x
I,α=
Satisfiability of atomic formulae:
I , α Ñ Ñ Ñ Ñ P(t
1,…,t
n) iff …t
1 I,α,…,t
n I,α ∈ P
IExample
Block(y) Ñ
Ñ Ñ I , α[ y/d
1] Ñ
Red(x) Ñ
Ñ Ñ I , α Ñ
{(x d
1),(y d
2)}
α =
Semantics of PL1:
Satisfiability
A formula ϕ is satisfied by an interpretation I and a variable assignment α , i.e. I , α Ñ Ñ Ñ Ñ ϕ :
I , α Ñ Ñ Ñ Ñ T I , α U U U U z
I , α Ñ Ñ Ñ Ñ ¬ ¬ϕ ¬ ¬ iff I , α U U U U ϕ
…
and all other propositional rules as well as
there exists a d ∈ D with I , α[ x/d] Ñ Ñ Ñ Ñ ϕ I , α Ñ Ñ Ñ Ñ ∃ x ϕ iff
for all d ∈ D, I , α[ x/d] Ñ Ñ Ñ Ñ ϕ I , α Ñ Ñ Ñ Ñ ∀ x ϕ iff
…t
1 I,α,…,t
n I,α ∈ P
Iiff
I , α Ñ Ñ Ñ Ñ P(t
1,…,t
n)
Example
{(x x d1), (y x d2)}
α ====
D
= RedI
{d1}
= BlockI
d2
= bI
d1
= aI
{d1,…,dn | n > 1}
= D
Block(a), Block(b)
∀x (Block(x) ⇒ Red(x))
=
Questions:
1. I,α ÑÑÑÑBlock(b) - ¬Block(b)?
2. I,α ÑÑÑÑ Block(x) ⇒ (Block(x) - ¬Block(y))?
3. I,α ÑÑÑÑ Block(a) . Block(b)?
4. I,α ÑÑÑÑ ∀x (Block(x) ⇒ Red(x))?
5. I,α ÑÑÑÑ ?
{ }
Free and Bound Variables
∀x[R( y , z ) . ∃y{¬P(y,x) - R(y, z )}]
Boxed appearances of y and z are free. All other appearances of x,y,z are bound.
Formulae with no free variables are called closed formulae or sentences. We form theories from closed formulae.
Note: With closed formulae, the concepts logical equivalence,
satisfiability, and implication, etc. are not dependent on the variable assignment α (i.e. we can always ignore all variable assignments).
With closed formulae, α can be left out on the left side of the model relationship symbol:
I Ñ Ñ Ñ Ñ ϕ
Terminology
An interpretation I is called a model of
ϕunder
αif
I,
α ÑÑÑÑ ϕA PL1 formula
ϕcan, as in propositional logic, be
satisfiable, unsatisfiable, falsifiable, or valid.Analogously, two formulae are logically equivalent (
ϕ≡ψ), if for all I ,α :
I
,
α ÑÑÑÑ ϕiff I ,
α ÑÑÑÑ ψ Note: P(x) ≡P(y)!
Logical Implication
is also analogous to propositional logic.
Question: How can we define derivation?
/
Prenex Normal Form
Because of the quantifiers, we cannot produce the CNF form of a formula directly.
First step: Produce the prenex normal form
quantifier prefix + (quantifier-free) Matrix ϕ :
∀ x
1∀ x
2∀ x3 … ∀ x
nϕ
Equivalences for the
Production of Prenex-Normal Form
∃x (ϕ - ψ) if x not free in ψ (∃xϕ) - ψ h
∃x (ϕ . ψ) if x not free in ψ (∃xϕ) . ψ h
∀x (ϕ - ψ) if x not free in ψ (∀xϕ) - ψ h
∀x¬ϕ
¬∃xϕ h
∃x¬ϕ
¬∀xϕ h
∃x (ϕ - ψ)
∃xϕ - ∃xψ h
∀x (ϕ . ψ)
∀xϕ . ∀xψ h
∀x (ϕ . ψ) if x not free in ψ (∀xϕ) . ψ h
… and propositional logic equivalents
Production of Prenex Normal Form
1. Eliminate ⇒ and ⇔ 2. Move ¬ inwards
3. Move quantifiers outwards Example:
¬∀x[(∀x P(x)) ⇒ Q(x)]
¬∀x[¬(∀x P(x)) - Q(x)]
∃x [(∀x P(x)) . ¬Q(x)]
and now? Solution: Renaming of variables
ϕ[x/t] comes from ϕ, in which all free appearances of x in ϕ are replaced by the term t.
Lemma: Let y be a variable that does not appear in ϕ. Then it holds that
∀xϕ h ∀yϕ[x/y] and ∃xϕ h ∃yϕ[x/y].
Theorem: There exists an algorithm that calculates the prenex normal form of any
Derivation in PL1
Why is prenex normal form useful?
Unfortunately, there is no simple law as in propositional logic that allows us to determine satisfiability or general validity (by transformation into DNF or CNF).
But: We can reduce the satisfiability problem in predicate logic to the satisfiability problem in
propositional logic. In general, however, this produces a very large number of propositional formulae (perhaps infinitely many)
Then: Apply resolution.
Skolemization
Idea: Elimination of existential quantifiers by applying a function that produces the “right” element.
Theorem (Skolem Normal Form): Let ϕ be a closed formula in prenex normal form such that all quantified variables are pair-wise distinct and the function symbols g
1,g
2,… do not appear in ϕ . Let
ϕ = ∀ x
1… ∀ x
i∃ y ψ , then ϕ is satisfiable iff
ϕ ’ = ∀ x
1… ∀ x
iψ [y/g
i(x
1, …, x
i)]
is satisfiable.
Example: ∀ x ∃ y [P(x) ⇒ Q(y)] ∀ x [P(x) ⇒ Q(g(x))]
Skolem Normal Form
Skolem Normal Form: Prenex normal form without existential quantifiers. Notation: ϕ * is the SNF of ϕ .
Theorem: It is possible to calculate the skolem normal form of every closed formula ϕϕϕϕ .
Example: ∃ x (( ∀ x P(x)) . ¬ Q(x)) develops as follows:
∃ y (( ∀ x P(x)) . ¬ Q(y))
∃ y ( ∀ x (P(x) . ¬ Q(y)))
∀ x (P(x) . ¬ Q(g
0))
Note: This transformation is not an equivalence transformation; it only preserves satisfiability!
Note: … and is not unique.
Example: ∃ x (p(x)) . ∀ y (q(y))
Ground Terms &
Herbrand Expansion
The set of ground terms (or Herbrand Universe) over a set of SNF formulae θ* is the (infinite) set of all ground terms formed from the symbols of θ* (in case there is no constant symbol, one is added). This set is denoted by D(θ*)
The Herbrand expansion E(θ*) is the instantiation of the Matrix ψi of all formulae in θ* through all terms t ∈D(θ*):
E(θ*)={ψi[x1/t1,…, xn/tn] | (∀ x1,…, xnψi) ∈ θ*, tj ∈D(θ*)}
Theorem (Herbrand): Let θ* be a set of formulae in SNF. Then θ* is satisfiable iff E(θ*) is satisfiable.
Note: If D(θ*) and θ* are finite, then the Herbrand expansion is finite finite propositional logic theory.
Infinite Propositional Logic Theories
Can a finite proof exist when the set is infinite?
Theorem (compactness of propositional logic): A (countable) set of formulae of propositional logic is
satisfiable if and only if every finite subset is satisfiable.
Corollary: A (countable) set of formulae in propositional logic is unsatisfiable if and only if a finite subset is
unsatisfiable.
Corollary: (compactness of PL1): A (countable) set of
formulae in predicate logic is satisfiable if and only if
every finite subset is satisfiable.
Recursive Enumeration and Decidability
We can construct a semi-decision procedure for validity, i.e. we can give a (rather inefficient) algorithm that enumerates all valid formulae step by step.
Theorem: The set of valid (and unsatisfiable) formulae in PL1 is recursively enumerable.
What about satisfiable formulae?
Theorem (undecidability of PL1): It is undecidable, whether a formula of PL1 is valid.
(Proof by reduction from PCP)
Corollary: The set of satisfiable formulae in PL1 is not recursively enumerable.
In other words: If a formula is valid, we can effectively confirm this fact.
Otherwise, we can end up in an infinite loop.
Derivation in PL1
Clausal Form instead of Herbrand Expansion
Clauses are universally quantified disjunctions of literals; all variables are universally quantified
1 1
1
1
( ,..., )( ... ) written as ... or
{ ,..., }
n n
n
n
x x l l
l l
l l
∀ ∨ ∨
∨ ∨
Production of Clausal Form from SNF
Skolem Normal Form
quantifier prefix + (quantifier-free) Matrix ϕ:
∀ x1 ∀ x2 ∀ x3 … ∀ xn ϕ 1. Put Matrix into CNF
– Use distribution rule
2. Eliminate universal quantifiers 3. Eliminate conjunction symbol
4. Rename variables so that no variable appears in more than one clause.
Theorem: It is possible to calculate the clausal form of every closed formula ϕϕϕϕ .
Note: same remarks as for SNF
Clauses and Resolution
Assumption: All formulae in the KB are clauses.
Equivalently, we can assume that the KB is a set of clauses.
Due to commutativity, associativity, and idempotence of -,
clauses can also be understood as sets of literals. The empty set of literals is denoted by .
Set of clauses: ∆∆∆∆
Set of literals: C, D Literal:
´´´´
Negation of a literal: ¥
´´´´
Propositional Resolution
C
1∪ C
2C
1∪ { ´´´´ }, C
2
∪ { ¥ ´´´´ }
C
1∪ C
2is the resolvent of the parent clauses C
1∪ { ´´´´ } and C
2
∪ { ´´´´ }. ´´´´ and ¥ ´´´´ are the resolution literals.
Example: {a,b, ¬ c} resolves with {a,d,c} to {a,b,d}.
Note: The resolvent is not equivalent to the parent clauses, but it follows from them!
Notation: R( ∆∆∆∆ ) = ∆∆∆∆ ∪ {C | C is a resolvent of two
clauses from ∆∆∆∆ }
What changes ?
Examples
We need unification, a way to make literals identical
Based on the notion of substitution, e.g. {x/A}
d d
d
{{Nat(s(A)),¬Nat(A)} ,{Nat(A)}} {Nat(s(A))}
{{Nat(s(A)),¬Nat(x)} ,{Nat(A)}} {Nat(s(A))}
{{Nat(s(x)),¬Nat(x)} ,{Nat(A)}} {Nat(s(A))}
Substitutions
ϕ
ϕ ϕ
=
1 1A { / ,..., / } substitutes
variables for terms ( does NOT contain )
Applying a to an expression yields the expression
substitutio
which n
sub
is with all occurrenc
st
es o itution
f
n n
i i i i
s v t v t
v t t v
s s
replaced by v
it
iSubstitution Examples
P(x,f(y),B)
P(z,f(w),B) s={x/z,y/w}
P(x,f(A),B) s={y/A}
P(g(z),f(A),B) s={x/g(z),y/A}
P(C,f(A),A) no substitution !
Composing substitutions
Composing substitutions s
1and s
2gives s
1s
2which is that substitution obtained by first applying s
2to the terms in s
1and
adding remaining term/vars pairs (not occurring in s
1) to s
1Apply to
{z/g(x,y)}{x/A,y/B,w/C,z/D}=
{z/g(A,B),x/A,y/B,w/C}
P(x,y,z) → P(A,B,g(A,B))
Properties of substitutions
ϕ ϕ = ϕ
=
≠
1 2
1 2 1 2
1 2 3 1 2 3
1 2 2 1
For a formula and substitutions ,
( ) ( )
( ) ( ) associativity not commutative
s s
s s s s
s s s s s s s s s s
Property
Unification
Unifying a set of expressions {w
i}
Find substitution s such that Example
The most general unifier, the mgu, g of {w
i} has the
property that if s is any unifier of {w
i} then there exists a substitution s’ such that {w
i}s={w
i}gs’
Property The common instance produced is unique up to alphabetic variants (variable renaming)
for all ,
i j
w s = w s i j {P(x,f(y),B),P(x,f(B),B)}
s={y/B,s/A} not the simplest unifier s={y/B} most general unifier (mgu)
Subsumption lattice
Disagreement set
The disagreement set of a set of expressions {w
i} is the set of
subterms { t
i} of {w
i} at the first position in {w
i} for which the {w
i} disagree
Example {P(x,A,f(y)),P(w,B,z)} gives {x,w}
{P(x,A,f(y)),P(x,B,z)} gives {A,B}
{P(x,y,f(y)),P(x,B,z)} gives {y,B}
Unification algorithm
{P(x,A,f(y)),P(w,B,z)}
{P(x,A,f(y)),P(x,B,z)}
{P(x,y,f(y)),P(x,B,z)}
( )
Initialize 0;
Initialize ;
Initialize {};
* If is a singleton, then output . Otherwise, continue.
Let be the disagreement set of If there exists a var and
Uni
a term y
f
k k
k k
k k
k k
Terms k
T Terms
T
D T
v t
σ
σ
←
=
=
1 1
in D such that does not occur in , continue. Otherwise, exit with failure.
{ / };
{ / };
1;
Goto *
k k
k
k k k k
k k k k
v t
v t
T T v t
k k σ + σ
+
←
←
← +
{P(x,f(y),y),P(z,f(B),B)}
Binary Resolution
[C
1∪ C
2]s C
1∪ { ´´´´
1
}, C
2∪ { ¥ ´´´´
2
}
where s=mgu( ´´´´
1
, ´´´´
2
), the most general unifier
[C
1∪ C
2]s is the resolvent of the parent clauses C
1∪ { ´´´´
1
} and C
2∪ { ¥ ´´´´
2
} C
1∪ { ´´´´
1
} and C
2∪ { ¥ ´´´´
2
} do not share variables
´´´´
1and ´´´´
2
are the resolution literals.
Examples:
– –
d d
d
{{Nat(s(A)),¬Nat(A)} ,{Nat(A)}} {Nat(s(A))}
{{Nat(s(A)),¬Nat(x)} ,{Nat(A)}} {Nat(s(A))}
{{Nat(s(x)),¬Nat(x)} ,{Nat(A)}} {Nat(s(A))}
Some further examples
θ
∨ ∨ ¬
∨ ∨ ¬
∨
∨ ¬ ∨ ¬
P(x) Q(f(x)) R(g(x)) Q(f(A))
P(x) Q(f(x)) R(g(y)) Q(f(A)) {A/x} P(A) R(g(y))
P(x) Q(x,y) P(A) R(B,z)
Resolve and
Standardizing the variables apart gives and Substitution = Resolvent
Resolve and
Stand
θ {A/x} Q(A,y)∨ ¬R(B,z) ardizing the variables apart
Substitution = and Resolvent
Factoring
[C ∪ ´´´´
1
]s C ∪ { ´´´´
1
} ∪ { ´´´´
2
}
where s=mgu( ´´´´
1
, ´´´´
2
), the most general unifier
– –
{{P(u),P(v)}, {¬P(x),¬P(y)} } |=
but cannot be derived by binary resolution
{P(u)} and {¬P(x)} whose resolvent is Needed because
Factoring yields
Derivations
Notation: R( ∆∆∆∆ ) = ∆∆∆∆ ∪ {C | C is a resolvent or a factor of two clauses from ∆∆∆∆ }
We say D can be derived from ∆ , i.e.
∆ d D,
If there exist C
1, C
2, C
3, …, C
n= D such that
C
i∈ R( ∆ ∪ {C
1, …, C
i-1}), for 1 ≤ i ≤ n.
An example
¥
Another example
Properties of resolution
Lemma (soundness) If ∆ d D, then ∆ ~ D.
Lemma resolution is refutation-complete:
∆ is unsatisfiable implies ∆ d .
Theorem: ∆ is unsatisfiable iff ∆ d . Technique :
to prove that ∆ ~ c
negate c and prove that ∆ ∪ { ¥ c} d
The lifting lemma
Lemma Let C1 and C2 be two clauses with no shared variables, and let C1’ and C2’ be
ground instances of C1 and C2. If C’ is a
resolvent of C1’ and C2’, then there exists a clause such that
(1) C is a resolvent of C1 and C2 (2) C’ is a ground instance of C
Can be easily generalized to derivations
The general picture
Closing Remarks: Processing
• PL1-Resolution: forms the basis of
– most state of the art theorem provers for PL1 – the programming language Prolog
• only Horn clauses
• considerably more efficient methods.
– not dealt with : search/resolution strategies
• Finite theories: In applications, we often have to deal with a fixed set of objects. Domain closure axiom:
∀ x[x=c
1- x=c
2- … - x=c
n]
– Translation into finite propositional theory is possible.
Closing Remarks: Possible Extensions
PL1 is definitely very expressive, but in some circumstances we would like more…
• Second-Order Logic: Also over predicate quantifiers
∀x,y [(x=y) ⇔ {∀p[p(x) ⇔ p(y)]}]
Validity is no longer semi-decidable (we have lost compactness)
• Lambda Calculus: Definition of predicates, e.g.
λx,y[∃z P(x,z) . Q(z,y)] defines a new predicate of arity 2 Reducible to PL1 through Lambda-Reduction
• Uniqueness quantifier: ∃!xϕ(x) – there is exactly one x …
→ Reduction to PL1:
∃x [ϕ(x) . ∀y {ϕ(y) ⇒ x = y}]
Summary
• PL1 makes it possible to structure statements, thereby giving us considerably more expressive power than propositional
logic.
• Formulae consist of terms and atomic formulae, which,
together with connectors and quantifiers, can be put together to produce formulae.
• Interpretations in PL1 consist of a universe and an interpretation function.
• The Herbrand Theory shows that satisfiability in PL1 can be reduced to satisfiability in propositional logic (although infinite sets of formulae can arise under certain circumstances).
• Resolution is refutation complete
• Validity in PL1 is not decidable (it is only semi-decidable)