~/bend-docscommunity

LAWS.bend open laws/TODOs

raw source on the hub · import bend-float64@0.1.8.0/LAWS.bend as LAWS

The laws of bend-float64. Where a NaN goes is proved for every input (the decision: x86's bits exactly). Correct rounding is pinned at literal inputs that walk each rounding path (ties, overflow, subnormals, cancellation, signed zeros), every expected value taken from this machine's hardware; test/check.py compares millions more. The square root's rounding law is in SQRT_LAWS.bend (a gate of its own, for the checker's time limit). Gate: ./bend-check PROOF.bend --verdict

2 imports
import Base
import ./float64.bend as F

Laws

law nan_first provedin PROOF.bendsource · line 15 · raw

@+m:0x72aa159312099184b98e33378b057a0a/float64.Rnd -> @+a:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+b:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+h:{0x72aa159312099184b98e33378b057a0a/float64.is_nan(a) == True{} : Bool} -> Pair({0x72aa159312099184b98e33378b057a0a/float64.add_m(m, a, b) == 0x72aa159312099184b98e33378b057a0a/float64.quiet(a) : 0x72aa159312099184b98e33378b057a0a/float64.F64}, Pair({0x72aa159312099184b98e33378b057a0a/float64.sub_m(m, a, b) == 0x72aa159312099184b98e33378b057a0a/float64.quiet(a) : 0x72aa159312099184b98e33378b057a0a/float64.F64}, Pair({0x72aa159312099184b98e33378b057a0a/float64.mul_m(m, a, b) == 0x72aa159312099184b98e33378b057a0a/float64.quiet(a) : 0x72aa159312099184b98e33378b057a0a/float64.F64}, {0x72aa159312099184b98e33378b057a0a/float64.div_m(m, a, b) == 0x72aa159312099184b98e33378b057a0a/float64.quiet(a) : 0x72aa159312099184b98e33378b057a0a/float64.F64})))

