• 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
            • Transdeps
            • Invert
              • Invert-outer-loop
              • Invert-inner-loop
            • 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
  • Depgraph

Invert

Invert a dependency graph.

Signature
(invert graph) → inverted-graph
Arguments
graph — Alist that binds nodes to the list of nodes they (directly) depend on.
Returns
inverted-graph — Fast alist that binds nodes to the list of nodes that (directly) depend on them.

See the discussion of graph representation in depgraph. This basically changes the directions of arrows in the graph. For instance, if our original graph was:

A ----->  B ---> C        ((A . (B))
          |      |         (B . (C D))
          |      |         (C . (D))
          v      |         (D . NIL))
          D <----+

Then inverting the graph just changes the directions of all the arrows, e.g., we would have:

A <-----  B <--- C        ((A . NIL)
          ^      ^         (B . (A))
          |      |         (C . (B))
          |      |         (D . (C B)))
          D -----+

We are careful to ensure that every node is bound in the resulting graph, e.g., we'll have a binding for A even though it is a leaf node.

Definitions and Theorems

Function: invert

(defun invert (graph)
 (declare (xargs :guard t))
 (let ((__function__ 'invert))
   (declare (ignorable __function__))
   (b* ((nodes (alist-keys graph))
        (acc (make-fast-alist (pairlis$ nodes nil)))
        (acc (with-fast-alist graph
                              (invert-outer-loop nodes graph acc))))
     (fast-alist-clean acc))))

Theorem: invert-correct

(defthm invert-correct
  (iff (member parent
               (cdr (hons-assoc-equal child (invert graph))))
       (member child
               (cdr (hons-assoc-equal parent graph)))))

Subtopics

Invert-outer-loop
Add all parent dependencies to all children.
Invert-inner-loop
Add a parent dependency to each of its children.