Top Banner
Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules not introduction, and introduction, or introduction, conditional introduction, biconditional introduction Elimination rules not elimination, and elimination, or elimination, conditional elimination and biconditional elimination
39

Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

Dec 29, 2015

Download

Documents

Derick Cannon
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

Natural deduction of logical proofs

• Kalish & Montegue: a set of heuristics for doing logical proofs

• Introduction rules– not introduction, and introduction, or introduction, conditional introduction, biconditional introduction

• Elimination rules– not elimination, and elimination, or elimination, conditional elimination and biconditional elimination

Page 2: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

Kalish & Montegue cont.

• Organized along five different modal relations:– NOT, AND, OR, IMPLIES (->), and IFF (<=>).

• Rules can either eliminate relations or introduce new relations– Elimination rules are much like the simplification rules in Bundy

system

– Introduction rules are require more control knowledge--cannot be used randomly

Page 3: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

The format of proofs

• A proof is a set of numbered lines

• Each line has the form<line number> <statement> <justification>

• Example:

27 (implies P Q) asn28 P given29 Q (CE 27 28)

InformantAntecedents

Page 4: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

• Divided into elimination rules and introduction rules

• Use boxes to denote logical contexts

• Example: Indirect proof schemata

h show P (IP i j k)

i (not P) asn..

j Q..

k (not Q)

Proof Rules for KM*

Page 5: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

Not Elimination

i (not (not P))

P (NE i)

(rule (not (not ?p))

(assert! ?p))

Page 6: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

AND Elimination

i (and P Q)

P (AE i)

Q (AE i)

(rule (and . ?conjuncts)

(dolist (con ?conjuncts)

(assert! con)))

Page 7: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

OR Elimination

i (or P Q)

j (implies P R)

k (implies Q R)

R (OE i j k)

(rule (show ?r)

(rule (or ?p ?q)

(assert! ‘(show (implies ,?p ,?r)))

(assert! ‘(show (implies ,?q ,?r)))

(rule (implies ?p ?r)

(rule (implies ?q ?r)

(assert! ?r)))))

Problems?

Page 8: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

Conditional Elimination

i (implies P Q)

j P

Q (CE i j)

(rule (implies ?ante ?cons)

(rule ?ante (assert! ?cons)))

