Kind/book/BBT.balance.kind2
Victor Taelin 85ad65b026 use-notation
Now, there are two local binders:

let x = ...
use x = ...

The 'let' binder will create a local definition, type-check it, and
assign a name to it. When compiled, it will create 'dup' nodes.

The 'use' binder is just an alias. It will not bind a new variable, and,
when compiled, will create inline copies. Also, for type-checking, it
allows creating aliases that are definitionaly equal for the checker.
2024-03-08 17:39:37 -03:00

66 lines
1.6 KiB
Plaintext

BBT.balance
: ∀(K: *)
∀(V: *)
∀(cmp: ∀(a: K) ∀(b: K) Cmp)
∀(set_key: K)
∀(node_key: K)
∀(val: V)
∀(lft: (BBT K V))
∀(rgt: (BBT K V))
(BBT K V)
= λK λV λcmp λset_key λnode_key λval λlft λrgt
use P = λx (BBT K V)
use new = λlft.size λlft
use P = λx (BBT K V)
use new = λrgt.size λrgt
use new_size = #(+ #1 (U60.max lft.size rgt.size))
use balance = (U60.abs_diff lft.size rgt.size)
use P = λx
∀(new_size: #U60)
∀(node_key: K)
∀(val: V)
∀(lft: (BBT K V))
∀(rgt: (BBT K V))
(BBT K V)
use true = λnew_size λnode_key λval λlft λrgt
use P = λx
∀(K: *)
∀(V: *)
∀(cmp: ∀(a: K) ∀(b: K) Cmp)
∀(new_size: #U60)
∀(node_key: K)
∀(set_key: K)
∀(val: V)
∀(lft: (BBT K V))
∀(rgt: (BBT K V))
(BBT K V)
use true = BBT.balance.lft_heavier
use false = BBT.balance.rgt_heavier
(~(U60.to_bool #(< rgt.size lft.size))
P
true
false
K
V
cmp
new_size
node_key
set_key
val
lft
rgt
)
use false = λnew_size λnode_key λval λlft λrgt
(BBT.bin K V new_size node_key val lft rgt)
(~(U60.to_bool #(> balance #1))
P
true
false
new_size
node_key
val
lft
rgt
)
(~(BBT.got_size K V rgt) P new)
(~(BBT.got_size K V lft) P new)