• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
          • Implementation
            • Jenkins-hash
            • Binary-tree
            • Tree-split
            • Heap<
            • Tree-join
            • Tree-delete
            • Rotations
              • Rotate-right
              • Rotate-left
            • Tree-insert
            • Tree-intersect
            • Tree-join-at
            • Tree-union
            • Hash
            • Tree-in
            • Tree-diff
            • Tree-nodes-count
          • Setp
          • Right
          • Left
          • Head
          • Double-containment
          • Subset
          • Intersect
          • Insert
          • In
          • Delete
          • Union
          • Diff
          • From-list
          • To-list
          • Set-equiv
          • Sfix
          • Pick-a-point
          • Cardinality
          • Set-induct
          • Set-bi-induct
          • Emptyp
        • Soft
        • C
        • Bv
        • Imp-language
        • Event-macros
        • Java
        • Bitcoin
        • Ethereum
        • Yul
        • Zcash
        • ACL2-programming-language
        • Prime-fields
        • Json
        • Syntheto
        • File-io-light
        • Cryptography
        • Number-theory
        • Lists-light
        • Axe
        • Builtins
        • Solidity
        • Helpers
        • Htclient
        • Typed-lists-light
        • Arithmetic-light
      • X86isa
      • Axe
      • Execloader
    • Math
    • Testing-utilities
  • Implementation

Rotations

Left and right tree rotations.

Rotations preserve the binary search tree property while rotating up the head of one or the other subtrees.

Definitions and Theorems

Function: rotate-left$inline

(defun rotate-left$inline (tree)
  (declare (xargs :guard (binary-tree-p tree)))
  (declare (xargs :guard (not (tree-emptyp (tree-right tree)))))
  (if (mbt (not (tree-emptyp (tree-right tree))))
      (tree-node (tree-head (tree-right tree))
                 (tree-node (tree-head tree)
                            (tree-left tree)
                            (tree-left (tree-right tree)))
                 (tree-right (tree-right tree)))
    (tree-fix tree)))

Theorem: binary-tree-p-of-rotate-left

(defthm binary-tree-p-of-rotate-left
  (b* ((tree$ (rotate-left$inline tree)))
    (binary-tree-p tree$))
  :rule-classes :rewrite)

Function: rotate-right$inline

(defun rotate-right$inline (tree)
  (declare (xargs :guard (binary-tree-p tree)))
  (declare (xargs :guard (not (tree-emptyp (tree-left tree)))))
  (if (mbt (not (tree-emptyp (tree-left tree))))
      (tree-node (tree-head (tree-left tree))
                 (tree-left (tree-left tree))
                 (tree-node (tree-head tree)
                            (tree-right (tree-left tree))
                            (tree-right tree)))
    (tree-fix tree)))

Theorem: binary-tree-p-of-rotate-right

(defthm binary-tree-p-of-rotate-right
  (b* ((tree$ (rotate-right$inline tree)))
    (binary-tree-p tree$))
  :rule-classes :rewrite)

Subtopics

Rotate-right
Perform a right tree rotation.
Rotate-left
Perform a left tree rotation.