@the-situation/core 0.5.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/distributions/distribution.d.ts +60 -0
- package/dist/distributions/distribution.d.ts.map +1 -0
- package/dist/distributions/distribution.js +10 -0
- package/dist/distributions/distribution.js.map +1 -0
- package/dist/distributions/normal-distribution.d.ts +125 -0
- package/dist/distributions/normal-distribution.d.ts.map +1 -0
- package/dist/distributions/normal-distribution.js +310 -0
- package/dist/distributions/normal-distribution.js.map +1 -0
- package/dist/distributions/normal-sqrt-hints-raw.d.ts +18 -0
- package/dist/distributions/normal-sqrt-hints-raw.d.ts.map +1 -0
- package/dist/distributions/normal-sqrt-hints-raw.js +9 -0
- package/dist/distributions/normal-sqrt-hints-raw.js.map +1 -0
- package/dist/errors/index.d.ts +90 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +45 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/math/sq128-raw.d.ts +69 -0
- package/dist/math/sq128-raw.d.ts.map +1 -0
- package/dist/math/sq128-raw.js +84 -0
- package/dist/math/sq128-raw.js.map +1 -0
- package/dist/math/sq128.d.ts +191 -0
- package/dist/math/sq128.d.ts.map +1 -0
- package/dist/math/sq128.js +611 -0
- package/dist/math/sq128.js.map +1 -0
- package/package.json +29 -0
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQ128x128 fixed-point number type.
|
|
3
|
+
*
|
|
4
|
+
* An immutable fixed-point number with 128 bits of integer precision
|
|
5
|
+
* and 128 bits of fractional precision.
|
|
6
|
+
*
|
|
7
|
+
* ## Range
|
|
8
|
+
* - Minimum: -2^128 ≈ -3.4×10³⁸
|
|
9
|
+
* - Maximum: 2^128 - 2^-128 ≈ 3.4×10³⁸
|
|
10
|
+
*
|
|
11
|
+
* ## Design
|
|
12
|
+
* - Immutable: all operations return new instances
|
|
13
|
+
* - Safe: operations return null on overflow/underflow
|
|
14
|
+
* - Compatible: toRaw()/fromRaw() for Starknet serialization
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
import { isValidSQ128x128Raw, MAX_LIMB, NEG_ONE_RAW, ONE_RAW, ZERO_RAW, } from './sq128-raw';
|
|
19
|
+
/** 2^64 for limb arithmetic */
|
|
20
|
+
const LIMB_BITS = 64n;
|
|
21
|
+
/** 2^128 - the scaling factor for the fractional part */
|
|
22
|
+
const SCALE = 1n << 128n;
|
|
23
|
+
/** Maximum magnitude (2^256 - 1) */
|
|
24
|
+
const MAX_MAG = (1n << 256n) - 1n;
|
|
25
|
+
/**
|
|
26
|
+
* Splits a 256-bit magnitude into four 64-bit limbs.
|
|
27
|
+
*/
|
|
28
|
+
function toLimbs(mag) {
|
|
29
|
+
return {
|
|
30
|
+
limb0: mag & MAX_LIMB,
|
|
31
|
+
limb1: (mag >> LIMB_BITS) & MAX_LIMB,
|
|
32
|
+
limb2: (mag >> 128n) & MAX_LIMB,
|
|
33
|
+
limb3: mag >> 192n,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Reconstructs magnitude from four 64-bit limbs.
|
|
38
|
+
*/
|
|
39
|
+
function fromLimbs(limb0, limb1, limb2, limb3) {
|
|
40
|
+
return limb0 + (limb1 << LIMB_BITS) + (limb2 << 128n) + (limb3 << 192n);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* An immutable signed Q128.128 fixed-point number.
|
|
44
|
+
*/
|
|
45
|
+
export class SQ128x128 {
|
|
46
|
+
magnitude;
|
|
47
|
+
negative;
|
|
48
|
+
constructor(magnitude, negative) {
|
|
49
|
+
this.magnitude = magnitude;
|
|
50
|
+
this.negative = negative;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates an SQ128x128 from a JavaScript number.
|
|
54
|
+
*
|
|
55
|
+
* @param value - The number to convert
|
|
56
|
+
* @returns The SQ128x128 value, or null if overflow/invalid
|
|
57
|
+
*/
|
|
58
|
+
static fromNumber(value) {
|
|
59
|
+
if (!Number.isFinite(value)) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const negative = value < 0;
|
|
63
|
+
const absValue = Math.abs(value);
|
|
64
|
+
// Separate integer and fractional parts for precise encoding.
|
|
65
|
+
// Directly multiplying by 2^128 loses precision because JavaScript
|
|
66
|
+
// numbers only have ~53 bits of mantissa precision.
|
|
67
|
+
const intPart = Math.floor(absValue);
|
|
68
|
+
const fracPart = absValue - intPart;
|
|
69
|
+
// Integer part contribution: intPart * 2^128 (exact for integers up to 2^53)
|
|
70
|
+
const intContrib = BigInt(intPart) * SCALE;
|
|
71
|
+
// Fractional part contribution: fracPart * 2^128
|
|
72
|
+
// Split into two 64-bit multiplications for better precision.
|
|
73
|
+
// fracPart * 2^64 fits in JavaScript's Number precision for fracPart < 1
|
|
74
|
+
const HALF_SCALE = 1n << 64n;
|
|
75
|
+
const fracScaled = BigInt(Math.round(fracPart * Number(HALF_SCALE)));
|
|
76
|
+
const fracContrib = fracScaled * HALF_SCALE;
|
|
77
|
+
const magnitude = intContrib + fracContrib;
|
|
78
|
+
if (magnitude > MAX_MAG) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
return new SQ128x128(magnitude, negative && magnitude !== 0n);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Creates an SQ128x128 from a bigint integer value.
|
|
85
|
+
*
|
|
86
|
+
* @param value - The integer to convert
|
|
87
|
+
* @returns The SQ128x128 value, or null if overflow
|
|
88
|
+
*/
|
|
89
|
+
static fromBigInt(value) {
|
|
90
|
+
const negative = value < 0n;
|
|
91
|
+
const absValue = negative ? -value : value;
|
|
92
|
+
const scaled = absValue * SCALE;
|
|
93
|
+
if (scaled > MAX_MAG) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
return new SQ128x128(scaled, negative && scaled !== 0n);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Creates an SQ128x128 from a raw representation.
|
|
100
|
+
*
|
|
101
|
+
* @param raw - The raw limb representation
|
|
102
|
+
* @returns The SQ128x128 value, or null if invalid
|
|
103
|
+
*/
|
|
104
|
+
static fromRaw(raw) {
|
|
105
|
+
if (!isValidSQ128x128Raw(raw)) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
const magnitude = fromLimbs(raw.limb0, raw.limb1, raw.limb2, raw.limb3);
|
|
109
|
+
return new SQ128x128(magnitude, raw.neg && magnitude !== 0n);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Converts to a raw representation for Starknet serialization.
|
|
113
|
+
*/
|
|
114
|
+
toRaw() {
|
|
115
|
+
const { limb0, limb1, limb2, limb3 } = toLimbs(this.magnitude);
|
|
116
|
+
return { limb0, limb1, limb2, limb3, neg: this.negative };
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Converts to a JavaScript number.
|
|
120
|
+
*
|
|
121
|
+
* Note: May lose precision for very large or very small values.
|
|
122
|
+
*/
|
|
123
|
+
toNumber() {
|
|
124
|
+
const value = Number(this.magnitude) / Number(SCALE);
|
|
125
|
+
return this.negative ? -value : value;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Returns the underlying scaled magnitude as a bigint.
|
|
129
|
+
*/
|
|
130
|
+
toScaledBigInt() {
|
|
131
|
+
return this.negative ? -this.magnitude : this.magnitude;
|
|
132
|
+
}
|
|
133
|
+
// ============================================================================
|
|
134
|
+
// Comparison
|
|
135
|
+
// ============================================================================
|
|
136
|
+
/**
|
|
137
|
+
* Tests equality with another SQ128x128.
|
|
138
|
+
*/
|
|
139
|
+
eq(other) {
|
|
140
|
+
return this.magnitude === other.magnitude && this.negative === other.negative;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Tests if this value is less than another.
|
|
144
|
+
*/
|
|
145
|
+
lt(other) {
|
|
146
|
+
if (this.negative !== other.negative) {
|
|
147
|
+
return this.negative;
|
|
148
|
+
}
|
|
149
|
+
if (this.negative) {
|
|
150
|
+
return this.magnitude > other.magnitude;
|
|
151
|
+
}
|
|
152
|
+
return this.magnitude < other.magnitude;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Tests if this value is greater than another.
|
|
156
|
+
*/
|
|
157
|
+
gt(other) {
|
|
158
|
+
return other.lt(this);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Tests if this value is less than or equal to another.
|
|
162
|
+
*/
|
|
163
|
+
lte(other) {
|
|
164
|
+
return this.eq(other) || this.lt(other);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Tests if this value is greater than or equal to another.
|
|
168
|
+
*/
|
|
169
|
+
gte(other) {
|
|
170
|
+
return this.eq(other) || this.gt(other);
|
|
171
|
+
}
|
|
172
|
+
// ============================================================================
|
|
173
|
+
// Predicates
|
|
174
|
+
// ============================================================================
|
|
175
|
+
/**
|
|
176
|
+
* Returns true if this value is zero.
|
|
177
|
+
*/
|
|
178
|
+
isZero() {
|
|
179
|
+
return this.magnitude === 0n;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Returns true if this value is negative.
|
|
183
|
+
*/
|
|
184
|
+
isNegative() {
|
|
185
|
+
return this.negative;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Returns true if this value is positive (greater than zero).
|
|
189
|
+
*/
|
|
190
|
+
isPositive() {
|
|
191
|
+
return !this.negative && this.magnitude > 0n;
|
|
192
|
+
}
|
|
193
|
+
// ============================================================================
|
|
194
|
+
// Arithmetic
|
|
195
|
+
// ============================================================================
|
|
196
|
+
/**
|
|
197
|
+
* Adds another SQ128x128 to this value.
|
|
198
|
+
*
|
|
199
|
+
* @returns The sum, or null on overflow
|
|
200
|
+
*/
|
|
201
|
+
add(other) {
|
|
202
|
+
const a = this.toScaledBigInt();
|
|
203
|
+
const b = other.toScaledBigInt();
|
|
204
|
+
const result = a + b;
|
|
205
|
+
const negative = result < 0n;
|
|
206
|
+
const magnitude = negative ? -result : result;
|
|
207
|
+
if (magnitude > MAX_MAG) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
return new SQ128x128(magnitude, negative && magnitude !== 0n);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Subtracts another SQ128x128 from this value.
|
|
214
|
+
*
|
|
215
|
+
* @returns The difference, or null on overflow
|
|
216
|
+
*/
|
|
217
|
+
sub(other) {
|
|
218
|
+
const a = this.toScaledBigInt();
|
|
219
|
+
const b = other.toScaledBigInt();
|
|
220
|
+
const result = a - b;
|
|
221
|
+
const negative = result < 0n;
|
|
222
|
+
const magnitude = negative ? -result : result;
|
|
223
|
+
if (magnitude > MAX_MAG) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
return new SQ128x128(magnitude, negative && magnitude !== 0n);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Multiplies by another SQ128x128.
|
|
230
|
+
*
|
|
231
|
+
* @returns The product (rounded toward zero), or null on overflow
|
|
232
|
+
*/
|
|
233
|
+
mul(other) {
|
|
234
|
+
const product = this.magnitude * other.magnitude;
|
|
235
|
+
// Scale back down: divide by SCALE (rounding toward zero)
|
|
236
|
+
const scaled = product / SCALE;
|
|
237
|
+
if (scaled > MAX_MAG) {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
const negative = this.negative !== other.negative;
|
|
241
|
+
return new SQ128x128(scaled, negative && scaled !== 0n);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Divides by another SQ128x128.
|
|
245
|
+
*
|
|
246
|
+
* @returns The quotient (rounded toward zero), or null on division by zero/overflow
|
|
247
|
+
*/
|
|
248
|
+
div(other) {
|
|
249
|
+
if (other.magnitude === 0n) {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
// Scale up before dividing to maintain precision
|
|
253
|
+
const scaled = (this.magnitude * SCALE) / other.magnitude;
|
|
254
|
+
if (scaled > MAX_MAG) {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
const negative = this.negative !== other.negative;
|
|
258
|
+
return new SQ128x128(scaled, negative && scaled !== 0n);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Returns the negation of this value.
|
|
262
|
+
*
|
|
263
|
+
* @returns The negated value, or null if negating MIN would overflow
|
|
264
|
+
*/
|
|
265
|
+
neg() {
|
|
266
|
+
if (this.magnitude === 0n) {
|
|
267
|
+
return new SQ128x128(0n, false);
|
|
268
|
+
}
|
|
269
|
+
return new SQ128x128(this.magnitude, !this.negative);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Returns the absolute value.
|
|
273
|
+
*/
|
|
274
|
+
abs() {
|
|
275
|
+
return new SQ128x128(this.magnitude, false);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Computes the square of this value (x * x).
|
|
279
|
+
*
|
|
280
|
+
* More efficient than mul(this) as we can skip sign computation.
|
|
281
|
+
*
|
|
282
|
+
* @returns The squared value, or null on overflow
|
|
283
|
+
*/
|
|
284
|
+
pow2() {
|
|
285
|
+
const product = this.magnitude * this.magnitude;
|
|
286
|
+
const scaled = product / SCALE;
|
|
287
|
+
if (scaled > MAX_MAG) {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
// Square is always non-negative
|
|
291
|
+
return new SQ128x128(scaled, false);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Computes the floor (integer part) of the absolute value.
|
|
295
|
+
*
|
|
296
|
+
* @returns The integer part as a number
|
|
297
|
+
*/
|
|
298
|
+
floor() {
|
|
299
|
+
// The integer part is stored in limb2 and limb3 (bits 128-255)
|
|
300
|
+
const integerPart = this.magnitude >> 128n;
|
|
301
|
+
return Number(integerPart);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Computes the fractional part (value - floor).
|
|
305
|
+
*
|
|
306
|
+
* @returns The fractional part as SQ128x128
|
|
307
|
+
*/
|
|
308
|
+
frac() {
|
|
309
|
+
// Mask to keep only the lower 128 bits (fractional part)
|
|
310
|
+
const fracMask = (1n << 128n) - 1n;
|
|
311
|
+
const fracMagnitude = this.magnitude & fracMask;
|
|
312
|
+
return new SQ128x128(fracMagnitude, false);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Computes exp(-|self|) for this value.
|
|
316
|
+
*
|
|
317
|
+
* Uses range reduction: exp(-u) = exp(-k) * exp(-(u mod 1))
|
|
318
|
+
* where k = floor(u) and the fractional part uses Taylor series.
|
|
319
|
+
*
|
|
320
|
+
* @returns The exponential value, or null if computation fails
|
|
321
|
+
*/
|
|
322
|
+
expNeg() {
|
|
323
|
+
// For negative values, exp(-negative) = exp(positive) > 1
|
|
324
|
+
// Clamp to 1 since exp(x) > 1 for x > 0
|
|
325
|
+
if (this.negative) {
|
|
326
|
+
return ONE;
|
|
327
|
+
}
|
|
328
|
+
// For very large values, exp(-u) is effectively zero
|
|
329
|
+
const absValue = this.abs();
|
|
330
|
+
if (absValue.floor() >= EXP_NEG_TABLE.length) {
|
|
331
|
+
return ZERO;
|
|
332
|
+
}
|
|
333
|
+
// Range reduction: find k = floor(u)
|
|
334
|
+
const k = absValue.floor();
|
|
335
|
+
const expNegK = EXP_NEG_TABLE[k];
|
|
336
|
+
if (!expNegK || expNegK.isZero()) {
|
|
337
|
+
return ZERO;
|
|
338
|
+
}
|
|
339
|
+
// Get fractional part: r = u - k, where r in [0, 1)
|
|
340
|
+
const r = absValue.frac();
|
|
341
|
+
// Taylor series for exp(-r) where r in [0, 1]
|
|
342
|
+
const expNegR = taylorExpNegSmall(r);
|
|
343
|
+
if (!expNegR) {
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
// exp(-u) = exp(-k) * exp(-r)
|
|
347
|
+
return expNegK.mul(expNegR);
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Computes exp(-x²/2) for this value.
|
|
351
|
+
*
|
|
352
|
+
* This is a common operation in normal distribution computations.
|
|
353
|
+
*
|
|
354
|
+
* @returns The exponential value, or null if computation fails
|
|
355
|
+
*/
|
|
356
|
+
expNegHalfSquared() {
|
|
357
|
+
const xSquared = this.pow2();
|
|
358
|
+
if (!xSquared) {
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
const half = HALF;
|
|
362
|
+
const u = xSquared.mul(half);
|
|
363
|
+
if (!u) {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
return u.expNeg();
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
// ============================================================================
|
|
370
|
+
// Constants
|
|
371
|
+
// ============================================================================
|
|
372
|
+
/** Zero (0.0) */
|
|
373
|
+
export const ZERO = SQ128x128.fromRaw(ZERO_RAW);
|
|
374
|
+
/** Half (0.5) */
|
|
375
|
+
export const HALF = SQ128x128.fromRaw({
|
|
376
|
+
limb0: 0n,
|
|
377
|
+
limb1: 0x8000000000000000n,
|
|
378
|
+
limb2: 0n,
|
|
379
|
+
limb3: 0n,
|
|
380
|
+
neg: false,
|
|
381
|
+
});
|
|
382
|
+
/** Two (2.0) */
|
|
383
|
+
export const TWO = SQ128x128.fromRaw({
|
|
384
|
+
limb0: 0n,
|
|
385
|
+
limb1: 0n,
|
|
386
|
+
limb2: 2n,
|
|
387
|
+
limb3: 0n,
|
|
388
|
+
neg: false,
|
|
389
|
+
});
|
|
390
|
+
/** One (1.0) */
|
|
391
|
+
export const ONE = SQ128x128.fromRaw(ONE_RAW);
|
|
392
|
+
/** Negative one (-1.0) */
|
|
393
|
+
export const NEG_ONE = SQ128x128.fromRaw(NEG_ONE_RAW);
|
|
394
|
+
/** Minimum value - practical limit for testing (using bigint for precision) */
|
|
395
|
+
export const MIN = SQ128x128.fromBigInt(-(1n << 64n));
|
|
396
|
+
/** Maximum value - practical limit for testing (using bigint for precision) */
|
|
397
|
+
export const MAX = SQ128x128.fromBigInt((1n << 64n) - 1n);
|
|
398
|
+
// ============================================================================
|
|
399
|
+
// Math Constants for PDF Computation
|
|
400
|
+
// ============================================================================
|
|
401
|
+
/**
|
|
402
|
+
* 1/√(2π) ≈ 0.3989422804014327
|
|
403
|
+
*
|
|
404
|
+
* This constant is used in normal distribution PDF computation.
|
|
405
|
+
*/
|
|
406
|
+
export const INV_SQRT_2PI = SQ128x128.fromRaw({
|
|
407
|
+
limb0: 0x3f2cf1402eae38bfn,
|
|
408
|
+
limb1: 0x662114cf50d94234n,
|
|
409
|
+
limb2: 0n,
|
|
410
|
+
limb3: 0n,
|
|
411
|
+
neg: false,
|
|
412
|
+
});
|
|
413
|
+
/**
|
|
414
|
+
* Precomputed exp(-k) lookup table for k = 0..10.
|
|
415
|
+
*
|
|
416
|
+
* For k > 10, exp(-k) < 2e-5, effectively zero for our precision.
|
|
417
|
+
*/
|
|
418
|
+
export const EXP_NEG_TABLE = [
|
|
419
|
+
// exp(-0) = 1.0
|
|
420
|
+
SQ128x128.fromRaw({ limb0: 0n, limb1: 0n, limb2: 1n, limb3: 0n, neg: false }),
|
|
421
|
+
// exp(-1) ≈ 0.36787944117144232
|
|
422
|
+
SQ128x128.fromRaw({
|
|
423
|
+
limb0: 0xb4c7e2563b8a0390n,
|
|
424
|
+
limb1: 0x5e2d58d8b3bcdf1an,
|
|
425
|
+
limb2: 0n,
|
|
426
|
+
limb3: 0n,
|
|
427
|
+
neg: false,
|
|
428
|
+
}),
|
|
429
|
+
// exp(-2) ≈ 0.13533528323661269
|
|
430
|
+
SQ128x128.fromRaw({
|
|
431
|
+
limb0: 0x5fc21ca1f0ead89bn,
|
|
432
|
+
limb1: 0x22a5dc02c1e4ebd2n,
|
|
433
|
+
limb2: 0n,
|
|
434
|
+
limb3: 0n,
|
|
435
|
+
neg: false,
|
|
436
|
+
}),
|
|
437
|
+
// exp(-3) ≈ 0.04978706836786394
|
|
438
|
+
SQ128x128.fromRaw({
|
|
439
|
+
limb0: 0x89571c88d8a3eacdn,
|
|
440
|
+
limb1: 0x0cbfbf00de0c6c61n,
|
|
441
|
+
limb2: 0n,
|
|
442
|
+
limb3: 0n,
|
|
443
|
+
neg: false,
|
|
444
|
+
}),
|
|
445
|
+
// exp(-4) ≈ 0.01831563888873418
|
|
446
|
+
SQ128x128.fromRaw({
|
|
447
|
+
limb0: 0x8b3e5e37fb91925en,
|
|
448
|
+
limb1: 0x04b08b4b7f06c6f9n,
|
|
449
|
+
limb2: 0n,
|
|
450
|
+
limb3: 0n,
|
|
451
|
+
neg: false,
|
|
452
|
+
}),
|
|
453
|
+
// exp(-5) ≈ 0.00673794699908547
|
|
454
|
+
SQ128x128.fromRaw({
|
|
455
|
+
limb0: 0xf4fce765679d0f2cn,
|
|
456
|
+
limb1: 0x01ba3fa6a10b78dcn,
|
|
457
|
+
limb2: 0n,
|
|
458
|
+
limb3: 0n,
|
|
459
|
+
neg: false,
|
|
460
|
+
}),
|
|
461
|
+
// exp(-6) ≈ 0.00247875217666636
|
|
462
|
+
SQ128x128.fromRaw({
|
|
463
|
+
limb0: 0x1b1af20c7dc7ab1dn,
|
|
464
|
+
limb1: 0x00a2515f16c37668n,
|
|
465
|
+
limb2: 0n,
|
|
466
|
+
limb3: 0n,
|
|
467
|
+
neg: false,
|
|
468
|
+
}),
|
|
469
|
+
// exp(-7) ≈ 0.00091188196555452
|
|
470
|
+
SQ128x128.fromRaw({
|
|
471
|
+
limb0: 0x9c51bea3e0c3a7ecn,
|
|
472
|
+
limb1: 0x003bc8fa73692c09n,
|
|
473
|
+
limb2: 0n,
|
|
474
|
+
limb3: 0n,
|
|
475
|
+
neg: false,
|
|
476
|
+
}),
|
|
477
|
+
// exp(-8) ≈ 0.00033546262790251
|
|
478
|
+
SQ128x128.fromRaw({
|
|
479
|
+
limb0: 0xa5f10cf3b5cddb19n,
|
|
480
|
+
limb1: 0x0015f41e9c1b12abn,
|
|
481
|
+
limb2: 0n,
|
|
482
|
+
limb3: 0n,
|
|
483
|
+
neg: false,
|
|
484
|
+
}),
|
|
485
|
+
// exp(-9) ≈ 0.00012340980408668
|
|
486
|
+
SQ128x128.fromRaw({
|
|
487
|
+
limb0: 0x17bef44e8b2d2e80n,
|
|
488
|
+
limb1: 0x00081458daa6a0c5n,
|
|
489
|
+
limb2: 0n,
|
|
490
|
+
limb3: 0n,
|
|
491
|
+
neg: false,
|
|
492
|
+
}),
|
|
493
|
+
// exp(-10) ≈ 0.00004539992976248
|
|
494
|
+
SQ128x128.fromRaw({
|
|
495
|
+
limb0: 0xe62e6db6b0d2efdfn,
|
|
496
|
+
limb1: 0x0002f7a9b11f8cden,
|
|
497
|
+
limb2: 0n,
|
|
498
|
+
limb3: 0n,
|
|
499
|
+
neg: false,
|
|
500
|
+
}),
|
|
501
|
+
];
|
|
502
|
+
/**
|
|
503
|
+
* Taylor coefficients for exp(-r) using Horner's method.
|
|
504
|
+
*
|
|
505
|
+
* exp(-r) = 1 + r*(-1 + r*(1/2 + r*(-1/6 + r*(1/24 + r*(-1/120 + r/720)))))
|
|
506
|
+
*
|
|
507
|
+
* Coefficients: c6 = 1/720, c5 = -1/120, c4 = 1/24, c3 = -1/6, c2 = 1/2, c1 = -1
|
|
508
|
+
*/
|
|
509
|
+
const TAYLOR_COEFFS = {
|
|
510
|
+
// c6 = 1/720 ≈ 0.00138888888888889
|
|
511
|
+
c6: SQ128x128.fromRaw({
|
|
512
|
+
limb0: 0n,
|
|
513
|
+
limb1: 0x5b05b05b05b05cn,
|
|
514
|
+
limb2: 0n,
|
|
515
|
+
limb3: 0n,
|
|
516
|
+
neg: false,
|
|
517
|
+
}),
|
|
518
|
+
// c5 = -1/120 ≈ -0.00833333333333333
|
|
519
|
+
c5: SQ128x128.fromRaw({
|
|
520
|
+
limb0: 0n,
|
|
521
|
+
limb1: 0x222222222222220n,
|
|
522
|
+
limb2: 0n,
|
|
523
|
+
limb3: 0n,
|
|
524
|
+
neg: true,
|
|
525
|
+
}),
|
|
526
|
+
// c4 = 1/24 ≈ 0.04166666666666667
|
|
527
|
+
c4: SQ128x128.fromRaw({
|
|
528
|
+
limb0: 0n,
|
|
529
|
+
limb1: 0xaaaaaaaaaaaaa80n,
|
|
530
|
+
limb2: 0n,
|
|
531
|
+
limb3: 0n,
|
|
532
|
+
neg: false,
|
|
533
|
+
}),
|
|
534
|
+
// c3 = -1/6 ≈ -0.16666666666666667
|
|
535
|
+
c3: SQ128x128.fromRaw({
|
|
536
|
+
limb0: 0n,
|
|
537
|
+
limb1: 0x2aaaaaaaaaaaaa00n,
|
|
538
|
+
limb2: 0n,
|
|
539
|
+
limb3: 0n,
|
|
540
|
+
neg: true,
|
|
541
|
+
}),
|
|
542
|
+
// c2 = 1/2 = 0.5
|
|
543
|
+
c2: HALF,
|
|
544
|
+
// c1 = -1
|
|
545
|
+
c1: NEG_ONE,
|
|
546
|
+
};
|
|
547
|
+
/**
|
|
548
|
+
* Taylor series for exp(-r) where r in [0, 1].
|
|
549
|
+
*
|
|
550
|
+
* Uses Horner's method with precomputed coefficients for numerical stability.
|
|
551
|
+
* exp(-r) = 1 + r*(-1 + r*(1/2 + r*(-1/6 + r*(1/24 + r*(-1/120 + r/720)))))
|
|
552
|
+
*
|
|
553
|
+
* @param r - The fractional part in [0, 1)
|
|
554
|
+
* @returns The approximation of exp(-r), clamped to [0, 1]
|
|
555
|
+
*/
|
|
556
|
+
function taylorExpNegSmall(r) {
|
|
557
|
+
const { c6, c5, c4, c3, c2, c1 } = TAYLOR_COEFFS;
|
|
558
|
+
// Horner's method: start from innermost coefficient
|
|
559
|
+
let result = c6;
|
|
560
|
+
// c5 + r * result
|
|
561
|
+
let term = r.mul(result);
|
|
562
|
+
if (!term)
|
|
563
|
+
return null;
|
|
564
|
+
result = c5.add(term);
|
|
565
|
+
if (!result)
|
|
566
|
+
return null;
|
|
567
|
+
// c4 + r * result
|
|
568
|
+
term = r.mul(result);
|
|
569
|
+
if (!term)
|
|
570
|
+
return null;
|
|
571
|
+
result = c4.add(term);
|
|
572
|
+
if (!result)
|
|
573
|
+
return null;
|
|
574
|
+
// c3 + r * result
|
|
575
|
+
term = r.mul(result);
|
|
576
|
+
if (!term)
|
|
577
|
+
return null;
|
|
578
|
+
result = c3.add(term);
|
|
579
|
+
if (!result)
|
|
580
|
+
return null;
|
|
581
|
+
// c2 + r * result
|
|
582
|
+
term = r.mul(result);
|
|
583
|
+
if (!term)
|
|
584
|
+
return null;
|
|
585
|
+
result = c2.add(term);
|
|
586
|
+
if (!result)
|
|
587
|
+
return null;
|
|
588
|
+
// c1 + r * result
|
|
589
|
+
term = r.mul(result);
|
|
590
|
+
if (!term)
|
|
591
|
+
return null;
|
|
592
|
+
result = c1.add(term);
|
|
593
|
+
if (!result)
|
|
594
|
+
return null;
|
|
595
|
+
// 1 + r * result
|
|
596
|
+
term = r.mul(result);
|
|
597
|
+
if (!term)
|
|
598
|
+
return null;
|
|
599
|
+
result = ONE.add(term);
|
|
600
|
+
if (!result)
|
|
601
|
+
return null;
|
|
602
|
+
// Clamp to [0, 1] for safety
|
|
603
|
+
if (result.isNegative()) {
|
|
604
|
+
return ZERO;
|
|
605
|
+
}
|
|
606
|
+
if (result.gt(ONE)) {
|
|
607
|
+
return ONE;
|
|
608
|
+
}
|
|
609
|
+
return result;
|
|
610
|
+
}
|
|
611
|
+
//# sourceMappingURL=sq128.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sq128.js","sourceRoot":"","sources":["../../src/math/sq128.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACL,mBAAmB,EACnB,QAAQ,EACR,WAAW,EACX,OAAO,EAEP,QAAQ,GACT,MAAM,aAAa,CAAC;AAErB,+BAA+B;AAC/B,MAAM,SAAS,GAAW,GAAG,CAAC;AAE9B,yDAAyD;AACzD,MAAM,KAAK,GAAW,EAAE,IAAI,IAAI,CAAC;AAEjC,o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ED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@the-situation/core",
|
|
3
|
+
"version": "0.5.0-alpha.0",
|
|
4
|
+
"description": "Core types, math primitives, and Effect error hierarchy for The Situation SDK",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": ["dist"],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc -b",
|
|
17
|
+
"typecheck": "tsc -b",
|
|
18
|
+
"test": "bun test src/ 2>/dev/null || true",
|
|
19
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"effect": "^3.12.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "^5.4.0",
|
|
26
|
+
"@types/bun": "^1.1.0"
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT"
|
|
29
|
+
}
|