~/bend-docscommunity

array-proof.bend checks

raw source on the hub · import bend-kit-bytes@0.3.3.2/array-proof.bend as Array_proof

Pure perfect-tree Array<U32> laws for the one, two, and four-word decimal buffers.

4 imports
import Base
import bend-kit-lemmas@0.1.5.1/lemmas.bend as Lemmas
import bend-mathlib@0.8.0.0/nat.bend as MNat
import bend-mathlib@0.8.0.0/bool.bend as MBool

Definitions

def nth source · line 7 · raw

@l:List<&2, U32> -> @i:Nat -> U32

def upd source · line 18 · raw

@l:List<&2, U32> -> @i:Nat -> @v:U32 -> List<&2, U32>

def len source · line 29 · raw

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

def drop source · line 36 · raw

@k:Nat -> @l:List<&2, U32> -> List<&2, U32>

def build source · line 48 · raw

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

The model itself is unrestricted; the Array bridge below needs only depth < 3.

def index_zero source · line 55 · raw

@n:Nat -> @h:0x78e347bf8d0582a322c01b02c727566f/nat.lt(n, 1n) -> {0n == n : Nat}

def nth_drop source · line 62 · raw

@+k:Nat -> @+l:List<&2, U32> -> @+i:Nat -> {nth(drop(k, l), i) == nth(l, Nat.add(k, i)) : U32}

def get_leaf source · line 73 · raw

@+l:List<&2, U32> -> @+x:U32 -> @e:{0n == U32.to_nat(x) : Nat} -> {Array.get(U32, build(0n, l), x) == (build(0n, l), nth(l, 0n)) : Pair(Array<U32>, U32)}

def get_pair source · line 77 · raw

@n:Nat -> @+l:List<&2, U32> -> @+x:U32 -> @e:{n == U32.to_nat(x) : Nat} -> @h:0x78e347bf8d0582a322c01b02c727566f/nat.lt(n, 2n) -> {Array.get(U32, build(1n, l), x) == (build(1n, l), nth(l, n)) : Pair(Array<U32>, U32)}

def get_quad source · line 91 · raw

@n:Nat -> @+l:List<&2, U32> -> @+x:U32 -> @e:{n == U32.to_nat(x) : Nat} -> @h:0x78e347bf8d0582a322c01b02c727566f/nat.lt(n, 4n) -> {Array.get(U32, build(2n, l), x) == (build(2n, l), nth(l, n)) : Pair(Array<U32>, U32)}

def get_small source · line 119 · raw

@+d:Nat -> @+l:List<&2, U32> -> @+x:U32 -> @hd:0x78e347bf8d0582a322c01b02c727566f/nat.lt(d, 3n) -> @+hi:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(x), 0xd8f70327683b21776ccf8aa205a4e092/lemmas.pow2(d)) -> {Array.get(U32, build(d, l), x) == (build(d, l), nth(l, U32.to_nat(x))) : Pair(Array<U32>, U32)}

Read preserves the entire affine tree and returns the logical list entry.

def set_leaf source · line 135 · raw

@+a:U32 -> @+t:List<&2, U32> -> @+x:U32 -> @+v:U32 -> @e:{0n == U32.to_nat(x) : Nat} -> {Array.set(U32, build(0n, a <> t), x, v) == build(0n, upd(a <> t, U32.to_nat(x), v)) : Array<U32>}

def set_pair source · line 139 · raw

@n:Nat -> @+a:U32 -> @+b:U32 -> @+t:List<&2, U32> -> @+x:U32 -> @+v:U32 -> @e:{n == U32.to_nat(x) : Nat} -> @h:0x78e347bf8d0582a322c01b02c727566f/nat.lt(n, 2n) -> {Array.set(U32, build(1n, a <> b <> t), x, v) == build(1n, upd(a <> b <> t, U32.to_nat(x), v)) : Array<U32>}

def set_quad source · line 152 · raw

@n:Nat -> @+a:U32 -> @+b:U32 -> @+c:U32 -> @+d:U32 -> @+t:List<&2, U32> -> @+x:U32 -> @+v:U32 -> @e:{n == U32.to_nat(x) : Nat} -> @h:0x78e347bf8d0582a322c01b02c727566f/nat.lt(n, 4n) -> {Array.set(U32, build(2n, a <> b <> c <> d <> t), x, v) == build(2n, upd(a <> b <> c <> d <> t, U32.to_nat(x), v)) : Array<U32>}

