Chapter 6 Logical Reasoning Xiu-jun GONG (Ph. D) School of Computer Science and Technology, Tianjin...

38
Chapter 6 Logical Reasoning Xiu-jun GONG (Ph. D) School of Computer Science and Technology, Tianjin University [email protected] http:// cs.tju.edu.cn/faculties/gongxj/course/ai /

Transcript of Chapter 6 Logical Reasoning Xiu-jun GONG (Ph. D) School of Computer Science and Technology, Tianjin...

Chapter 6

Logical Reasoning

Xiu-jun GONG (Ph. D)School of Computer Science and Technology, Tianjin

University

[email protected]

http://cs.tju.edu.cn/faculties/gongxj/course/ai/

Outline Intro to logic reasoning Preparation for resolution

Stand form clauses (9 steps) Substitution and unify Control strategies

Resolution reasoning In propositional logic In Predicate logic In particular interrogative sentence

Summary

Logic is the Calculus of Computer Science

The central role of logic in computer science is comparable to the role of differential equations in the natural sciences

Intro to logic Logic is the study of the principles of valid

demonstration and inference. Consistency, which means that none of the

theorems of the system contradict one another. Soundness, which means that the system's rules

of proof will never allow a false inference from a true premise. If a system is sound and its axioms are true then its theorems are also guaranteed to be true.

Completeness, which means that there are no true sentences in the system that cannot, at least in principle, be proved in the system.

Classifications of logic Informal logic is the study of natural

language arguments. Formal logic is the study of inference with

purely formal content Symbolic logic is the study of symbolic

abstractions that capture the formal features of logical inference

Mathematical logic is an extension of symbolic logic into other areas(model theory, proof theory, set theory, and recursion theory)

Symbolic logic Two languages

Propositional logic Predicate logic

Components Syntax Rules Semantic

Syntax Elements

Atoms: {A,B, …, T,F} Literal: atoms and a sign in front of them Connectives: , , , and Sentences: Syntax of well-formed formula (wff),

Any atom is a wff. If w1 and w2 are wffs, so are w1 w2, w1 w2, w1 w2, w1. There are no other wffs.

Universal sign: x Quantifier sign: x

Inference Reasoning is the cognitive process of

looking for reasons for beliefs, conclusions, actions or feelings.

Inference is the act or process of deriving a conclusion based solely on what one knows.

Logic reasoning Deduction: determining the conclusion Induction: determining the rule. Abduction: determining the precondition.

Semantics Semantics

associating elements of a logical language with elements of a domain of discourse

Interpretation the proposition associated with an atom (value)

Propositional Truth Table Given the values of atoms under some interpretation, use a

truth table to compute a value for any wff under that same interpretation.

Standard Form Clauses (1) Clause: a disjunction of literals.

Conjunctive Normal Form: CNF

Disjunctive Normal Form: DNF

CNFDNF