(rule (show ?q)

(unless (fetch ?q)

(rule (implies ?p ?q)

(assert! ‘(show ,?p)))

Back-chaining on CE,using control knowledge

Page 9: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

Biconditional Elimination

i (iff P Q)

(implies P Q) (BE i)

(implies Q P) (BE i)

(rule (iff ?arg1 ?arg2)

(assert! ?arg1)

(assert! ?arg2))

Page 10: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

Not Introduction

show (not P) (NI i j k)

i P

.

.

j Q

.

.

k (not Q)

Page 11: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

And Introduction

i P

j Q

(and P Q) (AI i j)

(and Q P) (AI j i)

Page 12: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

Or Introduction

i P

(or P Q) (OI i)

(or Q P) (OI i)

Page 13: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

Conditional Introduction

show (implies P Q) (CI i j)

i P asn

j show Q

Page 14: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

Biconditional Introduction

i (implies P Q)

j (implies Q P)

(iff P Q) (BI i j)

Page 15: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

KM* Examples

• Several of them in the book

• How to read them:– Don’t go directly to the proofs: Try proving them yourself

first, then peek.

– Think about what you are doing in the process of doing a proof. That is the process you will be modeling soon...

Page 16: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

Simple KM* Example

• Premises– If it is spring, there cannot be snow

– It snowed this week

• Show– It cannot be spring

• Formalization– (implies spring (not snow))– snow– (show (not spring))

Page 17: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

1. (implies spring (not snow)) Premise

2. snow Premise

3. (show (not spring))

Simple KM* Example

Page 18: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

1. (implies spring (not snow)) Premise

2. snow Premise

3. (show (not spring))

4. spring Asn

Simple KM* Example

Page 19: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

1. (implies spring (not snow)) Premise

2. snow Premise

3. (show (not spring))

4. spring Asn

5. (not snow) (CE 1 4)

Simple KM* Example

Page 20: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

1. (implies spring (not snow)) Premise

2. snow Premise

3. (show (not spring)) (NI 4 2 5)

4. spring Asn

5. (not snow) (CE 1 4)

Simple KM* Example

Page 21: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

Implementing KM* in TRE

• How to do boxes?

• Elimination rules are easy

• Introduction rules are harder

Page 22: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

Classic problem: Positive Feedback Loops

• Examples: And introduction, Or elimination

• Strategy: Limit applicability of rules syntactically

• Strategy: Reason about when to apply rules

• Insight: Many control decisions are non-local.

• Implication: Often need more global mechanism that feeds off locally determined alternatives to organize problem solving

Page 23: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

FTRE: An improved version of TRE

• Provides more powerful, easier-to-read rules

• Adds context mechanism

• Speeds up pattern-based retrieval using open-coded unification

Page 24: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

FTRE rule syntax

• Aimed at convenience– Triggers are now a list, interpreted conjunctively– rassert! to remove backquotes

• Examples(rule (show ?q) (rule (implies ?p ?q) (assert! `(show ,?p))))

becomes(rule ((show ?q) (implies ?p ?q)) (rassert! (show ?p)))

Page 25: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

FTRE Syntax: Trigger keywords

• :VAR = next item is a variable to be bound to entire pattern

• :TEST = next item is lisp code executed in environment so far. If NIL, match fails.

• Example:(rule ((show ?q) :test (not (fetch ?q)) (implies ?p ?q) :var ?imp) (debug-nd “~% BC-CE: Looking for ~A to use ~A..” ?p ?imp) (rassert! (show ?p)))

Page 26: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

Making RASSERT! work

(defmacro rassert! (fact)

`(assert! ,(quotize fact)))

(defun quotize (pattern)

"Given pattern, create evaluatable form that will return the original pattern, but also replace pattern variables with their bindings."

(cond ((null pattern) nil)

((variable? pattern) pattern)

((not (listp pattern)) (list 'QUOTE pattern))

((eq (car pattern) :EVAL) (cadr pattern))

(t `(cons ,(quotize (car pattern))

,(quotize (cdr pattern))))))

Page 27: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

Making RASSERT! work

> (quotize '(foo ?bar ?bat))

(CONS 'FOO (CONS ?BAR (CONS ?BAT NIL)))

> (macroexpand-1 '(rassert! (foo ?bar ?bat)))

(ASSERT! (CONS 'FOO (CONS ?BAR (CONS ?BAT NIL))))

… which is equivalent to… (assert! `(foo ,?bar ,?bat))

Page 28: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,
Page 29: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

Unifier #1: CPS match function

• For matching– (? x) : Matches symbol, binding to pattern var X– (?? x) : Matches sequence, binding to segment var X– (? x test) : Matches single symbol x that also returns true when

passed to function test.

• Matcher returns either a set of bindings or :FAIL

• For simplification– subst function for instantiating matched patterns.– (:eval (+ (? X) (? Y))) : Matches X and Y, and then adds

them and returns that value.

– :splice act similarly, but splices result into list.

Page 30: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

CPS match definition

(defun match (pat dat &optional (dict nil))

(cond ((eq dict :FAIL) :FAIL) ;; Propagate lossage

((eq pat dat) dict)

((element-var? pat)

(match-element-var pat dat dict))

((not (consp pat))

(if (equal? pat dat) dict :FAIL))

((segment-var? (car pat))

(match-segment-var pat dat dict))

((not (consp dat)) :FAIL)

(t (match (cdr pat) (cdr dat)

(match (car pat) (car dat) dict)))))

Page 31: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

Unifier #2: TRE unify function

• For matching– ?x : Matches symbol, binding to pattern var X

– No optional filter field in pattern.

– No segment variables.

• Matcher returns either a set of bindings (as alist) or :FAIL.

• For substitution of matched patterns– sublis function for instantiating matched patterns.

– No eval or splice, as in CPS matcher.

Page 32: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

CPS match -> TRE & FTRE Unify

(defun match (pat dat &optional (dict nil))

(cond

((eq dict :FAIL) :FAIL)

((eq pat dat) dict)

((element-var? pat)

(match-element-var pat dat dict))

((not (consp pat))

(if (equal? pat dat) dict :FAIL))

((segment-var? (car pat))

(match-segment-var pat dat dict))

((not (consp dat)) :FAIL)

(t (match (cdr pat) (cdr dat)

(match (car pat) (car dat) dict)))))

(defun unify (a b &optional (bindings nil)) (cond ((equal a b) bindings) ((variable? a) (unify-variable a b bindings)) ((variable? b) (unify-variable b a bindings)) ((or (not (listp a)) (not (listp b))) :FAIL) ((not (eq :FAIL (setq bindings (unify (car a) (car b) bindings)))) (unify (cdr a) (cdr b) bindings)) (t :FAIL)))

Page 33: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

CPS match -> TRE & FTRE Unify

(defun match (pat dat &optional (dict nil))

(cond

((eq dict :FAIL) :FAIL)

((eq pat dat) dict)

((element-var? pat)

(match-element-var pat dat dict))

((not (consp pat))

(if (equal? pat dat) dict :FAIL))

((segment-var? (car pat))

(match-segment-var pat dat dict))

((not (consp dat)) :FAIL)

(t (match (cdr pat) (cdr dat)

(match (car pat) (car dat) dict)))))

(defun unify (a b &optional (bindings nil)) (cond ((equal a b) bindings) ((variable? a) (unify-variable a b bindings)) ((variable? b) (unify-variable b a bindings)) ((or (not (listp a)) (not (listp b))) :FAIL) ((not (eq :FAIL (setq bindings (unify (car a) (car b) bindings)))) (unify (cdr a) (cdr b) bindings)) (t :FAIL)))

Page 34: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

CPS match -> TRE & FTRE Unify

(defun match (pat dat &optional (dict nil))

(cond

((eq dict :FAIL) :FAIL)

((eq pat dat) dict)

((element-var? pat)

(match-element-var pat dat dict))

((not (consp pat))

(if (equal? pat dat) dict :FAIL))

((segment-var? (car pat))

(match-segment-var pat dat dict))

((not (consp dat)) :FAIL)

(t (match (cdr pat) (cdr dat)

(match (car pat) (car dat) dict)))))

(defun unify (a b &optional (bindings nil)) (cond ((equal a b) bindings) ((variable? a) (unify-variable a b bindings)) ((variable? b) (unify-variable b a bindings)) ((or (not (listp a)) (not (listp b))) :FAIL) ((not (eq :FAIL (setq bindings (unify (car a) (car b) bindings)))) (unify (cdr a) (cdr b) bindings)) (t :FAIL)))

Page 35: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

CPS match -> TRE & FTRE Unify

(defun match (pat dat &optional (dict nil))

(cond

((eq dict :FAIL) :FAIL)

((eq pat dat) dict)

((element-var? pat)

(match-element-var pat dat dict))

((not (consp pat))

(if (equal? pat dat) dict :FAIL))

((segment-var? (car pat))

(match-segment-var pat dat dict))

((not (consp dat)) :FAIL)

(t (match (cdr pat) (cdr dat)

(match (car pat) (car dat) dict)))))

(defun unify (a b &optional (bindings nil)) (cond ((equal a b) bindings) ((variable? a) (unify-variable a b bindings)) ((variable? b) (unify-variable b a bindings)) ((or (not (listp a)) (not (listp b))) :FAIL) ((not (eq :FAIL (setq bindings (unify (car a) (car b) bindings)))) (unify (cdr a) (cdr b) bindings)) (t :FAIL)))

Page 36: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

CPS match -> TRE & FTRE Unify

(defun match (pat dat &optional (dict nil))

(cond

((eq dict :FAIL) :FAIL)

((eq pat dat) dict)

((element-var? pat)

(match-element-var pat dat dict))

((not (consp pat))

(if (equal? pat dat) dict :FAIL))

((segment-var? (car pat))

(match-segment-var pat dat dict))

((not (consp dat)) :FAIL)

(t (match (cdr pat) (cdr dat)

(match (car pat) (car dat) dict)))))

(defun unify (a b &optional (bindings nil)) (cond ((equal a b) bindings) ((variable? a) (unify-variable a b bindings)) ((variable? b) (unify-variable b a bindings)) ((or (not (listp a)) (not (listp b))) :FAIL) ((not (eq :FAIL (setq bindings (unify (car a) (car b) bindings)))) (unify (cdr a) (cdr b) bindings)) (t :FAIL)))

Page 37: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

CPS match -> TRE & FTRE Unify

(defun match (pat dat &optional (dict nil))

(cond

((eq dict :FAIL) :FAIL)

((eq pat dat) dict)

((element-var? pat)

(match-element-var pat dat dict))

((not (consp pat))

(if (equal? pat dat) dict :FAIL))

((segment-var? (car pat))

(match-segment-var pat dat dict))

((not (consp dat)) :FAIL)

(t (match (cdr pat) (cdr dat)

(match (car pat) (car dat) dict)))))

(defun unify (a b &optional (bindings nil)) (cond ((equal a b) bindings) ((variable? a) (unify-variable a b bindings)) ((variable? b) (unify-variable b a bindings)) ((or (not (listp a)) (not (listp b))) :FAIL) ((not (eq :FAIL (setq bindings (unify (car a) (car b) bindings)))) (unify (cdr a) (cdr b) bindings)) (t :FAIL)))

Page 38: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

CPS’s match-element-var -> TRE’s unify-variable

(defun match-element-var (pat dat dict &aux entry pred)

(setq entry (lookup-var pat dict))

(cond

(entry

(if (equal? (cadr entry) dat) dict :FAIL))

(t (setq pred (var-restriction pat))

(cond ((or (not pred) (funcall pred dat))

(bind-element-var (var-name pat) dat dict))

(t :FAIL)))))

(defun unify-variable (var exp bindings &aux binding) (setq binding (assoc var bindings)) (cond (binding (unify (cdr binding) exp bindings)) ((free-in? var exp bindings) (cons (cons var exp) bindings)) (t :FAIL)))

Page 39: Natural deduction of logical proofs Kalish & Montegue: a set of heuristics for doing logical proofs Introduction rules –not introduction, and introduction,

Summary and observations

• Unifier algorithm– treewalk pattern and datum

– when variable found, do bookkeeping on binding dictionary

– fail when conflicting bindings or structural (list to symbol) mismatches

• CPS’s filter test and :eval will be seen again, but not here (at the rule level)

• Treewalks on fixed patterns can be precompiled (see FTRE)