halves.bend checks
raw source on the hub · import lawful-halves@0.1.0.1/halves.bend as Halves
2 imports
import Base import ./defs.bend as D
Definitions
def half source · line 22 · raw
@n:Nat -> Nat
n / 2, rounded down.
def hi source · line 34 · raw
@n:Nat -> Nat
n - n / 2: n / 2 rounded up.
def split.put source · line 46 · raw
@-a:Quant -> @-A:Kind(a) -> @h:A -> @p:Pair(List<a, A>, List<a, A>) -> Pair(List<a, A>, List<a, A>)
h in front of the first list of p.
def split source · line 53 · raw
@-a:Quant -> @-A:Kind(a) -> @xs:List<a, A> -> @+k:Nat -> Pair(List<a, A>, List<a, A>)
The first k values of xs (all of them if fewer) and the rest, in one pass (the values may be ones that can be used only once).
def measure.put source · line 63 · raw
@-a:Quant -> @-A:Kind(a) -> @h:A -> @p:Pair(Nat, List<a, A>) -> Pair(Nat, List<a, A>)
One more value counted, h in front of the list.
def measure source · line 69 · raw
@-a:Quant -> @-A:Kind(a) -> @xs:List<a, A> -> Pair(Nat, List<a, A>)
The length of xs, and xs.
def cons source · line 77 · raw
@-a:Quant -> @-A:Kind(a) -> @x:A -> @s:0x9aaa3659911a785ceb143f33bf8fbe81/defs.Tree<a, A> -> 0x9aaa3659911a785ceb143f33bf8fbe81/defs.Tree<a, A>
x in front of the tree s: Leaf{x} if s is empty, else a Node.
def spine source · line 87 · raw
@-a:Quant -> @-A:Kind(a) -> @xs:List<a, A> -> 0x9aaa3659911a785ceb143f33bf8fbe81/defs.Tree<a, A>
The values of xs as a right spine: Tip, a Leaf, or a Leaf and the rest.
def join source · line 95 · raw
@-a:Quant -> @-A:Kind(a) -> @p:Pair(List<a, A>, List<a, A>) -> List<a, A>
The values of p's first list, then its second.
def build source · line 104 · raw
@-a:Quant -> @-A:Kind(a) -> @+f:Nat -> @big:Bool -> @+n:Nat -> @p:Pair(List<a, A>, List<a, A>) -> 0x9aaa3659911a785ceb143f33bf8fbe81/defs.Tree<a, A>
The tree of the values of p = (l, r): l and r hold n / 2 and n - n / 2 values (big: n >= 2), each split again, down to single values. f bounds the depth (f >= n is enough). The values stay in order whatever f and n are; a spine takes what is left at the bottom.
def tree.k source · line 118 · raw
@-a:Quant -> @-A:Kind(a) -> @p:Pair(Nat, List<a, A>) -> 0x9aaa3659911a785ceb143f33bf8fbe81/defs.Tree<a, A>
The tree of the n values of xs, p = (n, xs).
def tree source · line 123 · raw
@-a:Quant -> @-A:Kind(a) -> @xs:List<a, A> -> 0x9aaa3659911a785ceb143f33bf8fbe81/defs.Tree<a, A>
The balanced tree of xs.
def run source · line 128 · raw
@-b:Quant -> @-B:Kind(b) -> @t:0x9aaa3659911a785ceb143f33bf8fbe81/defs.Tree<&1, 0x9aaa3659911a785ceb143f33bf8fbe81/defs.Task<b, B>> -> 0x9aaa3659911a785ceb143f33bf8fbe81/defs.Tree<b, B>
Every task of t called, the two subtrees of each Node in parallel (the parallel let below; check.sh requires it).
def all source · line 140 · raw
@-b:Quant -> @-B:Kind(b) -> @ts:List<&1, 0x9aaa3659911a785ceb143f33bf8fbe81/defs.Task<b, B>> -> List<b, B>
The results of the tasks ts, in order, run in parallel: the balanced tree of ts, run (law all_tree, proven by {==}; check.sh requires that proof).