proofs/word_multiplication.bend checks
raw source on the hub · import stelliferous@0.0.3.0/proofs/word_multiplication.bend as Word_multiplication
5 imports
import Base import ./row_major_index.bend as RowMajor import ./natural_addition.bend as Addition import ./word_arithmetic.bend as WordArithmetic import ./nat_to_u32_bounds.bend as Bounds
Laws
law word_roundtrip provedsource · line 67 · raw
@+n:Nat -> @+w:Word(n) -> {0xd6aaab858a4fbd1461bd0fee27b97184/proofs/word_arithmetic.encode(Word.to_nat(n, w), n) == w : Word(n)}
law multiply_go provedsource · line 100 · raw
@+m:Nat -> @+n:Nat -> @+w:Word(m) -> @+b:Nat -> @+acc:Nat -> {Word.mul.go(n, m, w, 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/word_arithmetic.encode(b, n), 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/word_arithmetic.encode(acc, n)) == 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/word_arithmetic.encode(Nat.add(acc, Nat.mul(Word.to_nat(m, w), b)), n) : Word(n)}
Definitions
def truncate source · line 7 · raw
@n:Nat -> @w:Word(1n+n) -> Word(n)
def truncate_zero source · line 15 · raw
@+n:Nat -> {truncate(n, Word.zero(1n+n)) == Word.zero(n) : Word(n)}
def truncate_inc source · line 23 · raw
@+n:Nat -> @+w:Word(1n+n) -> {truncate(n, Word.inc(1n+n, w)) == Word.inc(n, truncate(n, w)) : Word(n)}
def truncate_encode source · line 35 · raw
@+a:Nat -> @+n:Nat -> {truncate(n, 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/word_arithmetic.encode(a, 1n+n)) == 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/word_arithmetic.encode(a, n) : Word(n)}
def put source · line 45 · raw
@+n:Nat -> @+b:Bool -> @+w:Word(n) -> {Word.shl.put(n, b, w) == truncate(n, WCon{b, w}) : Word(n)}
def shift source · line 54 · raw
@+n:Nat -> @+w:Word(1n+n) -> {Word.shl(1n+n, w) == WCon{False{}, truncate(n, w)} : Word(1n+n)}
def encoded_double source · line 59 · raw
@+a:Nat -> @+n:Nat -> {0xd6aaab858a4fbd1461bd0fee27b97184/proofs/word_arithmetic.encode(Nat.double(a), 1n+n) == WCon{False{}, 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/word_arithmetic.encode(a, n)} : Word(1n+n)}
def double_mul source · line 89 · raw
@+a:Nat -> @+b:Nat -> {Nat.mul(Nat.double(a), b) == Nat.mul(a, Nat.double(b)) : Nat}
def multiply source · line 135 · raw
@+n:Nat -> @+a:Word(n) -> @+b:Word(n) -> {Word.mul(n, a, b) == 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/word_arithmetic.encode(Nat.mul(Word.to_nat(n, a), Word.to_nat(n, b)), n) : Word(n)}
def native_multiply source · line 139 · raw
@+a:U32 -> @+b:U32 -> {U32.mul(a, b) == U32.from_nat(Nat.mul(U32.to_nat(a), U32.to_nat(b))) : U32}
def bounded_multiply source · line 148 · raw
@+a:U32 -> @+b:U32 -> @+cap:U32 -> @cap_ok:{U32.is_le(cap, 2147483648) == True{} : Bool} -> @h:{Nat.is_le(Nat.mul(U32.to_nat(a), U32.to_nat(b)), U32.to_nat(cap)) == True{} : Bool} -> {U32.to_nat(U32.mul(a, b)) == Nat.mul(U32.to_nat(a), U32.to_nat(b)) : Nat}
def encoded_product_roundtrip source · line 155 · raw
@+value:Nat -> @remaining:Nat -> @+width:Nat -> {0xd6aaab858a4fbd1461bd0fee27b97184/proofs/word_arithmetic.encode(Nat.mul(Word.to_nat(width, 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/word_arithmetic.encode(value, width)), remaining), width) == 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/word_arithmetic.encode(Nat.mul(value, remaining), width) : Word(width)}Encoding respects products even when the natural operands exceed a word.
def encoded_multiply source · line 177 · raw
@+left:Nat -> @+right:Nat -> @+width:Nat -> {Word.mul(width, 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/word_arithmetic.encode(left, width), 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/word_arithmetic.encode(right, width)) == 0xd6aaab858a4fbd1461bd0fee27b97184/proofs/word_arithmetic.encode(Nat.mul(left, right), width) : Word(width)}
def native_encoded_multiply source · line 191 · raw
@+left:Nat -> @+right:Nat -> {U32.mul(U32.from_nat(left), U32.from_nat(right)) == U32.from_nat(Nat.mul(left, right)) : U32}