Guarantees: when a is NaN, a + b, a - b, a * b and a / b are all a with its quiet bit set, whatever b is, in every rounding mode. Why it matters: x86 (and NumPy's scalar path) answer this way; a NaN that changed payload or lost its place to the second operand would make bend-float64's NaN bits differ from the hardware's, breaking bit-exact comparison.

law nan_second provedin PROOF.bendsource · line 26 · raw

@+m:0x72aa159312099184b98e33378b057a0a/float64.Rnd -> @+a:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+b:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+ha:{0x72aa159312099184b98e33378b057a0a/float64.is_nan(a) == False{} : Bool} -> @+hb:{0x72aa159312099184b98e33378b057a0a/float64.is_nan(b) == True{} : Bool} -> Pair({0x72aa159312099184b98e33378b057a0a/float64.add_m(m, a, b) == 0x72aa159312099184b98e33378b057a0a/float64.quiet(b) : 0x72aa159312099184b98e33378b057a0a/float64.F64}, Pair({0x72aa159312099184b98e33378b057a0a/float64.sub_m(m, a, b) == 0x72aa159312099184b98e33378b057a0a/float64.quiet(b) : 0x72aa159312099184b98e33378b057a0a/float64.F64}, Pair({0x72aa159312099184b98e33378b057a0a/float64.mul_m(m, a, b) == 0x72aa159312099184b98e33378b057a0a/float64.quiet(b) : 0x72aa159312099184b98e33378b057a0a/float64.F64}, {0x72aa159312099184b98e33378b057a0a/float64.div_m(m, a, b) == 0x72aa159312099184b98e33378b057a0a/float64.quiet(b) : 0x72aa159312099184b98e33378b057a0a/float64.F64})))

Guarantees: when a is not NaN and b is, a + b, a - b, a * b and a / b are all b with its quiet bit set (for a - b, b keeps its own sign). Why it matters: the same x86 rule for the second operand; a subtraction that flipped the NaN's sign, as negating b first would, gives different bits from the hardware.

law fma_nan_b provedin PROOF.bendsource · line 37 · raw

@+m:0x72aa159312099184b98e33378b057a0a/float64.Rnd -> @+a:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+b:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+c:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+hb:{0x72aa159312099184b98e33378b057a0a/float64.is_nan(b) == True{} : Bool} -> {0x72aa159312099184b98e33378b057a0a/float64.fma_m(m, a, b, c) == 0x72aa159312099184b98e33378b057a0a/float64.quiet(b) : 0x72aa159312099184b98e33378b057a0a/float64.F64}

Guarantees: fma(a, b, c) with a NaN among its operands is the first NaN of b, a, c, quieted (even for 0 * inf + NaN, which is not the default NaN). Why it matters: this is the order glibc's fma gives on x86-64; another order changes the NaN's bits.

law fma_nan_a provedin PROOF.bendsource · line 47 · raw

@+m:0x72aa159312099184b98e33378b057a0a/float64.Rnd -> @+a:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+b:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+c:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+hb:{0x72aa159312099184b98e33378b057a0a/float64.is_nan(b) == False{} : Bool} -> @+ha:{0x72aa159312099184b98e33378b057a0a/float64.is_nan(a) == True{} : Bool} -> {0x72aa159312099184b98e33378b057a0a/float64.fma_m(m, a, b, c) == 0x72aa159312099184b98e33378b057a0a/float64.quiet(a) : 0x72aa159312099184b98e33378b057a0a/float64.F64}

Guarantees: (fma_nan_a) when b is not NaN and a is, the result is a quieted. Why it matters: the second step of glibc's order on x86-64.

law fma_nan_c provedin PROOF.bendsource · line 58 · raw

@+m:0x72aa159312099184b98e33378b057a0a/float64.Rnd -> @+a:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+b:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+c:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+hb:{0x72aa159312099184b98e33378b057a0a/float64.is_nan(b) == False{} : Bool} -> @+ha:{0x72aa159312099184b98e33378b057a0a/float64.is_nan(a) == False{} : Bool} -> @+hc:{0x72aa159312099184b98e33378b057a0a/float64.is_nan(c) == True{} : Bool} -> {0x72aa159312099184b98e33378b057a0a/float64.fma_m(m, a, b, c) == 0x72aa159312099184b98e33378b057a0a/float64.quiet(c) : 0x72aa159312099184b98e33378b057a0a/float64.F64}

Guarantees: (fma_nan_c) when neither a nor b is NaN and c is, the result is c quieted, even when a * b is 0 * inf. Why it matters: the last step of glibc's order; x86 does not raise the default NaN here.

law unary_nan provedin PROOF.bendsource · line 70 · raw

@+m:0x72aa159312099184b98e33378b057a0a/float64.Rnd -> @+a:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+h:{0x72aa159312099184b98e33378b057a0a/float64.is_nan(a) == True{} : Bool} -> Pair({0x72aa159312099184b98e33378b057a0a/float64.sqrt_m(m, a) == 0x72aa159312099184b98e33378b057a0a/float64.quiet(a) : 0x72aa159312099184b98e33378b057a0a/float64.F64}, Pair({0x72aa159312099184b98e33378b057a0a/float64.trunc(a) == 0x72aa159312099184b98e33378b057a0a/float64.quiet(a) : 0x72aa159312099184b98e33378b057a0a/float64.F64}, Pair({0x72aa159312099184b98e33378b057a0a/float64.floor(a) == 0x72aa159312099184b98e33378b057a0a/float64.quiet(a) : 0x72aa159312099184b98e33378b057a0a/float64.F64}, Pair({0x72aa159312099184b98e33378b057a0a/float64.ceil(a) == 0x72aa159312099184b98e33378b057a0a/float64.quiet(a) : 0x72aa159312099184b98e33378b057a0a/float64.F64}, {0x72aa159312099184b98e33378b057a0a/float64.rint(a) == 0x72aa159312099184b98e33378b057a0a/float64.quiet(a) : 0x72aa159312099184b98e33378b057a0a/float64.F64}))))

Guarantees: the square root and the four roundings to an integer of a NaN are that NaN, quieted. Why it matters: as x86's sqrtsd and roundsd; a NaN must never turn into a number.

law compare_nan_a provedin PROOF.bendsource · line 79 · raw

@+a:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+b:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+h:{0x72aa159312099184b98e33378b057a0a/float64.is_nan(a) == True{} : Bool} -> Pair({0x72aa159312099184b98e33378b057a0a/float64.eq(a, b) == False{} : Bool}, Pair({0x72aa159312099184b98e33378b057a0a/float64.lt(a, b) == False{} : Bool}, Pair({0x72aa159312099184b98e33378b057a0a/float64.le(a, b) == False{} : Bool}, Pair({0x72aa159312099184b98e33378b057a0a/float64.gt(a, b) == False{} : Bool}, Pair({0x72aa159312099184b98e33378b057a0a/float64.ge(a, b) == False{} : Bool}, {0x72aa159312099184b98e33378b057a0a/float64.ne(a, b) == True{} : Bool})))))

Guarantees: when a is NaN, ==, <, <=, > and >= are all False and != is True. Why it matters: IEEE comparisons are unordered on NaN; a sort or a mask built on them would otherwise put NaNs among the numbers.

law compare_nan_b provedin PROOF.bendsource · line 87 · raw

@+a:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+b:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+h:{0x72aa159312099184b98e33378b057a0a/float64.is_nan(b) == True{} : Bool} -> Pair({0x72aa159312099184b98e33378b057a0a/float64.eq(a, b) == False{} : Bool}, Pair({0x72aa159312099184b98e33378b057a0a/float64.lt(a, b) == False{} : Bool}, Pair({0x72aa159312099184b98e33378b057a0a/float64.le(a, b) == False{} : Bool}, Pair({0x72aa159312099184b98e33378b057a0a/float64.gt(a, b) == False{} : Bool}, Pair({0x72aa159312099184b98e33378b057a0a/float64.ge(a, b) == False{} : Bool}, {0x72aa159312099184b98e33378b057a0a/float64.ne(a, b) == True{} : Bool})))))

Guarantees: when b is NaN, ==, <, <=, > and >= are all False and != is True. Why it matters: the same for the second operand, so no NaN compares as a number in either place.

law minmax_nan_first provedin PROOF.bendsource · line 96 · raw

@+a:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+b:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+h:{0x72aa159312099184b98e33378b057a0a/float64.is_nan(a) == True{} : Bool} -> Pair({0x72aa159312099184b98e33378b057a0a/float64.minimum(a, b) == a : 0x72aa159312099184b98e33378b057a0a/float64.F64}, {0x72aa159312099184b98e33378b057a0a/float64.maximum(a, b) == a : 0x72aa159312099184b98e33378b057a0a/float64.F64})

Guarantees: minimum and maximum of a NaN a are a itself, not quieted. Why it matters: np.minimum and np.maximum propagate NaN this way, bits unchanged; a min that skipped the NaN would be np.fmin, another function.

law minmax_nan_second provedin PROOF.bendsource · line 104 · raw

@+a:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+b:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+ha:{0x72aa159312099184b98e33378b057a0a/float64.is_nan(a) == False{} : Bool} -> @+hb:{0x72aa159312099184b98e33378b057a0a/float64.is_nan(b) == True{} : Bool} -> Pair({0x72aa159312099184b98e33378b057a0a/float64.minimum(a, b) == b : 0x72aa159312099184b98e33378b057a0a/float64.F64}, {0x72aa159312099184b98e33378b057a0a/float64.maximum(a, b) == b : 0x72aa159312099184b98e33378b057a0a/float64.F64})

Guarantees: minimum and maximum of a non-NaN a and a NaN b are b itself, not quieted. Why it matters: the same NumPy rule for the second operand.

law quiet_bits provedin PROOF.bendsource · line 114 · raw

{[0x72aa159312099184b98e33378b057a0a/float64.quiet(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2146435072, 291)), 0x72aa159312099184b98e33378b057a0a/float64.quiet(0x72aa159312099184b98e33378b057a0a/float64.of_bits(4293918720, 1)), 0x72aa159312099184b98e33378b057a0a/float64.quiet(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2146959360, 7)), 0x72aa159312099184b98e33378b057a0a/float64.add(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2146435072, 291), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072693248, 0))] == [0x72aa159312099184b98e33378b057a0a/float64.F64{2146959360, 291}, 0x72aa159312099184b98e33378b057a0a/float64.F64{4294443008, 1}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2146959360, 7}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2146959360, 291}] : List<&2, 0x72aa159312099184b98e33378b057a0a/float64.F64>}

