~/bend-docscommunity

LAWS.bend open laws/TODOs

raw source on the hub · import bend-osdev-array@0.1.0.0/LAWS.bend as LAWS

Laws about Base's Array (Array.size, Array.get, Array.set, Array.new), as Base 2.0.37 defines them, for every input:

* for every array, of any shape: a read hands back the same array; a read after a write at the same index answers the value written; a write keeps the size; every slot of Array.new holds its value; * perfect trees (Arrays.is_perfect): Array.new builds one, Array.set keeps one, and the size of one of depth d is 2^d; * for a perfect tree of depth d < 32, against the list model (Arrays.leaves, the slots in index order): a read answers the model's element at the masked index (Arrays.index), a write sets it, the model has 2^d elements, and a write leaves every read at a different masked index unchanged; * the masked index is below 2^d, and is k itself for a k below 2^d (for 2^d + k as well, which wraps to k; and for a U32 below 2^d, its value); * arrays built from a Data list (Arrays.of_list): every perfect array is one (reflect), and get, set and new answer one, so that a proof can follow a sequence of reads and writes on Data alone.

Arrays are single-owner values (Type), but a law's statement is checked dead, so it may mention one array several times; the proofs consume each array once (they reflect it into a Data tree).

2 imports
import Base
import ./array.bend as A

Laws

law get_same_array provedin PROOF.bendsource · line 28 · raw

@-T:Data -> @a:Array<T> -> @i:U32 -> {Pair.fst(Array<T>, T, Array.get(T, a, i)) == a : Array<T>}

law get_set_same provedin PROOF.bendsource · line 34 · raw

@-T:Data -> @a:Array<T> -> @i:U32 -> @v:T -> {Pair.snd(Array<T>, T, Array.get(T, Array.set(T, a, i, v), i)) == v : T}

law set_keeps_size provedin PROOF.bendsource · line 41 · raw

@-T:Data -> @a:Array<T> -> @i:U32 -> @v:T -> {Pair.snd(Array<T>, U32, Array.size(T, Array.set(T, a, i, v))) == Pair.snd(Array<T>, U32, Array.size(T, a)) : U32}

law get_new provedin PROOF.bendsource · line 48 · raw

@-T:Data -> @d:Nat -> @v:T -> @i:U32 -> {Pair.snd(Array<T>, T, Array.get(T, Array.new(T, d, v), i)) == v : T}

law new_perfect provedin PROOF.bendsource · line 57 · raw

@-T:Data -> @d:Nat -> @v:T -> {0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.is_perfect(T, d, Array.new(T, d, v)) == True{} : Bool}

law set_perfect provedin PROOF.bendsource · line 63 · raw

@-T:Data -> @d:Nat -> @a:Array<T> -> @h:{0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.is_perfect(T, d, a) == True{} : Bool} -> @i:U32 -> @v:T -> {0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.is_perfect(T, d, Array.set(T, a, i, v)) == True{} : Bool}

law size_perfect provedin PROOF.bendsource · line 72 · raw

@-T:Data -> @d:Nat -> @a:Array<T> -> @h:{0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.is_perfect(T, d, a) == True{} : Bool} -> {Array.size(T, a) == (a, U32.shln(1, d)) : Pair(Array<T>, U32)}

law new_leaves provedin PROOF.bendsource · line 79 · raw

@-T:Data -> @d:Nat -> @v:T -> {0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.leaves(T, Array.new(T, d, v)) == List.replicate(T, 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.slots(d), v) : List<&2, T>}

law model_length provedin PROOF.bendsource · line 87 · raw

@-T:Data -> @d:Nat -> @a:Array<T> -> @h:{0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.is_perfect(T, d, a) == True{} : Bool} -> {List.length(&2, T, 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.leaves(T, a)) == 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.slots(d) : Nat}

law model_get provedin PROOF.bendsource · line 94 · raw

@-T:Data -> @d:Nat -> @a:Array<T> -> @h:{0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.is_perfect(T, d, a) == True{} : Bool} -> @hd:{Nat.is_lt(d, 32n) == True{} : Bool} -> @i:U32 -> {List.get(&2, T, 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.leaves(T, a), 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.index(d, i)) == Some{Pair.snd(Array<T>, T, Array.get(T, a, i))} : Maybe<&2, T>}

law model_set provedin PROOF.bendsource · line 103 · raw

