~/bend-docscommunity

proof_num.bend checks

raw source on the hub · import 0xeb25eff332574f4f1d48668b83cdda30/proof_num.bend as Proof_num

Proof helpers for bend-osdev-asn1: numbers in octets. The digits of n in any base read back as n by Horner's rule, and are below the base; base-128 octets read back (a1.r128), big-endian octets read back (a1.fold256); and so the length octets (length.bend) and identifier octets (tag.bend) the encoder writes read back as what was written.

10 imports
import Base
import bend-osdev-bytes@0.1.0.0/bytes.bend as B
import ./number.bend as Nu
import ./tag.bend as T
import ./length.bend as L
import ./rules.bend as R
import ./proof_nat.bend as AN
import ./proof_list.bend as AL
import ./proof_u32.bend as AU
import ./proof_byte.bend as AB

Definitions

def pn.all_lt source · line 18 · raw

@ds:List<&2, Nat> -> @+b:Nat -> Bool

every element of ds is below b

def pn.all_lt_app source · line 25 · raw

@xs:List<&2, Nat> -> @+ys:List<&2, Nat> -> @+b:Nat -> @+hx:{pn.all_lt(xs, b) == True{} : Bool} -> @+hy:{pn.all_lt(ys, b) == True{} : Bool} -> {pn.all_lt(List.append(&2, Nat, xs, ys), b) == True{} : Bool}

def pn.ne source · line 32 · raw

@ds:List<&2, Nat> -> Bool

def pn.ne_app source · line 39 · raw

@xs:List<&2, Nat> -> @+d:Nat -> {pn.ne(List.append(&2, Nat, xs, [d])) == True{} : Bool}

def pn.horner_snoc source · line 48 · raw

@xs:List<&2, Nat> -> @+b:Nat -> @+acc:Nat -> @+d:Nat -> {0xeb25eff332574f4f1d48668b83cdda30/number.a1.horner(List.append(&2, Nat, xs, [d]), b, acc) == Nat.add(Nat.mul(0xeb25eff332574f4f1d48668b83cdda30/number.a1.horner(xs, b, acc), b), d) : Nat}

def pn.horner_digits source · line 56 · raw

@fuel:Nat -> @lt:Bool -> @+bp:Nat -> @+n:Nat -> {0xeb25eff332574f4f1d48668b83cdda30/number.a1.horner(0xeb25eff332574f4f1d48668b83cdda30/number.a1.digits.go(fuel, lt, 1n+bp, n), 1n+bp, 0n) == n : Nat}

the digits of n read back as n (b = 1 + bp; lt is whether n < b)

def pn.horner_digits_top source · line 69 · raw

@+bp:Nat -> @+n:Nat -> {0xeb25eff332574f4f1d48668b83cdda30/number.a1.horner(0xeb25eff332574f4f1d48668b83cdda30/number.a1.digits(1n+bp, n), 1n+bp, 0n) == n : Nat}

def pn.le_not_lt source · line 72 · raw

@+a:Nat -> @+b:Nat -> {Nat.is_le(a, b) == Bool.not(Nat.is_lt(b, a)) : Bool}

def pn.digits_lt source · line 84 · raw

@fuel:Nat -> @lt:Bool -> @+bp:Nat -> @+n:Nat -> @+hl:{Nat.is_lt(n, 2n+bp) == lt : Bool} -> @+hf:{Nat.is_le(n, fuel) == True{} : Bool} -> {pn.all_lt(0xeb25eff332574f4f1d48668b83cdda30/number.a1.digits.go(fuel, lt, 2n+bp, n), 2n+bp) == True{} : Bool}

the digits are below the base (b = 2 + bp; fuel at least n)

def pn.digits_lt_top source · line 104 · raw

@+bp:Nat -> @+n:Nat -> {pn.all_lt(0xeb25eff332574f4f1d48668b83cdda30/number.a1.digits(2n+bp, n), 2n+bp) == True{} : Bool}

def pn.digits_ne source · line 107 · raw

@fuel:Nat -> @lt:Bool -> @+b:Nat -> @+n:Nat -> {pn.ne(0xeb25eff332574f4f1d48668b83cdda30/number.a1.digits.go(fuel, lt, b, n)) == True{} : Bool}

def pn.digits_ne_top source · line 117 · raw

@+b:Nat -> @+n:Nat -> {pn.ne(0xeb25eff332574f4f1d48668b83cdda30/number.a1.digits(b, n)) == True{} : Bool}

def pn.lt128_256 source · line 122 · raw

@+d:Nat -> @+h:{Nat.is_lt(d, 128n) == True{} : Bool} -> {Nat.is_lt(d, 256n) == True{} : Bool}

def pn.lt_add128 source · line 125 · raw