edba ~

)bf(~)edba(~)cb~a(

Standard Form Clauses (2) Prenex Normal Form: A wff of predicate

logic is in prenex normal form, iff all its quantifiers are clustered at the left no quantifier is negated the scope of each quantifier extends to the end

of the wff no two quantifiers quantify the same variable every quantified variable occurs in the matrix

of the wff

Standard Form Clauses (3) Skolem Standard Form:

A formula is in SSF if it is in conjunctive prenex normal form with only universal first-order quantifiers

Removing existential quantifiers from formal logic statements

Standard Form Clauses: Clauses in SSF

P(c)

Convert WFF to SFCs (1)1. Eliminate implication signs, >

2. Reduce the scopes of ~

3. Rename variables

qp~qp

QPQP

QPQP

~~)(~

~~)(~ laws sMorgan' DePP )(~~ :law negative double

)(~)()()(~

)(~)()()(~

XPXXPX

XPXXPXlawconversionQuantifies

)))Y,X(r~)Y,X(q)(Y()Y,X(p~)Y)((X(

)))Z,X(r~)Z,X(q)(Z()Y,X(p~)Y)((X(

Convert WFF to SFC (2)4. Forward quantifiers

5. Skolem transfer Eliminate existential quantifiers

))),(~),()((),(~))((( ZXrZXqZYXpYX

)))Z,X(r~)Z,X(q()Y,X(p)(~Z)(Y)(X(

)c(president)X(president)X(

)()()())()(( ZrYqXpZYX

))(())(()()( XgrXfqXpX

Convert WFF to SFC (3)6. Get CNF with Skolem standard form

7. Eliminate universal quantifiers

))(())(()(()( XgrXfqXpX )))(())((()))(()(()( XgrXfqXgrXpX

)))(())((()))(()(( XgrXfqXgrXp

Convert WFF to SFC (4)8. Get clauses

9. Rename variables again

))}(())(()),(()({

)))(())((()))(()((

XgrXfqXgrXp

XgrXfqXgrXp

))}(())(()),(()({ ygryfqXgrXp

An example)))Y,X(r)Y,X(q)(Y(~)Y,X(p)Y)((X(

)))Y,X(r~)Y,X(q)(Y()Y,X(p~)Y)((X(

)))Y,X(r)Y,X(q)(~Y(~)Y,X(p)Y()(~X(

)))Z,X(r~)Z,X(q)(Z()Y,X(p~)Y)((X(

)))Z,X(r~)Z,X(q()Y,X(p)(~Z)(Y)(X(

)))Z,X(r~)Z,X(q())X(f,X(p)(~Z()X(

)))X(g,X(r~))X(g,X(q())X(f,X(p(~)X(

))))X(g,X(r~))X(f,X(p(~)))X(g,X(q))X(f,X(p)((~X(

)))X(g,X(r~))X(f,X(p(~)))X(g,X(q))X(f,X(p(~

))}(,(~))(,()),(,(~))(,({~ YgYrYfYpYgYrYfYp

Resolution reasoning of propositional logic Resolution is a rule of inference leading

to a refutation theorem-proving technique for sentences in propositional logic and first-order logic.

Procedure Choose two clauses that have exactly one pair

of literals that are complementary Produce a new clause by deleting the

complementary literals and combining the remaining literals

CB

BA

CA

General form of resolution'11 CPC '

22 CP~C

'2

'121 CC)C,C(R

'2

'1

'2

'1 CC)CP(~)CP(

Proof: Show that if C1 and C2 are true for explanation I, then R is true for I.

1. Under I, if P=false, then C1’ =true, so R=C1’VC2’=true

2. Under I, if P=true, then C2’ =true, so R=C1’VC2’=true

Resolution on propositional logic Convert all the expressions (facts, rules

and the negation of conclusion) into standard form clauses

Resolve on all the clauses until reaches contradict (nil)

resolution refutation

Example TQTSRQPP ,,, Conditions:

Conclusion: R

RQP ~~)2(

QS ~)3(

QT ~)4(

R~)6(

P)1(

)(~)(~)~(~ QTQSQTS

T)5(

QP ~~)7( Q~)8(

T~)9(NIL)10(

(6) (2)

(7) (1)

(8) (4)

(9) (5)

Q~P~

Q~

T~

NIL

(6) (2)

(1)

(4)

(5)

Example cont.

RQP ~~)2(

QS ~)3(

QT ~)4(

P)1(

T)5(

)2)(1(~)6( RQ

)5)(4()7( Q

)7)(6()8( R

Lucky enough

Substitution and Unify Preparing for predicate logic resolution Universal quantifications for all variables.

If two clauses have matching but complementary literals, it is possible to resolve them

))(,,( 11 kn k 1

literalClause

xyf /)(

Substitution Any substitution can be represented by a

set of ordered pairs}/,..../,/{ 2211 nn xtxtxt

variableaisxWhere i

functionor constant variable,)( abemayxy ii

on.substituti theof scope thethroughout variablethe

of occurrenceevery for dsubstitute is term/

i

i

t

xthatmeansxt ii

F predicateon ofon substituti of results theis F

Example

)y,x(gF

)z,y,x(PF

zu,y)b(f,xa

2

1

))b(f,a(gF

)u),b(f,a(PF

2

1

Unify F1 and F2 are predicate formula ,θ is a

substitution. if F1θ=F2θ,then θ is the Unifier of F1 and F2 P(c,y,b)and P(x,a,b), θ={c/x,a/y} P(x,y,b)and P(z,u,b) θ={z/x,u/y} other else? P(f(y),a)and P(x,a) θ={f(y)/x}

Three types of unifier Constant/variable —— 变量实例化 Variable/variable —— 变量一致化 Function/variable —— 变量函数化

Most General Unifier: MGU σ is a MGU between F1 and F2 if for any θ be one of unifiers between F1 and F2, there exists a λ such that θ=σ·λ

i.e. F1 =P(x), F2 =P(f(y)) θ1 ={f(a)/x,a/y},θ2 ={f(b)/x,b/y} θ1 ,θ2 are unifiers , but not MGUs σ = {f(y)/x}is a MGU, where

θ1=σ· {a/y}, λ= {a/y} θ2=σ· {b/y}, λ= {b/y}

Algorithms looking for a MGU Steps

Find out the difference sets of variables between two clauses

Identify the substitutions for each set

Ex1. F1= P(x,y,z) F2= P(x,f(a),h(b)) Difference set: D1={y,f(a)}, D2={z,h(b)}

MGU= {f(a)/ y, h(b)/z}

Ex2. F1= P(x), F2= P(y) Difference set: D={x,y} MGU={x/y} or {y/x}

Resolution Reasoning of Predicate Logic F1 and F2 are clauses, P1 in F1 and ~ P2 in F2 are

literals such that P1 and P2 have a MGU μ, then These two clauses have a resolvent ρ. The resolvent is obtained by applying the substitution μ to

the union of F1 and F2, leaving out the complementary literals.

Ρ=[(F1-{P1}) ∨(F1-{ ~ P2}) ] μ

Example Problem

Marcus is a man Caesar is a ruler A person trying to assassinate its ruler is not loyal Marcus want to assassinate Caesar

Step1 Convert to logic expression man (marcus) ruler (caesar) person(X) rule(Y) tryassassinate(X,Y)∧ ∧→~ loyalto(X,Y) tryassassinate (marcus, caesar) man(X) → person(X)

Show that Marcus is not loyal to Caesar

~loyalto(marcus,caesar)

Example cont. Step2, build standard form clauses (1) man(m)

(2) ruler(c)

(3) ~ person(X)∨ ~ ruler(Y)∨ ~ trya (X,Y)∨ ~ loyalto(X,Y)

(4) trya (m,c)

(5) ~ man (Z) person(Z)∨(6) loyalto(m,c)

Step3, resolution reasoning(7) ~ person(m)∨ ~ ruler(c)∨ ~ trya (m,c) (6) (3) {m/X, c/Y}

(8) ~ person(m)∨ ~ ruler(c) (7) (4)

(9) ~ person(m) (8) (2)

(10) ~ man (m) (9) (5) {m/Z}

(11) NIL (10)(1)

Example cont.

)m(man~

6 3

),(~)(~)(~ cmtryacrulermperson Yc,Xm

4

)c(ruler~)m(person~ 2

)m(person~ 5

Zm 1

NIL

Control Strategy (1) Problem

How to pick up clauses to resolve? Quick and completeness

Strategies1. Breadth-first resolution: completeness, time-

consuming2. Unit resolution: with priority with literals3. Input resolution: each resolvent at lease

involves a input clause

Control strategies (2)4. Linear resolution: Start from an initiate clause, then

resolve continue linearly.

(1) ~P ∨S

(2) P ∨Q

(3)~P ∨R

(4)~Q ∨R

(5)~R

(6)Q ∨R (2)(3)

(7)R (6)(4)

(8)NIL (7)(5)

The point is how to choose the initiate clause

Control strategies (3)5. Supported set resolution: for each resolvent, one of

clause must be in “supported set” The supported set includes negation of the conclusion and

its resolvents

(1) ~P ∨S

(2) P ∨Q

(3)~P ∨R

(4)~Q ∨R

(5)~R

R~ RP~

P~ QP

Q RQ~

R R~

NIL

Control strategies (4)6. One occurrence literal deletion

(1) ~P ∨S

(2) P ∨Q

(3)~P ∨R

(4)~Q ∨R

(5)~R

Resolution for Particular Interrogative Sentence Answers for who , what , when , where , how

Known as: pompeian(x)->died(x,70)

pompeian(marcus)

Ask: died(marcus,?) Clause set:

(1) ~pompeian(x) ∨ died(x,70)

(2) pompeian(marcus)

(3) ~died(marcus,t) ∨died(marus,t)

(ever-true expression is added for conclusion)

Example cont.

3 1

txmarcus /79,

)79,marcus(died)marcus(pompeian~ 2

)79,marcus(died

(1) ~pompeian(x) ∨ died(x,70)

(2) pompeian(marcus)

(3) ~died(marcus,t) ∨died(marus,t)

Summary Preparation for resolution

Stand form clauses (9 steps) Substitution and unify Control strategies

Resolution reasoning In propositional logic In Predicate logic In particular interrogative sentence