Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

37
Knowledge Repn. & Reasoning Lec. #6: First-Order Inference UIUC CS 498: Section EA Professor: Eyal Amir Fall Semester 2004

description

Knowledge Repn. & Reasoning Lec. #6: First-Order Inference. UIUC CS 498: Section EA Professor: Eyal Amir Fall Semester 2004. Today. Until now: First-order logic basics Clausal form for FOL Resolution refutation for FOL Application du jour: Temporal Reasoning - PowerPoint PPT Presentation

Transcript of Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Page 1: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Knowledge Repn. & ReasoningLec. #6: First-Order Inference

UIUC CS 498: Section EA

Professor: Eyal AmirFall Semester 2004

Page 2: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Today

• Until now: – First-order logic basics– Clausal form for FOL

• Resolution refutation for FOL

• Application du jour: Temporal Reasoning

• Applications we will not touch– Spatial reasoning, formal verification,

mathematics, planning, NLP, …

Page 3: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Resolution Theorem Proving

• Given:– KB – a set of first-order sentences– Query Q – a logical sentence

• Calling procedure:1. Add Q to KB

2. Convert KB into clausal form

3. Run theorem prover. If we prove contradiction, return T.

Page 4: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Resolution Theorem Proving

1. Add Q to KB

2. Convert KB into clausal form

3. Run theorem prover. If we prove contradiction, return T.

Deduction theorem:

KB Q iff KB Q FALSE

╨ ╨

Page 5: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Resolution Theorem Proving

1. Add Q to KB

2. Convert KB into clausal form

3. Run theorem prover. If we prove contradiction, return T.

Deduction theorem:

KB Q iff KB Q FALSE

╨ ╨

Page 6: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

First-Order Resolution

• Resolution inference rule:

C1: P(t1,…,tk) C1’(t1,…,tk)

C2: P(s1,…,sk) C2’(s1,…,sk)

mgu(<t1,…,tk>,<s1,…,sk>) = {r1,…,rn}

--------------------------------------------

C3: (C1’ C2’) {r1,…,rn}

Page 7: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

First-Order Resolution

• Resolution algorithm (saturation):1. While there are unresolved C1,C2:

(1) Select C1, C2 in KB(2) If C1, C2 are resolvable, resolve them

into a new clause C3(3) Add C3 to KB(4) If C3={ }

return T.

2. STOP

C1: P(t1,…,tk) C1’(t1,…,tk)C2: P(s1,…,sk) C2’(s1,…,sk)mgu(<t1,…,tk>,<s1,…,sk>) = {r1,…,rn}--------------------------------------------C3: (C1’ C2’) {r1,…,rn}