@+d:Nat -> @+h:{Nat.is_lt(d, 128n) == True{} : Bool} -> {Nat.is_lt(Nat.add(128n, d), 256n) == True{} : Bool}

def pn.r128_step source · line 129 · raw

@+x:U32 -> @+t:List<&2, U32> -> @+j:Nat -> @+acc:Nat -> @+v:Nat -> @+hv:{U32.to_nat(x) == v : Nat} -> {0xeb25eff332574f4f1d48668b83cdda30/number.a1.r128(x <> t, True{}, 1n+j, acc) == 0xeb25eff332574f4f1d48668b83cdda30/number.a1.num_cons(x, 0xeb25eff332574f4f1d48668b83cdda30/number.a1.r128(t, Nat.is_le(128n, v), j, Nat.add(Nat.mul(acc, 128n), Nat.sub(v, Bool.pick(Nat, Nat.is_le(128n, v), 128n, 0n))))) : Maybe<&2, 0xeb25eff332574f4f1d48668b83cdda30/number.A1Num>}

reading one base-128 octet whose value is v

def pn.r128_end source · line 133 · raw

@xs:List<&2, U32> -> @+k:Nat -> @+acc:Nat -> {0xeb25eff332574f4f1d48668b83cdda30/number.a1.r128(xs, False{}, k, acc) == Some{0xeb25eff332574f4f1d48668b83cdda30/number.A1Num{acc, [], xs}} : Maybe<&2, 0xeb25eff332574f4f1d48668b83cdda30/number.A1Num>}

def pn.step_sym source · line 140 · raw

@+x:U32 -> @+t:List<&2, U32> -> @+j:Nat -> @+acc:Nat -> @+v:Nat -> @+hv:{U32.to_nat(x) == v : Nat} -> {0xeb25eff332574f4f1d48668b83cdda30/number.a1.num_cons(x, 0xeb25eff332574f4f1d48668b83cdda30/number.a1.r128(t, Nat.is_le(128n, v), j, Nat.add(Nat.mul(acc, 128n), Nat.sub(v, Bool.pick(Nat, Nat.is_le(128n, v), 128n, 0n))))) == 0xeb25eff332574f4f1d48668b83cdda30/number.a1.r128(x <> t, True{}, 1n+j, acc) : Maybe<&2, 0xeb25eff332574f4f1d48668b83cdda30/number.A1Num>}

def pn.r128_last source · line 144 · raw

@+d:Nat -> @+rest:List<&2, U32> -> @+j:Nat -> @+acc:Nat -> @+hd:{Nat.is_lt(d, 128n) == True{} : Bool} -> {0xeb25eff332574f4f1d48668b83cdda30/number.a1.r128(0xeb25eff332574f4f1d48668b83cdda30/number.a1.b(d) <> rest, True{}, 1n+j, acc) == Some{0xeb25eff332574f4f1d48668b83cdda30/number.A1Num{Nat.add(Nat.mul(acc, 128n), d), [0xeb25eff332574f4f1d48668b83cdda30/number.a1.b(d)], rest}} : Maybe<&2, 0xeb25eff332574f4f1d48668b83cdda30/number.A1Num>}

the last octet of a base-128 number (d < 128): bit 8 clear, so it ends

def pn.r128_more source · line 155 · raw

@+d:Nat -> @+t:List<&2, U32> -> @+j:Nat -> @+acc:Nat -> @+hd:{Nat.is_lt(d, 128n) == True{} : Bool} -> {0xeb25eff332574f4f1d48668b83cdda30/number.a1.r128(0xeb25eff332574f4f1d48668b83cdda30/number.a1.b(Nat.add(128n, d)) <> t, True{}, 1n+j, acc) == 0xeb25eff332574f4f1d48668b83cdda30/number.a1.num_cons(0xeb25eff332574f4f1d48668b83cdda30/number.a1.b(Nat.add(128n, d)), 0xeb25eff332574f4f1d48668b83cdda30/number.a1.r128(t, True{}, j, Nat.add(Nat.mul(acc, 128n), d))) : Maybe<&2, 0xeb25eff332574f4f1d48668b83cdda30/number.A1Num>}

an octet before the last (bit 8 set): it goes on

def pn.r128_enc source · line 166 · raw