Guarantees: quieting sets only the quiet bit (0x7FF0000000000123 -> 0x7FF8000000000123, 0xFFF0000000000001 -> 0xFFF8000000000001, an already quiet NaN unchanged), and a signalling NaN through an addition comes out so. Why it matters: the NaN laws above are stated with quiet; this pins quiet itself to the hardware's bits.

law add_rounding provedin PROOF.bendsource · line 126 · raw

{[0x72aa159312099184b98e33378b057a0a/float64.add(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1069128089, 2576980378), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1070176665, 2576980378)), 0x72aa159312099184b98e33378b057a0a/float64.add(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072693248, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1017118720, 0)), 0x72aa159312099184b98e33378b057a0a/float64.add(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072693248, 1), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1017118720, 0)), 0x72aa159312099184b98e33378b057a0a/float64.add(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2146435071, 4294967295), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(2146435071, 4294967295)), 0x72aa159312099184b98e33378b057a0a/float64.add(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2146435071, 4294967295), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(2089811968, 0)), 0x72aa159312099184b98e33378b057a0a/float64.add(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2146435071, 4294967295), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(2088763392, 0)), 0x72aa159312099184b98e33378b057a0a/float64.add(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1070805811, 858993459), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(3218289459, 858993459)), 0x72aa159312099184b98e33378b057a0a/float64.add(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2147483648, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(2147483648, 0)), 0x72aa159312099184b98e33378b057a0a/float64.add(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2147483648, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 0)), 0x72aa159312099184b98e33378b057a0a/float64.add(0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 1), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 1)), 0x72aa159312099184b98e33378b057a0a/float64.add(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1048576, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(2147483648, 1)), 0x72aa159312099184b98e33378b057a0a/float64.add(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2146435072, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(4293918720, 0)), 0x72aa159312099184b98e33378b057a0a/float64.add(0x72aa159312099184b98e33378b057a0a/float64.of_bits(3218289459, 858993459), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1070805811, 858993459))] == [0x72aa159312099184b98e33378b057a0a/float64.F64{1070805811, 858993460}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1072693248, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1072693248, 2}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2146435072, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2146435072, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2146435071, 4294967295}, 0x72aa159312099184b98e33378b057a0a/float64.F64{0, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2147483648, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{0, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{0, 2}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1048575, 4294967295}, 0x72aa159312099184b98e33378b057a0a/float64.F64{4294443008, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{0, 0}] : List<&2, 0x72aa159312099184b98e33378b057a0a/float64.F64>}