@-T:Data -> @d:Nat -> @a:Array<T> -> @h:{0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.is_perfect(T, d, a) == True{} : Bool} -> @hd:{Nat.is_lt(d, 32n) == True{} : Bool} -> @i:U32 -> @v:T -> {0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.leaves(T, Array.set(T, a, i, v)) == List.set(&2, T, 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.leaves(T, a), 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.index(d, i), v) : List<&2, T>}

law get_set_other provedin PROOF.bendsource · line 113 · raw

@-T:Data -> @d:Nat -> @a:Array<T> -> @h:{0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.is_perfect(T, d, a) == True{} : Bool} -> @hd:{Nat.is_lt(d, 32n) == True{} : Bool} -> @i:U32 -> @j:U32 -> @v:T -> @hij:{U32.is_eq(U32.and(i, U32.sub(U32.shln(1, d), 1)), U32.and(j, U32.sub(U32.shln(1, d), 1))) == False{} : Bool} -> {Pair.snd(Array<T>, T, Array.get(T, Array.set(T, a, i, v), j)) == Pair.snd(Array<T>, T, Array.get(T, a, j)) : T}

law index_below provedin PROOF.bendsource · line 127 · raw

@d:Nat -> @i:U32 -> {Nat.is_lt(0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.index(d, i), 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.slots(d)) == True{} : Bool}

law index_of_nat provedin PROOF.bendsource · line 132 · raw

@d:Nat -> @hd:{Nat.is_lt(d, 32n) == True{} : Bool} -> @k:Nat -> @hk:{Nat.is_lt(k, 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.slots(d)) == True{} : Bool} -> {0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.index(d, U32.from_nat(k)) == k : Nat}

law index_wrap provedin PROOF.bendsource · line 139 · raw

@d:Nat -> @hd:{Nat.is_lt(d, 32n) == True{} : Bool} -> @k:Nat -> @hk:{Nat.is_lt(k, 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.slots(d)) == True{} : Bool} -> {0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.index(d, U32.from_nat(Nat.add(0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.slots(d), k))) == k : Nat}

law index_of_u32 provedin PROOF.bendsource · line 146 · raw

@d:Nat -> @i:U32 -> @hi:{Nat.is_lt(U32.to_nat(i), 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.slots(d)) == True{} : Bool} -> {0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.index(d, i) == U32.to_nat(i) : Nat}

law of_list_perfect provedin PROOF.bendsource · line 158 · raw

@-T:Data -> @+d:Nat -> @+xs:List<&2, T> -> @+f:T -> {0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.is_perfect(T, d, 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.of_list(T, d, xs, f)) == True{} : Bool}

law of_list_leaves provedin PROOF.bendsource · line 165 · raw

@-T:Data -> @+d:Nat -> @+xs:List<&2, T> -> @+f:T -> @+hl:{List.length(&2, T, xs) == 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.slots(d) : Nat} -> {0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.leaves(T, 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.of_list(T, d, xs, f)) == xs : List<&2, T>}

law of_list_size provedin PROOF.bendsource · line 173 · raw

@-T:Data -> @+d:Nat -> @+xs:List<&2, T> -> @+f:T -> {Array.size(T, 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.of_list(T, d, xs, f)) == (0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.of_list(T, d, xs, f), U32.shln(1, d)) : Pair(Array<T>, U32)}

law of_list_get provedin PROOF.bendsource · line 180 · raw

@-T:Data -> @+d:Nat -> @+xs:List<&2, T> -> @+f:T -> @+hl:{List.length(&2, T, xs) == 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.slots(d) : Nat} -> @+hd:{Nat.is_lt(d, 32n) == True{} : Bool} -> @+i:U32 -> {Array.get(T, 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.of_list(T, d, xs, f), i) == (0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.of_list(T, d, xs, f), 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.nth(T, xs, 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.index(d, i), f)) : Pair(Array<T>, T)}

law of_list_set provedin PROOF.bendsource · line 190 · raw

@-T:Data -> @+d:Nat -> @+xs:List<&2, T> -> @+f:T -> @+hl:{List.length(&2, T, xs) == 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.slots(d) : Nat} -> @+hd:{Nat.is_lt(d, 32n) == True{} : Bool} -> @+i:U32 -> @+v:T -> {Array.set(T, 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.of_list(T, d, xs, f), i, v) == 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.of_list(T, d, List.set(&2, T, xs, 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.index(d, i), v), f) : Array<T>}

law of_list_new provedin PROOF.bendsource · line 201 · raw

