• 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-loop

    Extract the topological loop from failed applications of toposort-aux.

    Signature
    (extract-topological-loop seen stop acc full-seen) → final-acc
    Arguments
    seen — A copy of the seen alist that we're recurring through.
        Guard (cons-listp seen).
    stop — The node that we looped back to, so we know when to stop (and won't include nodes that we were exploring before getting to the looping node, i.e., the "handle" of a "lasso").
    acc — Accumulator for nodes that really are in the loop.
    full-seen — Fast copy of the full seen alist so we can tell if nodes were finished or not.
    Returns
    final-acc — List of all the nodes in the loop.

    Definitions and Theorems

    Function: extract-topological-loop

    (defun extract-topological-loop (seen stop acc full-seen)
      (declare (xargs :guard (cons-listp seen)))
      (let ((__function__ 'extract-topological-loop))
        (declare (ignorable __function__))
        (cond ((atom seen)
               (prog2$ (er hard? 'extract-topological-loop
                           "Should never hit the end of seen!")
                       acc))
              ((eq (cdar seen) :started)
               (b* ((name (caar seen))
                    (finishedp (eq (cdr (hons-get name full-seen))
                                   :finished))
                    (acc (if finishedp acc (cons name acc))))
                 (if (hons-equal name stop)
                     acc
                   (extract-topological-loop (cdr seen)
                                             stop acc full-seen))))
              (t (extract-topological-loop (cdr seen)
                                           stop acc full-seen)))))

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

    (defthm true-listp-of-extract-topological-loop
     (implies
       (true-listp acc)
       (true-listp (extract-topological-loop seen stop acc full-seen))))

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

    (defthm subsetp-equal-of-extract-topological-loop
      (subsetp-equal (extract-topological-loop seen stop acc full-seen)
                     (append (alist-keys seen) acc)))