Main depth-first topological sorting routine.
(toposort-aux queue seen graph) → (mv successp seen)
The status of each node is either:
On success, a topologically sorted list of nodes can be extracted from
Function:
(defun toposort-aux (queue seen graph) (declare (xargs :guard t)) (let ((__function__ 'toposort-aux)) (declare (ignorable __function__)) (b* (((when (atom queue)) (mv t seen)) (orig-seen-al seen) (node (car queue)) (status (hons-get node seen)) ((when (eq (cdr status) :finished)) (toposort-aux (cdr queue) seen graph)) ((when status) (mv nil (hons-acons node :started seen))) (deps-look (hons-get node graph)) ((unless deps-look) (er hard? 'toposort-aux "No binding for ~x0." node) (toposort-aux (cdr queue) seen graph)) (seen (hons-acons node :started seen)) (deps (cdr deps-look)) ((mv deps-okp seen) (toposort-aux deps seen graph)) ((unless deps-okp) (mv nil seen)) (seen (hons-acons node :finished seen)) ((unless (mbt (o< (toposort-measure (cdr queue) seen graph) (toposort-measure queue orig-seen-al graph)))) (mv nil seen))) (toposort-aux (cdr queue) seen graph))))
Theorem:
(defthm cons-listp-of-toposort-aux (implies (cons-listp seen) (cons-listp (mv-nth 1 (toposort-aux queue seen graph)))))
Theorem:
(defthm subsetp-equal-of-alist-keys-of-toposort-aux (implies (subsetp-equal (alist-keys seen) (alist-keys graph)) (subsetp-equal (alist-keys (mv-nth 1 (toposort-aux queue seen graph))) (alist-keys graph))))
Theorem:
(defthm toposort-aux-consp-on-failure (implies (not (mv-nth 0 (toposort-aux queue seen graph))) (consp (mv-nth 1 (toposort-aux queue seen graph)))))