logic - dhbw stuttgarthladik/logik/2015/logic - handout.pdfindustry experience: sap research work in...
TRANSCRIPT
-
Logic
Jan Hladik
DHBW Stuttgart
Wintersemester 2015/16
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 1 / 120
-
Introduction
Jan Hladik
Dipl.-Inform.: RWTH Aachen, 2001
Dr. rer. nat.: TU Dresden, 2007
Industry experience: SAP Research
Work in publicly funded research projectsCollaboration with SAP product groupsSupervision of Bachelor, Master, and PhD students
Professor: DHBW Stuttgart, 2014
Research
Semantic Web, Semantic Technologies, Automated Reasoning
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 2 / 120
-
Outline
1 Why logic?
2 propositional and first-order logic
1 syntax and semantics of propositional logic2 reasoning
1 resolution2 tableaus
3 syntax and semantics of first-order logic4 reasoning
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 3 / 120
-
Logic, logic, logic. . .
Why do computer scientists need logic?
Mr Spock says:
Logic isthe beginning of wisdom,not the end.
Logic is not the ultimate purpose of a computer science course
but it lays the foundation for other topics
and is necessary to understand what computer science is about
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 4 / 120
-
What we need logic for
You can be a hacker without knowing anything about logiclike you can drive a car without knowing about engines
You need to know about the theoretical foundations of computerscience if you want to
understand what’s going on in a computer (Boolean logic)ensure that your program computes the right functiondesign your communication protocol so that it does not allow fordeadlocksensure that your algorithm runs as fast as possible
Without logic, you will only be a
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 5 / 120
-
Propositional logic
most basic logic we consider in this course
limited expressivity
easy to understand and use
contains many concepts that are also used in more expressive logics
Propostional variables represent propositions
Example
A ; “it rains”
Operators represent relations between propositions
Example
A→ B ; “if it rains, the ground is wet”
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 6 / 120
-
Propositional variables
are referenced by capital letters A,B,X, Y, . . .
represent propositions that can be true or false
“It rains.”“Peter loves Mary.”“Socrates is mortal.”
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 7 / 120
-
Syntax of propositional logic
Definition (propositional formula)
every propositional variable is a propositional formula
> and ⊥ are propositional formulasif ϕ and ψ are propositional formulas, then so are
¬ϕ (negation)ϕ ∧ ψ (conjunction)ϕ ∨ ψ (disjunction)ϕ→ ψ (material implication)ϕ↔ ψ (material equivalence)(ϕ) (brackets indicate precedence)
Examples
A ∧B⊥ ∨A¬>
A ∧ (B ∨ C)¬(A ∨B)C → (B ∨D)
A→ (B∧(C ↔ D)∨(D → E))A↔ (A↔ D)((A↔ B)↔ (C ↔ D))→ E
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 8 / 120
-
Exercise: syntax of PL
Which of the following are propositional formulas?
a) A→ ⊥b) A ∧ (B ∨ C)c) A¬Bd) (A→ C) ∧ (¬A→ C)→ Ce) ∨B ∨ C ∧Df) A→ (B ∨ ¬B)(C ∨ ¬C)
g) A→ Ah) A ∧ ¬Ai) A¬ ∧Bj) ¬A ∧Bk) (¬A) ∧Bl) ¬(A ∧B)
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 9 / 120
-
Precedence and associativity of logical operators
Precedence of operators:
operator precedence
¬ 1 (strongest)∧ 2∨ 3→ 4↔ 5 (weakest)
Example
A ∧B → B ∨ C means (A ∧B)→ (B ∨ C)
Operators of the same precedence are left-associative.
Example
A→ B → C means (A→ B)→ C
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 10 / 120
-
Exercise: Precedence and brackets
Remove as many brackets as possible without changing the precedence.
a) ((A ∧B) ∨ ((C ∧D)→ (A ∨ C)))b) ((((A ∧ (B ∨ C) ∧D))→ A) ∨ C)c) (A ∧ (B ∨ (C ∧ (D → (A ∨ C)))))
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 11 / 120
-
Semantics of propositional logic
assigning meaning to a logical formula.
assigning 0 or 1 to the variables
making the formula true or false
An interpretation assigns a truth value to variables (and thus formulas)
Definition (interpretation)
Function I : V → B whereV is a set of propositional variables
B is the binary set {0, 1}
Example
A 7→ 0 ; “it does not rain”
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 12 / 120
-
Interpretation of complex formulas
⊥I >I0 1
ϕI 0 1
(¬ϕ)I 1 0
(ϕ ∧ ψ)IϕI 0 1
ψI
0 0 01 0 1
(ϕ ∨ ψ)IϕI 0 1
ψI
0 0 11 1 1
(ϕ→ ψ)IϕI 0 1
ψI
0 1 01 1 1
(ϕ↔ ψ)IϕI 0 1
ψI
0 1 01 0 1
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 13 / 120
-
Example: interpretations
The interpretation I = {A 7→ 1, B 7→ 1, C 7→ 0} makes the formulaB true;
A ∧B true;A ∧ C false;(A ∧B) ∨ (A ∧ C) true;((A ∧B) ∨ (A ∧ C))→ C false.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 14 / 120
-
Basic equivalences
Definition (equivalent)
Two propisitional formulas ϕ and ψ are equivalent if every interpretationassigns the same truth value to both formulas, i.e.
ϕI = ψI for every I
Due to the semantics, one can express some operators by using other ones
Theorem (equivalences)
ϕ↔ ψ is equivalent to (ϕ→ ψ) ∧ (ψ → ϕ) or (ϕ ∧ ψ) ∨ (¬ϕ ∧ ¬ψ)ϕ→ ψ is equivalent to ¬ϕ ∨ ψϕ ∧ ψ is equivalent to ¬(¬ϕ ∨ ¬ψ)ϕ ∨ ψ is equivalent to ¬(¬ϕ ∧ ¬ψ)
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 15 / 120
-
Exercise: interpretations
Find two interpretations for each of the following formulas
one that makes them true
one that makes them false
a) A ∧B → Cb) (A ∨B) ∧ (A ∨ C)→ (B ∧ C)c) A→ B ↔ ¬B → ¬A
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 16 / 120
-
Tautologies
Definition (tautology)
A tautology is a formula which is true in every interpretation.
Examples (tautologies)
A↔ A (identity)¬(A ∧ ¬A) (noncontradiction)A ∨ ¬A (excluded middle)A→ B ↔ ¬B → ¬A (contraposition)(A→ B) ∧ (A→ ¬B)→ ¬A (reductio ad absurdum)(A→ B) ∧ (B → C)→ (A→ C) (syllogism)(A ∨B) ∧ (A→ C) ∧ (B → C)→ C (proof by cases)
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 17 / 120
-
Further tautologies
(A ∧B) ∨ C ↔ (A ∨ C) ∧ (B ∨ C) (distributivity)(A ∧B) ∧ C ↔ A ∧ (B ∧ C) (associativity)A ∧B ↔ B ∧A (commutativity)¬(A ∧B)↔ ¬A ∨ ¬B (de Morgan’s law)A ∧A↔ A; A ∨A↔ A (idempotence)A ∧ > ↔ A; A ∨ ⊥ ↔ A (neutral element)A ∧ ⊥ ↔ ⊥; A ∨ > ↔ > (absorbing element)¬¬A↔ A (double negation)
Distributivity, associativity, commutativity, and deMorgan’s law also hold if∧ is replaced with ∨ and vice versa.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 18 / 120
-
Models, validity, satisfiability
Definition (model)
A model for a formula ϕ is an interpretation I that makes ϕ true (I |= ϕ).
I = {A 7→ 1, B 7→ 0} is a model for A ∨B, but not for A ∧B.
Definition (satisfiable, valid)
A formula ϕ is called satisfiable if it has a model.A formula ϕ is called valid (|= ϕ) if every interpretation is a model (i.e. ifit is a tautology).
satisfiable A, A ∨B, A ∧ ¬B, A↔ Bvalid A ∨ ¬A, A→ A, A↔ ¬(¬A)
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 19 / 120
-
Outline
1 propositional and first-order logic
1 syntax and semantics of propositional logic2 reasoning
1 resolution2 tableaus
3 syntax and semantics of first-order logic4 reasoning
2 Prolog
3 modal and description logics
4 Semantic Web
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 20 / 120
-
Reasoning in propositional logic
Determine if a formula ϕ is
valid (a tautology, i.e. every interpretation is a model)satisfiable (there is a model)unsatisfiable (there are no models)
Determine if a formula ϕ implies another formula ψ (ϕ |= ψ),i.e every model for ϕ is a model for ψ
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 21 / 120
-
Showing that a formula is valid
A formula can be shown to be a tautology by using known equivalences:
Example: reductio ad absurdum
(A→ B) ∧ (A→ ¬B)→ ¬A definition of → (twice)(¬A ∨B) ∧ (¬A ∨ ¬B)→ ¬A definition of →¬((¬A ∨B) ∧ (¬A ∨ ¬B)) ∨ ¬A De Morgan¬(¬A ∨B) ∨ ¬(¬A ∨ ¬B) ∨ ¬A De Morgan (twice)
(A ∧ ¬B) ∨ (A ∧B) ∨ ¬A distributivity(A ∧ (¬B ∨B)) ∨ ¬A excluded middle
(A ∧ >) ∨ ¬A > is neutral element for ∧A ∨ ¬A excluded middle>
Drawbacks:
One has to guess which transformation to use.
Failure to prove ϕ does not imply that ϕ is not valid.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 22 / 120
-
Showing that a formula is valid
The same result can be shown using a truth table:
Example: reductio ad absurdum
A B C := A→ B D := A→ ¬B C ∧D ¬A C ∧D → ¬A0 0 1 1 1 1 10 1 1 1 1 1 11 0 0 1 0 0 11 1 1 0 0 0 1
Problems:
inefficient, especially with many propositional variables
redundant, since many valuation changes do not affect results
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 23 / 120
-
Exercise: reasoning
Prove that the following formula is a tautology
A ∧B → C ↔ A→ (B → C)
using
a) known equivalences,
b) a truth table.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 24 / 120
-
Outline
1 propositional and first-order logic
1 syntax and semantics of propositional logic2 reasoning
1 resolution2 tableaus
3 syntax and semantics of first-order logic4 reasoning
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 25 / 120
-
Resolution
method to test satisfiability of a propositional formula ϕ
introduced in 1965 by John Robinson
can also be used to test
validity: |= ϕ holds iff ¬ϕ is usatisfiable.(logical) implication: ϕ |= ψ holds iff ϕ ∧ ¬ψ is unsatisfiable.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 26 / 120
-
Resolution principle
Find contradiction in ϕ
operate on set of disjunctions (clauses)
find pairs of contradictory literals L,L in clauses C1, C2generate resolvent C3 by joining C1 and C2 (parent clauses) andeliminating L and L
C3 is not equivalent to C1 ∧ C2!C1 ∧ C2 satisfiable ; C3 satisfiableC3 unsatisfiable ; C1 ∧ C2 unsatisfiable
empty clause 2: contradiction
Example (ϕ = (X ∨ Y ) ∧ (¬Y ∨ Z) ∧ ¬Z ∧ ¬X)X ∨ Y ¬Y ∨ Z ¬Z ¬X
X ∨ ZX
2
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 27 / 120
-
Literals and their negations
Definition (Literal)
A literal is a (possibly negated) propositional variable.
Example
For the set of variables {A,B}, the set of possible literals is{A,¬A,B,¬B}.
Definition (Negation of a literal)
The negation L of a literal L is defined as follows
for a variable A: A = ¬A;for a negated variable ¬A: ¬A = A
Example
B = ¬B; ¬C = C, . . .Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 28 / 120
-
Conjunctive Normal Form
Conjunctive Normal Form
A propositional formula ϕ is in conjunctive normal form (CNF) if ϕ is aconjunction of disjunctions of literals.
Example
(X ∨ Y ) ∧ (¬Y ∨ Z) ∧ ¬Z ∧ ¬X is in CNF;(X ∧ Y ) ∨ ¬(¬Y ∨ Z) is not in CNF.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 29 / 120
-
Transformation into CNF
Theorem
Every propositional formula can be transformed into an equivalent formulain CNF.
Goal: (L1 ∨ L2 ∨ L3) ∧ (L4 ∨ L5) ∧ L6 . . .
1. eliminate material implication ϕ→ ψ ; ¬ϕ ∨ ψ1. and material equivalence ϕ↔ ψ ; ϕ ∧ ψ ∨ ¬ϕ ∧ ¬ψ2. De Morgan’s laws ¬(ϕ ∨ ψ) ; ¬ϕ ∧ ¬ψ3. eliminate double negation ¬¬ϕ ; ϕ4. distributivity ϕ ∨ (ψ ∧ χ) ; (ϕ ∨ ψ) ∧ (ϕ ∨ χ)5. associativity ϕ ∨ (ψ ∨ χ) ; ϕ ∨ ψ ∨ χ
Example
(X ∧ Y )∨¬(¬Y ∨Z) ; (X ∨ Y )∧ (Y ∨ Y )∧ (X ∨¬Z)∧ (Y ∨¬Z)
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 30 / 120
-
Exercise: Conjunctive Normal Form
Transform the following formulas into CNF:
(X ∨ Y ) ∧ (A ∧B)(X ∨ Y )→ (A ∨B)X ∨ (¬A ∧ ¬(B ∧ ¬C))
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 31 / 120
-
Clauses
Definition (Clause)
A clause is a disjunction of literals, written as a set.
Example
(X ∨ ¬Y ∨ Z) ; {X,¬Y,Z}
Every propositional formula can be written as a set of clauses.
ϕ = (X ∨ Y ) ∧ (¬Y ∨ Z) ∧ ¬Z ∧ ¬XK(ϕ) = {{X,Y }, {¬Y, Z}, {¬Z}, {¬X}}
Intuitively:
∧ between the sets∨ between the elements of the sets
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 32 / 120
-
Resolution of clauses
We have two clauses C1 = {X,Y } and C2 = {¬Y , Z}.We are looking for a model for C1 ∧ C2.
In an interpretation I, Y I is either 0 or 1.if Y I = 1 holds, then CI1 = 1 and C
I2 = 1 iff Z
I = 1;
if Y I = 0 holds, then CI2 = 1 and CI1 = 1 iff X
I = 1.
Every model for C1 and C2 is also a model for C3 = {X,Z}.If {C1, C2} is satisfiable, then {C1, C2, C3} is also satisfiable.
Definition (Resolvent)
Let C1 = {L1, L2, L3, . . .} and C2 = {L1, L6, L7, . . .} be propositionalclauses. Then C3 = {L2, L3, . . . , L6, L7, . . .} is called the resolvent of C1and C2 ({C1, C2} ` C3).
If a clause C can be obtained from a clause set S using several resolutionsteps, we write S `∗ C.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 33 / 120
-
Exercise: Resolution
Find as many resolvents as possible for the clause set S.
S = {{A,B,¬C}, {B,C,D}, {¬D}, {¬A,D}, {¬B,¬E}, {D,E}}
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 34 / 120
-
Using resolution to test satisfiability
Let S ` C.Every model for S is also a model for C.
If S is satisfiable, then so is S ∪ {C}.If S ∪ {C} is unsatisfiable, then so is S.The empty clause 2 is unsatisfiable.(It is obtained by resolving A and ¬A for some A.)
Theorem (soundness of resolution)
Let S be a set of clauses.If 2 can be obtained from S by resolution, then S is unsatisfiable.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 35 / 120
-
Resolution algorithm for propositional logic
input: propositional formula ϕoutput: “satisfiable” or “unsatisfiable”
1: transform ϕ into CNF2: initialise C with disjunctions of ϕ3: while there is C3 = res(C1, C2) with C3 /∈ C do4: if C3 = 2 then5: output “unsatisfiable”6: else7: C := C ∪ {C3}8: output “satisfiable”
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 36 / 120
-
Properties of the resolution algorithm
Theorem (soundness)
K(ϕ) `∗ 2 implies unsatisfiability of ϕ.
Theorem (refutation completeness)
If ϕ is unsatisfiable, then K(ϕ) `∗ 2 holds.
Theorem (termination)
The resolution algorithm terminates for every input.
Proof.
Only new clauses are added.
New clauses contain only literals from the input.
Clauses are never removed.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 37 / 120
-
Resolution and non-determinism
If several possibilities for new resolvents exist:
the algorithm will terminate for every choice
. . . but some choices will be faster than others
Definition (don’t-care-nondeterminism)
An algorithm is called don’t-care-nondeterministic if at any point withseveral choices every choice will lead to a solution.
no backtracking required
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 38 / 120
-
Turning natural language into propositional formulas
1 If John is not sick and he is invited to the meeting, he attends it.¬S ∧ I → A ; S ∨ ¬I ∨A
2 If the boss wants John at the meeting, he invites him.B → I ; ¬B ∨ I
3 If the boss does not want John at the meeting, John will be fired.¬B → F ; B ∨ F
4 John did not attend the meeting. ¬A5 John is not sick. ¬S6 Conjecture: John will be fired. F
To test if the conjecture is valid, we check if the premises together withthe negation of the conjecture are satisfiable.
{{S,¬I, A}, {¬B, I}, {B,F}, {¬A}, {¬S}, {¬F}}
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 39 / 120
-
Determining John’s future by resolution
{{S,¬I, A}, {¬B, I}, {B,F}, {¬A}, {¬S}, {¬F}}
S,¬I, A ¬A
S,¬I
¬B, I B, F
I, F
S, F ¬S
F ¬F
2
So unfortunately, the conjecture is valid and John will be fired . . .
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 40 / 120
-
Determining the answer using a truth table
1 S,¬I, A2 ¬B, I3 B,F
4 ¬A5 ¬S6 F
S I A B F 1 2 3 4 5 6 1 ∧ . . . ∧ 5 ∧ ¬60 0 0 0 0 1 1 0 1 1 0 00 0 0 0 1 1 1 1 1 1 1 0
......
...1 0 1 0 0 1 1 0 0 0 0 0
......
...1 1 1 1 1 1 1 1 0 0 1 0
The only valuation that makes clauses 1–5 true also makes clause 6true (line 2).
The last column always remains 0.
The conjecture follows from the premises.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 41 / 120
-
Exercise: resolution algorithm
Inspector Craig is called to a jewelry store that has been subject to arobbery where three suspects, Austin, Brian, and Colin, were arrested.After evaluation of all facts, this is known:
1 At least one of the suspects is guilty.
2 If Austin is guilty he had exactly one accomplice.
3 If Brian is innocent, so is Colin.
4 If exactly two suspects are guilty, Colin is one of them.
5 If Colin is innocent then Austin is guilty.
6 Conjecture: Brian and Colin are guilty.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 42 / 120
-
Optimisation of the resolution procedure
Choosing the right parent clauses is crucial for practical efficiency.
Heuristics:
prioritise short clauses
prioritise clauses with high derivation depth ; depth-first search
ignore tautologies {X,¬X, . . .}ignore C1 if C2 ⊆ C1 existsperform resolution with more than two clauses (hyperresolution)
Restriction to special cases, e.g. Horn formulas
Horn clause: at most one positive literal
X ∧ Y ∧ Z . . .→Wuseful for rule-based systems (Prolog)
polynomial runtime
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 43 / 120
-
Outline
1 propositional and first-order logic
1 syntax and semantics of propositional logic2 reasoning
1 resolution2 tableaus
3 syntax and semantics of first-order logic4 reasoning
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 44 / 120
-
Tableau algorithms
Different method to test satisfiability of propositional formulas
resolution: try to find the contradiction
tableau: try to build a model
Properties of tableau algorithms
rules: break down complex formulas into simpler ones“If you have ϕ ∧ ψ but not both ϕ and ψ, add ϕ and ψ.”
clash triggers: define cases when a contradiction has been found“If you have ϕ and ¬ϕ, there is a contradiction.”
tableau: table of formulas that have to be satisfied
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 45 / 120
-
Tableau algorithms: rules
precondition: describes which kind of formula is processed“If you have ϕ ∧ ψ . . . ”
applicability condition: describes when a rule is not applicable anymore, toensure termination“. . . and not both ϕ and ψ, . . . ”
postcondition: describes what to do to process the formula“. . . add ϕ and ψ.”
Rules can require testing different alternatives:
“If you have ϕ ∨ ψ . . . , add ϕ or ψ”This means: split the current table column,try ϕ in one column, ψ in the other one
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 46 / 120
-
Tableau algorithms: termination
The algorithm terminates if
there is one clash-free column where no rules are applicable; satisfiable
all columns contain to a clash; unsatisfiable
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 47 / 120
-
Tableau algorithm for propositional logic
input: propositional formula ϕoutput: “satisfiable” or “unsatisfiable”
1: initialise S with {ϕ}2: while there is a formula ϕ in S to which a rule R is applicable do3: apply R to ϕ4: if every column contains a clash then5: output “unsatisfiable”6: else7: output “satisfiable”
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 48 / 120
-
Tableau rules for propositional logic
∧ If ϕ ∧ ψ ∈ S and {ϕ,ψ} * Sthen S := S ∪ {ϕ,ψ}
∨ If ϕ ∨ ψ ∈ S and {ϕ,ψ} ∩ S = ∅then S := S ∪ {ϕ} or S := S ∪ {ψ}
→ If ϕ→ ψ ∈ S and {¬ϕ,ψ} ∩ S = ∅then S := S ∪ {¬ϕ} or S := S ∪ {ψ}
↔ If ϕ↔ ψ ∈ S and {ϕ,ψ} ∩ S = ∅ and {¬ϕ,¬ψ} ∩ S = ∅then S := S ∪ {ϕ,ψ} or S := S ∪ {¬ϕ,¬ψ}
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 49 / 120
-
Tableau rules: negated formulas
¬∧ If ¬(ϕ ∧ ψ) ∈ S and {¬ϕ,¬ψ} ∩ S = ∅then S := S ∪ {¬ϕ} or S := S ∪ {¬ψ}
¬∨ If ¬(ϕ ∨ ψ) ∈ S and {¬ϕ,¬ψ} * Sthen S := S ∪ {¬ϕ,¬ψ}
¬ → If ¬(ϕ→ ψ) ∈ S and {ϕ,¬ψ} * Sthen S := S ∪ {ϕ,¬ψ}
¬ ↔ If ¬(ϕ↔ ψ) ∈ S and {ϕ ∨ ψ,¬ϕ ∨ ¬ψ} * Sthen S := S ∪ {ϕ ∨ ψ,¬ϕ ∨ ¬ψ}
¬¬ If ¬(¬ϕ) ∈ S and ϕ /∈ Sthen S := S ∪ {ϕ}
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 50 / 120
-
Tableau rules
Effectively, only two kinds of rules exist:
deterministic rules that add formulas to the corresponding column
∧, ¬¬, ¬∨, . . .non-deterministic rules that split the column
∨, →, ↔, . . .
For efficiency reasons, deterministic rules should be applied first.Otherwise, they have to be applied separately in each column.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 51 / 120
-
Example: determining John’s future with a tableau
Premises: (¬S ∧ I → A); (B → I); (¬B → F ); ¬A; ¬SConjecture: F
Test if premises together with negation of conjecture are satisfiable.(¬S ∧ I → A) ∧ (B → I) ∧ (¬B → F ) ∧ ¬A ∧ ¬S ∧ ¬F . . . ∧ . . . ∧ . . .
(¬S ∧ I → A); (B → I); (¬B → F );¬A;¬S;¬F ¬S ∧ I → A¬(¬S ∧ I) A ¬(¬S ∧ I)
¬¬S ¬I ¬¬SS B → I
¬B I ¬B → F¬¬B F ¬¬BB
all columns contain a clash; ϕ is unsatisfiable; conjecture follows from premises
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 52 / 120
-
Tableau rules and negation normal form
Definition (NNF)
A propostional formula is in negation normal form (NNF) if the only binaryconnectives that appear are ∧ and ∨ and negation only appearsimmediately before propositional variables.
Every propositional formula can be transformed into NNF by
1 eliminating → and ↔2 applying deMorgan’s laws
3 removing double negation
as for CNF.
For formulas in NNF, the only tableau rules that are needed are those forconjunction and disjunction.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 53 / 120
-
Exercise: tableau algorithm
Prove that Brian and Colin are guilty using a tableau.
(A ∨B ∨ C) ∧(A→ B ∧ ¬C ∨ ¬B ∧ C) ∧
(¬B → ¬C) ∧¬(A ∧B ∧ ¬C) ∧
(¬C → A) ∧¬(B ∧ C)
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 54 / 120
-
Tableaus and nondeterminism
if several rules are applicable, the choice which one to apply isdon’t-care-nondeterministic
reminder: every choice leads to a solution
if a rule is nondeterministic (like the ∨-rule), the choice whichalternative to take is don’t-know-nondeterministic
finding of a solution may depend on the choiceall alternatives must be tested
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 55 / 120
-
Practical application of tableaus
the tree generated by the TA can be exponential in the size of theinput
example: (A ∨B) ∧ (C ∨D) ∧ (E ∨ F )to save time and space, the TA is created depth-first:
only operate on one branchapply every rule in this branchno clash: abort and output “satisfiable”clash: try next branch
requires storing backtracking information for every application of anon-deterministic rule
another reason to delay application of non-deterministic rules as longas possible
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 56 / 120
-
Tableaus vs. resolution
Advantages of tableaus
fast for satisfiable inputs
no preprocessing necessary (CNF)
generates a model (justification) for satisfiable inputs
Advantages of resolution
fast for unsatisfiable inputs
don’t-care-nondeterministic procedure (no backtracking)
only one operation, easy to optimise
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 57 / 120
-
Outline
1 propositional and first-order logic
1 syntax and semantics of propositional logic2 reasoning
1 resolution2 tableaus
3 syntax and semantics of first-order logic4 reasoning
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 58 / 120
-
Limitations of propositional logic
PL can only deal with propositions as a whole
propositions can only be true or false
structure of propositions cannot be analysed
Example
Some chickens cannot fly.
All chickens are birds.
Conjecture: Some birds cannot fly.
Translation into PL:
C → ¬F ?C → BB → ¬F ?
formalisation is questionable; inference cannot be proved
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 59 / 120
-
First-order predicate logic: syntax
constructor notation real-life domain math domain
variables x, y (people) (numbers)
constant a, b, c Calvin, Hobbes 1, 2, πsymbols
function f(x), h(x, y) has-mother, married-to x+ y, sqrt(x),symbols log(x, b)
predicate R(x), S(x, y) has-daughter, has-friend, x > y, x = y,symbols likes prime(x)
quantifiers ∀,∃operators ∧,∨,¬,→
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 60 / 120
-
Functions and their arity
Function symbols come with an arity
an n-ary function symbol has exactly n arguments
+ is binary (x+ y)
sqrt() is unary (sqrt(x))
has-mother and married-to are unary
nullary function symbols are constant symbols
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 61 / 120
-
Terms
Variables and function symbols (and thus also constant symbols) can beused to build terms.
Definition (term)
Terms are defined inductively as follows:
every variable is a term.
if f is n-ary and t1, . . . , tn are terms, then f(t1, . . . , tn) is a term.
every constant is a termbinary functions are often written in infix notation:x+ y rather than +(x, y)
terms without variables are called ground terms
Note: terms denote elements of the domain.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 62 / 120
-
Example: terms
Let
x, y be variables,
c, d be constant symbols,
f be a unary function symbol,
+ be a binary function symbol.
Example (ground terms)
c
f(d)
c+ f(c) or +(c, f(c))
+(c,+(d,+(f(c), f(f(d)))))
Example (non-ground terms)
x
f(y)
c+ f(y)
+(c,+(y,+(f(x), f(y))))
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 63 / 120
-
Predicates and their arity
Predicate symbols also come with an arity.
an n-ary predicate symbol has exactly n arguments
> is binary (x > y)
prime() is unary (prime(x))
has-daughter and likes are binary
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 64 / 120
-
Atoms
Predicate symbols and terms can be used to build atoms.
Definition (Atom)
Atoms are defined as follows:
if R is an n-ary predicate symbol and t1, . . . , tn are terms, thenR(t1, . . . , tn) is an atom
binary relations are often written in infix notation:x > y rather than > (x, y)
atoms without variables are called ground atoms
Note: Atoms are either true or false.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 65 / 120
-
Example: atoms
Let
> be a binary predicate symbol
P be a unary predicate symbol
Example (ground atoms)
P (c)
c > f(c) or > (c, f(c))
c > c
P (c+ f(c))
Example (non-ground atoms)
x > y
f(y) > c+ f(x)
P (f(c+ y))
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 66 / 120
-
Boolean operators, quantifiers, and formulas
Atoms can be used to build complex formulas.
Definition (formula)
Formulas are defined recursively as follows:
every atom is a formula
if ϕ and ψ are formulas and x is a variable, then the following are alsoformulas:
¬ϕ, >, ⊥ϕ ∧ ψ, ϕ ∨ ψ, ϕ→ ψ, ϕ↔ ψ∀xϕ, ∃xϕ
if x appears in ϕ, it is called bound by the quantifierotherwise, it is called free
a formula with free variables is called an open formula
a formula without free variables is called a closed formula or asentence
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 67 / 120
-
Example: Formulas
Example (open formulas)
P (x)
f(y) > c+ f(x)
P (y) ∨ x > cx > y → ¬∀x(x > y)∀xP (x) ∨ x > c (!)
Example (sentences)
∀xx > c∀x∀y(x > y∨y > x∨x = y)∃xP (x)∃x(P (x) ∨ x > d)∃x(P (x)→ ∀y(y + c > x))
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 68 / 120
-
Operator precedence in predicate logic
∀ and ∃ are stronger than all boolean operators∀xR(x, y) ∧ S(x) means (∀xR(x, y)) ∧ S(x)∃xR(x, y)→ S(y) means (∃xR(x, y))→ S(y)
functions and predicates are stronger than quantifiers
∀x∀yx+ y = y + x means ∀x∀y(x+ y = y + x)otherwise, it would not be a formula anymore: (∀x∀yx) + y = y + xin prefix notation, this is obvious: ∀x∀y = (+(x, y),+(y, x))
functions are stronger than predicates
x+ y > c+ d means (x+ y) > (c+ d)
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 69 / 120
-
Exercise: syntax of predicate logic
Determine if the following are
(ground) terms,
(ground) atoms,
formulas,
sentences,
nonsense.
Determine which appearances of variables are bound and which are free.
a) x+ y
b) x+ y > c
c) P (c, d)
d) x > P (d)
e) ∀x(x+ c > x)f) ∀x > (+(x, c), x)g) ∀x, y(x > y)h) ∃x∃y(x+ y)
i) P (∀x(x = x))j) x > y ∧ x+ yk) ∀x(x > c ∨ c > x) ∨ x = cl) c > f(d)
m) P (P (x))
n) f(f(x))
o) ∀x∀y(P (x) > P (y))p) ∃xP (x)→ ∀xP (x)
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 70 / 120
-
First-order semantics: interpretation
An interpretation I gives meaning to the symbols of a formal language.determines the universe or domain
assigns to every n-ary function symbol f an n-ary function fI overthe universe
assigns to every n-ary predicate symbol n-ary relation RI over theuniverse
The interpretation is extended to complex terms in the natural way: for aterm t = f(t1, . . . , tn), t
I is obtained by
recursively interpreting the terms t1, . . . , tn
and finally the interpretation fI
tI = fI(tI1 , . . . , tIn)
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 71 / 120
-
Example: interpretation
ϕ = ∀xR(x, f(x))
Example: Interpretation I with people domain
Universe ∆I : P = {Alice,Bob,Clara,Don}Function fI : married-toP = {Alice 7→ Bob, Bob 7→ Alice, Clara 7→Don, Don 7→ Clara}Relation RI : likesP = {(Alice,Bob), (Alice,Clara), (Bob,Alice),(Bob,Don), (Clara,Don), (Don,Alice), (Don,Bob)}I makes ϕ false (because Don does not like Clara)
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 72 / 120
-
Example: interpretation (cont’)
ϕ = ∀xR(x, f(x))
Example: Interpretation J with number domain
Universe ∆J : N = {0, 1, 2, . . .}Function fJ : sN (successor) = {0 7→ 1, 1 7→ 2, . . .}Relation RJ : N, then ϕ is evaluated as falsethe universe∀x∃y(y < x) is true in Z, but false in N.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 73 / 120
-
Exercise: Interpretation
Letϕ = ∀x∀y((¬(x = y) ∧R(x, y))→ ∃z((¬(z = x)) ∧ (¬(z = y)) ∧ P (z)))and I be as follows:
∆I is given by the set of all human beings;
RI = quarrel;
P I = rejoice.
What is ϕI? What is the meaning of ϕI?
Let ψ = ∀x∃yf(x, y) = c and J be as follows:∆I = Z;fI = +Z, i.e. addition for integers;
cI = 0Z, i.e. zero (in the set of integers).
What is ψI? What is the meaning of ψI?
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 74 / 120
-
Interpretation of free variables and open formulas
What happens to free variables?
each free variable is mapped to an element of the domain
similar to variable assignment in propositional logic
each propositional variable mapped to an element of Bextended to complex terms in the natural way
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 75 / 120
-
Interpretation: formal definition
Definition (FOL interpretation)
For a formula ϕ with free variables V , an interpretation I is a triple(∆I , ·I , µ)
∆I is a set,
·I assignsan n-ary function fI over ∆I to each n-ary function symbol f(including constants),an n-ary relation RI over ∆I to each n-ary predicate R.
µ : V → ∆I assigns an element of ∆I to each free variable.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 76 / 120
-
First-order semantics: model
Definition (model)
An interpretation I = (∆I , ·I , µ) satisfies a formula ϕ (is a model for ϕ,I |= ϕ) if the following holds:
ϕ = P (t1, . . . , tn) is an atom and ((µ(t1))I , . . . , (µ(tn))
I) ∈ P I ,ϕ is a formula involving logical operators (e.g., ϕ = ¬ϕ1,ϕ = ϕ1 ∧ ϕ2) and evaluates to > according to the truth table,ϕ = ∀xψ(x), and for every x ∈ ∆I , ψ(x) evaluates to >ϕ = ∃xψ(x), and there is an x ∈ ∆I for which ψ(x) evaluates to >
Definition (logical implication)
A formula ϕ is the logical implication of a set of formulas Φ, Φ |= ϕ, ifevery model of Φ is also a model of ϕ.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 77 / 120
-
Exercise: interpretations
For each of the following sentences, find one interpretation that makesthem true and one that makes them false.
a) ∀x∀y(R(x, y)→ ∃z(R(x, z) ∧R(z, y)))b) ¬∃x(f(x) = c)c) ∀x∀y(f(x) = f(y)→ x = y)
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 78 / 120
-
FOL in algebra
Example (field axioms)
Closure under addition ∀x∀y∃z(x+ y = z)Associativity of addition ∀x∀y∀z((x+ (y + z)) = ((x+ y) + z))Commutativity of addition ∀x∀y(x+ y = y + x)Neutral element for addition ∀x(x+ 0 = x)Inverse element for addition ∀x∃y(x+ y = 0)(same for multiplication)
Distributivity of multiplication over addition∀x∀y∀z(x · (y + z) = (x · y) + (x · z))
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 79 / 120
-
Why “first-order”?
first-order quantification of elements (∃xP (x))second-order quantification of predicates (∃P∀xP (x))
third-order quantification of predicates over predicates (∃R∀P (R(P ))). . .
first-order logic suffices for rational numbers (; algebra)
second-order is needed for real numbers (; analysis)
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 80 / 120
-
Formalisation in second-order logic
Definition (Dedekind completeness)
A set M is Dedekind complete if every non-empty subset S ⊆M with anupper bound has a least upper bound.
S = {x | x · x ≤ 2}. Least upper bound of S:√
2
Example (Dedekind completenes in SOL)
∀S 〈[∃xS(x) ∧ ∃x∀y(S(y)→ y < x)]→∃x[∀y(S(y)→ y ≤ x) ∧ ∀z(z < x→ ∃t(z < t ∧ S(t)))]〉
“For every set S the following holds: if S has at least one member andthere exists an x that is greater than every member y of S, then there alsoexists an x that is greater (or equal) than every member y of S and forevery z that is smaller than x, there a t that is greater than z and in S.”
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 81 / 120
-
Translating natural language into FOL
FOL is more powerful in expressingnatural language than PL . . .
Chickens revisited
Some chickens cannot fly.∃x(C(x) ∧ ¬F (x))All chickens are birds.∀x(C(x)→ B(x))Some birds cannot fly.∃x(B(x) ∧ ¬F (x))
. . . but reasoning requires moreattention than for PL.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 82 / 120
-
Exercise: translation of natural language into FOL
Using
the unary predicates Student, Professor, and Course, and
the binary predicates likes, supervises, teaches,
translate the following sentences into FOL:
a) Every student likes some professor.
b) Every professor likes every student.
c) Students are only supervised by professors.
d) Every professor teaches at least two courses.
e) Each professor only supervises students that like him.
f) There is a course that is only taught by one professor.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 83 / 120
-
Outline
1 propositional and first-order logic
1 syntax and semantics of propositional logic2 reasoning
1 resolution2 tableaus
3 syntax and semantics of first-order logic4 reasoning
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 84 / 120
-
Resolution in first-order logic
How can the resolution principle be transferred from PL to FOL?
Example (naive resolution in FOL)
∀x(H(x)→ ∃yM(x, y)) H(c)
?
Difficulties:
contradictions between quantifiers:∀xϕ(x),∀x¬ϕ(x) vs. ∃xϕ(x),∃x¬ϕ(x)interaction of variables and constants
generation of CNF in the presence of quantifiers
Approach:
elimination of existential quantification
replacement of variables with terms to make atoms equal
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 85 / 120
-
Negation normal form
Similar to propositonal logic: allow negation only for atoms
1 eliminate → and ↔ϕ→ ψ ; ¬ϕ ∨ ψϕ↔ ψ ; (ϕ ∧ ψ) ∨ (¬ϕ ∧ ¬ψ)
2 apply de Morgan rules and their equivalents for quantifiers
¬(ϕ ∧ ψ) ; ¬ϕ ∨ ¬ψ¬(ϕ ∨ ψ) ; ¬ϕ ∧ ¬ψ¬∀xϕ ; ∃x¬ϕ¬∃xϕ ; ∀x¬ϕ
3 remove double negation
¬¬ϕ ; ϕ
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 86 / 120
-
Prenex normal form: separation of quantifiers
Definition (prenex normal form)
A formula is in PNF if it has the shape Q1x1 . . . Qnxnϕ(x1, . . . , xn) with
prefix Q1x1 . . . Qnxn mit Qi ∈ {∀, ∃}matrix quantifier-free formula ϕ with variables x1 . . . xn.
Algorithm for transformation into PNF:
1 rename variables so they are distinct
2 move quantifiers to the front, maintaining original order
Example (PNF)
people have mother and father ∀x(H(x)→ ∃yM(x, y) ∧ ∃yF (x, y))transform into NNF ∀x(¬H(x) ∨ ∃yM(x, y) ∧ ∃yF (x, y))replace second y with z ∀x(¬H(x) ∨ ∃yM(x, y) ∧ ∃zF (x, z))move quantifiers to the front ∀x∃y∃z(¬H(x) ∨M(x, y) ∧ F (x, z))
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 87 / 120
-
Skolem normal form: elimination of existential quantifier
Idea: replacement of existentially quantified variables with terms
Example (Skolemisation)
”There is a president.“∃xP (x) ; P (c) c is new!
”Every human being has a mother.“∀x∃y(H(x)→M(x, y)) ; ∀x(H(x)→M(x, f(x))) f is new!
Definition (Skolemisation)
For a formula ϕ = ∀x1 . . . ∀xn∃yϕ(x1, . . . , xn, y) in PNF, the Skolemnormal form is obtained by replacing each existentially quantified variable,which is in the scope of n universal quantifiers, by a new n-ary functionsymbol f : ∀x1 . . . ∀xnϕ(x1, . . . , xn, f(x1, . . . , xn))
A formula ϕ and its SNF are not equivalent, but equisatisfiable.All variables are universally quantified ; ∀x not needed anymore.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 88 / 120
-
Exercise: Skolem normal form
Transform the following formulas into SNF:
a) ∀x(∃yR(x, y) ∧ ∃y¬R(x, y)) ∧ ∀xR(x, x) ∧ ∃y∃z¬R(y, z)b) ∃x∀y(R(x, y)∨R(y, x))∧¬∀y¬(R(y, y)∧¬R(y, f(y)))∨¬(∀xR(x, x)→∃xR(x, x))
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 89 / 120
-
SNF: Optimisation
Computing PNF first and Skolemizing afterwards has drawbacks
Example (unnecessarily complex Skolem function)
∀xP (x)∧∃yQ(y) ; ∀x∃y(P (x)∧Q(y)) ; ∀x(P (x)∧Q(f(x)))Since y does not appear in the scope of ∀x, y could be replaced by aconstant rather than a unary function.
Standard procedure:
1 negation normal form
eliminate → and ↔apply de Morgan ruleseliminate double negation
2 rename variables
3 prenex normal form
4 Skolem normal form
More complex procedure leading tosimpler Skolem functions:
1 NNF
2 miniscoping
3 rename variables
4 Skolemise
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 90 / 120
-
Miniscoping
Goal: minimise the scope of quantifiers while maintaining equivalence
Definition (miniscoping)
Assumption: x occurs freely in ϕ and ψ, but not in χ
Qx(ϕ ∧ χ) ; Qxϕ ∧ χ for Q ∈ {∀,∃}Qx(ϕ ∨ χ) ; Qxϕ ∨ χ for Q ∈ {∀,∃}∀x(ϕ ∧ ψ) ; ∀xϕ ∧ ∀xψ∃x(ϕ ∨ ψ) ; ∃xϕ ∨ ∃xψ
Example (miniscoping)
Miniscoping:∀x∃y(P (x) ∧Q(y)) ; ∀x(P (x) ∧ ∃yQ(y)) ; ∀xP (x) ∧ ∃yQ(y)Skolemisation:∀xP (x) ∧ ∃yQ(y) ; ∀xP (x) ∧Q(c)
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 91 / 120
-
Preprocessing for FOL resolution: overview
Standard:
1 negation normal form
2 rename variables
3 prenex normal form
4 Skolem normal form
5 drop ∀6 conjunctive normal form
as for propositional logic
Alternative:
1 negation normal form
2 miniscoping
3 rename variables
4 Skolemize
5 drop ∀6 conjunctive normal form
as for propositional logic
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 92 / 120
-
Resolution and variables
Example (FOL resolution)
formula ∃xH(x) ∧ ∀x(H(x)→ ∃yM(x, y))NNF ∃xH(x) ∧ ∀x(¬H(x) ∨ ∃yM(x, y)) → eliminatedSNF ∀x(H(c) ∧ (¬H(x) ∨M(x, f(x)))) ∃ eliminatedCNF H(c) ∧ (¬H(x) ∨M(x, f(x))) FOL atoms instead of PL variables
H(c) ¬H(x),M(x, f(x))
M(c, f(c)) [x/c]
find variable assignment that makes atoms syntactically equal
replace variables in entire clause
create resolventJan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 93 / 120
-
Substitutions
Definition (substitution)
A substition is a mapping from variables to terms.
Example (substitution)
The substitutionσ = ([x/f(y)], [y/m(c, d)])
maps x to f(y) and y to m(c, d).Sequence is important:
([x/y], [y/z]) is different from ([y/z], [x/y])
σ(g(x)) = g(f(m(c, d)))
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 94 / 120
-
Unifiers
Definition (unifier)
A unifier is a substitution mapping two formulas to the same formula.
Example (unifier of R(a, y) and R(x, f(a)))
ϕ = R(a, y) ψ = R(x, f(a)) σ = ([x/a], [y/f(a)])σ(ϕ) = R(a, f(a)) = σ(ψ)
Resolution of C1 und C2 is possible if two atoms ϕ,ψ and a substitution σexist such that
ϕ ∈ C1 and ¬ψ ∈ C2σ is unifier of ϕ and ψ.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 95 / 120
-
Unification: variable renaming and occur check
Example (one variable appears in several clauses)
problem no unifier for P (x, c) and P (d, x)
solution rename variables so they are disjointP (x, c), P (d, y), σ = ([x/d], [y/c])
Example (mapping from x to f(x))
problem unification of P (x) and P (f(x)) results in σ = [x/f(x)]
solution occur check: x cannot be mapped to a term containing x
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 96 / 120
-
Exercise: unification
Let
w, x, y, z be variables,
c, d be constant symbols,
f be a unary and g be a binary function symbol,
N and P be unary, R be a binary, and S be a ternary relation symbol.
Try to find unifiers for the following pairs of atoms.
a) P (x) and P (f(g(y, z)))
b) P (x) and N(f(x))
c) R(x, f(x)) and R(f(y), z)
d) R(x, f(x)) and R(f(y), y)
e) R(x, f(x)) and R(f(c), d)
f) S(x, f(g(x, y)), g(x, f(d)) and S(g(c, d), f(z), g(g(c, y), w))
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 97 / 120
-
Most general unifiers
Example: several possible unifiers
P (x), R(x) ¬P (y) ¬R(c)
R(x) R(d)
2
[y/x]
[x/c]
[x/d][y/d]
problem some unifiers prevent resolution
solution most general unifier (MGU): only substitute as much asneeded
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 98 / 120
-
Unification algorithm
input: terms s, toutput: mgu(s, t), if s and t are unifiable
”not unifiable“, otherwise
1: σ := ()2: while σ(s) 6= σ(t) do3: let i be the first position where σ(s) and σ(t) differ4: if σ(s)|i oder σ(t)|i is a predicate symbol then5: output
”not unifiable“
6: else if neither σ(s)|i nor σ(t)|i is a variable then7: output
”not unifiable“
8: else9: let x be the variable, y the other term
10: if x is proper subterm of y then11: output
”not unifiable“
12: else13: σ := σ · ([x/y])14: output σ
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 99 / 120
-
Unification: example
ϕ = R(f(c), z, g(f(c), f(g(z, f(c)))))ψ = R(f(c), z, g(f(c), f(g(z, f(c)))))
x / f(c) occur checku / z MGUw / f(c)y / g(z, f(c))
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 100 / 120
-
Exercise: unification algorithm
Let
v, w, x, y, z be variables,
c, d be constants,
f be a unary, g be a binary, and h be a ternary function symbol,
S and T be ternary relation symbols.
Use the unification algorithm to find most general unifiers for the followingpairs of terms:
a) S(x, f(y), g(z, d)) and S(c, f(x), g(f(z), z))
b) T (x, f(x), h(f(y), z, d)) and T (c, f(y), h(z, f(v), w))
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 101 / 120
-
Example: Halloween
1 Tim buys a pumpkin.
∃x(Buys(tim, x) ∧ Pumpkin(x))2 Whoever buys a pumpkin eats it or carves a Jack-O-Lantern.
∀x∀y((Buys(x, y) ∧ Pumpkin(y))→ (Eats(x, y) ∨ Carves(x, y)))3 Children don’t eat pumpkins.
∀x(Child(x)→ (∀y(Pumpkin(y)→ ¬Eats(x, y))))4 Conjecture: if Tim is a child, then he carves a Jack-O-Lantern.
Child(tim)→ ∃xCarves(tim, x)
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 102 / 120
-
Step 1: preprocessing
1 negation
2 renaming of variables
3 replacement of ϕ→ ψ by ¬ϕ ∨ ψ4 De Morgan rules
5 double negation
6 prenex normal form . . .
¬(¬((∃x(Buys(tim, x) ∧ Pumpkin(x))) ∧(∀y∀z(¬(¬Buys(y, z) ∨ ¬Pumpkin(z)) ∨ (Eats(y, z) ∨ Carves(y, z)))) ∧(∀u(¬Child(u) ∨ (∀w(¬Pumpkin(w) ∨ ¬Eats(u,w)))))) ∧¬(¬¬Child(tim) ∧ ¬∀t¬Carves(tim, t)))
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 103 / 120
-
Step 2: Skolem normal form and clauses
1 prenex normal form
2 Skolemisation
3 drop universal quantifiers
4 CNF
∃x∀y∀z∀u∀w∀t(Buys(tim, p) ∧Pumpkin(p) ∧(¬Buys(y, z) ∨ ¬Pumpkin(z) ∨ Eats(y, z) ∨ Carves(y, z)) ∧(¬Child(u) ∨ ¬Pumpkin(w) ∨ ¬Eats(u,w)) ∧Child(tim) ∧¬Carves(tim, t))¬Carves(tim, t)
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 104 / 120
-
Step 3: resolution
¬Child(u),¬Pumpkin(w),¬Eats(u,w) Child(tim)
Pumpkin(p)
¬Buys(y, z),¬Pumpkin(z),Eats(y, z),Carves(y, z)
Buys(tim, p)
¬Carves(tim, t)
¬Pumpkin(w),¬Eats(tim, w)
¬Eats(tim, p)
¬Buys(tim, p),¬Pumpkin(p),Carves(tim, p)
¬Buys(tim, p),Carves(tim, p)
Carves(tim, p)
2
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 105 / 120
-
First-order resolution: exercise
Prove the following conjecture using resolution:
1 All dogs howl at night.
2 Anyone who has any cats will not have any mice.
3 Light sleepers do not have anything which howls at night.
4 John has a cat or a dog.
5 Conjecture: If John is a light sleeper, then John does not have anymice.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 106 / 120
-
Incompleteness of algorithm described so far
Example (Resolution of {P (w), P (x)} and {(¬P (y),¬P (z)})P (w), P (x) ¬P (y),¬P (z)
P (t),¬P (u)
[w/y]
¬P (r),¬P (s)
[t/y]
...
reason:
redundant literals
∀x∀y(P (x) ∨ P (y))is equivalent to ∀xP (x)
solution:
eliminate redundancy
perform unification within aclause
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 107 / 120
-
Factors
Definition (Factor)
Let C = {L1, L2, L3, . . .}; σ be MGU of L1 and L2.Then σ(C) is a factor of C.
Example (factors)
{P (y)} is a factor of {P (x), P (y)}.{P (c)} is a factor of {P (x), P (c)}.{P (c), R(c, y)} is a factor of {P (x), P (c), R(x, y)}.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 108 / 120
-
Factorisation
New rule:
Derive C2 from C1 if C2 is factor of C1.
Example (factorisation)
P (w), P (x) ¬P (y),¬P (z)
P (x)
[w/x]
¬P (y)[z/y]
2 [x/y]
Factorisation can be performed by introducing a new rule or by integratingit with resolution, i.e. checking the resolvent for factors.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 109 / 120
-
Properties of the FOL resolution algorithm
Theorem (soundness of FOL resolution)
K(ϕ) `∗ 2 implies unsatisfiability of ϕ.
Theorem (refutation completeness of FOL resolution)
If ϕ is unsatisfiable, then K(ϕ) `∗ 2 holds.
Termination?
Does the algorithm terminate for every input?
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 110 / 120
-
Termination of FOL Resolution
Example (non-terminating set of clauses)
P (x),¬Q(f(x)) ¬P (f(y)), Q(f(y))
¬Q(f(f(y))), Q(f(y))
[x/f(y)]
P (x),¬Q(f(f(x)))
[y/x]
¬Q(f(f(f(y)))), Q(f(y))
[x/f(y)]
P (x),¬Q(f(f(f(x))))
[y/x]
...
Since the satisfiability problem for FOL formulas is undecidable,termination cannot be achieved.
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 111 / 120
-
Tableau algorithm for FOL
basic algorithm remains unchanged
rulesclash triggers
no preprocessing necessary
. . . but NNF makes things easier
additional rules to deal with quantifiers
∀-rule∃-rule
definition of clash extended to first-order formulas
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 112 / 120
-
Additional tableau rules for FOL
∃ If ∃xϕ(x) ∈ Sand there is no ground term t with ϕ(t) ∈ Sthen S := S ∪ ϕ(c) for a new constant symbol c
use Skolemisation to eliminate ∃analogous for ¬∀xϕ(x): add ¬ϕ(c)only constants are needed (no function symbols of higher arity)
∀ quantifiers are processed previously by ∀-rule
∀ If ∀xϕ(x) ∈ Sand t is an arbitrary ground termthen S := S ∪ ϕ(t)
analogous for ¬∃xϕ(x): add ¬ϕ(t)applicable to infinite number of ground terms
always applicable!termination cannot be ensured
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 113 / 120
-
Example: Halloween tableau
ϕ = ∃x(Buys(tim, x) ∧ Pumpkin(x)) ∧∀x∀y(Buys(x, y) ∧ Pumpkin(y) → Eats(x, y) ∨ Carves(x, y)) ∧∀x(Child(x) → (∀y(Pumpkin(y) → ¬Eats(x, y)))) ∧¬(Child(tim) → ∃xCarves(tim, x))
1 ϕ
2 ∃x(Buys(tim, x) ∧ Pumpkin(x)) 1: ∧3 ∀x∀y(Buys(x, y) ∧ Pumpkin(y) → Eats(x, y) ∨ Carves(x, y))4 ∀x(Child(x) → (∀y(Pumpkin(y) → ¬Eats(x, y))))5 ¬(Child(tim) → ∃xCarves(tim, x))6 Child(tim) 5: ¬ →7 ¬∃xCarves(tim, x))8 Buys(tim, p) ∧ Pumpkin(p) 2: ∃(x/p)9 Buys(tim, p) 8: ∧
10 Pumpkin(p)
11 Buys(tim, p) ∧ Pumpkin(p) → Eats(tim, p) ∨ Carves(tim, p) 3: ∀(x/tim, y/p)12 Child(tim) → (Pumpkin(p) → ¬Eats(tim, p)) 4: ∀(x/tim, y/p)13 ¬Carves(tim, p) 7: ¬∃(x/p)Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 114 / 120
-
Example: Halloween tableau (cont’)
6 Child(tim)9 Buys(tim, p)10 Pumpkin(p)11 (Buys(tim, p) ∧ Pumpkin(p)) → (Eats(tim, p) ∨ Carves(tim, p))12 Child(tim) → (Pumpkin(p) → ¬Eats(tim, p))13 ¬Carves(tim, p)14 ¬Child(tim) Pumpkin(p) → ¬Eats(tim, p) 12: →15 ¬Pumpkin(p) ¬Eats(tim, p) 14: →16 ¬(Buys(tim, p) ∧ Pumpkin(p)) Eats(tim, p) ∨ Carves(tim, p) 11: →17 ¬Buys(tim, p) ¬Pumpkin(p) 16: ¬∧18 Eats(tim, p) Carves(tim, p) 16: ∨
6 10 9 10 15 13
all columns contain a clash
ϕ is unsatisfiable
premises imply conjecture
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 115 / 120
-
Exercise: First-order tableau
Prove that John does not have any mice using a tableau.
ϕ = ∀x(D(x)→ HAN(x)) ∧∀x(∃y(H(x, y) ∧ C(y))→ ¬∃z(H(x, z) ∧M(z))) ∧∀x(L(x)→ ¬∃y(H(x, y) ∧HAN(y))) ∧∃x(H(j, x) ∧ (C(x) ∨D(x))) ∧¬(L(j)→ ¬∃x(H(j, x) ∧M(x)))
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 116 / 120
-
Problems with naive tableau algorithm
efficiency depends highly on choice of terms for ∀-rulewe intuitively used the right constants in our examplesalgorithm needs to try all possible combinationsassume a vocabulary with 4 constant symbols a formula with 5universally quantified variables: 45 = 1024 possible applicationsas soon as function symbols are available, the number is infinite
heuristics: start with ground terms that appear in other atoms
modify algorithm itself: tableau algorithm with unification
delay substitutionuse unification to find substition that leads to a clash
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 117 / 120
-
Tableau algorithm with unification
∀u If ∀xϕ(x) ∈ Sthen S := S ∪ ϕ(y) for a new variable symbol y
y is a free variable!always applicable
∃u If ∃xϕ(x) ∈ Sand there is no term t with ϕ(t) ∈ Sand ϕ contains the free variables y1, . . . , ynthen S := S ∪ ϕ(f(y1, . . . , yn)) for a new n-ary function symbol f
complex Skolem functions are needed
S If there are formulas ϕ and ψ in one branch such thatthere exists a unifier σ for the free variables with σ(ϕ) = ¬σ(ψ)then apply σ to the entire tableau
not only the current branch!we have to act as if we had used σ from the startfree variables have to be replaced everywhere
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 118 / 120
-
Example: tableau with unification
ϕ = ∀x∃y(m(x, y) ∨ f(x, y)) ∧ ∀z(¬m(c, z) ∧ ¬f(c, z))
1 ϕ
2 MM ∀x∃y(m(x, y) ∨ f(x, y)) MM 1: ∧3 ∀z(¬m(c, z) ∧ ¬f(c, z))4 ∃y(m(c, y) ∨ f(c, y)) 2: ∀u(x/r)5 m(c, p(c)) ∨ f(c, p(c)) 4: ∃u(y/p(r))6 ¬m(c, p(c)) ∧ ¬f(c, p(c)) 3: ∀u(z/s)7 ¬m(c, p(c)) 6: ∧8 ¬f(c, p(c))9 m(c, p(c)) f(c, p(c)) 5: ∨
S ([r/c], [s/p(c)])
7 8
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 119 / 120
-
Propositional and first-order logic: summary
PL: ∧,∨,¬,→,↔limited expressivity
resolution and TA terminate
best algorithm depends on context
FOL: also ∀, ∃, variables, functions, relationshigher expressivity
both resolution and TA can be adapted
reasoning more complex
Skolemisationfactorsunification
termination cannot be ensured
Jan Hladik (DHBW Stuttgart) Logic Wintersemester 2015/16 120 / 120