POWER_LAWS.bend source
POWER_LAWS.bend on the hub · documented module
# The laws of bend-float64's power (math.bend), at literal inputs: C99's special-case table and the exact answers# found before any ball is evaluated. A gate of its own so that each proof file stays within the checker's limit.# Gate: ./bend-check POWER_PROOF.bend --verdictimport Baseimport ./float64.bend as Fimport ./math.bend as M# Guarantees: C99's table for power: x^0 = 1 even for a quiet NaN x; 1^y = 1 even for a quiet NaN y; (-1)^inf = 1;# 0.5^-inf = inf and 2^-inf = +0; (-0)^-3 = -inf, (-0)^-2 = inf, (-0)^3 = -0, (-0)^2 = +0; (-inf)^3 = -inf,# (-inf)^-3 = -0, (-inf)^2 = inf; (-2)^0.5 is the default NaN; (-2)^3 = -8; a signalling NaN to the 0 is that NaN# quieted, as glibc gives it.# Why it matters: power has the largest special-case table of the set, and each entry is a separate decision.law power_table: {[M.power(F.F64{2146959360, 5}, F.F64{0, 0}), M.power(F.F64{1072693248, 0}, F.F64{2146959360, 5}), M.power(F.F64{3220176896, 0}, F.F64{2146435072, 0}), M.power(F.F64{1071644672, 0}, F.F64{4293918720, 0}), M.power(F.F64{1073741824, 0}, F.F64{4293918720, 0}), M.power(F.F64{2147483648, 0}, F.F64{3221749760, 0}), M.power(F.F64{2147483648, 0}, F.F64{3221225472, 0}), M.power(F.F64{2147483648, 0}, F.F64{1074266112, 0}), M.power(F.F64{2147483648, 0}, F.F64{1073741824, 0}), M.power(F.F64{4293918720, 0}, F.F64{1074266112, 0}), M.power(F.F64{4293918720, 0}, F.F64{3221749760, 0}), M.power(F.F64{4293918720, 0}, F.F64{1073741824, 0}), M.power(F.F64{3221225472, 0}, F.F64{1071644672, 0}), M.power(F.F64{3221225472, 0}, F.F64{1074266112, 0}), M.power(F.F64{2146435072, 5}, F.F64{0, 0})] == [F.F64{1072693248, 0}, F.F64{1072693248, 0}, F.F64{1072693248, 0}, F.F64{2146435072, 0}, F.F64{0, 0}, F.F64{4293918720, 0}, F.F64{2146435072, 0}, F.F64{2147483648, 0}, F.F64{0, 0}, F.F64{4293918720, 0}, F.F64{2147483648, 0}, F.F64{2146435072, 0}, F.F64{4294443008, 0}, F.F64{3223322624, 0}, F.F64{2146959360, 5}] : List<&2, F.F64>}# Guarantees: power comes out exact when the answer is: 2^10 = 1024, 6^3 = 216, 3^3 = 27, 36^0.5 = 6 (36 = 3^2 2^2),# 2^-1075 = 0 (halfway, to even).# Why it matters: an exact or halfway power never settles by refining a ball, so each is found and computed exactly# first; without that the evaluation would loop, and a halfway case could round the wrong way.law exact_power: {[M.power(F.from_i32(2), F.from_i32(10)), M.power(F.from_i32(6), F.from_i32(3)), M.power(F.from_i32(3), F.from_i32(3)), M.power(F.from_i32(36), F.F64{1071644672, 0}), M.power(F.from_i32(2), F.from_i32(4294966221))] == [F.F64{1083179008, 0}, F.F64{1080754176, 0}, F.F64{1077608448, 0}, F.F64{1075314688, 0}, F.F64{0, 0}] : List<&2, F.F64>}