;; ;; assign-3-lisp.txt ;; ;; As before, the assignment is to successfully execute a function, ;; in this case "(second-test dbaseIV)" which appears below. ;; The assignment is due the last day of class: Thursday, May 18th ;; Turn in: ;; 1. a listing of your code (as efficient as possible, with comments) ;; 2. a listing of a successful execution of "second-test" ;; 3. a listing of dbaseIV ;; ;; modify your theorem prover in the following ways: ;; 1. when a new fact is proven (through the use of a consequent ;; theorem), add that fact to the database ;; 2. new facts added to the database must include a "justification ;; list" that shows what facts and rules went into the ;; proof of the new fact ;; 3. when a new fact is added to the database, a message appears ;; that explains why the new fact is justified ;; ;; Sample Output (yours should be quite similar) ;; (load "lisp/theorem-prover-2.txt") ;; Loading file lisp\theorem-prover-2.txt . ;; Loaded file lisp\theorem-prover-2.txt ;; T ;; (load "lisp/assign-3-lisp.txt") ;; Loading file lisp\assign-3-lisp.txt ... ;; Loaded file lisp\assign-3-lisp.txt ;; T ;; (second-test dbaseIV) ;; PROVING: Daniel is MALE ;; TRUE: DANIEL is MALE ;; END OF PROOF ;; ;; etc.... ;; ;; PROVING: Billy is the CHILD of Violet ;; TRUE: Billy is the CHILD of Violet ;; Adding a new fact: Billy is the CHILD of Violet ;; This new fact is justified by the following rule - Number 3 ;; It can be shown that ?x is the CHILD of ?y ;; If ANY of the following can be proven: ;; ?x is the SON of ?y ;; ?x is the DAUGHTER of ?y ;; As well as the following facts: ;; Fact - Number 8 - Billy is the SON of Violet ;; END OF PROOF ;; ;; > dbaseIV ;; ((MALE JOHN) (FEMALE VIOLET) (DAUGHTER VIOLET JOHN) (MALE PATRICK) ;; (HUSBAND PATRICK VIOLET) (MALE BILLY) (SON BILLY PATRICK) (SON BILLY VIOLET) ;; (CHILD BILLY VIOLET ((F . 8) (R . 3))) (WIFE VIOLET PATRICK ((F . 5) (R . 1))) ;; (SPOUSE PATRICK VIOLET ((F . 5) (R . 2))) ;; (PARENT PATRICK BILLY ((F . 7) (R . 4))) ;; (PARENT VIOLET BILLY ((F . 8) (R . 4))) ;; (GUARDIAN VIOLET BILLY ((F . 8) (R . 4) (F . 13) (R . 5))) ;; (FATHER PATRICK BILLY ((F . 12) (F . 4) (R . 6))) ;; (WARD BILLY VIOLET ((F . 14) (R . 7))) ;; (CONSE (WIFE ?X ?Y) (GOAL (HUSBAND ?Y ?X))) ;; (CONSE (SPOUSE ?X ?Y) (GOAL (OR (HUSBAND ?X ?Y) (WIFE ?X ?Y)))) ;; (CONSE (CHILD ?X ?Y) (GOAL (OR (SON ?X ?Y) (DAUGHTER ?X ?Y)))) ;; (CONSE (PARENT ?X ?Y) (GOAL (OR (SON ?Y ?X) (DAUGHTER ?Y ?X)))) ;; (CONSE (GUARDIAN ?X ?Y) (GOAL (PARENT ?X ?Y))) ;; (CONSE (FATHER ?X ?Y) (GOAL (AND (PARENT ?X ?Y) (MALE ?X)))) ;; (CONSE (WARD ?X ?Y) (GOAL (GUARDIAN ?Y ?X))) ;; (CONSE (GRANDPARENT ?X ?Y) (GOAL (AND (PARENT ?X ?Z) (PARENT ?Z ?Y))))) ;; ;; Hints: ;; 1. You must define a predicate, "fact-equal" to use in "provesit" ;; and elsewhere since "(equal stmnt assrt)" will not return "t" with ;; "(CHILD Billy Violet ((F . 8) (R . 3)))" and "(CHILD Billy Violet)" ;; 2. you must find a way to insert new facts in the database, after ;; the existing facts but before the rules -- otherwise the numbers ;; in your justification lists will come out wrong (read the manual ;; under "rplacd" to find a way to do this) ;; 3. you will need two simple routines that accept facts or rules and ;; return the number; i.e. "fact number 5" or "rule number 3" ;; 4. you will probably want to define a global variable to hold the ;; results of proofs ;; 5. you will probably want to put all your "cadaddaadar" calls into ;; access functions (setq dbaseIV '( (MALE John) (FEMALE Violet) (DAUGHTER Violet John) (MALE Patrick) (HUSBAND Patrick Violet) (MALE Billy) (SON Billy Patrick) (SON Billy Violet) (CONSE (WIFE ?x ?y) (GOAL (HUSBAND ?y ?x))) (CONSE (SPOUSE ?x ?y) (GOAL (or (HUSBAND ?x ?y) (WIFE ?x ?y)))) (CONSE (CHILD ?x ?y) (GOAL (or (SON ?x ?y) (DAUGHTER ?x ?y)))) (CONSE (PARENT ?x ?y) (GOAL (or (SON ?y ?x) (DAUGHTER ?y ?x)))) (CONSE (GUARDIAN ?x ?y) (GOAL (PARENT ?x ?y))) (CONSE (FATHER ?x ?y) (GOAL (and (PARENT ?x ?y) (MALE ?x)))) (CONSE (WARD ?x ?y) (GOAL (GUARDIAN ?y ?x))) (CONSE (GRANDPARENT ?x ?y) (GOAL (and (PARENT ?x ?z) (PARENT ?z ?y)))) )) (defun second-test (dbase-in) ; these should still work (princ "PROVING: Patrick is MALE")(terpri) (prove '(MALE Patrick) dbase-in) (princ "PROVING: Billy is the CHILD of Violet")(terpri) (prove '(CHILD Billy Violet) dbase-in) ; later proof of (CHILD Billy Violet) should be different (princ "RE-PROVING: Billy is the CHILD of Violet")(terpri) (prove '(CHILD Billy Violet) dbase-in) (princ "PROVING: Violet is the CHILD of Billy")(terpri) (prove '(CHILD Violet Billy) dbase-in) (princ "PROVING: Violet is the WIFE of Patrick")(terpri) (prove '(WIFE Violet Patrick) dbase-in) (princ "PROVING: Patrick is the SPOUSE of Violet")(terpri) (prove '(SPOUSE Patrick Violet) dbase-in) (princ "PROVING: Patrick is the PARENT of Billy")(terpri) (prove '(PARENT Patrick Billy) dbase-in) (princ "PROVING: Violet is the GUARDIAN of Billy")(terpri) (prove '(GUARDIAN Violet Billy) dbase-in) (princ "PROVING: Patrick is the FATHER of Billy")(terpri) (prove '(FATHER Patrick Billy) dbase-in) (princ "PROVING: Billy is the WARD of Violet")(terpri) (prove '(WARD Billy Violet) dbase-in) (princ "PROVING: Billy is the GUARDIAN of Violet")(terpri) (prove '(GUARDIAN Billy Violet) dbase-in) ; later proof of (WARD Billy Violet) should be different (princ "RE-PROVING: Billy is the WARD of Violet")(terpri) (prove '(WARD Billy Violet) dbase-in) ; and for extra credit ; (princ "PROVING: John is the GRANDPARENT of Billy")(terpri) ; (prove '(GRANDPARENT John Billy) dbase-in) )