~/bend-docscommunity

word-proof.bend checks

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

Packed-byte word laws, proved one independent Bool at a time.

2 imports
import Base
import bend-mathlib@0.8.0.0/nat.bend as MNat

Definitions

def read source · line 5 · raw

@+w:U32 -> @+lane:Nat -> U32

def write source · line 8 · raw

@+w:U32 -> @+v:U32 -> @+lane:Nat -> U32

def bit_equal source · line 14 · raw

@n:Nat -> @a:Word(n) -> @b:Word(n) -> Type

Extensionality walks the Word spine, never the 2^32 possible words.

def word_ext source · line 23 · raw

@+n:Nat -> @+a:Word(n) -> @+b:Word(n) -> @h:bit_equal(n, a, b) -> {a == b : Word(n)}

def u32_bits source · line 37 · raw

@a:U32 -> @b:U32 -> Type

def u32_ext source · line 42 · raw

@+a:U32 -> @+b:U32 -> @h:u32_bits(a, b) -> {a == b : U32}

def own_bit source · line 47 · raw

@+w:Bool -> @+v:Bool -> {Bool.and(Bool.or(Bool.and(w, False{}), Bool.and(v, True{})), True{}) == Bool.and(v, True{}) : Bool}

def keep_bit source · line 60 · raw

@+w:Bool -> @+v:Bool -> {Bool.and(Bool.or(Bool.and(w, True{}), Bool.and(v, False{})), True{}) == Bool.and(w, True{}) : Bool}

def zero_bit source · line 73 · raw

@+a:Bool -> @+b:Bool -> {Bool.and(a, False{}) == Bool.and(b, False{}) : Bool}

def same_0 source · line 84 · raw

@+w:U32 -> @+v:U32 -> {read(write(w, v, 0n), 0n) == U32.and(v, 255) : U32}

def other_0_1 source · line 92 · raw

@+w:U32 -> @+v:U32 -> {read(write(w, v, 0n), 1n) == read(w, 1n) : U32}

def other_0_2 source · line 100 · raw

@+w:U32 -> @+v:U32 -> {read(write(w, v, 0n), 2n) == read(w, 2n) : U32}

def other_0_3 source · line 108 · raw

@+w:U32 -> @+v:U32 -> {read(write(w, v, 0n), 3n) == read(w, 3n) : U32}

def other_1_0 source · line 116 · raw

@+w:U32 -> @+v:U32 -> {read(write(w, v, 1n), 0n) == read(w, 0n) : U32}

def same_1 source · line 124 · raw

@+w:U32 -> @+v:U32 -> {read(write(w, v, 1n), 1n) == U32.and(v, 255) : U32}

def other_1_2 source · line 132 · raw

@+w:U32 -> @+v:U32 -> {read(write(w, v, 1n), 2n) == read(w, 2n) : U32}

def other_1_3 source · line 140 · raw

@+w:U32 -> @+v:U32 -> {read(write(w, v, 1n), 3n) == read(w, 3n) : U32}

def other_2_0 source · line 148 · raw

@+w:U32 -> @+v:U32 -> {read(write(w, v, 2n), 0n) == read(w, 0n) : U32}

def other_2_1 source · line 156 · raw

@+w:U32 -> @+v:U32 -> {read(write(w, v, 2n), 1n) == read(w, 1n) : U32}

def same_2 source · line 164 · raw

@+w:U32 -> @+v:U32 -> {read(write(w, v, 2n), 2n) == U32.and(v, 255) : U32}

def other_2_3 source · line 172 · raw

@+w:U32 -> @+v:U32 -> {read(write(w, v, 2n), 3n) == read(w, 3n) : U32}

def other_3_0 source · line 180 · raw

@+w:U32 -> @+v:U32 -> {read(write(w, v, 3n), 0n) == read(w, 0n) : U32}

def other_3_1 source · line 188 · raw

@+w:U32 -> @+v:U32 -> {read(write(w, v, 3n), 1n) == read(w, 1n) : U32}

def other_3_2 source · line 196 · raw

@+w:U32 -> @+v:U32 -> {read(write(w, v, 3n), 2n) == read(w, 2n) : U32}

def same_3 source · line 204 · raw

