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