anchor.diff:               (list r)))
             rules))
   
  -(defun make-predicate-zdd (predicate term->number)
  +(defun make-predicate-zdd (predicate-prefix term->number)
     "Make a ZDD with a single member: the set of all terms for a single predicate.
   
     For example:
   
  -    (make-predicate-zdd 'ggp-rules::legal ...)
  -    (make-predicate-zdd 'ggp-rules::true ...)
  -
  -  "
  -  (-<> term->number
  -    hash-table-alist
  -    (remove-if-not (lambda (rule)
  -                     (eql predicate (first (first rule))))
  -                   <>)
  -    (mapcar #'cdr <>)
  -    (zdd-set <>)))
  +    (make-predicate-zdd '(ggp-rules::legal) ...)
  +    (make-predicate-zdd '(ggp-rules::true) ...)
  +    (make-predicate-zdd '(ggp-rules::sees ggp-rules::white) ...)
  +
  +  "
  +  (let ((prefix-length (length predicate-prefix)))
  +    (-<> term->number
  +      hash-table-alist
  +      (mapcar (lambda (rule-mapping)
  +                (destructuring-bind (term . number) rule-mapping
  +                  (if (equal predicate-prefix
  +                             (take prefix-length term))
  +                    number
  +                    nil)))
  +              <>)
  +      (remove nil <>)
  +      (zdd-set <>))))
   
   
   (defun make-zdd-reasoner (rules)
  
positive.code:    goal-zdd
     terminal-zdd
     next-zdd
     possible-forest
     happens-forest))
  
  
negative.code:          (rule-tree-1 rule-tree-2 ...)
  
    "
    (let* ((rules (scully.gdl::normalize-rules rules))
           (roles (find-roles rules)))
      (destructuring-bind (term->number number->term possible happens)
          (scully.terms::integerize-rules rules)
        (with-zdd
          (make-instance 'zdd-reasoner
            :rules rules
            :roles roles
            :possible-forest (build-rule-forest possible)
            :happens-forest (build-rule-forest happens)
            :initial-zdd (zdd-set (find-initial-state rules term->number))
            :legal-zdd (make-predicate-zdd '(ggp-rules::legal) term->number)
            :goal-zdd (make-predicate-zdd '(ggp-rules::goal) term->number)
            :terminal-zdd (make-predicate-zdd '(ggp-rules::terminal) term->number)
            :next-zdd (make-predicate-zdd '(ggp-rules::next) term->number)
            :percept-zdds (iterate
                            (for role :in roles)
                            (collect-hash (role . (make-predicate-zdd
                                                    `(ggp-rules::sees ,role)
                                                    term->number))
                                          :test #'equal))
            :term->number term->number
            :number->term number->term)))))
  
  