natural deduction of logical proofs kalish & montegue: a set of heuristics for doing logical...

39
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

Upload: derick-cannon

Post on 29-Dec-2015

223 views

Category:

Documents


0 download

TRANSCRIPT

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

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

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

• 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*

Not Elimination

i (not (not P))

P (NE i)

(rule (not (not ?p))

(assert! ?p))

AND Elimination

i (and P Q)

P (AE i)

Q (AE i)

(rule (and . ?conjuncts)

(dolist (con ?conjuncts)

(assert! con)))

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?

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

Biconditional Elimination

i (iff P Q)

(implies P Q) (BE i)

(implies Q P) (BE i)

(rule (iff ?arg1 ?arg2)

(assert! ?arg1)

(assert! ?arg2))

Not Introduction

show (not P) (NI i j k)

i P

.

.

j Q

.

.

k (not Q)

And Introduction

i P

j Q

(and P Q) (AI i j)

(and Q P) (AI j i)

Or Introduction

i P

(or P Q) (OI i)

(or Q P) (OI i)

Conditional Introduction

show (implies P Q) (CI i j)

i P asn

j show Q

Biconditional Introduction

i (implies P Q)

j (implies Q P)

(iff P Q) (BI i j)

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...

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))

1. (implies spring (not snow)) Premise

2. snow Premise

3. (show (not spring))

Simple KM* Example

1. (implies spring (not snow)) Premise

2. snow Premise

3. (show (not spring))

4. spring Asn

Simple KM* Example

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

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

Implementing KM* in TRE

• How to do boxes?

• Elimination rules are easy

• Introduction rules are harder

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

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

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)))

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)))

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))))))

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))

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.

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)))))

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.

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)))

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)))

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)))

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)))

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)))

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)))

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)))

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)