Guarantees: 0.1 + 0.2 = 0.30000000000000004; 1 + 2^-53 ties down to 1 and (1 + 2^-52) + 2^-53 ties up to 1 + 2^-51 (ties to even); max + max and max + half an ulp overflow to infinity, max + a quarter ulp stays max; 0.3 - 0.3 and -0.3 + 0.3 are +0, -0 + -0 is -0, -0 + +0 is +0; two smallest subnormals add exactly; the smallest normal minus the smallest subnormal is the largest subnormal; inf - inf is the default NaN. Why it matters: these are the cases where an addition is most often wrong: the tie rule, the overflow threshold, the sign of an exact zero, and gradual underflow.

law mul_rounding provedin PROOF.bendsource · line 143 · raw

{[0x72aa159312099184b98e33378b057a0a/float64.mul(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1069128089, 2576980378), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1074266112, 0)), 0x72aa159312099184b98e33378b057a0a/float64.mul(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1048576, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1071644672, 0)), 0x72aa159312099184b98e33378b057a0a/float64.mul(0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 1), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1071644672, 0)), 0x72aa159312099184b98e33378b057a0a/float64.mul(0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 3), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1071644672, 0)), 0x72aa159312099184b98e33378b057a0a/float64.mul(0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 1), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072168960, 0)), 0x72aa159312099184b98e33378b057a0a/float64.mul(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2146435071, 4294967295), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1073741824, 0)), 0x72aa159312099184b98e33378b057a0a/float64.mul(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2147483648, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1075052544, 0)), 0x72aa159312099184b98e33378b057a0a/float64.mul(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2146435072, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 0)), 0x72aa159312099184b98e33378b057a0a/float64.mul(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072693248, 1), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072693247, 4294967295)), 0x72aa159312099184b98e33378b057a0a/float64.mul(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1069128089, 2576980378), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1069128089, 2576980378)), 0x72aa159312099184b98e33378b057a0a/float64.mul(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1070945621, 1431655765), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1069697316, 2454267026)), 0x72aa159312099184b98e33378b057a0a/float64.mul(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072064102, 1717986918), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072483532, 3435973837)), 0x72aa159312099184b98e33378b057a0a/float64.mul(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072939210, 1116494331), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1076084938, 1167159825))] == [0x72aa159312099184b98e33378b057a0a/float64.F64{1070805811, 858993460}, 0x72aa159312099184b98e33378b057a0a/float64.F64{524288, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{0, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{0, 2}, 0x72aa159312099184b98e33378b057a0a/float64.F64{0, 1}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2146435072, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2147483648, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{4294443008, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1072693248, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1065646817, 1202590844}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1067999622, 409044504}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1071917301, 3264175145}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1076388595, 1644281720}] : List<&2, 0x72aa159312099184b98e33378b057a0a/float64.F64>}

