interplane.Get Omega
Read in your language

yang

This project has not described itself yet.

Brought by drakestapleton

branch main Branches Tags History

yang / src / ufbi_ivmath.om

155 lines · 3610 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Dyadic trigonometric enclosures and padding for the remaining binary64 diagnostics.
3note The shared trigonometric grid and the radian-index brackets are checked in DyadicTrig.lean.
4note W2 energy arithmetic lives in ufbi_w2_dyadic.om. The III-A moment sums and
5note star-cell exponential, logarithm and quadrature still use these padding functions.
6
7fn ivLo x f64 to f64
8m = add mul uAbs64 x 0.000000000001f64 0.0000000000001f64
9ret sub x m
10end
11
12fn ivHi x f64 to f64
13m = add mul uAbs64 x 0.000000000001f64 0.0000000000001f64
14ret add x m
15end
16
17note Dyadic bounds for cos(i*pi/2048), backed by proofs/DyadicTrig.lean.
18note Q=2^30. The half-angle radicand is (Q+parent)*Q/2, in [0,2^60].
19global gridLo long 2049
20global gridHi long 2049
21
22fn gridRoot a long to long
23rad = mul ulong add 1073741824 a 536870912
24lo = ulong 0
25hi = ulong 1073741825
26while gt sub hi lo 1 bound 31
27mid = shr add lo hi 1
28if le mul mid mid rad
29lo = mid
30else
31hi = mid
32end
33end
34ret long lo
35end
36
37fn initTrigGrid to void
38put gridLo 0 1073741824
39put gridHi 0 1073741824
40put gridLo 1024 0
41put gridHi 1024 0
42put gridLo 2048 neg 1073741824
43put gridHi 2048 neg 1073741824
44stride = ulong 512
45for level ulong 10
46i = stride
47while lt i 1024 bound 512
48parent = mul 2 i
49lo = gridRoot get gridLo parent
50hi = add gridRoot get gridHi parent 1
51if gt hi 1073741824
52hi = long 1073741824
53end
54put gridLo i lo
55put gridHi i hi
56put gridLo sub 2048 i neg hi
57put gridHi sub 2048 i neg lo
58i = add i mul 2 stride
59end
60stride = shr stride 1
61end
62end
63
64fn gridCosLo i ulong to f64
65ret div f64 get gridLo add i 1 1073741824.0f64
66end
67
68fn gridCosHi i ulong to f64
69ret div f64 get gridHi i 1073741824.0f64
70end
71
72note Endpoint sine values are cos(|1024-i|*pi/2048). Each cell lies on one side of pi/2.
73note Squaring is exact in 64 bits. Convert on a 2^-50 grid to represent the endpoints exactly in f64.
74fn gridSinSqLoUnits i ulong to ulong
75j = ulong 0
76if lt i 1024
77j = sub 1024 i
78else
79j = sub i 1023
80end
81s = ulong get gridLo j
82ret shr mul s s 10
83end
84
85fn gridSinSqHiUnits i ulong to ulong
86j = ulong 0
87if lt i 1024
88j = sub 1023 i
89else
90j = sub i 1024
91end
92s = ulong get gridHi j
93ret shr add mul s s 1023 10
94end
95
96fn gridSinSqLo i ulong to f64
97ret div f64 gridSinSqLoUnits i 1125899906842624.0f64
98end
99
100fn gridSinSqHi i ulong to f64
101ret div f64 gridSinSqHiUnits i 1125899906842624.0f64
102end
103
104note For a binary64 radian argument t in [0,1.5], let a=floor(t*2^28).
105note Multiplication by a power of two is exact here. Bracket 2048*t/pi using
106note 3.14159 < pi < 3.14160; largest numerator < 2^57. On this first-quadrant
107note interval sine increases and cosine decreases. Other inputs get global bounds.
108fn radialIndexLo t f64 to ulong
109a = ulong mul t 268435456.0f64
110ret div mul a 204800000 mul ulong 314160 268435456
111end
112
113fn radialIndexHi t f64 to ulong
114a = ulong mul t 268435456.0f64
115d = mul ulong 314159 268435456
116ret div add mul add a 1 204800000 sub d 1 d
117end
118
119fn radialCosLo t f64 to f64
120if or lt t 0.0f64 gt t 1.5f64
121ret neg 1.0f64
122end
123ret div f64 get gridLo radialIndexHi t 1073741824.0f64
124end
125
126fn radialCosHi t f64 to f64
127if or lt t 0.0f64 gt t 1.5f64
128ret 1.0f64
129end
130ret div f64 get gridHi radialIndexLo t 1073741824.0f64
131end
132
133fn radialSinLo t f64 to f64
134if or lt t 0.0f64 gt t 1.5f64
135ret neg 1.0f64
136end
137ret div f64 get gridLo sub 1024 radialIndexLo t 1073741824.0f64
138end
139
140fn radialSinHi t f64 to f64
141if or lt t 0.0f64 gt t 1.5f64
142ret 1.0f64
143end
144ret div f64 get gridHi sub 1024 radialIndexHi t 1073741824.0f64
145end
146
147fn trigGridOK to long
148if ne get gridHi 0 1073741824
149ret 0
150end
151if ne get gridLo 2048 neg long 1073741824
152ret 0
153end
154ret 1
155end