@ds:List<&2, Nat> -> @+rest:List<&2, U32> -> @k:Nat -> @+acc:Nat -> @+hne:{pn.ne(ds) == True{} : Bool} -> @+hall:{pn.all_lt(ds, 128n) == True{} : Bool} -> @+hk:{Nat.is_le(List.length(&2, Nat, ds), k) == True{} : Bool} -> {0xeb25eff332574f4f1d48668b83cdda30/number.a1.r128(List.append(&2, U32, 0xeb25eff332574f4f1d48668b83cdda30/number.a1.enc128(ds), rest), True{}, k, acc) == Some{0xeb25eff332574f4f1d48668b83cdda30/number.A1Num{0xeb25eff332574f4f1d48668b83cdda30/number.a1.horner(ds, 128n, acc), 0xeb25eff332574f4f1d48668b83cdda30/number.a1.enc128(ds), rest}} : Maybe<&2, 0xeb25eff332574f4f1d48668b83cdda30/number.A1Num>}

base-128 octets of digits below 128 read back as their value, within a budget of k octets

def pn.len_enc128 source · line 187 · raw

@ds:List<&2, Nat> -> {List.length(&2, U32, 0xeb25eff332574f4f1d48668b83cdda30/number.a1.enc128(ds)) == List.length(&2, Nat, ds) : Nat}

def pn.r128_b128 source · line 200 · raw

@+n:Nat -> @+rest:List<&2, U32> -> @+k:Nat -> @+hk:{Nat.is_le(List.length(&2, U32, 0xeb25eff332574f4f1d48668b83cdda30/number.a1.b128(n)), k) == True{} : Bool} -> {0xeb25eff332574f4f1d48668b83cdda30/number.a1.r128(List.append(&2, U32, 0xeb25eff332574f4f1d48668b83cdda30/number.a1.b128(n), rest), True{}, k, 0n) == Some{0xeb25eff332574f4f1d48668b83cdda30/number.A1Num{n, 0xeb25eff332574f4f1d48668b83cdda30/number.a1.b128(n), rest}} : Maybe<&2, 0xeb25eff332574f4f1d48668b83cdda30/number.A1Num>}

a number's base-128 octets (at most k of them) read back as it

def pn.fold_bytes source · line 209 · raw

@ds:List<&2, Nat> -> @+acc:Nat -> @+hall:{pn.all_lt(ds, 256n) == True{} : Bool} -> {0xeb25eff332574f4f1d48668b83cdda30/number.a1.fold256(0xeb25eff332574f4f1d48668b83cdda30/number.a1.bytes_of(ds), acc) == 0xeb25eff332574f4f1d48668b83cdda30/number.a1.horner(ds, 256n, acc) : Nat}

def pn.len_bytes_of source · line 219 · raw

@ds:List<&2, Nat> -> {List.length(&2, U32, 0xeb25eff332574f4f1d48668b83cdda30/number.a1.bytes_of(ds)) == List.length(&2, Nat, ds) : Nat}

def pn.ne_len source · line 227 · raw

@ds:List<&2, Nat> -> @+h:{pn.ne(ds) == True{} : Bool} -> {Nat.is_le(1n, List.length(&2, Nat, ds)) == True{} : Bool}

def pn.fold_be source · line 235 · raw

@+n:Nat -> {0xeb25eff332574f4f1d48668b83cdda30/number.a1.fold256(0xeb25eff332574f4f1d48668b83cdda30/number.a1.be(n), 0n) == n : Nat}

the octets of be(n) read back as n (fold256)

def pn.be_len source · line 239 · raw

@+n:Nat -> {Nat.is_le(1n, List.length(&2, U32, 0xeb25eff332574f4f1d48668b83cdda30/number.a1.be(n))) == True{} : Bool}

def pn.lb_short source · line 246 · raw

@+n:Nat -> @+h:{Nat.is_lt(n, 128n) == True{} : Bool} -> {0xeb25eff332574f4f1d48668b83cdda30/length.a1.len_bytes(n) == [0xeb25eff332574f4f1d48668b83cdda30/number.a1.b(n)] : List<&2, U32>}

def pn.lr_short source · line 250 · raw

@+n:Nat -> @+rest:List<&2, U32> -> @+h:{Nat.is_lt(n, 128n) == True{} : Bool} -> {0xeb25eff332574f4f1d48668b83cdda30/length.a1.len.read(0xeb25eff332574f4f1d48668b83cdda30/number.a1.b(n) <> rest) == 0xeb25eff332574f4f1d48668b83cdda30/length.A1LDef{n, [0xeb25eff332574f4f1d48668b83cdda30/number.a1.b(n)], rest} : 0xeb25eff332574f4f1d48668b83cdda30/length.A1Len}

def pn.lb_long source · line 255 · raw

@+n:Nat -> @+h:{Nat.is_lt(n, 128n) == False{} : Bool} -> {0xeb25eff332574f4f1d48668b83cdda30/length.a1.len_bytes(n) == 0xeb25eff332574f4f1d48668b83cdda30/number.a1.b(Nat.add(128n, List.length(&2, U32, 0xeb25eff332574f4f1d48668b83cdda30/number.a1.be(n)))) <> 0xeb25eff332574f4f1d48668b83cdda30/number.a1.be(n) : List<&2, U32>}

