anchor.diff:      h))
   
   
  -(defun fa-numerize (fa)
  -  "Returns an edge list with all states and transitions as fixnums.
  -0 is epsilon"
  -  (let ((state-hash (make-hash-table :test #'equal))
  -        (token-hash (make-hash-table :test #'equal))
  -        (state-counter -1)
  -        (token-counter 0)
  -        nedges)
  -    (setf (gethash :epsilon token-hash) 0)
  -    ;; start states
  -    (map nil (lambda (x)
  -               (setf (gethash x state-hash)
  -                     (incf state-counter)))
  -         (fa-start fa))
  -    ;; build hashes
  -    (dolist (e (fa-edges fa))
  -      (destructuring-bind (q0 z q1) e
  -        (unless (gethash q0 state-hash)
  -          (setf (gethash q0 state-hash) (incf state-counter)))
  -        (unless (gethash q1 state-hash)
  -          (setf (gethash q1 state-hash) (incf state-counter)))
  -        (unless (gethash z token-hash)
  -          (setf (gethash z token-hash) (incf token-counter)))
  -        (push (list (gethash q0 state-hash)
  -                    (gethash z token-hash)
  -                    (gethash q1 state-hash))
  -              nedges)))
  -    ;; map hashes to build new edges and mapping arrays
  -    (let ((state-array (make-array (1+ state-counter)))   ; i -> q
  -          (token-array (make-array (1+ token-counter))))  ; i -> z
  -      (maphash (lambda (n d) (setf (aref state-array d) n))
  -               state-hash)
  -      (maphash (lambda (n d) (setf (aref token-array d) n))
  -               token-hash)
  -      (values (make-fa nedges
  -                       (mapcar (lambda (x) (gethash x state-hash))
  -                               (fa-start fa))
  -                       (mapcar (lambda (x) (gethash x state-hash))
  -                               (fa-accept fa)))
  -              state-array token-array))))
  -
   
   ;;; See Aho, 2nd p. 153-154. These closure computations are a
   ;;; functional variation thereof.
  
positive.code: ;; See Aho, 2nd p. 152
  (defun nfa->dfa (nfa)
    "Convert an NFA to a DFA"
    (multiple-value-bind (i-nfa i-states i-tokens) (fa-numerize nfa)
      (let ((move (make-array (list (length i-states) (length i-tokens))
                              :initial-element nil)))
        ;; index moves
        (loop for (q0 z q1) in (fa-edges i-nfa)
           do (push q1 (aref move q0 z)))
        ;; d-states
        (let ((d-states (make-array 0 :adjustable t :fill-pointer t))
              (d-hash (make-hash-table :test #'equal))
              (d-edge)
              (mover (lambda (state token) (aref move state token))))
          ;; start state
          (vector-push-extend (nfa-e-closure (fa-start i-nfa) mover) d-states)
          (setf (gethash (aref d-states 0) d-hash) 0)
          ;; subset construction
          (loop for mark = 0 then (1+ mark)
             while (< mark (length d-states))
             for ds = (aref d-states mark)
             do (progn
                  (loop
                     for i-z from 1 below (length i-tokens)
                     for u = (sort (nfa-move-e-closure ds i-z mover) #'<)
                     when u
                     do (progn
                          (when (not (gethash u d-hash))
                            (setf (gethash u d-hash) (length d-states))
                            (vector-push-extend u d-states))
                          (push (list mark (aref i-tokens i-z) (gethash u d-hash))
                                d-edge)))))
          ;; result
          (values
           (make-fa d-edge
                    (loop ; start
                       for q across d-states
                       for i from 0
                       when (intersection q (fa-start i-nfa))
                       collect i)
                    (loop ; accept
                       for q across d-states
                       for i from 0
                       when (intersection q (fa-accept i-nfa))
                       collect i))
           (loop for d across d-states
              collect (loop for i in d
                         collect (aref i-states i)))
           i-states
           i-tokens
           move)))))
  
  
  ;; (defun nfa-e-close (n e-lookup)
  
negative.code: ;;         (e-close i)))
  ;;     e-closure))
  
  
  
  ;; (defun fa-numerize (fa)
  ;;   "Returns an edge list with all states and transitions as fixnums.
  ;; 0 is epsilon"
  ;;   (let ((state-hash (make-hash-table :test #'equal))
  ;;         (token-hash (make-hash-table :test #'equal))
  ;;         (state-counter -1)
  ;;         (token-counter 0)
  ;;         nedges)
  ;;     (setf (gethash :epsilon token-hash) 0)
  ;;     ;; start states
  ;;     (map nil (lambda (x)
  ;;                (setf (gethash x state-hash)
  ;;                      (incf state-counter)))
  ;;          (fa-start fa))
  ;;     ;; build hashes
  ;;     (dolist (e (fa-edges fa))
  ;;       (destructuring-bind (q0 z q1) e
  ;;         (unless (gethash q0 state-hash)
  ;;           (setf (gethash q0 state-hash) (incf state-counter)))
  ;;         (unless (gethash q1 state-hash)
  ;;           (setf (gethash q1 state-hash) (incf state-counter)))
  ;;         (unless (gethash z token-hash)
  ;;           (setf (gethash z token-hash) (incf token-counter)))
  ;;         (push (list (gethash q0 state-hash)
  ;;                     (gethash z token-hash)
  ;;                     (gethash q1 state-hash))
  ;;               nedges)))
  ;;     ;; map hashes to build new edges and mapping arrays
  ;;     (let ((state-array (make-array (1+ state-counter)))   ; i -> q
  ;;           (token-array (make-array (1+ token-counter))))  ; i -> z
  ;;       (maphash (lambda (n d) (setf (aref state-array d) n))
  ;;                state-hash)
  ;;       (maphash (lambda (n d) (setf (aref token-array d) n))
  ;;                token-hash)
  ;;       (values (make-fa nedges
  ;;                        (mapcar (lambda (x) (gethash x state-hash))
  ;;                                (fa-start fa))
  ;;                        (mapcar (lambda (x) (gethash x state-hash))
  ;;                                (fa-accept fa)))
  ;;               state-array token-array))))
  