F64_LAWS.bend open laws/TODOs
raw source on the hub · import bend-ndarray@0.1.4.0/F64_LAWS.bend as F64_LAWS
The laws of bend-ndarray's float64 dtype, at literal inputs, in a gate of its own (with LAWS.bend's they came too close to the checker's 10-second limit): NumPy's floor_divide and remainder, and each element's two cells kept together through the operations that move elements. Values are tested against NumPy by test/f64_check.py. Gate: ./bend-check F64_PROOF.bend --verdict
6 imports
import Base import ./shape.bend as S import ./ndarray.bend as NP import ./tree.bend as T import ./cells64.bend as C64 import bend-float64@0.1.8.0/float64.bend as F
Laws
law f64_divmod provedin F64_PROOF.bendsource · line 33 · raw
Pair({[0xb394b5997edb05025e33977930018c47/cells64.dm_div(0xb394b5997edb05025e33977930018c47/cells64.divmod(0x72aa159312099184b98e33378b057a0a/float64.F64{1075707904, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{3221225472, 0})), 0xb394b5997edb05025e33977930018c47/cells64.dm_div(0xb394b5997edb05025e33977930018c47/cells64.divmod(0x72aa159312099184b98e33378b057a0a/float64.F64{3223191552, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1073741824, 0})), 0xb394b5997edb05025e33977930018c47/cells64.dm_div(0xb394b5997edb05025e33977930018c47/cells64.divmod(0x72aa159312099184b98e33378b057a0a/float64.F64{2147483648, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1074266112, 0})), 0xb394b5997edb05025e33977930018c47/cells64.dm_div(0xb394b5997edb05025e33977930018c47/cells64.divmod(0x72aa159312099184b98e33378b057a0a/float64.F64{1075052544, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{0, 0})), 0xb394b5997edb05025e33977930018c47/cells64.dm_div(0xb394b5997edb05025e33977930018c47/cells64.divmod(0x72aa159312099184b98e33378b057a0a/float64.F64{1069128089, 2576980378}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1065646817, 1202590843}))] == [0x72aa159312099184b98e33378b057a0a/float64.F64{3222274048, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{3222274048, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2147483648, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2146435072, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1076101120, 0}] : List<&2, 0x72aa159312099184b98e33378b057a0a/float64.F64>}, {[0xb394b5997edb05025e33977930018c47/cells64.dm_mod(0xb394b5997edb05025e33977930018c47/cells64.divmod(0x72aa159312099184b98e33378b057a0a/float64.F64{1075707904, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{3221225472, 0})), 0xb394b5997edb05025e33977930018c47/cells64.dm_mod(0xb394b5997edb05025e33977930018c47/cells64.divmod(0x72aa159312099184b98e33378b057a0a/float64.F64{3223191552, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1073741824, 0})), 0xb394b5997edb05025e33977930018c47/cells64.dm_mod(0xb394b5997edb05025e33977930018c47/cells64.divmod(0x72aa159312099184b98e33378b057a0a/float64.F64{2147483648, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1074266112, 0})), 0xb394b5997edb05025e33977930018c47/cells64.dm_mod(0xb394b5997edb05025e33977930018c47/cells64.divmod(0x72aa159312099184b98e33378b057a0a/float64.F64{1075052544, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{0, 0})), 0xb394b5997edb05025e33977930018c47/cells64.dm_mod(0xb394b5997edb05025e33977930018c47/cells64.divmod(0x72aa159312099184b98e33378b057a0a/float64.F64{1069128089, 2576980378}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1065646817, 1202590843})), 0xb394b5997edb05025e33977930018c47/cells64.fmod(0x72aa159312099184b98e33378b057a0a/float64.F64{4294443008, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2146959360, 0}), 0xb394b5997edb05025e33977930018c47/cells64.fmod(0x72aa159312099184b98e33378b057a0a/float64.F64{2146959360, 1}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2146959360, 2}), 0xb394b5997edb05025e33977930018c47/cells64.fmod(0x72aa159312099184b98e33378b057a0a/float64.F64{2146959360, 2}, 0x72aa159312099184b98e33378b057a0a/float64.F64{4294443008, 1})] == [0x72aa159312099184b98e33378b057a0a/float64.F64{3219128320, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1071644672, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{0, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{4294443008, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1011875840, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2146959360, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2146959360, 2}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2146959360, 2}] : List<&2, 0x72aa159312099184b98e33378b057a0a/float64.F64>})Guarantees: float64 floor_divide and remainder are NumPy's (Python's // and %): 7.5 // -2 = -4 and 7.5 % -2 = -0.5, -7.5 // 2 = -4 and -7.5 % 2 = 0.5, -0.0 // 3 = -0.0 and -0.0 % 3 = +0.0, 5 // 0 = inf and 5 % 0 = NaN (x86's default NaN), 0.1 // 0.01 = 9 and 0.1 % 0.01 as fmod gives it exactly; of two NaNs, the remainder is the one glibc's fmod picks: the larger significand (payloads 1 and 2: 2, whichever comes first and whatever its sign), then of two equal ones the positive. Why it matters: the sign conventions of // and % are where float code and NumPy most often disagree; a remainder with the dividend's sign, or a quotient off by one, changes results silently.
law f64_layout provedin F64_PROOF.bendsource · line 47 · raw
{[cells_r(0xb394b5997edb05025e33977930018c47/ndarray.reshape(a32, [2n, 3n])), Some{0xb394b5997edb05025e33977930018c47/ndarray.to_list(0xb394b5997edb05025e33977930018c47/ndarray.t(a32))}, cells_r(0xb394b5997edb05025e33977930018c47/ndarray.slice(a32, 0n, 1n, 3n, 1n)), cells_r(0xb394b5997edb05025e33977930018c47/ndarray.slice(a32, 1n, 0n, 1n, 1n)), cells_r(0xb394b5997edb05025e33977930018c47/ndarray.slice(0xb394b5997edb05025e33977930018c47/ndarray.t(a32), 1n, 0n, 3n, 1n)), cells_r(0xb394b5997edb05025e33977930018c47/ndarray.sum(a32, 0n, False{})), cells_r(0xb394b5997edb05025e33977930018c47/ndarray.less(a32, 0xb394b5997edb05025e33977930018c47/ndarray.full(0xb394b5997edb05025e33977930018c47/ndarray.f64, [], 1074528256))), Some{0xb394b5997edb05025e33977930018c47/ndarray.to_list(0xb394b5997edb05025e33977930018c47/ndarray.astype(a32, 0xb394b5997edb05025e33977930018c47/ndarray.i32))}, Some{0xb394b5997edb05025e33977930018c47/ndarray.to_list(0xb394b5997edb05025e33977930018c47/ndarray.astype(0xb394b5997edb05025e33977930018c47/ndarray.astype(a32, 0xb394b5997edb05025e33977930018c47/ndarray.i32), 0xb394b5997edb05025e33977930018c47/ndarray.f64))}] == [Some{[1072693248, 0, 1073741824, 0, 1074266112, 0, 1074790400, 0, 1075052544, 0, 1075314688, 0]}, Some{[1072693248, 0, 1074266112, 0, 1075052544, 0, 1073741824, 0, 1074790400, 0, 1075314688, 0]}, Some{[1074266112, 0, 1074790400, 0, 1075052544, 0, 1075314688, 0]}, Some{[1072693248, 0, 1074266112, 0, 1075052544, 0]}, Some{[1072693248, 0, 1074266112, 0, 1075052544, 0, 1073741824, 0, 1074790400, 0, 1075314688, 0]}, Some{[1075970048, 0, 1076363264, 0]}, Some{[1, 1, 1, 0, 0, 0]}, Some{[1, 2, 3, 4, 5, 6]}, Some{[1072693248, 0, 1073741824, 0, 1074266112, 0, 1074790400, 0, 1075052544, 0, 1075314688, 0]}] : List<&2, Maybe<&2, List<&2, U32>>>}Guarantees: a float64 (3, 2) array of 1 .. 6 keeps each element's two cells together through a reshape to (2, 3) (no padding then, so it is laid out again), a transpose, a slice of rows 1 to 2, a slice of column 0 and one of all three columns of the transpose (both leaving padding), a sum along axis 0 (9, 12), a comparison with 3.5 (bool cells), and astype to int32 and back. Why it matters: a float64 element is two cells under one node; an operation that treated the low word as an element of its own would mix halves of different numbers, and every value after it would be garbage.
law f64_convert provedin F64_PROOF.bendsource · line 64 · raw
Pair({[0xb394b5997edb05025e33977930018c47/cells64.to_cell(0xb394b5997edb05025e33977930018c47/shape.DI32{}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1097859072, 268435456}), 0xb394b5997edb05025e33977930018c47/cells64.to_cell(0xb394b5997edb05025e33977930018c47/shape.DU32{}, 0x72aa159312099184b98e33378b057a0a/float64.F64{3220176896, 0}), 0xb394b5997edb05025e33977930018c47/cells64.to_cell(0xb394b5997edb05025e33977930018c47/shape.DU8{}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1081262080, 0}), 0xb394b5997edb05025e33977930018c47/cells64.to_cell(0xb394b5997edb05025e33977930018c47/shape.DI32{}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1105615371, 3221225472}), 0xb394b5997edb05025e33977930018c47/cells64.to_cell(0xb394b5997edb05025e33977930018c47/shape.DI32{}, 0x72aa159312099184b98e33378b057a0a/float64.F64{3221487616, 0}), 0xb394b5997edb05025e33977930018c47/cells64.to_cell(0xb394b5997edb05025e33977930018c47/shape.DBool{}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2146959360, 0}), 0xb394b5997edb05025e33977930018c47/cells64.to_cell(0xb394b5997edb05025e33977930018c47/shape.DBool{}, 0x72aa159312099184b98e33378b057a0a/float64.F64{2147483648, 0})] == [16777217, 4294967295, 44, 2147483648, 4294967294, 1, 0] : List<&2, U32>}, {[0xb394b5997edb05025e33977930018c47/cells64.of_cell(0xb394b5997edb05025e33977930018c47/shape.DI32{}, 4294967291), 0xb394b5997edb05025e33977930018c47/cells64.of_cell(0xb394b5997edb05025e33977930018c47/shape.DU32{}, 4294967295)] == [0x72aa159312099184b98e33378b057a0a/float64.F64{3222536192, 0}, 0x72aa159312099184b98e33378b057a0a/float64.F64{1106247679, 4292870144}] : List<&2, 0x72aa159312099184b98e33378b057a0a/float64.F64>})Guarantees: astype from float64 as NumPy's on x86-64: 16777217.0 to int32 is 16777217 (exact, not through float32), -1.0 to uint32 is 4294967295 (through int64), 300.0 to uint8 is 44 (the low byte), 3e9 to int32 is -2^31 (out of range), -2.5 to int32 is -2 (toward zero), NaN to bool is True and -0.0 to bool is False; and to float64 exactly: int32 -5 and uint32 4294967295. Why it matters: these are the conversions where an implementation going through float32, or through the wrong integer width, gives a different integer with no error.
law f64_padding provedin F64_PROOF.bendsource · line 92 · raw
{[tree_cells(0xb394b5997edb05025e33977930018c47/ndarray.slice(a32, 0n, 0n, 3n, 1n)), tree_cells(0xb394b5997edb05025e33977930018c47/ndarray.slice(0xb394b5997edb05025e33977930018c47/ndarray.t(a32), 1n, 0n, 3n, 1n)), tree_cells(0xb394b5997edb05025e33977930018c47/ndarray.concatenate(0n, 0xb394b5997edb05025e33977930018c47/ndarray.astype(0xb394b5997edb05025e33977930018c47/ndarray.arange(0xb394b5997edb05025e33977930018c47/ndarray.i32, 3n), 0xb394b5997edb05025e33977930018c47/ndarray.f64), 0xb394b5997edb05025e33977930018c47/ndarray.astype(0xb394b5997edb05025e33977930018c47/ndarray.arange(0xb394b5997edb05025e33977930018c47/ndarray.i32, 2n), 0xb394b5997edb05025e33977930018c47/ndarray.f64)))] == [16, 16, 16] : List<&2, U32>}Guarantees: when a slice or a join leaves padding, it is whole float64 elements: the (3, 2) array's three rows (padded to four rows of two) hold 16 cells, its transpose cut to 3 columns (two rows of four) holds 16, and a join of 3 and 2 elements (padded to 8) holds 16. Why it matters: the runtime keeps an array as a balanced tree and stops on one that is not; padding one level short (a cell where an element's two belong) reads back as the right values in the checker, yet stops the compiled program.
Definitions
def lit source · line 12 · raw
@+dt:0xb394b5997edb05025e33977930018c47/shape.DType -> @+s:List<&2, Nat> -> @+xs:List<&2, U32> -> 0xb394b5997edb05025e33977930018c47/ndarray.ND
def cells_r source · line 15 · raw
@r:Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, 0xb394b5997edb05025e33977930018c47/ndarray.ND> -> Maybe<&2, List<&2, U32>>
def a32 source · line 23 · raw
0xb394b5997edb05025e33977930018c47/ndarray.ND
a float64 (3, 2) array: 1, 2, 3, 4, 5, 6
def leaves source · line 72 · raw
@t:Array<U32> -> U32
every cell of a tree, padding included
def tree_cells source · line 79 · raw
@r:Result<&1, &1, 0xb394b5997edb05025e33977930018c47/shape.NdErr, 0xb394b5997edb05025e33977930018c47/ndarray.ND> -> U32