formal.methods.06.predicate.logics
formal.methods.06.predicate.logics
Formal Methods
Lecture 6
Farn Wang
Dept. of Electrical Engineering
National Taiwan University
Predicate Logic
Invented by Gottlob
Frege (1848–1925).
Predicate Logic is also
called “first-order logic”.
1
Motivation
Motivation
2
Apt-pet
Quantifiers
3
Functions
Predicate Logic
4
Predicate Logic: Syntax
variables x, y, …
logical connectives ∧, ∨, ¬, Æ, ↔
quantifiers ∀, ∃
punctuations: , . ( )
5
Predicate Logic
- syntax
Definition. Well-formed formulas (wffs) are defined
inductively as follows:
Base cases:
P(t1,t2,t3,…,tn) is a wff, where ti is a term, and P is an n-ary
predicate. These are called atomic formulas.
inductive cases:
If A and B are wffs, then so are
¬A, A∧B, A∨B, A⇒B, A⇔B
If A is a wff, so is ∃x. A
If A is a wff, so is ∀x. A
Nothing else is a wff.
We often omit the brackets using the same
precedence rules as propositional logic for the logical
connectives.
11
6
Scope and Binding of Variables (I)
Example:
A wff is closed if it contains no free occurrences of
any variable.
∀x.(∀x.( P( x) ∧ Q( x))) ⇒ (¬P( x) ∨ Q( y ))
scope
scope of this xof this x 13
x y
P Q
x x free variable
bound variables 14
7
Scope and Binding of Variables
interpreted with ∃x S
interpreted with ⇒ x y
P Q
x x free variable
scope of ∃x
bound variables 15
Substitution
16
8
Substitution
17
equivalent
(∀z(mom(x)∧dad(z)))[f(y)/x] = ∀z(mom(f(y))∧dad(f(z)))
18
9
Predicate Logic: Semantics
19
Interpretations (Models)
20
10
Example of a Model
Example: P(c,f(c))
In our model, choose the domain to be the natural
numbers
I(c) is 0.
I(P) is `<‘
I(Q) is `=‘
21
Example of an Model
22
11
Valuations
Definition.
A valuation v, in an interpretation I, is a function
from the terms to the domain DI such that:
ν(c) = I(c)
23
Example of a Valuation
DI is the set of Natural Numbers
g is the function +
h is the function suc
c (constant) is 3
y (variable) is 1
v( g (h(c), y )) = v(h(c)) + v( y )
= suc(v(c)) + 1
= suc(3) + 1
=5
24
12
Workout
DI is the set of Natural Numbers
g is the function +
h is the function suc
c (constant) is 3
y (variable) is 1
ν(h(h(g(h(y),g(h(y),h(c)))))) = ?
25
On(A,B) False
Clear(B) True
On(C,Fl) True
On(C,Fl)∧ ¬On(A,B) True
26
13
Workout
Interpret the following formulas with respect to
the world (model) in the previous page.
On(A,Fl)⇒ Clear(B)
Clear(B)∧ Clear(C)⇒ On(A,Fl) B
Clear(B) ∨ Clear(A)
A
Clear(B)
Clear(C) C
27
Konwoledge
Does the following knowledge base (set of
formulae) have a model ?
On(A,Fl)⇒ Clear(B)
Clear(B)∧ Clear(C)⇒ On(A,Fl)
Clear(B) ∨ Clear(A)
Clear(B)
Clear(C)
28
14
An example
(∀x)[On(x,C)⇒ ¬Clear(C)]
29
Closed Formulas
30
15
Validity (Tautologies)
31
16
Tautologies
33
Semantic Entailment
34
17
An Axiomatic System for Predicate Logic
35
36
18
Soundness and Completeness of FO_AL
37
Deduction Theorem
38
19
Proof by Refutation
39
Counterexamples
40
20
Example
41
Workout: Counterexamples
42
21
What does ‘first-order’ mean?
43
44
22
• To formalize all existing
46
23
Kurt Gödel
American is in danger
I knew the because
of dictatorship
1906-1978I can
general
prove the
• Einstein, “his work no longer meant
much,anthat
• Born he relativity
contradiction
came to the in
Austro-Hugarian Institute
merely
• 12 Æ Czech… to was
have wrong.
American constitution.
the privilege of
walking
• refuse home withCzech
to learn Gödel.”
• thought
OnÆ
•• 23 someone
hisAustrian
citizen exam, … was to poison
him.
• established
• proved the completeness
a paradoxial solution to theof
The
g re a • general
ate1st-order
onlyrelativity
hislogic
wife’s cooking.
in his Ph.D. thesis
in th tes
e 20 t logicia ••• 25, established
1977, wifethe
his position,
wasincompleteness
ill and could
th ce n Permanent Princeton, 1946
ntury of N
notAlbert
t • 1st cook.Einstein Award, 1951
e g r eates • 32 Æ German
f th • Full
Jan.professor,
1978, died 1953of mal-nutrition.
One o evements . •• 34 Æ joined Princeton
achi h century •• 42 Æ American
National Science Medal, 1974
th e 20t
in • Emeritus professor, 1976
47
48
24
Predicate Logic: Natural Deduction
Extend the set of rules we used for
propositional logic with ones to handle
quantifiers.
49
50
25
Example
51
Workout
52
26
Proof by Refutation
53
Herbrand’s theorem
- Herbrand universe of a formula S
Let H0 be the set of constants appearing in S.
If no constant appears in S, then H0 is to consist of a
single constant, H0={a}.
For i=0,1,2,…
Hi+1=Hi ∪ {f n(t1,…,tn)| f is an n-place function in S; t1,…,tn ∈ Hi }
Hi is called the i-level constant set of S.
H∞ is the Herbrand universe of S.
54
27
Herbrand’s theorem
- Herbrand universe of a formula S
Example 1: S={P(a),∼P(x)∨P(f(x))}
H0={a}
H1={a,f(a)}
H2={a,f(a),f(f(a))}
.
.
H∞={a,f(a),f(f(a)),f(f(f(a))),…}
55
Herbrand’s theorem
- Herbrand universe of a formula S
Example 2: S={P(x)∨Q(x),R(z),T(y)∨∼W(y)}
There is no constant in S, so we let H0={a}
There is no function symbol in S, hence
H=H0=H1=…={a}
Example 3: S={P(f(x),a,g(y),b)}
H0={a,b}
H1={a,b,f(a),f(b),g(a),g(b)}
H2={a,b,f(a),f(b),g(a),g(b),f(f(a)),f(f(b)),f(g(a)),f(g
(b)),g(f(a)),g(f(b)),g(g(a)),g(g(b))}
…
56
28
Herbrand’s theorem
- Herbrand universe of a formula S
Expression
a term, a set of terms, an atom, a set of atoms, a
literal, a clause, or a set of clauses.
Ground expressions
expressions without variables.
It is possible to use a ground term, a ground
atom, a ground literal, and a ground clause –
this means that no variable occurs in respective
expressions.
Subexpression of an expression E
an expression that occurs in E.
57
Herbrand’s theorem
- Herbrand base of a formula S
Ground atoms Pn(t1,…,tn)
Pn is an n-place predicate occurring in S,
t1,…,tn ∈ H∞
Herbrand base of S (atom set)
the set of all ground atoms of S
Ground instance of S
obtained by replacing variables in S by members of
the Herbrand universe of S.
58
29
Herbrand’s theorem
- Herbrand universe & base of a formula S
Example
S={P(x),Q(f(y))∨R(y)}
C=P(x) is a clause in S
59
Workout
{P(x), Q(g(x,y),a)∨R(f(x))}
please construct the set of ground terms
60
30
Herbrand’s theorem
- Herbrand interpretation of a formula S
S, a set of clauses.
i.e., a conjunction of the clauses
H, the Herbrand universe of S and
H-interpretation I of S
I maps all constants in S to themselves.
Forall n-place function symbol f and h1,…,hn
elements of H,
I (f (h1,…,hn) ) = f(h1,…,hn)
61
Herbrand’s theorem
- Herbrand interpretation of a formula S
There is no restriction on the assignment to
each n-place predicate symbol in S.
Let A={A1,A2,…,An,…} be the atom set of S.
An H-interpretation I can be conveniently
represented as a subset of A.
If Aj ∈ I, then Aj is assigned “true”,
otherwise Aj is assigned “false”.
62
31
Herbrand’s theorem
- Herbrand interpretation of a formula S
Example: S={P(x)∨Q(x),R(f(y))}
The Herbrand universe of S is
H={a,f(a),f(f(a)),…}.
Predicate symbols: P, Q, R.
The atom set of S:
A={P(a),Q(a),R(a),P(f(a)),Q(f(a)),R(f(a)),…}.
Some H-interpretations for S:
I1={P(a),Q(a),R(a),P(f(a)),Q(f(a)),R(f(a)),…}
I2= ∅
I3={P(a),Q(a),P(f(a)),Q(f(a)),…}
63
Herbrand’s theorem
- Herbrand interpretation of a formula S
An interpretation of a set S of clauses does
not necessarily have to be defined over the
Herbrand universe of S.
Thus an interpretation may not be an
H-interpretation.
Example:
S={P(x),Q(y,f(y,a))}
D={1,2}
64
32
Herbrand’s theorem
- Herbrand interpretation of a formula S
But Herbrand is conceptually general enough.
Example (cont.) S={P(x),Q(y,f(y,a))}
D={1,2}
– an interpretation of S:
Herbrand’s theorem
- Herbrand interpretation of a formula S
But Herbrand is conceptually general enough.
66
33
Herbrand’s theorem
- Herbrand interpretation of a formula S
If there is no constant in S, the element a used to
initiate the Herbrand universe of S can be mapped
into any element of the domain D.
If there is more than one element in D, then there is
more than one H-interpretation corresponding to I.
67
Herbrand’s theorem
- Herbrand interpretation of a formula S
Example: S={P(x),Q(y,f(y,z))}, D={1,2}
34
Herbrand’s theorem
- Herbrand interpretation of a formula S
Definition: Given an interpretation I over a domain D,
an H-interpretation I* corresponding to I is an H-
interpretation that satisfies the condition:
Let h1,…,hn be elements of H (the Herbrand
universe of S).
Let every hi be mapped to some di in D.
69
Herbrand’s theorem
70
35
Herbrand’s theorem
71
Herbrand’s theorem
Example: Consider the clause C=∼P(x)∨Q(f(x)). Let I1, I2,
and I3 be defined as follows:
I 1= ∅
I2={P(a),Q(a),P(f(a)),Q(f(a)),P(f(f(a))),Q(f(f(a))),…}
I3={P(a),P(f(a)),P(f(f(a))),…}
C is satisfied by I1 and I2, but falsified by I3.
Example: S={P(x),∼P(a)}.
The only two H-interpretations are:
I1={P(a)},
I2= ∅.
S is falsified by both H-interpretations and therefore is
unsatisfiable.
72
36
Resolution Principle
- Clausal Forms
Clauses are universally quantified disjunctions
of literals;
all variables in a clause are universally
quantified
(∀x1 ,..., xn )(l1 ∨ ... ∨ ln )
written as
l1 ∨ ... ∨ ln
or
{l1 ,..., ln } 73
Resolution Principle
- Clausal forms
{Nat(s(A)),¬Nat(A)} {Nat(s(A)),¬Nat(A)}
{Nat(A)} {Nat(x)}
Examples: gives gives
{Nat(s(A))} {Nat(s(A))}
{Nat(s(s(x))),¬Nat(s(x))}
{Nat(s(A))}
gives
{Nat(s(s(A)))}
74
37
Resolution Principle
- Terms and instances
Consider following atoms
P(x,f(y),B)
75
Resolution Principle
- Substitution
A substitution s = {t1 / v1 ,..., tn / vn } substitutes
variables vi for terms ti ( ti does NOT contain vi )
P(z,f(w),B) s ={z/x,w/y}
P(x,f(A),B) s ={A/y}
P(g(z),f(A),B) s ={g(z)/x,A/y}
P(C,f(A),A) no substitution !
76
38
Workout
¬P(g(x,a)), P(y)∨Q(f(y),g(a,b))
¬P(g(x,f(a))), P(g(b,y))∨Q(f(y),g(a,b))
¬P(g(f(x),x)), P(g(y,f(f(y)))∨Q(f(y),g(a,b)))
77
Resolution Principle
- Composing substitutions
Composing substitutions s1 and s2 gives s1 s2
which is that substitution obtained by first
applying s2 to the terms in s1and adding
remaining term/vars pairs to s1
θ ={g(x,y)/z}{A/x,B/y,C/w,D/z}=
{g(A,B)/z,A/x,B/y,C/w}
Apply to P(x,y,z)θ
gives
P(A,B,g(A,B))
78
39
ωs
Resolution Principle
- Properties of substitutions
(ω s1 ) s2 = ω ( s1s2 )
( s1s2 ) s3 = s1 ( s2 s3 ) associativity
s1s2 ≠ s2 s1 not commutative
79
Resolution Principle
- Unification
Unifying a set of expressions {wi}
Find substitution s such that wi s = w j s for all i, j
Example
{P(x,f(y),B),P(x,f(B),B)}
s={B/y,A/x} not the simplest unifier
s={B/y} most general unifier (mgu)
The most general unifier, the mgu, g of {wi} has the
property that if s is any unifier of {wi} then there
exists a substitution s’ such that {wi}s={wi}gs’
The common instance produced is unique up to
alphabetic variants (variable renaming)
usually we assume there is no common variables 80
in the two atoms
40
Workout
81
Workout
{Q(a,x),Q(a,a)}
{Q(a,x,f(x)),Q(a,y,y)}
{Q(x,y,z),Q(u,h(v,v),u)}
{P(x1,g(x1),x2,h(x1,x2),x3,k(x1,x2,x3)),
P(y1,y2,e(y2),y3,f(y2,y3),y4)}
82
41
Resolution Principle
- Disagreement set in unification
The disagreement set of a set of expressions
{wi} is the set of subterms { ti } of {wi} at the
first position in {wi} for which the {wi} disagree
83
Resolution Principle
- Unification algorithm
U nify( T erm s )
Initialize k ← 0;
Initialize T k = T erm s ;
Initialize σ k = {};
* If T k is a singleton, then output σ k . O therw ise, continue.
Let D k be the disagreem ent set of T k
If there exists a var v k and a term t k in D k such that v k
does not occur in t k , continue. O therw ise, exit w ith failure.
σ k + 1 ← σ k {t k / v k };
T k + 1 ← T k {t k / v k };
k ← k + 1;
G oto * 84
42
Predicate calculus Resolution
43
Resolution Principle
- Example P(x)∨ Q(f(x)) and R(g(x))∨ ¬Q(f(A))
Standardizing the variables apart
Why P(x)∨ Q(f(x)) and R(g(y))∨ ¬Q(f(A))
can we Substitution θ ={A/x}
do this ? Resolvent P(A)∨ R(g(y))
Workout
88
44
Workout
¬P(x)∨Q(x,x), ¬Q(a,f(a))
¬P(x,y,u)∨¬P(y,z,v)∨¬P(x,v,w)∨P(u,z,w),
P(g(x,y),x,y)
¬P(v,z,v)∨P(w,z,w), P(w,h(x,x),w)
89
Resolution Principle
- A stronger version of resolution
Use more than one literal per clause
90
45
Resolution Principle
- Factors
Let C1 be a clause such that there exists
a substitution θ that is a mgu of a set of literals
in C1. Then C1θ is a factor of C1
91
Resolution Principle
- Example of refutation
92
46
Resolution Principle
- Example
Hypothesies Clausal Form
∀x (dog(x) ⇒ animal(x)) ¬dog(x) ∨ animal(x)
dog(fido) dog(fido)
∀y (animal(y) ⇒ die(y)) ¬animal(y) ∨ die(y)
93
Resolution Principle
- Example ¬dog(x) ∨ animal(x) ¬animal(y) ∨ die(y)
{x {x → y}
{y → fido}
die(fido) ¬die(fido)
94
47
Workout (resolution)
- Proof with resolution principle
Hypotheses:
P(m(x),x) ∨ Q(m(x))
¬P(y,z) ∨ R(y)
¬Q(m(f(x,y))) ∨ ¬T(x,g(y))
S(a) ∨ T(f(a),g(x))
¬R(m(y))
¬S(x) ∨ W(x,f(x,y))
Conclusion
W(a, y)
95
Resolution
Properties
Resolution is sound
Incomplete
Given P(A)
Infer {P(A),P(B)}
96
48
Resolution Principle
- Refutation Completeness
To decide whether a formula KB ⊨ w, do
Convert KB to clausal form KB’
Convert ¬w to clausal form ¬w’
Combine ¬w’ and KB’ to give Δ
Iteratively apply resolution to Δ and add the
results back to Δ until either no more
resolvents can be added, or until the empty
clause is produced.
97
Resolution Principle
- Converting to clausal form (1/2)
To convert a formula KB into clausal form
1. Eliminate implication signs*
( p ⇒ q ) becomes (¬p ∨ q)
2. Reduce scope of negation signs*
¬( p ∧ q) becomes (¬p ∨ ¬q )
3. Standardize variables
(∀x)[¬P(x)∨(∃x)Q(x)] becomes (∀x)[¬P(x)∨(∃y)Q(y)]
4. Eliminate existential quantifiers using Skolemization
* Same as in prop. logic
98
49
Resolution Principle
- Converting to clausal form (2/2)
5. Convert to prenex form
Move all universal quantifiers to the front
6. Put the matrix in conjunctive normal form*
Use distribution rule
7. Eliminate universal quantifiers
8. Eliminate conjunction symbol *
9. Rename variables so that no variable occurs in
more than one clause.
99
Resolution Principle
- Skolemization
Consider(∀x)[(∃y)Height(x,y)]
The y depends on the x
Define this dependence explicitly using a skolem function h(x)
Formula becomes (∀x)[Height(x,h(x))]
General rule is that each occurrence of an existentially
quantified variable is replaced by a skolem function whose
arguments are those universally quantified variables
whose scopes includes the scope of the existentially
quantified one
50
Resolution Principle
- Examples of Skolemization
[(∀w)Q(w)]⇒(∀x){(∀y){(∃z)[P(x,y,z)⇒(∀u)R(x,y,u,z)]}}
gives
[(∀w)Q(w)]⇒(∀x){(∀y)[P(x,y,g(x,y))⇒(∀u)R(x,y,u,g(x,y))]}
(∀x)[(∃y) F(x,y)] gives (∀x)F(x,h(x))
but
(∃y)[(∀x)F(x,y)] gives [(∀x)F(x,sk)] skolem constant
Not logically equivalent !
A well formed formula and its Skolem form are not logically
equivalent.
However, a set of formulae is (un)satisfiable if and only if
its skolem form is (un)satisfiable. 101
Resolution Principle
- Example of conversion to clausal form
102
51
Workout
103
Resolution Principle
- Example of refutation by resolution
1.¬P(x)∨ ¬P(y)∨ ¬I(x,27)∨ ¬I(y,28)∨ S(x,y)
all packages in room 27 are smaller than any of those in 28
2.P(A)
3.P(B)
4.I(A,27)∨ I(A,28)
5.I(B,27)
6.¬S(B,A)
Prove I(A,27)
104
52
Resolution Principle
- Search Strategies
Ordering strategies
In what order to perform resolution ?
Breadth-first, depth-first, iterative deepening ?
Unit-preference strategy :
Prefer those resolution steps in which at least one
clause is a unit clause (containing a single literal)
Refinement strategies
Unit resolution : allow only resolution with unit
clauses
105
Resolution Principle
- Input Resolution
at least one of the clauses being resolved is a
member of the original set of clauses
Input resolution is complete for Horn-clauses
but incomplete in general
E.g. {P, Q},{¬P, Q},{P, ¬Q},{¬P, ¬Q}
106
53
Workout
107
Resolution Principle
- Linear Resolution
Linear resolvent is one in which at least one
of the parents is either
an initial clause or
the resolvent of the previous resolution step.
Refutation complete
Many other resolution strategies exist
108
54
workout
109
Resolution Principle
- Set of support
Ancestor : c2 is a descendant of c1 iff c2 is a
resolvent of c1 (and another clause) or if c2 is a
resolvent of a descendant of c1 (and another
clause); c1 is an ancestor of c2
Set of support : the set of clauses coming from
the negation of the theorem (to be proven) and
their descendants
Set of support strategy : require that at least one
of the clauses in each resolution step belongs to
the set of support
110
55
workout
111
Resolution Principle
- Answer extraction
Suppose we wish to prove whether KB |=
(∃w)f(w)
We are probably interested in knowing the w for
which f(w) holds.
Add Ans(w) literal to each clause coming from
the negation of the theorem to be proven;
stop resolution process when there is a
clause containing only Ans literal
112
56
1.¬P(x)∨ ¬P(y)∨ ¬I(x,27)∨ ¬I(y,28)∨ S(x,y)
Resolution all packages in room 27 are smaller than any of those in 28
Principle 2.P(A)
3.P(B)
- Example 4.I(A,27)∨ I(A,28)
of answer
5.I(B,27)
6.¬S(B,A)
extraction Prove (∃u)I(A,u), i.e. in which room is A?
113
Workout
114
57
Theory of Equality
Herbrand Theorem does not apply to FOL with equality.
So far we’ve looked at predicate logic from the point of view of
what is true in all interpretations.
This is very open-ended.
115
Theory of Equality
- An Axiomatic System with Equality
To the previous axioms and rules of inference,
we add:
EAx1 ∀x.x = x
EAx2 ∀x.∀y.x = y ⇒ ( A( x, x) ⇒ A( x, y ))
EAx3 ∀x.∀y.x = y ⇒ f ( x) = f ( y )
116
58
Theory of Equality
- Natural Deduction Rules for Equality
117
Theory of Equality
- Natural Deduction Rules for Equality
118
59
Theory of Equality
- Substitution
Recall: Given a variable x, a term t and a
formula P, we define P[t / x] to be the formula
obtained by replacing ALL free occurrence of
variable x in P with t.
But with equality, we sometimes don’t want to
substitute for all occurrences of a variable.
When we write P[t / x] above the line, we get to
choose what P is and therefore can choose
the occurrences of a term that we wish to
substitute for.
119
Theory of Equality
- Substitution
Recall from existential introduction:
120
60
Theory of Equality
- Examples
From these two inference rules, we can derive
two other properties that we expect equality
to have:
Symmetry : ND A ∀x, y.( x = y ) ⇒ ( y = x)
A ∀x, y, z.( x = y ) ∧ ( y = z ) ⇒ ( x = z )
Transitivity : ND
121
Theory of Equality
- Example
122
61
Theory of Equality
- Example
123
Theory of Equality
- Leibniz’s Law
The substitution inference rule is related to
Leibniz’s Law.
Leibniz’s Law:
if t1 = t2 is a theorem, then so is P[t1 / x] ⇔ P[t2 / x]
Leibniz’s Law is generally referred to as the
ability to substitute “equals for equals”.
124
62
Leibniz
Theory of Equality
- Example
From our natural deduction rules, we can
derive Leibniz’s Law:
t1 = t2 A P(t1 ) ⇔ P(t2 )
ND
126
63
Theory of Equality
- Equality: Semantics
The semantics of the equality symbol is
equality on the objects of the domain.
In ALL interpretations it means the same
thing.
Normal interpretations are interpretations in
which the symbol = is interpreted as
designating the equality relation on the
domain.
We will restrict ourselves to normal
interpretations from now on.
127
Theory of Equality
- Extensional Equality
Equality in the domain is extensional, meaning it is
equality in meaning rather than form.
This is in contrast to intensional equality which is
equality in form rather than meaning.
In logic, we are interested in whether two terms
represent the same object, not whether they are the
same symbols.
If two terms are intensionally equal then they are
also extensionally equal, but not necessarily the
other way around.
128
64
Theory of Equality
- Equality: Counterexamples
Show the following argument is not valid:
∃x.P ( x) ∧ Q ( x), P ( A), A = B B Q( B)
where A,B are constants
129
Theory of Arithmetic
130
65
Peano’s Axioms
131
Intuitionistic Logic
132
66
Summary
133
67