def pn.okm source · line 259 · raw

@+n:Nat -> @+h:{Nat.is_lt(n, 128n) == False{} : Bool} -> @+hok:{0xeb25eff332574f4f1d48668b83cdda30/length.a1.len_ok(n) == True{} : Bool} -> {Nat.is_le(List.length(&2, U32, 0xeb25eff332574f4f1d48668b83cdda30/number.a1.be(n)), 6n) == True{} : Bool}

def pn.le_nlt source · line 263 · raw

@+a:Nat -> @+b:Nat -> @+h:{Nat.is_le(a, b) == True{} : Bool} -> {Nat.is_lt(b, a) == False{} : Bool}

a <= b: not b < a

def pn.long_pos source · line 272 · raw

@+k:Nat -> @+y:U32 -> @+t:List<&2, U32> -> @+hk:{Nat.is_le(1n, k) == True{} : Bool} -> {0xeb25eff332574f4f1d48668b83cdda30/length.a1.len.long(k, y, t) == 0xeb25eff332574f4f1d48668b83cdda30/length.a1.len.reserved(Nat.is_eq(k, 127n), k, y, t) : 0xeb25eff332574f4f1d48668b83cdda30/length.A1Len}

def pn.rbe_app source · line 279 · raw

@+ds:List<&2, U32> -> @+rest:List<&2, U32> -> {0xeb25eff332574f4f1d48668b83cdda30/number.a1.rbe(List.length(&2, U32, ds), List.append(&2, U32, ds, rest)) == Some{0xeb25eff332574f4f1d48668b83cdda30/number.A1Num{0xeb25eff332574f4f1d48668b83cdda30/number.a1.fold256(ds, 0n), ds, rest}} : Maybe<&2, 0xeb25eff332574f4f1d48668b83cdda30/number.A1Num>}

def pn.lr_long source · line 288 · raw

@+n:Nat -> @+rest:List<&2, U32> -> @+h:{Nat.is_lt(n, 128n) == False{} : Bool} -> @+hok:{0xeb25eff332574f4f1d48668b83cdda30/length.a1.len_ok(n) == True{} : Bool} -> {0xeb25eff332574f4f1d48668b83cdda30/length.a1.len.read(0xeb25eff332574f4f1d48668b83cdda30/number.a1.b(Nat.add(128n, List.length(&2, U32, 0xeb25eff332574f4f1d48668b83cdda30/number.a1.be(n)))) <> List.append(&2, U32, 0xeb25eff332574f4f1d48668b83cdda30/number.a1.be(n), rest)) == 0xeb25eff332574f4f1d48668b83cdda30/length.A1LDef{n, 0xeb25eff332574f4f1d48668b83cdda30/number.a1.b(Nat.add(128n, List.length(&2, U32, 0xeb25eff332574f4f1d48668b83cdda30/number.a1.be(n)))) <> 0xeb25eff332574f4f1d48668b83cdda30/number.a1.be(n), rest} : 0xeb25eff332574f4f1d48668b83cdda30/length.A1Len}

def pn.len_read.go source · line 308 · raw

@lt:Bool -> @+n:Nat -> @+rest:List<&2, U32> -> @+hl:{Nat.is_lt(n, 128n) == lt : Bool} -> @+hok:{0xeb25eff332574f4f1d48668b83cdda30/length.a1.len_ok(n) == True{} : Bool} -> {0xeb25eff332574f4f1d48668b83cdda30/length.a1.len.read(List.append(&2, U32, 0xeb25eff332574f4f1d48668b83cdda30/length.a1.len_bytes(n), rest)) == 0xeb25eff332574f4f1d48668b83cdda30/length.A1LDef{n, 0xeb25eff332574f4f1d48668b83cdda30/length.a1.len_bytes(n), rest} : 0xeb25eff332574f4f1d48668b83cdda30/length.A1Len}

def pn.len_read source · line 319 · raw

@+n:Nat -> @+rest:List<&2, U32> -> @+hok:{0xeb25eff332574f4f1d48668b83cdda30/length.a1.len_ok(n) == True{} : Bool} -> {0xeb25eff332574f4f1d48668b83cdda30/length.a1.len.read(List.append(&2, U32, 0xeb25eff332574f4f1d48668b83cdda30/length.a1.len_bytes(n), rest)) == 0xeb25eff332574f4f1d48668b83cdda30/length.A1LDef{n, 0xeb25eff332574f4f1d48668b83cdda30/length.a1.len_bytes(n), rest} : 0xeb25eff332574f4f1d48668b83cdda30/length.A1Len}

the length octets of n (that has them) read back as n