@+w:U32 -> @+v:U32 -> {read(write(w, v, 3n), 3n) == U32.and(v, 255) : U32}

def read_write source · line 213 · raw

@+w:U32 -> @+v:U32 -> @+lane:Nat -> @h:0x78e347bf8d0582a322c01b02c727566f/nat.lt(lane, 4n) -> {read(write(w, v, lane), lane) == U32.and(v, 255) : U32}

The public API keeps lanes natural and makes both bounds explicit.

def read_write_other source · line 228 · raw

@+w:U32 -> @+v:U32 -> @+i:Nat -> @+j:Nat -> @hi:0x78e347bf8d0582a322c01b02c727566f/nat.lt(i, 4n) -> @hj:0x78e347bf8d0582a322c01b02c727566f/nat.lt(j, 4n) -> @ne:(@_:{i == j : Nat} -> Empty) -> {read(write(w, v, i), j) == read(w, j) : U32}

def false_true source · line 281 · raw

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

Boolean and comparison helpers for the byte range.

def and_true source · line 285 · raw

@+x:Bool -> {Bool.and(x, True{}) == x : Bool}

def and_false source · line 292 · raw

@+x:Bool -> {Bool.and(x, False{}) == False{} : Bool}

def word_and_zero source · line 299 · raw

@+n:Nat -> @+w:Word(n) -> {Word.and(n, w, Word.zero(n)) == Word.zero(n) : Word(n)}

def cmp_zero_self source · line 311 · raw

@+n:Nat -> {Word.cmp(n, Word.zero(n), Word.zero(n)) == EQ{} : Cmp}

def fin_not_gt_tail source · line 319 · raw

@+x:Bool -> @+t:Cmp -> @h:{Cmp.is_gt(Word.cmp.fin(x, False{}, t)) == False{} : Bool} -> {Cmp.is_gt(t) == False{} : Bool}

def zero_of_ne_gt source · line 336 · raw

@+n:Nat -> @+w:Word(n) -> @+h:{Cmp.is_gt(Word.cmp(n, w, Word.zero(n))) == False{} : Bool} -> {w == Word.zero(n) : Word(n)}

def fin_ne_gt source · line 361 · raw

@+x:Bool -> @+y:Bool -> @+t:Cmp -> @h:{Cmp.is_lt(Word.cmp.fin(x, y, t)) == True{} : Bool} -> {Cmp.is_gt(t) == False{} : Bool}

def fin_lt_tail source · line 371 · raw

@+x:Bool -> @+t:Cmp -> @h:{Cmp.is_lt(Word.cmp.fin(x, False{}, t)) == True{} : Bool} -> {Cmp.is_lt(t) == True{} : Bool}

def lt_one_head source · line 387 · raw

@+x:Bool -> @+t:Cmp -> @ct:{t == EQ{} : Cmp} -> @h:{Cmp.is_lt(Word.cmp.fin(x, True{}, t)) == True{} : Bool} -> {x == False{} : Bool}

def lt_one source · line 398 · raw

@+p:Nat -> @+w:Word(1n+p) -> @+h:{Cmp.is_lt(Word.cmp(1n+p, w, WCon{True{}, Word.zero(p)})) == True{} : Bool} -> {w == Word.zero(1n+p) : Word(1n+p)}

def and255_small source · line 413 · raw

@+v:U32 -> @h:{U32.is_lt(v, 256) == True{} : Bool} -> {U32.and(v, 255) == v : U32}

def and255_lt source · line 429 · raw

@+v:U32 -> {U32.is_lt(U32.and(v, 255), 256) == True{} : Bool}

def read_small source · line 435 · raw

@+w:U32 -> @+v:U32 -> @+lane:Nat -> @h:0x78e347bf8d0582a322c01b02c727566f/nat.lt(lane, 4n) -> @hv:{U32.is_lt(v, 256) == True{} : Bool} -> {read(write(w, v, lane), lane) == v : U32}

def read_lt source · line 441 · raw

@+w:U32 -> @+lane:Nat -> @h:0x78e347bf8d0582a322c01b02c727566f/nat.lt(lane, 4n) -> {U32.is_lt(read(w, lane), 256) == True{} : Bool}