~/bend-docscommunity

LAWS_mul.bend open laws/TODOs

raw source on the hub · import bend-osdev-word64@0.1.1.0/LAWS_mul.bend as LAWS_mul

bend-osdev-word64's laws of multiplication, for every input: the high half of a 32-bit product (W64.mulhi), and W64.mul as the low 64 bits of the product of the values. Proved in PROOF_mul.bend.

3 imports
import Base
import bend-osdev-u32@0.1.0.0/u32.bend as U
import ./word64.bend as W

Laws

law mulhi_value provedin PROOF_mul.bendsource · line 13 · raw

@+a:U32 -> @+b:U32 -> {Nat.add(U32.to_nat(U32.mul(a, b)), 0xab9c812df432dacce3e8b343e9fd7ab7/u32.U32Nat.dbl(32n, U32.to_nat(0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64.mulhi(a, b)))) == Nat.mul(U32.to_nat(a), U32.to_nat(b)) : Nat}

Multiplication. W64.mulhi(a, b) is the high 32 bits of the product of two 32-bit words: with the low 32 bits (U32.mul), the whole product. W64.mul is the product modulo 2^64: its value is the low 64 bits of the product of the values (U32Nat.low, from bend-osdev-u32), what wraps is 2^64 times the rest, and with the product no more than a word's value nothing wraps.

law mul_wrap provedin PROOF_mul.bendsource · line 18 · raw

@+a:0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64 -> @+b:0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64 -> {Nat.add(0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64.to_nat(0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64.mul(a, b)), 0xab9c812df432dacce3e8b343e9fd7ab7/u32.U32Nat.dbl(64n, 0xab9c812df432dacce3e8b343e9fd7ab7/u32.U32Nat.high(64n, Nat.mul(0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64.to_nat(a), 0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64.to_nat(b))))) == Nat.mul(0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64.to_nat(a), 0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64.to_nat(b)) : Nat}

law mul_low provedin PROOF_mul.bendsource · line 23 · raw

@+a:0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64 -> @+b:0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64 -> {0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64.to_nat(0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64.mul(a, b)) == 0xab9c812df432dacce3e8b343e9fd7ab7/u32.U32Nat.low(64n, Nat.mul(0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64.to_nat(a), 0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64.to_nat(b))) : Nat}

law mul_value provedin PROOF_mul.bendsource · line 28 · raw

@+a:0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64 -> @+b:0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64 -> @+c:0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64 -> @h:{Nat.is_le(Nat.mul(0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64.to_nat(a), 0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64.to_nat(b)), 0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64.to_nat(c)) == True{} : Bool} -> {0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64.to_nat(0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64.mul(a, b)) == Nat.mul(0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64.to_nat(a), 0xea9c6e6209a3ac3fb21596f70f09f650/word64.W64.to_nat(b)) : Nat}