Guarantees: 0.1 * 3 = 0.30000000000000004; the smallest normal halves exactly into a subnormal; the smallest subnormal halved ties down to 0, three of them halved tie up to two (even), and times 0.75 rounds up to one; max * 2 overflows; -0 * 5 is -0; inf * 0 is the default NaN; (1 + 2^-52)(1 - 2^-53) rounds to 1; 0.1 * 0.1, (1/3)(1/7), 0.7 * 0.9 and 1.2345678901234567 * 9.87654321098765 round to nearest. Why it matters: products that leave the normal range must round once, at the subnormal's own precision.

law div_rounding provedin PROOF.bendsource · line 158 · raw

{[0x72aa159312099184b98e33378b057a0a/float64.div(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072693248, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1074266112, 0)), 0x72aa159312099184b98e33378b057a0a/float64.div(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072693248, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 0)), 0x72aa159312099184b98e33378b057a0a/float64.div(0x72aa159312099184b98e33378b057a0a/float64.of_bits(3220176896, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 0)), 0x72aa159312099184b98e33378b057a0a/float64.div(0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 0)), 0x72aa159312099184b98e33378b057a0a/float64.div(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072693248, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(2146435072, 0)), 0x72aa159312099184b98e33378b057a0a/float64.div(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1048576, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1074790400, 0)), 0x72aa159312099184b98e33378b057a0a/float64.div(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2146435071, 4294967295), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1071644672, 0)), 0x72aa159312099184b98e33378b057a0a/float64.div(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072693248, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1076101120, 0))] == [0x72aa159312099184b98e33378b057a0a/float64.F64{1070945621, 1431655765}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2146435072, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{4293918720, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{4294443008, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{0, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{262144, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2146435072, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1069128089, 2576980378}] : List<&2, 0x72aa159312099184b98e33378b057a0a/float64.F64>}

Guarantees: 1 / 3 and 1 / 10 round to nearest; 1 / 0 = inf, -1 / 0 = -inf, 0 / 0 = default NaN, 1 / inf = 0; the smallest normal / 4 is an exact subnormal; max / 0.5 overflows. Why it matters: division is the long loop of the core; its remainder decides the rounding.

law fma_rounding provedin PROOF.bendsource · line 170 · raw

{[0x72aa159312099184b98e33378b057a0a/float64.fma(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1069128089, 2576980378), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1076101120, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(3220176896, 0)), 0x72aa159312099184b98e33378b057a0a/float64.fma(0x72aa159312099184b98e33378b057a0a/float64.of_bits(27618847, 3271095129), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(2175102495, 3271095129), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 0)), 0x72aa159312099184b98e33378b057a0a/float64.fma(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072693248, 1), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072693247, 4294967294), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(3220176896, 0)), 0x72aa159312099184b98e33378b057a0a/float64.fma(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2146435071, 4294967295), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1073741824, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(4293918719, 4294967295)), 0x72aa159312099184b98e33378b057a0a/float64.fma(0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 1), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1071644672, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 0)), 0x72aa159312099184b98e33378b057a0a/float64.fma(0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 1), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(1071644672, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 1))] == [0x72aa159312099184b98e33378b057a0a/float64.F64{1016070144, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2147483648, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{3111124992, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2146435071, 4294967295}, 0x72aa159312099184b98e33378b057a0a/float64.F64{0, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{0, 2}] : List<&2, 0x72aa159312099184b98e33378b057a0a/float64.F64>}

Guarantees: fma(0.1, 10, -1) is 2^-54 (the exact error of 0.1 * 10, where a multiply then an add gives 0); fma(1e-300, -1e-300, 0) is -0; (1 + 2^-52)(1 - 2^-52) - 1 is -2^-104 exactly; max * 2 - max is max (no overflow in the middle); a subnormal product ties to even with and without an addend. Why it matters: fma's whole point is one rounding; a core that rounded the product first passes none of these.

law to_integer provedin PROOF.bendsource · line 183 · raw

{[0x72aa159312099184b98e33378b057a0a/float64.rint(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1071644672, 0)), 0x72aa159312099184b98e33378b057a0a/float64.rint(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1073217536, 0)), 0x72aa159312099184b98e33378b057a0a/float64.rint(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1074003968, 0)), 0x72aa159312099184b98e33378b057a0a/float64.rint(0x72aa159312099184b98e33378b057a0a/float64.of_bits(3219128320, 0)), 0x72aa159312099184b98e33378b057a0a/float64.rint(0x72aa159312099184b98e33378b057a0a/float64.of_bits(3221487616, 0)), 0x72aa159312099184b98e33378b057a0a/float64.rint(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072168960, 0)), 0x72aa159312099184b98e33378b057a0a/float64.rint(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1127219199, 4294967295)), 0x72aa159312099184b98e33378b057a0a/float64.floor(0x72aa159312099184b98e33378b057a0a/float64.of_bits(3219128320, 0)), 0x72aa159312099184b98e33378b057a0a/float64.ceil(0x72aa159312099184b98e33378b057a0a/float64.of_bits(3219128320, 0)), 0x72aa159312099184b98e33378b057a0a/float64.ceil(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1070596096, 0)), 0x72aa159312099184b98e33378b057a0a/float64.trunc(0x72aa159312099184b98e33378b057a0a/float64.of_bits(3220963328, 0)), 0x72aa159312099184b98e33378b057a0a/float64.floor(0x72aa159312099184b98e33378b057a0a/float64.of_bits(3274702848, 1)), 0x72aa159312099184b98e33378b057a0a/float64.floor(0x72aa159312099184b98e33378b057a0a/float64.of_bits(3220701184, 0)), 0x72aa159312099184b98e33378b057a0a/float64.ceil(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072955392, 0))] == [0x72aa159312099184b98e33378b057a0a/float64.F64{0, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1073741824, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1073741824, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2147483648, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{3221225472, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1072693248, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1127219200, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{3220176896, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2147483648, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1072693248, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{3220176896, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{3274702848, 1}, 0x72aa159312099184b98e33378b057a0a/float64.F64{3221225472, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1073741824, 0}] : List<&2, 0x72aa159312099184b98e33378b057a0a/float64.F64>}

Guarantees: rint ties to even (0.5 -> 0, 1.5 -> 2, 2.5 -> 2, -0.5 -> -0, -2.5 -> -2, 2^52 - 0.5 -> 2^52) and rounds 0.75 to 1; floor(-0.5) = -1, ceil(-0.5) = -0, ceil(0.25) = 1, trunc(-1.75) = -1, floor(-1.5) = -2, ceil(1.25) = 2; an integer beyond 2^52 is kept. Why it matters: np.round is rint; rounding halves away from zero, the schoolbook rule, gives different data.

law conversions provedin PROOF.bendsource · line 198 · raw

{[0x72aa159312099184b98e33378b057a0a/float64.to_i32(0x72aa159312099184b98e33378b057a0a/float64.of_bits(3221487616, 0)), 0x72aa159312099184b98e33378b057a0a/float64.to_i32(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1105199103, 4294547866)), 0x72aa159312099184b98e33378b057a0a/float64.to_i32(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1105199104, 0)), 0x72aa159312099184b98e33378b057a0a/float64.to_i32(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2146959360, 0)), 0x72aa159312099184b98e33378b057a0a/float64.to_i32(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1105615371, 3221225472)), 0x72aa159312099184b98e33378b057a0a/float64.to_u32(0x72aa159312099184b98e33378b057a0a/float64.of_bits(3220176896, 0)), 0x72aa159312099184b98e33378b057a0a/float64.to_u32(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1106247679, 4293918720)), 0x72aa159312099184b98e33378b057a0a/float64.to_u32(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1106247680, 0)), 0x72aa159312099184b98e33378b057a0a/float64.to_u32(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1142271773, 2025163840)), 0x72aa159312099184b98e33378b057a0a/float64.to_f32_bits(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072693248, 268435456)), 0x72aa159312099184b98e33378b057a0a/float64.to_f32_bits(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1072693248, 805306368)), 0x72aa159312099184b98e33378b057a0a/float64.to_f32_bits(0x72aa159312099184b98e33378b057a0a/float64.of_bits(1206910975, 4026531840)), 0x72aa159312099184b98e33378b057a0a/float64.to_f32_bits(0x72aa159312099184b98e33378b057a0a/float64.of_bits(912409806, 606885217)), 0x72aa159312099184b98e33378b057a0a/float64.to_f32_bits(0x72aa159312099184b98e33378b057a0a/float64.of_bits(915406848, 1)), 0x72aa159312099184b98e33378b057a0a/float64.to_f32_bits(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2147483648, 0)), 0x72aa159312099184b98e33378b057a0a/float64.to_f32_bits(0x72aa159312099184b98e33378b057a0a/float64.of_bits(4293918720, 536870913))] == [4294967294, 2147483647, 2147483648, 2147483648, 2147483648, 4294967295, 4294967295, 0, 0, 1065353216, 1065353218, 2139095040, 0, 1, 2147483648, 4290772993] : List<&2, U32>}