def set_small source · line 176 · raw

@+d:Nat -> @+l:List<&2, U32> -> @+x:U32 -> @+v:U32 -> @hd:0x78e347bf8d0582a322c01b02c727566f/nat.lt(d, 3n) -> @hi:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(x), 0xd8f70327683b21776ccf8aa205a4e092/lemmas.pow2(d)) -> @hl:0x78e347bf8d0582a322c01b02c727566f/nat.le(0xd8f70327683b21776ccf8aa205a4e092/lemmas.pow2(d), len(l)) -> {Array.set(U32, build(d, l), x, v) == build(d, upd(l, U32.to_nat(x), v)) : Array<U32>}

A sufficient source list makes the model's ordinary list update exact.

def len_upd source · line 219 · raw

@+l:List<&2, U32> -> @+i:Nat -> @+v:U32 -> {len(upd(l, i, v)) == len(l) : Nat}

def nth_upd_same source · line 231 · raw

@+l:List<&2, U32> -> @+i:Nat -> @+v:U32 -> @h:0x78e347bf8d0582a322c01b02c727566f/nat.lt(i, len(l)) -> {nth(upd(l, i, v), i) == v : U32}

def nth_upd_other source · line 242 · raw

@+l:List<&2, U32> -> @+i:Nat -> @+j:Nat -> @+v:U32 -> @h:{Nat.is_eq(i, j) == False{} : Bool} -> {nth(upd(l, i, v), j) == nth(l, j) : U32}

def replicate source · line 262 · raw

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

Uniform initialization bridges the actual allocator and the list model.

def new_small source · line 269 · raw

@+d:Nat -> @+v:U32 -> @hd:0x78e347bf8d0582a322c01b02c727566f/nat.lt(d, 3n) -> {Array.new(U32, d, v) == build(d, replicate(0xd8f70327683b21776ccf8aa205a4e092/lemmas.pow2(d), v)) : Array<U32>}

def lt_le_trans source · line 284 · raw

@+a:Nat -> @+b:Nat -> @+c:Nat -> @hab:0x78e347bf8d0582a322c01b02c727566f/nat.lt(a, b) -> @hbc:0x78e347bf8d0582a322c01b02c727566f/nat.le(b, c) -> 0x78e347bf8d0582a322c01b02c727566f/nat.lt(a, c)

def get_set_same source · line 308 · raw

@+d:Nat -> @+l:List<&2, U32> -> @+x:U32 -> @+v:U32 -> @+hd:0x78e347bf8d0582a322c01b02c727566f/nat.lt(d, 3n) -> @+hi:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(x), 0xd8f70327683b21776ccf8aa205a4e092/lemmas.pow2(d)) -> @+hl:0x78e347bf8d0582a322c01b02c727566f/nat.le(0xd8f70327683b21776ccf8aa205a4e092/lemmas.pow2(d), len(l)) -> {Array.get(U32, Array.set(U32, build(d, l), x, v), x) == (Array.set(U32, build(d, l), x, v), v) : Pair(Array<U32>, U32)}

Both conclusions retain the updated tree, rather than discarding affine state.

def get_set_other source · line 313 · raw

@+d:Nat -> @+l:List<&2, U32> -> @+x:U32 -> @+y:U32 -> @+v:U32 -> @+hd:0x78e347bf8d0582a322c01b02c727566f/nat.lt(d, 3n) -> @hx:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(x), 0xd8f70327683b21776ccf8aa205a4e092/lemmas.pow2(d)) -> @hy:0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(y), 0xd8f70327683b21776ccf8aa205a4e092/lemmas.pow2(d)) -> @hl:0x78e347bf8d0582a322c01b02c727566f/nat.le(0xd8f70327683b21776ccf8aa205a4e092/lemmas.pow2(d), len(l)) -> @hne:{Nat.is_eq(U32.to_nat(x), U32.to_nat(y)) == False{} : Bool} -> {Array.get(U32, Array.set(U32, build(d, l), x, v), y) == (Array.set(U32, build(d, l), x, v), nth(l, U32.to_nat(y))) : Pair(Array<U32>, U32)}