KnowledgeWorks and Prolog User Guide > 6 Advanced Topics > 6.4 Logical Dependencies and Truth Maintenance

NextPrevUpTopContentsIndex

6.4.1 Example

Given the following classes and rules

(def-kb-class number-object ()
  ((value :initarg :value)))
 
(def-kb-class have-some-large-numbers ()
  ())
 
(defrule notice-a-large-number :forward
  (logical (number-object ? value ?value)
           (test (> ?value 100)))
  -->
  (assert (have-some-large-numbers ?)))

then a have-some-large-numbers object will be created when a number larger than 100 exists:

(setq n1 (make-instance 'number-object :value 10))
(infer)
(any '?x '(have-some-large-numbers ?x)) ==> false
(setf (slot-value n1 'value) 200) ; this is large
(infer)
(any '?x '(have-some-large-numbers ?x)) ==> true

In addition, when the large number becomes smaller, the have-some-large-numbers object will be erased again:

(setf (slot-value n1 'value) 55)
(infer)
(any '?x '(have-some-large-numbers ?x)) ==> false

because a logical dependency was tracked between the preconditions

(number-object ? value ?value)
(test (> ?value 100)

and the have-some-large-numbers object.


KnowledgeWorks and Prolog User Guide (Unix version) - 22 Dec 2009

NextPrevUpTopContentsIndex