~/bend-docscommunity

proof_bsearch.bend checks

raw source on the hub · import bend-osdev-algo@0.1.0.0/proof_bsearch.bend as Proof_bsearch

Proof helpers for bend-osdev-algo: the Array binary search, through bend-osdev-array's laws. PROOF.bend uses them for the laws that tie bsearch.array_lower_bound and bsearch.array_find to the list reference.

A perfect array is reflected, once, into Arrays.of_list(d, l, 0) for a Data list l (array's reflect); array's of_list_get then turns each read of the search into a literal pair: the same array, and the element of l at the masked index. So the search on the array is bq.run, the same halving on Data (bq.go), which hands the array back. The value of each index is then followed as a Nat (proof_u32.bend): mid is lo + (hi - lo) / 2, and a halving at least halves hi - lo.

6 imports
import Base
import ./bsearch.bend as S
import bend-osdev-array@0.1.0.0/array.bend as A
import bend-osdev-array@0.1.0.0/LAWS.bend as AL
import bend-osdev-array@0.1.0.0/PROOF.bend as APF
import ./proof_u32.bend as U

Definitions

def bq.ol source · line 21 · raw

@+d:Nat -> @+l:List<&2, U32> -> Array<U32>

def bq.mid source · line 24 · raw

@+lo:U32 -> @+hi:U32 -> U32

def bq.x source · line 28 · raw

@+d:Nat -> @+l:List<&2, U32> -> @+lo:U32 -> @+hi:U32 -> U32

the element the search reads between lo and hi

def bq.pre source · line 33 · raw

@+l:List<&2, U32> -> @+n:U32 -> List<&2, U32>

the searched prefix, its lower bound, and the range's size and middle as Nats

def bq.lb source · line 36 · raw

@+l:List<&2, U32> -> @+n:U32 -> @+key:U32 -> Nat

def bq.s source · line 39 · raw

@+lo:U32 -> @+hi:U32 -> Nat

def bq.m source · line 42 · raw

@+lo:U32 -> @+hi:U32 -> Nat

def bq.lo_b source · line 47 · raw

@b:Bool -> @+lo:U32 -> @+mid:U32 -> U32

def bq.hi_b source · line 54 · raw

@b:Bool -> @+hi:U32 -> @+mid:U32 -> U32

def bq.nlo.a source · line 61 · raw

@c:Bool -> @b:Bool -> @+lo:U32 -> @+mid:U32 -> U32

def bq.nhi.a source · line 68 · raw

@c:Bool -> @b:Bool -> @+hi:U32 -> @+mid:U32 -> U32

def bq.nlo source · line 75 · raw

@+d:Nat -> @+l:List<&2, U32> -> @+lo:U32 -> @+hi:U32 -> @+key:U32 -> U32

def bq.nhi source · line 78 · raw

@+d:Nat -> @+l:List<&2, U32> -> @+lo:U32 -> @+hi:U32 -> @+key:U32 -> U32

def bq.run source · line 82 · raw

@f:Nat -> @+d:Nat -> @+l:List<&2, U32> -> @+lo:U32 -> @+hi:U32 -> @+key:U32 -> U32

f halvings, then lo

def bq.pick_eq source · line 91 · raw

@b:Bool -> @-a:Array<U32> -> @+lo:U32 -> @+hi:U32 -> @+mid:U32 -> {0xaca75f7679c88e3442b04b98baf3b711/bsearch.bsearch.array.pick(b, a, lo, hi, mid) == 0xaca75f7679c88e3442b04b98baf3b711/bsearch.BsearchState{a, bq.lo_b(b, lo, mid), bq.hi_b(b, hi, mid)} : 0xaca75f7679c88e3442b04b98baf3b711/bsearch.BsearchState}

def bq.step_eq source · line 98 · raw

@c:Bool -> @-a:Array<U32> -> @+x:U32 -> @+key:U32 -> @+lo:U32 -> @+hi:U32 -> @+mid:U32 -> {0xaca75f7679c88e3442b04b98baf3b711/bsearch.bsearch.array.step(c, (a, x), key, lo, hi, mid) == 0xaca75f7679c88e3442b04b98baf3b711/bsearch.BsearchState{a, bq.nlo.a(c, U32.is_lt(x, key), lo, mid), bq.nhi.a(c, U32.is_lt(x, key), hi, mid)} : 0xaca75f7679c88e3442b04b98baf3b711/bsearch.BsearchState}

def bq.go source · line 105 · raw

@f:Nat -> @+d:Nat -> @+l:List<&2, U32> -> @+hl:{List.length(&2, U32, l) == 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.slots(d) : Nat} -> @+hd:{Nat.is_lt(d, 32n) == True{} : Bool} -> @+lo:U32 -> @+hi:U32 -> @+key:U32 -> {0xaca75f7679c88e3442b04b98baf3b711/bsearch.bsearch.array.go(f, 0xaca75f7679c88e3442b04b98baf3b711/bsearch.BsearchState{bq.ol(d, l), lo, hi}, key) == (bq.ol(d, l), bq.run(f, d, l, lo, hi, key)) : Pair(Array<U32>, U32)}

def bq.bt source · line 119 · raw

@b:Bool -> Type

def bq.ft source · line 126 · raw

@e:{False{} == True{} : Bool} -> Empty

def bq.tf source · line 130 · raw

@e:{True{} == False{} : Bool} -> Empty

def bq.nt source · line 134 · raw

@n:Nat -> Type

def bq.sz source · line 141 · raw

@-k:Nat -> @e:{1n+k == 0n : Nat} -> Empty

def bq.le_zero source · line 147 · raw

@x:Nat -> {Nat.is_le(0n, x) == True{} : Bool}

def bq.le_refl source · line 154 · raw

@x:Nat -> {Nat.is_le(x, x) == True{} : Bool}

def bq.le_succ_r source · line 161 · raw

@x:Nat -> @y:Nat -> @h:{Nat.is_le(x, y) == True{} : Bool} -> {Nat.is_le(x, 1n+y) == True{} : Bool}

def bq.lt_le source · line 170 · raw

@x:Nat -> @y:Nat -> @h:{Nat.is_lt(x, y) == True{} : Bool} -> {Nat.is_le(x, y) == True{} : Bool}

def bq.le_trans source · line 179 · raw

@a:Nat -> @b:Nat -> @c:Nat -> @e:{Nat.is_le(a, b) == True{} : Bool} -> @f:{Nat.is_le(b, c) == True{} : Bool} -> {Nat.is_le(a, c) == True{} : Bool}

def bq.lt_le_trans source · line 190 · raw

@a:Nat -> @b:Nat -> @c:Nat -> @e:{Nat.is_lt(a, b) == True{} : Bool} -> @f:{Nat.is_le(b, c) == True{} : Bool} -> {Nat.is_lt(a, c) == True{} : Bool}

def bq.le_antisym source · line 205 · raw

@x:Nat -> @y:Nat -> @h1:{Nat.is_le(x, y) == True{} : Bool} -> @h2:{Nat.is_le(y, x) == True{} : Bool} -> {x == y : Nat}

def bq.not_lt source · line 216 · raw

@x:Nat -> @y:Nat -> @e:{Nat.is_lt(x, y) == False{} : Bool} -> {Nat.is_le(y, x) == True{} : Bool}

def bq.lt_one source · line 227 · raw

@x:Nat -> @e:{Nat.is_lt(x, 1n) == True{} : Bool} -> {x == 0n : Nat}

def bq.lt_succ_le source · line 238 · raw

@x:Nat -> @y:Nat -> @h:{Nat.is_le(x, y) == True{} : Bool} -> {Nat.is_lt(x, 1n+y) == True{} : Bool}

def bq.lt_rw source · line 247 · raw

@-x:Nat -> @-y:Nat -> @-x2:Nat -> @-y2:Nat -> @ex:{x == x2 : Nat} -> @ey:{y == y2 : Nat} -> @h:{Nat.is_lt(x, y) == True{} : Bool} -> {Nat.is_lt(x2, y2) == True{} : Bool}

def bq.le_rw source · line 252 · raw

@-x:Nat -> @-y:Nat -> @-x2:Nat -> @-y2:Nat -> @ex:{x == x2 : Nat} -> @ey:{y == y2 : Nat} -> @h:{Nat.is_le(x, y) == True{} : Bool} -> {Nat.is_le(x2, y2) == True{} : Bool}

def bq.lt_cancel source · line 257 · raw

@s:Nat -> @-r:Nat -> @-u:Nat -> {Nat.is_lt(Nat.add(s, r), Nat.add(s, u)) == Nat.is_lt(r, u) : Bool}

def bq.pw_pos source · line 264 · raw

@f:Nat -> {Nat.is_lt(0n, 0xaca75f7679c88e3442b04b98baf3b711/proof_u32.uq.pw(f)) == True{} : Bool}

def bq.sub_zero source · line 273 · raw

@x:Nat -> {Nat.sub(x, 0n) == x : Nat}

def bq.add_sub source · line 280 · raw

@d:Nat -> @s:Nat -> @e:{Nat.is_le(d, s) == True{} : Bool} -> {Nat.add(d, Nat.sub(s, d)) == s : Nat}

def bq.sub_cancel source · line 289 · raw

@l:Nat -> @-s:Nat -> @-t:Nat -> {Nat.sub(Nat.add(l, s), Nat.add(l, t)) == Nat.sub(s, t) : Nat}

def bq.sub_pos source · line 296 · raw

@l:Nat -> @h:Nat -> @e:{Nat.is_lt(l, h) == True{} : Bool} -> {Nat.is_lt(0n, Nat.sub(h, l)) == True{} : Bool}

def bq.sub_le0 source · line 307 · raw

@h:Nat -> @l:Nat -> @e:{Nat.is_le(h, l) == True{} : Bool} -> {Nat.sub(h, l) == 0n : Nat}

def bq.sub0_le source · line 316 · raw

@h:Nat -> @l:Nat -> @e:{Nat.sub(h, l) == 0n : Nat} -> {Nat.is_le(h, l) == True{} : Bool}

def bq.sub_step source · line 327 · raw

@q:Nat -> @k:Nat -> {Nat.is_le(Nat.sub(q, k), 1n+Nat.sub(q, 1n+k)) == True{} : Bool}

def bq.half_le source · line 339 · raw

@q:Nat -> {Nat.is_le(0xaca75f7679c88e3442b04b98baf3b711/proof_u32.uq.half(q), q) == True{} : Bool}

def bq.half_lt source · line 350 · raw

@s:Nat -> @h:{Nat.is_lt(0n, s) == True{} : Bool} -> {Nat.is_lt(0xaca75f7679c88e3442b04b98baf3b711/proof_u32.uq.half(s), s) == True{} : Bool}

def bq.half_lt_pw source · line 362 · raw

@s:Nat -> @p:Nat -> @h:{Nat.is_lt(s, Nat.double(p)) == True{} : Bool} -> {Nat.is_lt(0xaca75f7679c88e3442b04b98baf3b711/proof_u32.uq.half(s), p) == True{} : Bool}

s < 2p: s / 2 < p

def bq.hr_lt_pw source · line 386 · raw

@s:Nat -> @p:Nat -> @h:{Nat.is_lt(s, Nat.double(p)) == True{} : Bool} -> {Nat.is_lt(Nat.sub(s, 1n+0xaca75f7679c88e3442b04b98baf3b711/proof_u32.uq.half(s)), p) == True{} : Bool}

s < 2p: s - (1 + s / 2) < p

def bq.get_take source · line 411 · raw

@xs:List<&2, U32> -> @k:Nat -> @m:Nat -> @h:{Nat.is_lt(m, k) == True{} : Bool} -> {List.get(&2, U32, List.take(&2, U32, xs, k), m) == List.get(&2, U32, xs, m) : Maybe<&2, U32>}

def bq.get_nth source · line 424 · raw

@xs:List<&2, U32> -> @m:Nat -> @h:{Nat.is_lt(m, List.length(&2, U32, xs)) == True{} : Bool} -> {List.get(&2, U32, xs, m) == Some{0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.nth(U32, xs, m, 0)} : Maybe<&2, U32>}

def bq.len_take source · line 435 · raw

@xs:List<&2, U32> -> @k:Nat -> @h:{Nat.is_le(k, List.length(&2, U32, xs)) == True{} : Bool} -> {List.length(&2, U32, List.take(&2, U32, xs, k)) == k : Nat}

def bq.get_len source · line 446 · raw

@xs:List<&2, U32> -> {List.get(&2, U32, xs, List.length(&2, U32, xs)) == None{} : Maybe<&2, U32>}