Balancing operations #
This file contains the implementation of internal balancing operations used by the modification operations of the tree map and proves that these operations produce balanced trees.
Implementation #
Although it is desirable to separate the implementation from the balancedness proofs as much as
possible, we want the Lean to optimize away some impossible case distinctions. Therefore, we need to
prove them impossible in the implementation itself. Most proofs are automated using a custom
tactic tree_tac, but the proof terms tend to be large, so we should be cautious.
Implementations marked with an exclamation mark do not rely on balancing proofs and just panic when a case occurs that is impossible for balanced trees. These implementations are slower because the impossible cases need to be checked for.
Implementation #
Precondition for balanceL: at most one element was added to left subtree.
Equations
Instances For
Precondition for balanceLErase. As Breitner et al. remark, "not very educational".
Equations
Instances For
Internal implementation detail of the tree map
Equations
Instances For
Internal implementation detail of the tree map
Equations
Instances For
Rebalances a tree after at most one element was added to the left subtree. Uses balancing information to show that some cases are impossible.
Equations
Instances For
Slower version of balanceL with weaker balancing assumptions that hold after erasing from
the right side of the tree.
Equations
Instances For
Slower version of balanceL which can be used in the complete absence of balancing information
but still assumes that the preconditions of balanceL or balanceL are satisfied
(otherwise panics).
Equations
Instances For
Rebalances a tree after at most one element was added to the right subtree. Uses balancing information to show that some cases are impossible.
Equations
Instances For
Slower version of balanceR with weaker balancing assumptions that hold after erasing from
the left side of the tree.
Equations
Instances For
Slower version of balanceR which can be used in the complete absence of balancing information
but still assumes that the preconditions of balanceR or balanceRErase are satisfied
(otherwise panics).
Equations
Instances For
Rebalances a tree after at most one element was added or removed from either subtree.
Equations
Instances For
Slower version of balance which can be used in the complete absence of balancing information
but still assumes that the preconditions of balance are satisfied
(otherwise panics).
Equations
Instances For
Lemmas about balancing operations #
The following definitions are not actually used by the tree map implementation. They are only used
in the model function balanceₘ, which exists for proof purposes only.
The terminology is consistent with the comment above
the balance implementation
in Haskell.