tree.spad line 307 [edit on github]
BalancedBinaryTree(S) is the domain of balanced binary trees (bbtree). A balanced binary tree of 2^k leaves, for some k > 0, is symmetric, that is, the left and right subtree of each interior node have identical shape. In general, the left and right subtree of a given node can differ by at most one leaf node.
balancedBinaryTree(n, s) creates a balanced binary tree with n nodes each with value s.
mapDown!(t,p,f) returns t after traversing t in "preorder" (node then left then right) fashion replacing the successive interior nodes as follows. The root value x is replaced by q := f(p, x). The mapDown!(l, q, f) and mapDown!(r, q, f) are evaluated for the left and right subtrees l and r of t.
mapDown!(t,p,f) returns t after traversing t in "preorder" (node then left then right) fashion replacing the successive interior nodes as follows. Let l and r denote the left and right subtrees of t. The root value x of t is replaced by p. Then f(value l, value r, p), where l and r denote the left and right subtrees of t, is evaluated producing two values pl and pr. Then mapDown!(l, pl, f) and mapDown!(l, pr, f) are evaluated.
mapUp!(t,t1,f) traverses t in an "endorder" (left then right then node) fashion returning t with the value at each successive interior node of t replaced by f(l, r, l1, r1) where l and r are the values at the immediate left and right nodes. Values l1 and r1 are values at the corresponding nodes of a balanced binary tree t1, of identical shape at t.
mapUp!(t,f) traverses balanced binary tree t in an "endorder" (left then right then node) fashion returning t with the value at each successive interior node of t replaced by f(l, r) where l and r are the values at the immediate left and right nodes.
setleaves!(t, ls) sets the leaves of t in left-to-right order to the elements of ls.
InnerEvalable(S, S)
Evalable(S)