Guarantees: to_i32 truncates (-2.5 -> -2, 2147483647.9 -> 2147483647) and gives -2^31 for 2^31, 3e9 and NaN; to_u32 gives -1.0 -> 4294967295, 4294967295.5 -> 4294967295, 2^32 -> 0, 1e20 -> 0 (NumPy's astype on x86-64); to_f32 ties to even (1 + 2^-24 -> 1, 1 + 3 * 2^-24 -> 1 + 2^-22), overflows to infinity past float32's rounding threshold, flushes 1e-46 to 0 and rounds just over half the smallest subnormal up to it, keeps -0, and keeps a NaN's top payload bits. Why it matters: conversions are where values silently wrap or saturate; these pin the choice to the hardware's.

law widening provedin PROOF.bendsource · line 211 · raw

{[0x72aa159312099184b98e33378b057a0a/float64.from_i32(2147483648), 0x72aa159312099184b98e33378b057a0a/float64.from_f32_bits(2139095041), 0x72aa159312099184b98e33378b057a0a/float64.from_f32_bits(1)] == [0x72aa159312099184b98e33378b057a0a/float64.F64{3252682752, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2146959360, 536870912}, 0x72aa159312099184b98e33378b057a0a/float64.F64{916455424, 0}] : List<&2, 0x72aa159312099184b98e33378b057a0a/float64.F64>}

Guarantees: from_i32(-2^31) is -2147483648.0 exactly; from_f32 of a signalling NaN is quiet with the payload moved up; from_f32 of the smallest float32 subnormal is 2^-149 exactly. Why it matters: widening must never change a value; only a NaN's quiet bit changes, as on the hardware.

law signed_zeros provedin PROOF.bendsource · line 218 · raw

Pair({[0x72aa159312099184b98e33378b057a0a/float64.eq(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2147483648, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 0)), 0x72aa159312099184b98e33378b057a0a/float64.lt(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2147483648, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 0)), 0x72aa159312099184b98e33378b057a0a/float64.le(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2147483648, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 0))] == [True{}, False{}, True{}] : List<&2, Bool>}, {[0x72aa159312099184b98e33378b057a0a/float64.minimum(0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(2147483648, 0)), 0x72aa159312099184b98e33378b057a0a/float64.minimum(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2147483648, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 0)), 0x72aa159312099184b98e33378b057a0a/float64.maximum(0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(2147483648, 0)), 0x72aa159312099184b98e33378b057a0a/float64.maximum(0x72aa159312099184b98e33378b057a0a/float64.of_bits(2147483648, 0), 0x72aa159312099184b98e33378b057a0a/float64.of_bits(0, 0))] == [0x72aa159312099184b98e33378b057a0a/float64.F64{2147483648, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{0, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2147483648, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{0, 0}] : List<&2, 0x72aa159312099184b98e33378b057a0a/float64.F64>})

Guarantees: -0 == +0, -0 < +0 is False, -0 <= +0; minimum(+0, -0) is -0 and minimum(-0, +0) is +0 (the second of two equal values), and the same for maximum. Why it matters: these are NumPy's answers on signed zeros; a minimum that compared bits would order -0 below +0.