Lean4
/-- **Internal use only**, because it violates the BST property on the original order.
O(n). The dual of a tree is a tree with its left and right sides reversed throughout.
The dual of a valid BST is valid under the dual order. This is convenient for exploiting
symmetries in the algorithms. -/
@[simp]
def dual : Ordnode α → Ordnode α
| nil => nil
| node s l x r => node s (dual r) x (dual l)