Page 8: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Resolution in Action

)()()(

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

)()()()(

AaBfAc

BfCercwfCezaBfycAa

tfsaxcxa

On board

Negated Query

KB

C1: P(t1,…,tk) C1’(t1,…,tk)C2: P(s1,…,sk) C2’(s1,…,sk)mgu(<t1,…,tk>,<s1,…,sk>) = {r1,…,rn}--------------------------------------------C3: (C1’ C2’) {r1,…,rn}

Page 9: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Resolution in Action

)()()(

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

)()()()(

AaBfAc

BfCercwfCezaBfycAa

sfsaxcxa

On board

Negated Query

KB

C1: P(t1,…,tk) C1’(t1,…,tk)C2: P(s1,…,sk) C2’(s1,…,sk)mgu(<t1,…,tk>,<s1,…,sk>) = {r1,…,rn}--------------------------------------------C3: (C1’ C2’) {r1,…,rn}

Page 10: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

First-Order Resolution

• Resolution algorithm (saturation):1. While there are unresolved C1,C2:

(1) Select C1, C2 in KB(2) If C1, C2 are resolvable, resolve them

into a new clause C3(3) Add C3 to KB(4) If C3={ }

return T.

2. STOP

C1: P(t1,…,tk) C1’(t1,…,tk)C2: P(s1,…,sk) C2’(s1,…,sk)mgu(<t1,…,tk>,<s1,…,sk>) = {r1,…,rn}--------------------------------------------C3: (C1’ C2’) {r1,…,rn}

Page 11: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

First-Order Resolution Rule

(2) If C1, C2 are resolvable, resolve them into a new clause C3

If C1,C2 have two literals l1,l2 with same predicates (P) and opposite polarity, and

If l1= P(t1,…,tk), l2= P(s1,…,sk), unifiable

with mgu (most general unifier) {r1,…,rn},

then… C1: P(t1,…,tk) C1’(t1,…,tk)C2: P(s1,…,sk) C2’(s1,…,sk)mgu(<t1,…,tk>,<s1,…,sk>) = {r1,…,rn}--------------------------------------------C3: (C1’ C2’) {r1,…,rn}

Page 12: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Unification

…P(t1,…,tk),P(s1,…,sk), unifiable with mgu (most general unifier) σ={r1,…rk}

• Substitution: replace vars. by terms– Term: constant, variable, or a function of

terms

• Composition of substitutions

{x/g(w,v)} {w/A,v/f(B,z)} =

{x/g(A,f(B,z),w/A,v/f(B,z)}(P(x) v Q(f(x)) v P(g(B,x)) v P(f(y))) {x/B,y/z}

(P(B) v Q(f(B)) v P(g(B,B)) v P(f(z)))

{x/B,y/z} {x/B,y/z,x/w} {x/B,y/z,z/w}

Page 13: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Unification

• Unification: find a substitution σ for• C1: P(t1,…,tk) C1’(t1,…,tk)• C2: P(s1,…,sk) C2’(s1,…,sk)

such that P(t1,…,tk)σ = P(s1,…,sk)σ

P(A,y,g(x,y)){y/f(A)} = P(z,f(z),g(x,f(w))){z/A,w/A}σ={y/f(A),z/A,w/A}

P(A,y,g(x,y)){y/f(w)} = P(z,f(w),g(x,f(w))){z/A}σ={y/f(w),z/A}

Most general unifier

Page 14: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Unification

• Substitution σ1 more general than σ2 if there is substitution γ such that

σ1 γ = σ2

P(A,y,g(x,y)){y/f(A)} = P(z,f(z),g(x,f(w))){z/A,w/A}σ={y/f(A),z/A,w/A}

P(A,y,g(x,y)){y/f(w)} = P(z,f(w),g(x,f(w))){z/A}σ={y/f(w),z/A}

Most general unifier

Page 15: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Unification

• Substitution σ1 more general than σ2 if there is substitution γ such that

σ1 γ = σ2

σ2={y/f(A),z/A,w/A}

σ1={y/f(w),z/A}

Most general unifier

γ={w/A}

Page 16: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Finding the MGUProcedure MGU(x,y)

1. If x=y, return { }

2. If x or y are vars., return MGUvar(x,y)

3. If x or y are const.,or Len(x)=/=Len(y), return F.

4. σ ← { }; For i ← 1 to Len(x)1. s ← MGU(part(i,x),part(i,y)); if s=F, return F.

2. σ ← compose(σ,s); x ← subst(x,σ); y ← subst(y,σ);

5. Return σ

x = P(A,y,g(x,y)) y = P(z,f(w),g(v,w))

Page 17: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Finding the MGUProcedure MGU(x,y)

1. If x=y, return { }

2. If x or y are vars., return MGUvar(x,y)

3. If x or y are const.,or Len(x)=/=Len(y), return F.

4. σ ← { }; For i ← 1 to Len(x)1. s ← MGU(part(i,x),part(i,y)); if s=F, return F.

2. σ ← compose(σ,s); x ← subst(x,σ); y ← subst(y,σ);

5. Return σ

x = P(A,y,g(x,y)) y = P(z,f(w),g(v,w))

Page 18: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Finding the MGUProcedure MGU(x,y)

1. If x=y, return { }

2. If x or y are vars., return MGUvar(x,y)

3. If x or y are const.,or Len(x)=/=Len(y), return F.

4. σ ← { }; For i ← 1 to Len(x)1. s ← MGU(part(i,x),part(i,y)); if s=F, return F.

2. σ ← compose(σ,s); x ← subst(x,σ); y ← subst(y,σ);

5. Return σ

x = P(A,y,g(x,y)) y = P(z,f(w),g(v,w))

Page 19: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Finding the MGUProcedure MGU(x,y)

1. If x=y, return { }

2. If x or y are vars., return MGUvar(x,y)

3. If x or y are const.,or Len(x)=/=Len(y), return F.

4. σ ← { }; For i ← 1 to Len(x)1. s ← MGU(part(i,x),part(i,y)); if s=F, return F.

2. σ ← compose(σ,s); x ← subst(x,σ); y ← subst(y,σ);

5. Return σ

x = P(A,y,g(x,y)) y = P(z,f(w),g(v,w))

Page 20: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Finding the MGUProcedure MGU(x,y)

1. If x=y, return { }

2. If x or y are vars., return MGUvar(x,y)

3. If x or y are const.,or Len(x)=/=Len(y), return F.

4. σ ← { }; For i ← 1 to Len(x)1. s ← MGU(part(i,x),part(i,y)); if s=F, return F.

2. σ ← compose(σ,s); x ← subst(x,σ); y ← subst(y,σ);

5. Return σ

x = P(A,y,g(x,y)) y = P(z,f(w),g(v,w))

Page 21: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

part(3,x) = y part(3,y) = f(w)part(1,x) = P part(1,y) = Ppart(2,x) = A part(2,y) = z

Finding the MGUProcedure MGU(x,y)

1. If x=y, return { }

2. If x or y are vars., return MGUvar(x,y)

3. If x or y are const.,or Len(x)=/=Len(y), return F.

4. σ ← { }; For i ← 1 to Len(x)1. s ← MGU(part(i,x),part(i,y)); if s=F, return F.

2. σ ← compose(σ,s); x ← subst(x,σ); y ← subst(y,σ);

5. Return σ

x = P(A,y,g(x,y)) y = P(z,f(w),g(v,w))part(4,x) = g(x,f(w)) part(4,y) = g(v,w)

FOccurs check

Page 22: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Finding the MGU: another exampleProcedure MGU(x,y)

1. If x=y, return { }

2. If x or y are vars., return MGUvar(x,y)

3. If x or y are const.,or Len(x)=/=Len(y), return F.

4. σ ← { }; For i ← 1 to Len(x)1. s ← MGU(part(i,x),part(i,y)); if s=F, return F.

2. σ ← compose(σ,s); x ← subst(x,σ); y ← subst(y,σ);

5. Return σ

x = P(A,y,g(x,y)) y = P(z,f(w),g(v,f(w)))

Page 23: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Finding the MGU: another exampleProcedure MGU(x,y)

1. If x=y, return { }

2. If x or y are vars., return MGUvar(x,y)

3. If x or y are const.,or Len(x)=/=Len(y), return F.

4. σ ← { }; For i ← 1 to Len(x)1. s ← MGU(part(i,x),part(i,y)); if s=F, return F.

2. σ ← compose(σ,s); x ← subst(x,σ); y ← subst(y,σ);

5. Return σ

x = P(A,y,g(x,y)) y = P(z,f(w),g(v,f(w)))

Page 24: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Finding the MGU: another exampleProcedure MGU(x,y)

1. If x=y, return { }

2. If x or y are vars., return MGUvar(x,y)

3. If x or y are const.,or Len(x)=/=Len(y), return F.

4. σ ← { }; For i ← 1 to Len(x)1. s ← MGU(part(i,x),part(i,y)); if s=F, return F.

2. σ ← compose(σ,s); x ← subst(x,σ); y ← subst(y,σ);

5. Return σ

x = P(A,y,g(x,y)) y = P(z,f(w),g(v,f(w)))

Page 25: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Finding the MGU: another exampleProcedure MGU(x,y)

1. If x=y, return { }

2. If x or y are vars., return MGUvar(x,y)

3. If x or y are const.,or Len(x)=/=Len(y), return F.

4. σ ← { }; For i ← 1 to Len(x)1. s ← MGU(part(i,x),part(i,y)); if s=F, return F.

2. σ ← compose(σ,s); x ← subst(x,σ); y ← subst(y,σ);

5. Return σ

x = P(A,y,g(x,y)) y = P(z,f(w),g(v,f(w)))

Page 26: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Finding the MGU: another exampleProcedure MGU(x,y)

1. If x=y, return { }

2. If x or y are vars., return MGUvar(x,y)

3. If x or y are const.,or Len(x)=/=Len(y), return F.

4. σ ← { }; For i ← 1 to Len(x)1. s ← MGU(part(i,x),part(i,y)); if s=F, return F.

2. σ ← compose(σ,s); x ← subst(x,σ); y ← subst(y,σ);

5. Return σ

x = P(A,y,g(x,y)) y = P(z,f(w),g(v,f(w)))

Page 27: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

part(3,x) = y part(3,y) = f(w)part(1,x) = P part(1,y) = Ppart(2,x) = A part(2,y) = z

Finding the MGU: another exampleProcedure MGU(x,y)

1. If x=y, return { }

2. If x or y are vars., return MGUvar(x,y)

3. If x or y are const.,or Len(x)=/=Len(y), return F.

4. σ ← { }; For i ← 1 to Len(x)1. s ← MGU(part(i,x),part(i,y)); if s=F, return F.

2. σ ← compose(σ,s); x ← subst(x,σ); y ← subst(y,σ);

5. Return σ

part(4,x) = g(x,f(w)) part(4,y) = g(v,f(w))σ={y/f(w),z/A,v/x}

x = P(A,y,g(x,y)) y = P(z,f(w),g(v,f(w)))

Page 28: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Correctness of FOL Resolution

• Soundness: Resolution is sound for first-order inference

• Refutation Completeness: Resolution will find the empty clause, if FALSE is entailed

• No guarantee of termination (saturation), if FALSE not entailed: FOL semi-decidable

Page 29: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Simple Efficiency Improvements

• Subsumption between clauses:– If clause C subsumes clause D (C entails D),

then we can remove D from the KB.

{P(A)} {P(A),P(B)}

{P(A)} {~P(A)}

{P(f(x),A),Q(g(x),B)} {P(f(v),y),Q(g(v),y)}

• Algorithm for checking subsumption?╨

╨╨

{P(A)} {P(t)}╨

Page 30: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Simple Efficiency Improvements

• Subsumption within the clause:– If literal a subsumes literal b (a entails b), then

we can remove a from the clause…– But, notice the variables’ scope

{P(A),P(t)}

{P(A),~P(B),P(t)}

{P(A,x),P(y,B)}

{P(x),Q(x),P(A)}

{P(A)}{P(A),~P(B)}

{P(A,x),P(y,B)}

{P(x),Q(x),P(A)}

Page 31: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Properties of Resolution

• Unifying two literals of length nO(n2) – because of occurs check

• Finding two resolvable clauses from m clauses of length n:

O(m2n2) – the simple bound

• Overall algorithm: – Semi-decidable– Unbounded length of proof as function of n,m

Page 32: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Related to FOL Resolution

• Clause selection and restriction strategies

• Consequence finding

• Constraint Satisfaction Problem

• Reasoning with equality

• DPLL in FOL

• Decidable fragments of FOL

• BDDs in FOL

Page 33: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Summary So Far

• Resolution theorem proving allows us to find contradictions and explanation.– The deduction theorem tells us how to ask

queries from Resolution

• Next: Temporal Reasoning

Page 34: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Situation Calculus

• A first-order language for describing the effects of actions and events over time– Constants: S0 – initial state; action constants– Functions: result(<action>,<situation>)– Predicates: “fluents” – properties that change

over time

at(1, S0)at(x,s) at(x+1,result(move_fwd,s))Query: at(1+1,s’) ans(s’) ?at(1+1,s’) ans(s’)

Page 35: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Situation Calculus

• Requires axioms describing effects and non-effects of actions/events

• Can be used for planning, projection, diagnosis, filtering (tracking)

• Frame Problem: the compact and natural-language-like specification of effects of actions

• Qualification Problem: the preconditions of actions

Page 36: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Notations

• Substitutions– φσ σ = {x1/t1,…,xk/tk}

– φσ σ = [x1/t1,…,xk/tk]

Page 37: Knowledge Repn. & Reasoning Lec. #6: First-Order Inference

Next Time

• Resolution Strategies