~/bend-docscommunity

TRIG_LAWS.bend open laws/TODOs

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

The laws of bend-float64's large-argument reduction for sin, cos and tan (fast.bend), at literal inputs: the window of 2/pi's bits taken for an exponent, and the quadrant and fraction found for an argument. The expected values come from test/gen_trig_laws.py, which computes them from mpmath's 2/pi with Python integers and checks each fraction against |x| 2/pi computed by mpmath. The functions' results are tested instead (test/trig_check.py). Gate: ./bend-check TRIG_PROOF.bend --verdict

7 imports
import Base
import ./wide.bend as W
import ./float64.bend as F
import ./fb.bend as Q
import ./fast.bend as FS
import ./big.bend as B
import ./math.bend as M

Laws

law trig_window provedin TRIG_PROOF.bendsource · line 18 · raw

{[0x72aa159312099184b98e33378b057a0a/fast.window(1053), 0x72aa159312099184b98e33378b057a0a/fast.window(1600), 0x72aa159312099184b98e33378b057a0a/fast.window(2046)] == [0x72aa159312099184b98e33378b057a0a/fast.R4{0x72aa159312099184b98e33378b057a0a/wide.W64{162, 4186140238}, 0x72aa159312099184b98e33378b057a0a/wide.W64{1142237692, 660066805}, 0x72aa159312099184b98e33378b057a0a/wide.W64{886948059, 1653971260}, 0x72aa159312099184b98e33378b057a0a/wide.W64{1133527550, 1365486558}}, 0x72aa159312099184b98e33378b057a0a/fast.R4{0x72aa159312099184b98e33378b057a0a/wide.W64{3816895906, 4226943436}, 0x72aa159312099184b98e33378b057a0a/wide.W64{2394016794, 2580522212}, 0x72aa159312099184b98e33378b057a0a/wide.W64{586964463, 3376535807}, 0x72aa159312099184b98e33378b057a0a/wide.W64{3300916976, 750813049}}, 0x72aa159312099184b98e33378b057a0a/fast.R4{0x72aa159312099184b98e33378b057a0a/wide.W64{1333104599, 3420649082}, 0x72aa159312099184b98e33378b057a0a/wide.W64{242478868, 2770719959}, 0x72aa159312099184b98e33378b057a0a/wide.W64{4139737663, 448401580}, 0x72aa159312099184b98e33378b057a0a/wide.W64{106991096, 4141307873}}] : List<&2, 0x72aa159312099184b98e33378b057a0a/fast.R4>}

Guarantees: the window of 2/pi's bits the fast path takes for an argument with biased exponent 1053 (|x| near 2^30, the smallest that uses it), 1600 and 2046 (the largest finite) is exactly the 256 bits that matter there. Why it matters: a window one bit off still gives a plausible-looking fraction, wrong for every argument with that exponent; the error bounds cannot catch it, since they assume the right bits.

law trig_far provedin TRIG_PROOF.bendsource · line 31 · raw

