~/bend-docscommunity

ascii-proof.bend checks

raw source on the hub · import bend-kit-bytes@0.3.3.1/ascii-proof.bend as Ascii_proof

Exact ASCII digit boundaries for packed decimal parsing.

5 imports
import Base
import ./bytes.bend as Bytes
import ./decimal-proof.bend as Decimal
import bend-kit-lemmas@0.1.5.1/lemmas.bend as Lemmas
import bend-mathlib@0.8.0.0/nat.bend as MNat

Definitions

def ascii source · line 8 · raw

@+d:U32 -> U32

def Facts source · line 11 · raw

@+d:U32 -> Type

def facts_nat source · line 18 · raw

@+k:Nat -> @+d:U32 -> @e:{U32.to_nat(d) == k : Nat} -> @h:0x78e347bf8d0582a322c01b02c727566f/nat.lt(k, 10n) -> Facts(d)

Ten natural digit cases, not enumeration of U32 bit patterns.

def digit_facts source · line 54 · raw

@+d:U32 -> @h:{U32.is_lt(d, 10) == True{} : Bool} -> Facts(d)

def b8_ascii.pair source · line 60 · raw

@+d:U32 -> @p:Facts(d) -> {0xec25e4adfb02e59e4b817801115988ee/bytes.b8(ascii(d)) == ascii(d) : U32}

def sub_ascii.pair source · line 65 · raw

@+d:U32 -> @p:Facts(d) -> {U32.sub(ascii(d), 48) == d : U32}

def in_ascii.pair source · line 71 · raw

@+d:U32 -> @p:Facts(d) -> {0xec25e4adfb02e59e4b817801115988ee/bytes.in(48, ascii(d), 57) == True{} : Bool}

def ascii_lt.pair source · line 78 · raw

@+d:U32 -> @p:Facts(d) -> {U32.is_lt(ascii(d), 256) == True{} : Bool}

def b8_ascii source · line 85 · raw

@+d:U32 -> @h:{U32.is_lt(d, 10) == True{} : Bool} -> {0xec25e4adfb02e59e4b817801115988ee/bytes.b8(ascii(d)) == ascii(d) : U32}

def sub_ascii source · line 89 · raw

@+d:U32 -> @h:{U32.is_lt(d, 10) == True{} : Bool} -> {U32.sub(ascii(d), 48) == d : U32}

def in_ascii source · line 93 · raw

@+d:U32 -> @h:{U32.is_lt(d, 10) == True{} : Bool} -> {0xec25e4adfb02e59e4b817801115988ee/bytes.in(48, ascii(d), 57) == True{} : Bool}

def ascii_lt source · line 97 · raw

@+d:U32 -> @h:{U32.is_lt(d, 10) == True{} : Bool} -> {U32.is_lt(ascii(d), 256) == True{} : Bool}

def value source · line 101 · raw

@+acc:U32 -> @+d:U32 -> U32

def guard source · line 104 · raw

@+acc:U32 -> @+d:U32 -> Bool

def step_value source · line 107 · raw

@+acc:U32 -> @+d:U32 -> @+n:U32 -> @hd:{U32.is_lt(d, 10) == True{} : Bool} -> @e:{U32.add(U32.mul(acc, 10), d) == n : U32} -> {value(acc, d) == n : U32}

def step_guard source · line 114 · raw

@+acc:U32 -> @+d:U32 -> @+n:U32 -> @+hd:{U32.is_lt(d, 10) == True{} : Bool} -> @e:{U32.add(U32.mul(acc, 10), d) == n : U32} -> @hq:{0xec25e4adfb02e59e4b817801115988ee/decimal-proof.quotient(n) == acc : U32} -> {guard(acc, d) == True{} : Bool}

def step source · line 126 · raw

