• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Mutual-recursion
        • Memoize
        • Mbe
        • Io
        • Defpkg
        • Apply$
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
        • Time$
        • Defmacro
        • Loop$-primer
        • Fast-alists
        • Defconst
        • Evaluation
        • Guard
        • Equality-variants
        • Compilation
        • Hons
        • ACL2-built-ins
        • Developers-guide
        • System-attachments
        • Advanced-features
        • Set-check-invariant-risk
        • Numbers
        • Efficiency
        • Irrelevant-formals
        • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
        • Redefining-programs
        • Lists
        • Invariant-risk
        • Errors
        • Defabbrev
        • Conses
        • Alists
          • Omaps
          • Std/alists
          • Fast-alists
          • Alistp
          • Misc/records
          • Remove-assocs
          • Assoc
          • Symbol-alistp
          • Rassoc
          • Remove-assoc
          • Remove1-assoc
          • Alist-map-vals
          • Depgraph
            • Toposort
              • Toposort-aux
              • Extract-topological-loop
              • Extract-topological-order
              • Transdeps
              • Invert
              • Mergesort-alist-values
              • Alist-values-are-sets-p
              • Topologically-ordered-p
              • Dependency-chain-p
            • Alist-map-keys
            • Put-assoc
            • Strip-cars
            • Pairlis$
            • Strip-cdrs
            • Sublis
            • Acons
            • Eqlable-alistp
            • Assoc-string-equal
            • Alist-to-doublets
            • Character-alistp
            • String-alistp
            • Alist-keys-subsetp
            • R-symbol-alistp
            • R-eqlable-alistp
            • Pairlis
            • Pairlis-x2
            • Pairlis-x1
            • Delete-assoc
          • Set-register-invariant-risk
          • Strings
          • Program-wrapper
          • Get-internal-time
          • Basics
          • Packages
          • Oracle-eval
          • Defmacro-untouchable
          • <<
          • Primitive
          • Revert-world
          • Unmemoize
          • Set-duplicate-keys-action
          • Symbols
          • Def-list-constructor
          • Easy-simplify-term
          • Defiteration
          • Fake-oracle-eval
          • Defopen
          • Sleep
        • Operational-semantics
        • Real
        • Start-here
        • Debugging
        • Miscellaneous
        • Output-controls
        • Macros
        • Interfacing-tools
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Toposort

    Extract-topological-order

    Extract the topological order from successful applications of toposort-aux.

    Signature
    (extract-topological-order seen acc) → nodelist
    Arguments
    seen — Guard (cons-listp seen).

    Definitions and Theorems

    Function: extract-topological-order

    (defun extract-topological-order (seen acc)
      (declare (xargs :guard (cons-listp seen)))
      (let ((__function__ 'extract-topological-order))
        (declare (ignorable __function__))
        (cond ((atom seen) acc)
              ((eq (cdar seen) :finished)
               (extract-topological-order (cdr seen)
                                          (cons (caar seen) acc)))
              (t (extract-topological-order (cdr seen)
                                            acc)))))

    Theorem: true-listp-of-extract-topological-order

    (defthm true-listp-of-extract-topological-order
      (implies (true-listp acc)
               (true-listp (extract-topological-order seen acc))))

    Theorem: subsetp-equal-of-extract-topological-order

    (defthm subsetp-equal-of-extract-topological-order
      (subsetp-equal (extract-topological-order seen acc)
                     (append (alist-keys seen) acc)))

    Now we prove a completeness theorem that shows extract-topological-order will get us at least everything that was in the queue.

    Theorem: extract-topological-order-includes-queue

    (defthm extract-topological-order-includes-queue
     (implies
          (and (mv-nth 0 (toposort-aux queue seen graph))
               (subsetp-equal queue (alist-keys graph)))
          (subsetp-equal queue
                         (extract-topological-order
                              (mv-nth 1 (toposort-aux queue seen graph))
                              nil))))

    And a uniqueness theorem that shows the extracted elements are at least duplicate-free.

    Theorem: no-duplicatesp-equal-of-extract-topological-order

    (defthm no-duplicatesp-equal-of-extract-topological-order
      (implies
           (no-duplicatesp-equal (extract-topological-order seen nil))
           (no-duplicatesp-equal
                (extract-topological-order
                     (mv-nth 1 (toposort-aux queue seen graph))
                     nil))))