Download presentation
Presentation is loading. Please wait.
Published byDerick Cannon Modified over 9 years ago
1
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
2
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
3
The format of proofs A proof is a set of numbered lines Each line has the form Example: 27(implies P Q)asn 28Pgiven 29Q(CE 27 28) Informant Antecedents
4
Divided into elimination rules and introduction rules Use boxes to denote logical contexts Example: Indirect proof schemata hshow P(IP i j k) i(not P)asn.. jQ.. k(not Q) Proof Rules for KM*
5
Not Elimination i(not (not P)) P(NE i) (rule (not (not ?p)) (assert! ?p))
6
AND Elimination i(and P Q) P(AE i) Q(AE i) (rule (and. ?conjuncts) (dolist (con ?conjuncts) (assert! con)))
7
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?
8
Conditional Elimination i(implies P Q) jP 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
9
Biconditional Elimination i(iff P Q) (implies P Q)(BE i) (implies Q P)(BE i) (rule (iff ?arg1 ?arg2) (assert! ?arg1) (assert! ?arg2))
10
Not Introduction show (not P)(NI i j k) iP. jQ. k(not Q)
11
And Introduction iP jQ (and P Q)(AI i j) (and Q P)(AI j i)
12
Or Introduction iP (or P Q)(OI i) (or Q P)(OI i)
13
Conditional Introduction show (implies P Q)(CI i j) iPasn jshow Q
14
Biconditional Introduction i(implies P Q) j(implies Q P) (iff P Q)(BI i j)
15
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...
16
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))
17
1. (implies spring (not snow)) Premise 2. snow Premise 3. (show (not spring)) Simple KM* Example
18
1. (implies spring (not snow))Premise 2. snow Premise 3. (show (not spring)) 4. springAsn Simple KM* Example
19
1. (implies spring (not snow))Premise 2. snow Premise 3. (show (not spring)) 4. springAsn 5. (not snow)(CE 1 4) Simple KM* Example
20
1. (implies spring (not snow))Premise 2. snowPremise 3. (show (not spring))(NI 4 2 5) 4. springAsn 5. (not snow)(CE 1 4) Simple KM* Example
21
Implementing KM* in TRE How to do boxes? Elimination rules are easy Introduction rules are harder
22
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
23
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
24
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)))
25
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)))
26
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))))))
27
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))
29
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.
30
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)))))
31
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.
32
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)))
33
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)))
34
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)))
35
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)))
36
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)))
37
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)))
38
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)))
39
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)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.