@-T:Data -> @+d:Nat -> @+v:T -> {Array.new(T, d, v) == 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.of_list(T, d, List.replicate(T, 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.slots(d), v), v) : Array<T>}

law reflect provedin PROOF.bendsource · line 207 · raw

@-T:Data -> @+d:Nat -> @a:Array<T> -> @h:{0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.is_perfect(T, d, a) == True{} : Bool} -> @+f:T -> &xs:List<&2, T> -> Pair({0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.of_list(T, d, xs, f) == a : Array<T>}, {List.length(&2, T, xs) == 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.slots(d) : Nat})

law set_length provedin PROOF.bendsource · line 218 · raw

@-T:Data -> @xs:List<&2, T> -> @k:Nat -> @v:T -> {List.length(&2, T, List.set(&2, T, xs, k, v)) == List.length(&2, T, xs) : Nat}

law nth_set_same provedin PROOF.bendsource · line 225 · raw

@-T:Data -> @xs:List<&2, T> -> @k:Nat -> @v:T -> @f:T -> @h:{Nat.is_lt(k, List.length(&2, T, xs)) == True{} : Bool} -> {0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.nth(T, List.set(&2, T, xs, k, v), k, f) == v : T}

law nth_set_other provedin PROOF.bendsource · line 234 · raw

@-T:Data -> @xs:List<&2, T> -> @k:Nat -> @m:Nat -> @v:T -> @f:T -> @h:{Nat.is_eq(k, m) == False{} : Bool} -> {0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.nth(T, List.set(&2, T, xs, k, v), m, f) == 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.nth(T, xs, m, f) : T}

law nth_replicate provedin PROOF.bendsource · line 244 · raw

@-T:Data -> @n:Nat -> @v:T -> @k:Nat -> @f:T -> @h:{Nat.is_lt(k, n) == True{} : Bool} -> {0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.nth(T, List.replicate(T, n, v), k, f) == v : T}

law witness_perfect provedin PROOF.bendsource · line 256 · raw

{Bool.and(0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.is_perfect(U32, 2n, Array.new(U32, 2n, 0)), Nat.is_lt(2n, 32n)) == True{} : Bool}

law witness_other provedin PROOF.bendsource · line 259 · raw

{U32.is_eq(U32.and(1, U32.sub(U32.shln(1, 2n), 1)), U32.and(2, U32.sub(U32.shln(1, 2n), 1))) == False{} : Bool}

law witness_index provedin PROOF.bendsource · line 262 · raw

{Nat.is_lt(3n, 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.slots(2n)) == True{} : Bool}

law witness_index_wrap provedin PROOF.bendsource · line 265 · raw

{Bool.and(Nat.is_lt(U32.to_nat(5), 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.slots(3n)), Nat.is_lt(3n, 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.slots(2n))) == True{} : Bool}

law witness_list provedin PROOF.bendsource · line 268 · raw

{Bool.and(Nat.is_eq(List.length(&2, U32, [5, 6, 7, 8]), 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.slots(2n)), Bool.and(Nat.is_lt(1n, 4n), Nat.is_ne(1n, 2n))) == True{} : Bool}

law vector_wrap provedin PROOF.bendsource · line 273 · raw

{Pair.snd(Array<U32>, U32, Array.get(U32, Array.set(U32, Array.new(U32, 2n, 0), 6, 9), 2)) == 9 : U32}

law vector_leaves provedin PROOF.bendsource · line 276 · raw

{0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.leaves(U32, Array.set(U32, Array.new(U32, 2n, 0), 1, 7)) == [0, 7, 0, 0] : List<&2, U32>}

law vector_index provedin PROOF.bendsource · line 279 · raw

{0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.index(3n, 13) == 5n : Nat}

law vector_of_list provedin PROOF.bendsource · line 282 · raw

{Pair.snd(Array<U32>, U32, Array.get(U32, Array.set(U32, 0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.of_list(U32, 2n, [5, 6, 7, 8], 0), 1, 9), 5)) == 9 : U32}

law vector_index_wrap provedin PROOF.bendsource · line 285 · raw

{0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.index(2n, U32.from_nat(Nat.add(0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.slots(2n), 3n))) == 3n : Nat}

law vector_not_perfect provedin PROOF.bendsource · line 288 · raw

{0x4fcda21d38b51a2f03fa460c0b81cfc3/array.Arrays.is_perfect(U32, 2n, [1, 2, 3]) == False{} : Bool}