{[0x72aa159312099184b98e33378b057a0a/fast.far(0x72aa159312099184b98e33378b057a0a/float64.F64{1963371611, 640459263}), 0x72aa159312099184b98e33378b057a0a/fast.far(0x72aa159312099184b98e33378b057a0a/float64.F64{2145386496, 0}), 0x72aa159312099184b98e33378b057a0a/fast.far(0x72aa159312099184b98e33378b057a0a/float64.F64{1104150528, 7}), 0x72aa159312099184b98e33378b057a0a/fast.far(0x72aa159312099184b98e33378b057a0a/float64.F64{3251634176, 1}), 0x72aa159312099184b98e33378b057a0a/fast.far(0x72aa159312099184b98e33378b057a0a/float64.F64{1107126453, 3591395173}), 0x72aa159312099184b98e33378b057a0a/fast.far(0x72aa159312099184b98e33378b057a0a/float64.F64{1279188277, 1146862456})] == [0x72aa159312099184b98e33378b057a0a/fast.KF{1, 0x72aa159312099184b98e33378b057a0a/fb.FB{False{}, 0x72aa159312099184b98e33378b057a0a/wide.W128{0x72aa159312099184b98e33378b057a0a/wide.W64{2955153520, 1083003905}, 0x72aa159312099184b98e33378b057a0a/wide.W64{1775977343, 1447033185}}, 4294967107, 2}}, 0x72aa159312099184b98e33378b057a0a/fast.KF{2, 0x72aa159312099184b98e33378b057a0a/fb.FB{True{}, 0x72aa159312099184b98e33378b057a0a/wide.W128{0x72aa159312099184b98e33378b057a0a/wide.W64{3271083528, 1974299925}, 0x72aa159312099184b98e33378b057a0a/wide.W64{2483331150, 3765609207}}, 4294967167, 2}}, 0x72aa159312099184b98e33378b057a0a/fast.KF{4, 0x72aa159312099184b98e33378b057a0a/fb.FB{True{}, 0x72aa159312099184b98e33378b057a0a/wide.W128{0x72aa159312099184b98e33378b057a0a/wide.W64{3638415812, 1831613176}, 0x72aa159312099184b98e33378b057a0a/wide.W64{549741046, 4145596303}}, 4294967167, 2}}, 0x72aa159312099184b98e33378b057a0a/fast.KF{4, 0x72aa159312099184b98e33378b057a0a/fb.FB{True{}, 0x72aa159312099184b98e33378b057a0a/wide.W128{0x72aa159312099184b98e33378b057a0a/wide.W64{3638423635, 902881700}, 0x72aa159312099184b98e33378b057a0a/wide.W64{3837542718, 1469064585}}, 4294967167, 2}}, 0x72aa159312099184b98e33378b057a0a/fast.KF{1, 0x72aa159312099184b98e33378b057a0a/fb.FB{False{}, 0x72aa159312099184b98e33378b057a0a/wide.W128{0x72aa159312099184b98e33378b057a0a/wide.W64{2461211933, 1465160887}, 0x72aa159312099184b98e33378b057a0a/wide.W64{2915416632, 4029660304}}, 4294967167, 2}}, 0x72aa159312099184b98e33378b057a0a/fast.KF{1, 0x72aa159312099184b98e33378b057a0a/fb.FB{False{}, 0x72aa159312099184b98e33378b057a0a/wide.W128{0x72aa159312099184b98e33378b057a0a/wide.W64{2272790719, 2815997824}, 0x72aa159312099184b98e33378b057a0a/wide.W64{5751004, 2178804378}}, 4294967165, 2}}] : List<&2, 0x72aa159312099184b98e33378b057a0a/fast.KF>}

Guarantees: the quadrant and fraction found for 6381956970095103 * 2^797 (the float64 closest to a multiple of pi/2, 2^-60.9 of a quadrant away), for the largest power of two 2^1023, for 2^30 (1 + 7 * 2^-52) and for -2^30 (1 + 2^-52), and two arguments whose product with the window carries from its first and from its second 64-bit word: quadrant (counted past 3 when a fraction from 1/2 up moves to the next), the fraction's sign, its 128 bits, its exponent and its error count. Why it matters: these pin the product with the window (its carries), the split into quadrant and fraction, the switch to the next quadrant from 1/2 up, and the normalization of a fraction 61 bits below 1.

law trig_slow_quadrant provedin TRIG_PROOF.bendsource · line 44 · raw

{0x72aa159312099184b98e33378b057a0a/math.red_k(0x72aa159312099184b98e33378b057a0a/math.reduce(0x72aa159312099184b98e33378b057a0a/big.of_w64(0x72aa159312099184b98e33378b057a0a/wide.W64{1485915, 640459263}), 797, 128)) == 1 : U32}

Guarantees: the slow path's windowed reduction puts 6381956970095103 * 2^797 in quadrant 1, as the fast path does. Why it matters: the slow path takes only a window of 2/pi's bits now; a window starting one word too low would drop bits that are not whole turns and change the quadrant.