@+acc:U32 -> @+d:U32 -> @+n:U32 -> @+hd:{U32.is_lt(d, 10) == True{} : Bool} -> @+e:{U32.add(U32.mul(acc, 10), d) == n : U32} -> @hq:{0xec25e4adfb02e59e4b817801115988ee/decimal-proof.quotient(n) == acc : U32} -> Pair({value(acc, d) == n : U32}, {guard(acc, d) == True{} : Bool})

def Good source · line 133 · raw

@xs:List<&2, U32> -> Type

Decimal.read stores raw digits; this bridge follows the actual ASCII parser.

def ascii_list source · line 140 · raw

@xs:List<&2, U32> -> List<&2, U32>

def read_ascii source · line 147 · raw

@xs:List<&2, U32> -> @+acc:U32 -> @+ok:Bool -> Maybe<&2, U32>

def read_false source · line 156 · raw

@xs:List<&2, U32> -> @+acc:U32 -> {read_ascii(xs, acc, False{}) == None{} : Maybe<&2, U32>}

def raw_value source · line 164 · raw

@+acc:U32 -> @+d:U32 -> U32

def raw_guard source · line 167 · raw

@+acc:U32 -> @+d:U32 -> Bool

def guard_raw source · line 170 · raw

@+acc:U32 -> @+d:U32 -> @+hd:{U32.is_lt(d, 10) == True{} : Bool} -> {guard(acc, d) == raw_guard(acc, d) : Bool}

def read_cons_bridge source · line 182 · raw

@+d:U32 -> @+tail:List<&2, U32> -> @+acc:U32 -> @+hd:{U32.is_lt(d, 10) == True{} : Bool} -> {read_ascii(ascii_list(d <> tail), acc, True{}) == read_ascii(ascii_list(tail), raw_value(acc, d), raw_guard(acc, d)) : Maybe<&2, U32>}

def read_branch source · line 195 · raw

@+ok:Bool -> @+xs:List<&2, U32> -> @+acc:U32 -> @ih:{read_ascii(ascii_list(xs), acc, True{}) == 0xec25e4adfb02e59e4b817801115988ee/decimal-proof.read(xs, acc) : Maybe<&2, U32>} -> {read_ascii(ascii_list(xs), acc, ok) == Maybe.bind(&2, U32, U32, 0xec25e4adfb02e59e4b817801115988ee/decimal-proof.digit.if(ok, acc), x => 0xec25e4adfb02e59e4b817801115988ee/decimal-proof.read(xs, x)) : Maybe<&2, U32>}

def read_good source · line 205 · raw

@+xs:List<&2, U32> -> @+acc:U32 -> @h:Good(xs) -> {read_ascii(ascii_list(xs), acc, True{}) == 0xec25e4adfb02e59e4b817801115988ee/decimal-proof.read(xs, acc) : Maybe<&2, U32>}

def remainder_lt.pair source · line 218 · raw

@+n:U32 -> @p:Pair({Nat.add(Nat.mul(U32.to_nat(0xec25e4adfb02e59e4b817801115988ee/decimal-proof.quotient(n)), 10n), U32.to_nat(U32.mod(n, 10))) == U32.to_nat(n) : Nat}, 0x78e347bf8d0582a322c01b02c727566f/nat.lt(U32.to_nat(U32.mod(n, 10)), 10n)) -> {U32.is_lt(U32.mod(n, 10), 10) == True{} : Bool}

def remainder_lt source · line 226 · raw

@+n:U32 -> {U32.is_lt(U32.mod(n, 10), 10) == True{} : Bool}

def text_good source · line 229 · raw

@f:Nat -> @+n:U32 -> @+tail:List<&2, U32> -> @ht:Good(tail) -> Good(0xec25e4adfb02e59e4b817801115988ee/decimal-proof.text(f, n, tail))

def ascii_append source · line 236 · raw

@+xs:List<&2, U32> -> @+ys:List<&2, U32> -> {ascii_list(List.append(&2, U32, xs, ys)) == List.append(&2, U32, ascii_list(xs), ascii_list(ys)) : List<&2, U32>}