@numero-uno-jpn/rstats 0.6.1 → 0.8.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/CHANGELOG.md +98 -0
- package/README.ja.md +18 -12
- package/README.md +18 -12
- package/THIRD_PARTY_NOTICES.md +30 -0
- package/dist/chunks/{chunk-DRNMIEYH.js → chunk-32PRRONF.js} +1 -1
- package/dist/chunks/chunk-3I6EKGB6.js +2 -0
- package/dist/chunks/chunk-EJRCDJ76.js +2 -0
- package/dist/chunks/{chunk-Y4IZV7XK.js → chunk-I3LAZE6C.js} +2 -2
- package/dist/chunks/chunk-JERGQKZM.js +2 -0
- package/dist/chunks/{chunk-ZWJ42QN6.js → chunk-JVYV4633.js} +1 -1
- package/dist/chunks/chunk-LXMMKO26.js +2 -0
- package/dist/chunks/{chunk-2JCIB5H2.js → chunk-MJQLKEO5.js} +2 -2
- package/dist/chunks/{chunk-UGUQYWRQ.js → chunk-OHPHNE3O.js} +1 -1
- package/dist/chunks/chunk-RZ7SBJEG.js +2 -0
- package/dist/chunks/{chunk-TPC6MTYC.js → chunk-SPQC445Q.js} +2 -2
- package/dist/chunks/{chunk-AJYQNFXK.js → chunk-U633VFH3.js} +2 -2
- package/dist/chunks/{chunk-7NK4SA6B.js → chunk-VIPSPG3Y.js} +2 -2
- package/dist/chunks/chunk-XU4BGFZ6.js +2 -0
- package/dist/chunks/{chunk-NOCEAM44.js → chunk-YGWPU67I.js} +1 -1
- package/dist/descriptive.js +2 -2
- package/dist/distributions/beta.js +21 -5
- package/dist/distributions.js +2 -2
- package/dist/entries/distributions.d.ts +3 -1
- package/dist/entries/distributions.js +3 -1
- package/dist/entries/special.d.ts +1 -0
- package/dist/entries/special.js +1 -0
- package/dist/entries/tests.d.ts +2 -1
- package/dist/entries/tests.js +2 -1
- package/dist/htest/ansariTest.d.ts +18 -1
- package/dist/htest/ansariTest.js +181 -8
- package/dist/htest/brunnerMunzelTest.d.ts +28 -0
- package/dist/htest/brunnerMunzelTest.js +86 -0
- package/dist/htest/chisqTest.d.ts +34 -2
- package/dist/htest/chisqTest.js +140 -37
- package/dist/htest/core/ansari.d.ts +7 -0
- package/dist/htest/core/ansari.js +65 -0
- package/dist/htest/core/simulate.d.ts +2 -0
- package/dist/htest/core/simulate.js +16 -0
- package/dist/htest/fisherTest.d.ts +12 -1
- package/dist/htest/fisherTest.js +53 -7
- package/dist/linalg.js +2 -2
- package/dist/numerics.js +2 -2
- package/dist/random/lecuyer.d.ts +20 -0
- package/dist/random/lecuyer.js +71 -0
- package/dist/random/r2dtable.d.ts +26 -0
- package/dist/random/r2dtable.js +153 -0
- package/dist/random/rng.d.ts +78 -11
- package/dist/random/rng.js +128 -26
- package/dist/random/sample.js +24 -7
- package/dist/random/streams.d.ts +34 -0
- package/dist/random/streams.js +75 -0
- package/dist/rstats.js +3 -2
- package/dist/special/igam.d.ts +1 -0
- package/dist/special/igam.js +1 -1
- package/dist/special/incbet.js +487 -6
- package/dist/special/incbetLargeA.d.ts +15 -0
- package/dist/special/incbetLargeA.js +200 -0
- package/dist/special/incbetTemme.d.ts +19 -0
- package/dist/special/incbetTemme.js +216 -0
- package/dist/special/loader.js +151 -118
- package/dist/special/log1p.d.ts +53 -0
- package/dist/special/log1p.js +93 -0
- package/dist/special.js +2 -2
- package/dist/tests.js +3 -2
- package/package.json +1 -1
- package/dist/chunks/chunk-7JVSDGQQ.js +0 -2
- package/dist/chunks/chunk-NAYDS7CL.js +0 -2
- package/dist/chunks/chunk-QNAIK4PY.js +0 -2
- package/dist/chunks/chunk-XM2TVD63.js +0 -2
package/dist/special/igam.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** sum_n x^n / ((a + 1) ... (a + n)): P(a, x) = x^a e^-x / Gamma(a + 1) times this */
|
|
2
2
|
export declare function igamSeriesSum(a: number, x: number): number;
|
|
3
|
+
export declare function igamSeriesSumDD(a: number, x: number): number;
|
|
3
4
|
/** The continued fraction of DLMF 8.9.2: Q(a, x) = x^a e^-x / Gamma(a) times this */
|
|
4
5
|
export declare function igamcContinuedFractionValue(a: number, x: number): number;
|
|
5
6
|
/**
|
package/dist/special/igam.js
CHANGED
package/dist/special/incbet.js
CHANGED
|
@@ -13,9 +13,11 @@
|
|
|
13
13
|
// - The log is formed directly from the result of each computation
|
|
14
14
|
import { MACHEP } from "./constants.js";
|
|
15
15
|
import { dbinomExponent, dbinomRawDD } from "./loader.js";
|
|
16
|
-
import { ddAdd, ddDiv, ddLog, ddMul, ddMulNum, ddSub, twoProd, twoSum } from "./dd.js";
|
|
16
|
+
import { ddAdd, ddDiv, ddLog, ddMul, ddMulNum, ddSub, isDoubleDouble, SPLITTER, twoProd, twoSum } from "./dd.js";
|
|
17
17
|
import { lgamma1p } from "./gamma.js";
|
|
18
18
|
import { lgammaDiff } from "./lgammaDiff.js";
|
|
19
|
+
import { betaIncTemme, TEMME_MIN_M } from "./incbetTemme.js";
|
|
20
|
+
import { betaIncLargeA, LARGE_A_MIN, SMALL_B_MAX } from "./incbetLargeA.js";
|
|
19
21
|
const BIG = 4.503599627370496e15;
|
|
20
22
|
const BIGINV = 2.22044604925031308085e-16;
|
|
21
23
|
/**
|
|
@@ -133,7 +135,459 @@ function pseries(a, b, xd, xcd, log) {
|
|
|
133
135
|
* (5e-11 relative at a = 1e8, b = 0.01, x = 1 - 1e-6; checked against mpmath). From 2^52 on, the steps k += 1 of
|
|
134
136
|
* the other coefficients would be lost as well, so there every coefficient is a double-double (huge)
|
|
135
137
|
*/
|
|
138
|
+
// ddDiv for the loop of the continued fraction without allocating: the same operations as in dd.ts, with the
|
|
139
|
+
// result left in R (a typed array, so that storing it allocates nothing). Generated with python3 scripts/ddgen.py scalar
|
|
140
|
+
const R = new Float64Array(2);
|
|
141
|
+
function sDiv(ah, al, bh, bl) {
|
|
142
|
+
const q1 = ah / bh;
|
|
143
|
+
const p2 = bh * q1;
|
|
144
|
+
const t3 = SPLITTER * bh;
|
|
145
|
+
const ah4 = t3 - (t3 - bh);
|
|
146
|
+
const al5 = bh - ah4;
|
|
147
|
+
const t6 = SPLITTER * q1;
|
|
148
|
+
const bh7 = t6 - (t6 - q1);
|
|
149
|
+
const bl8 = q1 - bh7;
|
|
150
|
+
const e9 = ah4 * bh7 - p2 + ah4 * bl8 + al5 * bh7 + al5 * bl8;
|
|
151
|
+
const u10 = e9 + bl * q1;
|
|
152
|
+
const s11 = p2 + u10;
|
|
153
|
+
const e12 = u10 - (s11 - p2);
|
|
154
|
+
const n13 = -s11;
|
|
155
|
+
const n14 = -e12;
|
|
156
|
+
const s15 = ah + n13;
|
|
157
|
+
const bb16 = s15 - ah;
|
|
158
|
+
const e17 = ah - (s15 - bb16) + (n13 - bb16);
|
|
159
|
+
const s18 = al + n14;
|
|
160
|
+
const bb19 = s18 - al;
|
|
161
|
+
const e20 = al - (s18 - bb19) + (n14 - bb19);
|
|
162
|
+
const u21 = e17 + s18;
|
|
163
|
+
const s22 = s15 + u21;
|
|
164
|
+
const e23 = u21 - (s22 - s15);
|
|
165
|
+
const w24 = e23 + e20;
|
|
166
|
+
const s25 = s22 + w24;
|
|
167
|
+
const e26 = w24 - (s25 - s22);
|
|
168
|
+
const q27 = s25 / bh;
|
|
169
|
+
const p28 = bh * q27;
|
|
170
|
+
const t29 = SPLITTER * bh;
|
|
171
|
+
const ah30 = t29 - (t29 - bh);
|
|
172
|
+
const al31 = bh - ah30;
|
|
173
|
+
const t32 = SPLITTER * q27;
|
|
174
|
+
const bh33 = t32 - (t32 - q27);
|
|
175
|
+
const bl34 = q27 - bh33;
|
|
176
|
+
const e35 = ah30 * bh33 - p28 + ah30 * bl34 + al31 * bh33 + al31 * bl34;
|
|
177
|
+
const u36 = e35 + bl * q27;
|
|
178
|
+
const s37 = p28 + u36;
|
|
179
|
+
const e38 = u36 - (s37 - p28);
|
|
180
|
+
const n39 = -s37;
|
|
181
|
+
const n40 = -e38;
|
|
182
|
+
const s41 = s25 + n39;
|
|
183
|
+
const bb42 = s41 - s25;
|
|
184
|
+
const e43 = s25 - (s41 - bb42) + (n39 - bb42);
|
|
185
|
+
const s44 = e26 + n40;
|
|
186
|
+
const bb45 = s44 - e26;
|
|
187
|
+
const e46 = e26 - (s44 - bb45) + (n40 - bb45);
|
|
188
|
+
const u47 = e43 + s44;
|
|
189
|
+
const s48 = s41 + u47;
|
|
190
|
+
const e49 = u47 - (s48 - s41);
|
|
191
|
+
const w50 = e49 + e46;
|
|
192
|
+
const s51 = s48 + w50;
|
|
193
|
+
const e52 = w50 - (s51 - s48);
|
|
194
|
+
const q53 = s51 / bh;
|
|
195
|
+
const s54 = q1 + q27;
|
|
196
|
+
const e55 = q27 - (s54 - q1);
|
|
197
|
+
const s56 = s54 + q53;
|
|
198
|
+
const bb57 = s56 - s54;
|
|
199
|
+
const e58 = s54 - (s56 - bb57) + (q53 - bb57);
|
|
200
|
+
const s59 = e55 + 0;
|
|
201
|
+
const bb60 = s59 - e55;
|
|
202
|
+
const e61 = e55 - (s59 - bb60) + (0 - bb60);
|
|
203
|
+
const u62 = e58 + s59;
|
|
204
|
+
const s63 = s56 + u62;
|
|
205
|
+
const e64 = u62 - (s63 - s56);
|
|
206
|
+
const w65 = e64 + e61;
|
|
207
|
+
const s66 = s63 + w65;
|
|
208
|
+
const e67 = w65 - (s66 - s63);
|
|
209
|
+
R[0] = s66;
|
|
210
|
+
R[1] = e67;
|
|
211
|
+
}
|
|
136
212
|
function continuedFractionCore(a, b, xd, xcd, second) {
|
|
213
|
+
if (!isDoubleDouble() || Math.max(a, b) >= 2 ** 52)
|
|
214
|
+
return continuedFractionCoreOps(a, b, xd, xcd, second);
|
|
215
|
+
// The loop of continuedFractionCoreOps below on local variables, without allocating [hi, lo] arrays: the same
|
|
216
|
+
// operations in the same order, so the result is bit-identical. Generated with python3 scripts/ddgen.py cf
|
|
217
|
+
let zh = xd[0];
|
|
218
|
+
let zl = xd[1];
|
|
219
|
+
if (second) {
|
|
220
|
+
sDiv(xd[0], xd[1], xcd[0], xcd[1]);
|
|
221
|
+
zh = R[0];
|
|
222
|
+
zl = R[1];
|
|
223
|
+
}
|
|
224
|
+
const s1 = b + -1;
|
|
225
|
+
const bb2 = s1 - b;
|
|
226
|
+
const e3 = b - (s1 - bb2) + (-1 - bb2);
|
|
227
|
+
const s4 = a + b;
|
|
228
|
+
const bb5 = s4 - a;
|
|
229
|
+
const e6 = a - (s4 - bb5) + (b - bb5);
|
|
230
|
+
let k2h = second ? s1 : s4;
|
|
231
|
+
let k2l = second ? e3 : e6;
|
|
232
|
+
let k6h = second ? s4 : s1;
|
|
233
|
+
let k6l = second ? e6 : e3;
|
|
234
|
+
let k1 = a;
|
|
235
|
+
let k3 = a;
|
|
236
|
+
let k4 = a + 1;
|
|
237
|
+
let k5 = 1;
|
|
238
|
+
let k7 = a + 1;
|
|
239
|
+
let k8 = a + 2;
|
|
240
|
+
const d1 = second ? -1 : 1;
|
|
241
|
+
const nd1 = -d1;
|
|
242
|
+
let pkm2h = 0;
|
|
243
|
+
let pkm2l = 0;
|
|
244
|
+
let qkm2h = 1;
|
|
245
|
+
let qkm2l = 0;
|
|
246
|
+
let pkm1h = 1;
|
|
247
|
+
let pkm1l = 0;
|
|
248
|
+
let qkm1h = 1;
|
|
249
|
+
let qkm1l = 0;
|
|
250
|
+
let ansh = 1;
|
|
251
|
+
let ansl = 0;
|
|
252
|
+
for (let n = 0; n < 100000; n++) {
|
|
253
|
+
// xk = z k1 k2 / (k3 k4); pk = pkm1 - pkm2 xk, qk = qkm1 - qkm2 xk
|
|
254
|
+
const p7 = zh * k1;
|
|
255
|
+
const t8 = SPLITTER * zh;
|
|
256
|
+
const ah9 = t8 - (t8 - zh);
|
|
257
|
+
const al10 = zh - ah9;
|
|
258
|
+
const t11 = SPLITTER * k1;
|
|
259
|
+
const bh12 = t11 - (t11 - k1);
|
|
260
|
+
const bl13 = k1 - bh12;
|
|
261
|
+
const e14 = ah9 * bh12 - p7 + ah9 * bl13 + al10 * bh12 + al10 * bl13;
|
|
262
|
+
const u15 = e14 + zl * k1;
|
|
263
|
+
const s16 = p7 + u15;
|
|
264
|
+
const e17 = u15 - (s16 - p7);
|
|
265
|
+
const p18 = s16 * k2h;
|
|
266
|
+
const t19 = SPLITTER * s16;
|
|
267
|
+
const ah20 = t19 - (t19 - s16);
|
|
268
|
+
const al21 = s16 - ah20;
|
|
269
|
+
const t22 = SPLITTER * k2h;
|
|
270
|
+
const bh23 = t22 - (t22 - k2h);
|
|
271
|
+
const bl24 = k2h - bh23;
|
|
272
|
+
const e25 = ah20 * bh23 - p18 + ah20 * bl24 + al21 * bh23 + al21 * bl24;
|
|
273
|
+
const u26 = e25 + (s16 * k2l + e17 * k2h);
|
|
274
|
+
const s27 = p18 + u26;
|
|
275
|
+
const e28 = u26 - (s27 - p18);
|
|
276
|
+
const p29 = k3 * k4;
|
|
277
|
+
const t30 = SPLITTER * k3;
|
|
278
|
+
const ah31 = t30 - (t30 - k3);
|
|
279
|
+
const al32 = k3 - ah31;
|
|
280
|
+
const t33 = SPLITTER * k4;
|
|
281
|
+
const bh34 = t33 - (t33 - k4);
|
|
282
|
+
const bl35 = k4 - bh34;
|
|
283
|
+
const e36 = ah31 * bh34 - p29 + ah31 * bl35 + al32 * bh34 + al32 * bl35;
|
|
284
|
+
sDiv(s27, e28, p29, e36);
|
|
285
|
+
const qh37 = R[0];
|
|
286
|
+
const ql38 = R[1];
|
|
287
|
+
const p39 = pkm2h * qh37;
|
|
288
|
+
const t40 = SPLITTER * pkm2h;
|
|
289
|
+
const ah41 = t40 - (t40 - pkm2h);
|
|
290
|
+
const al42 = pkm2h - ah41;
|
|
291
|
+
const t43 = SPLITTER * qh37;
|
|
292
|
+
const bh44 = t43 - (t43 - qh37);
|
|
293
|
+
const bl45 = qh37 - bh44;
|
|
294
|
+
const e46 = ah41 * bh44 - p39 + ah41 * bl45 + al42 * bh44 + al42 * bl45;
|
|
295
|
+
const u47 = e46 + (pkm2h * ql38 + pkm2l * qh37);
|
|
296
|
+
const s48 = p39 + u47;
|
|
297
|
+
const e49 = u47 - (s48 - p39);
|
|
298
|
+
const n50 = -s48;
|
|
299
|
+
const n51 = -e49;
|
|
300
|
+
const s52 = pkm1h + n50;
|
|
301
|
+
const bb53 = s52 - pkm1h;
|
|
302
|
+
const e54 = pkm1h - (s52 - bb53) + (n50 - bb53);
|
|
303
|
+
const s55 = pkm1l + n51;
|
|
304
|
+
const bb56 = s55 - pkm1l;
|
|
305
|
+
const e57 = pkm1l - (s55 - bb56) + (n51 - bb56);
|
|
306
|
+
const u58 = e54 + s55;
|
|
307
|
+
const s59 = s52 + u58;
|
|
308
|
+
const e60 = u58 - (s59 - s52);
|
|
309
|
+
const w61 = e60 + e57;
|
|
310
|
+
const s62 = s59 + w61;
|
|
311
|
+
const e63 = w61 - (s62 - s59);
|
|
312
|
+
const p64 = qkm2h * qh37;
|
|
313
|
+
const t65 = SPLITTER * qkm2h;
|
|
314
|
+
const ah66 = t65 - (t65 - qkm2h);
|
|
315
|
+
const al67 = qkm2h - ah66;
|
|
316
|
+
const t68 = SPLITTER * qh37;
|
|
317
|
+
const bh69 = t68 - (t68 - qh37);
|
|
318
|
+
const bl70 = qh37 - bh69;
|
|
319
|
+
const e71 = ah66 * bh69 - p64 + ah66 * bl70 + al67 * bh69 + al67 * bl70;
|
|
320
|
+
const u72 = e71 + (qkm2h * ql38 + qkm2l * qh37);
|
|
321
|
+
const s73 = p64 + u72;
|
|
322
|
+
const e74 = u72 - (s73 - p64);
|
|
323
|
+
const n75 = -s73;
|
|
324
|
+
const n76 = -e74;
|
|
325
|
+
const s77 = qkm1h + n75;
|
|
326
|
+
const bb78 = s77 - qkm1h;
|
|
327
|
+
const e79 = qkm1h - (s77 - bb78) + (n75 - bb78);
|
|
328
|
+
const s80 = qkm1l + n76;
|
|
329
|
+
const bb81 = s80 - qkm1l;
|
|
330
|
+
const e82 = qkm1l - (s80 - bb81) + (n76 - bb81);
|
|
331
|
+
const u83 = e79 + s80;
|
|
332
|
+
const s84 = s77 + u83;
|
|
333
|
+
const e85 = u83 - (s84 - s77);
|
|
334
|
+
const w86 = e85 + e82;
|
|
335
|
+
const s87 = s84 + w86;
|
|
336
|
+
const e88 = w86 - (s87 - s84);
|
|
337
|
+
pkm2h = pkm1h;
|
|
338
|
+
pkm2l = pkm1l;
|
|
339
|
+
pkm1h = s62;
|
|
340
|
+
pkm1l = e63;
|
|
341
|
+
qkm2h = qkm1h;
|
|
342
|
+
qkm2l = qkm1l;
|
|
343
|
+
qkm1h = s87;
|
|
344
|
+
qkm1l = e88;
|
|
345
|
+
// xk = z k5 k6 / (k7 k8); pk = pkm1 + pkm2 xk, qk = qkm1 + qkm2 xk
|
|
346
|
+
const p89 = zh * k5;
|
|
347
|
+
const t90 = SPLITTER * zh;
|
|
348
|
+
const ah91 = t90 - (t90 - zh);
|
|
349
|
+
const al92 = zh - ah91;
|
|
350
|
+
const t93 = SPLITTER * k5;
|
|
351
|
+
const bh94 = t93 - (t93 - k5);
|
|
352
|
+
const bl95 = k5 - bh94;
|
|
353
|
+
const e96 = ah91 * bh94 - p89 + ah91 * bl95 + al92 * bh94 + al92 * bl95;
|
|
354
|
+
const u97 = e96 + zl * k5;
|
|
355
|
+
const s98 = p89 + u97;
|
|
356
|
+
const e99 = u97 - (s98 - p89);
|
|
357
|
+
const p100 = s98 * k6h;
|
|
358
|
+
const t101 = SPLITTER * s98;
|
|
359
|
+
const ah102 = t101 - (t101 - s98);
|
|
360
|
+
const al103 = s98 - ah102;
|
|
361
|
+
const t104 = SPLITTER * k6h;
|
|
362
|
+
const bh105 = t104 - (t104 - k6h);
|
|
363
|
+
const bl106 = k6h - bh105;
|
|
364
|
+
const e107 = ah102 * bh105 - p100 + ah102 * bl106 + al103 * bh105 + al103 * bl106;
|
|
365
|
+
const u108 = e107 + (s98 * k6l + e99 * k6h);
|
|
366
|
+
const s109 = p100 + u108;
|
|
367
|
+
const e110 = u108 - (s109 - p100);
|
|
368
|
+
const p111 = k7 * k8;
|
|
369
|
+
const t112 = SPLITTER * k7;
|
|
370
|
+
const ah113 = t112 - (t112 - k7);
|
|
371
|
+
const al114 = k7 - ah113;
|
|
372
|
+
const t115 = SPLITTER * k8;
|
|
373
|
+
const bh116 = t115 - (t115 - k8);
|
|
374
|
+
const bl117 = k8 - bh116;
|
|
375
|
+
const e118 = ah113 * bh116 - p111 + ah113 * bl117 + al114 * bh116 + al114 * bl117;
|
|
376
|
+
sDiv(s109, e110, p111, e118);
|
|
377
|
+
const qh119 = R[0];
|
|
378
|
+
const ql120 = R[1];
|
|
379
|
+
const p121 = pkm2h * qh119;
|
|
380
|
+
const t122 = SPLITTER * pkm2h;
|
|
381
|
+
const ah123 = t122 - (t122 - pkm2h);
|
|
382
|
+
const al124 = pkm2h - ah123;
|
|
383
|
+
const t125 = SPLITTER * qh119;
|
|
384
|
+
const bh126 = t125 - (t125 - qh119);
|
|
385
|
+
const bl127 = qh119 - bh126;
|
|
386
|
+
const e128 = ah123 * bh126 - p121 + ah123 * bl127 + al124 * bh126 + al124 * bl127;
|
|
387
|
+
const u129 = e128 + (pkm2h * ql120 + pkm2l * qh119);
|
|
388
|
+
const s130 = p121 + u129;
|
|
389
|
+
const e131 = u129 - (s130 - p121);
|
|
390
|
+
const s132 = pkm1h + s130;
|
|
391
|
+
const bb133 = s132 - pkm1h;
|
|
392
|
+
const e134 = pkm1h - (s132 - bb133) + (s130 - bb133);
|
|
393
|
+
const s135 = pkm1l + e131;
|
|
394
|
+
const bb136 = s135 - pkm1l;
|
|
395
|
+
const e137 = pkm1l - (s135 - bb136) + (e131 - bb136);
|
|
396
|
+
const u138 = e134 + s135;
|
|
397
|
+
const s139 = s132 + u138;
|
|
398
|
+
const e140 = u138 - (s139 - s132);
|
|
399
|
+
const w141 = e140 + e137;
|
|
400
|
+
const s142 = s139 + w141;
|
|
401
|
+
const e143 = w141 - (s142 - s139);
|
|
402
|
+
const p144 = qkm2h * qh119;
|
|
403
|
+
const t145 = SPLITTER * qkm2h;
|
|
404
|
+
const ah146 = t145 - (t145 - qkm2h);
|
|
405
|
+
const al147 = qkm2h - ah146;
|
|
406
|
+
const t148 = SPLITTER * qh119;
|
|
407
|
+
const bh149 = t148 - (t148 - qh119);
|
|
408
|
+
const bl150 = qh119 - bh149;
|
|
409
|
+
const e151 = ah146 * bh149 - p144 + ah146 * bl150 + al147 * bh149 + al147 * bl150;
|
|
410
|
+
const u152 = e151 + (qkm2h * ql120 + qkm2l * qh119);
|
|
411
|
+
const s153 = p144 + u152;
|
|
412
|
+
const e154 = u152 - (s153 - p144);
|
|
413
|
+
const s155 = qkm1h + s153;
|
|
414
|
+
const bb156 = s155 - qkm1h;
|
|
415
|
+
const e157 = qkm1h - (s155 - bb156) + (s153 - bb156);
|
|
416
|
+
const s158 = qkm1l + e154;
|
|
417
|
+
const bb159 = s158 - qkm1l;
|
|
418
|
+
const e160 = qkm1l - (s158 - bb159) + (e154 - bb159);
|
|
419
|
+
const u161 = e157 + s158;
|
|
420
|
+
const s162 = s155 + u161;
|
|
421
|
+
const e163 = u161 - (s162 - s155);
|
|
422
|
+
const w164 = e163 + e160;
|
|
423
|
+
const s165 = s162 + w164;
|
|
424
|
+
const e166 = w164 - (s165 - s162);
|
|
425
|
+
pkm2h = pkm1h;
|
|
426
|
+
pkm2l = pkm1l;
|
|
427
|
+
pkm1h = s142;
|
|
428
|
+
pkm1l = e143;
|
|
429
|
+
qkm2h = qkm1h;
|
|
430
|
+
qkm2l = qkm1l;
|
|
431
|
+
qkm1h = s165;
|
|
432
|
+
qkm1l = e166;
|
|
433
|
+
if (s165 !== 0) {
|
|
434
|
+
sDiv(s142, e143, s165, e166);
|
|
435
|
+
const qh167 = R[0];
|
|
436
|
+
const ql168 = R[1];
|
|
437
|
+
const t = qh167 !== 0 ? Math.abs((ansh - qh167) / qh167) : 1;
|
|
438
|
+
ansh = qh167;
|
|
439
|
+
ansl = ql168;
|
|
440
|
+
if (t < MACHEP && n > 1)
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
const s169 = k2h + d1;
|
|
444
|
+
const bb170 = s169 - k2h;
|
|
445
|
+
const e171 = k2h - (s169 - bb170) + (d1 - bb170);
|
|
446
|
+
const s172 = k2l + 0;
|
|
447
|
+
const bb173 = s172 - k2l;
|
|
448
|
+
const e174 = k2l - (s172 - bb173) + (0 - bb173);
|
|
449
|
+
const u175 = e171 + s172;
|
|
450
|
+
const s176 = s169 + u175;
|
|
451
|
+
const e177 = u175 - (s176 - s169);
|
|
452
|
+
const w178 = e177 + e174;
|
|
453
|
+
const s179 = s176 + w178;
|
|
454
|
+
const e180 = w178 - (s179 - s176);
|
|
455
|
+
k2h = s179;
|
|
456
|
+
k2l = e180;
|
|
457
|
+
const s181 = k6h + nd1;
|
|
458
|
+
const bb182 = s181 - k6h;
|
|
459
|
+
const e183 = k6h - (s181 - bb182) + (nd1 - bb182);
|
|
460
|
+
const s184 = k6l + 0;
|
|
461
|
+
const bb185 = s184 - k6l;
|
|
462
|
+
const e186 = k6l - (s184 - bb185) + (0 - bb185);
|
|
463
|
+
const u187 = e183 + s184;
|
|
464
|
+
const s188 = s181 + u187;
|
|
465
|
+
const e189 = u187 - (s188 - s181);
|
|
466
|
+
const w190 = e189 + e186;
|
|
467
|
+
const s191 = s188 + w190;
|
|
468
|
+
const e192 = w190 - (s191 - s188);
|
|
469
|
+
k6h = s191;
|
|
470
|
+
k6l = e192;
|
|
471
|
+
k5 += 1;
|
|
472
|
+
k1 += 1;
|
|
473
|
+
k3 += 2;
|
|
474
|
+
k4 += 2;
|
|
475
|
+
k7 += 2;
|
|
476
|
+
k8 += 2;
|
|
477
|
+
// Rescaling (both conditions are tested on this step's pk, qk)
|
|
478
|
+
if (Math.abs(s165) + Math.abs(s142) > BIG) {
|
|
479
|
+
const p193 = pkm2h * BIGINV;
|
|
480
|
+
const t194 = SPLITTER * pkm2h;
|
|
481
|
+
const ah195 = t194 - (t194 - pkm2h);
|
|
482
|
+
const al196 = pkm2h - ah195;
|
|
483
|
+
const t197 = SPLITTER * BIGINV;
|
|
484
|
+
const bh198 = t197 - (t197 - BIGINV);
|
|
485
|
+
const bl199 = BIGINV - bh198;
|
|
486
|
+
const e200 = ah195 * bh198 - p193 + ah195 * bl199 + al196 * bh198 + al196 * bl199;
|
|
487
|
+
const u201 = e200 + pkm2l * BIGINV;
|
|
488
|
+
const s202 = p193 + u201;
|
|
489
|
+
const e203 = u201 - (s202 - p193);
|
|
490
|
+
pkm2h = s202;
|
|
491
|
+
pkm2l = e203;
|
|
492
|
+
const p204 = pkm1h * BIGINV;
|
|
493
|
+
const t205 = SPLITTER * pkm1h;
|
|
494
|
+
const ah206 = t205 - (t205 - pkm1h);
|
|
495
|
+
const al207 = pkm1h - ah206;
|
|
496
|
+
const t208 = SPLITTER * BIGINV;
|
|
497
|
+
const bh209 = t208 - (t208 - BIGINV);
|
|
498
|
+
const bl210 = BIGINV - bh209;
|
|
499
|
+
const e211 = ah206 * bh209 - p204 + ah206 * bl210 + al207 * bh209 + al207 * bl210;
|
|
500
|
+
const u212 = e211 + pkm1l * BIGINV;
|
|
501
|
+
const s213 = p204 + u212;
|
|
502
|
+
const e214 = u212 - (s213 - p204);
|
|
503
|
+
pkm1h = s213;
|
|
504
|
+
pkm1l = e214;
|
|
505
|
+
const p215 = qkm2h * BIGINV;
|
|
506
|
+
const t216 = SPLITTER * qkm2h;
|
|
507
|
+
const ah217 = t216 - (t216 - qkm2h);
|
|
508
|
+
const al218 = qkm2h - ah217;
|
|
509
|
+
const t219 = SPLITTER * BIGINV;
|
|
510
|
+
const bh220 = t219 - (t219 - BIGINV);
|
|
511
|
+
const bl221 = BIGINV - bh220;
|
|
512
|
+
const e222 = ah217 * bh220 - p215 + ah217 * bl221 + al218 * bh220 + al218 * bl221;
|
|
513
|
+
const u223 = e222 + qkm2l * BIGINV;
|
|
514
|
+
const s224 = p215 + u223;
|
|
515
|
+
const e225 = u223 - (s224 - p215);
|
|
516
|
+
qkm2h = s224;
|
|
517
|
+
qkm2l = e225;
|
|
518
|
+
const p226 = qkm1h * BIGINV;
|
|
519
|
+
const t227 = SPLITTER * qkm1h;
|
|
520
|
+
const ah228 = t227 - (t227 - qkm1h);
|
|
521
|
+
const al229 = qkm1h - ah228;
|
|
522
|
+
const t230 = SPLITTER * BIGINV;
|
|
523
|
+
const bh231 = t230 - (t230 - BIGINV);
|
|
524
|
+
const bl232 = BIGINV - bh231;
|
|
525
|
+
const e233 = ah228 * bh231 - p226 + ah228 * bl232 + al229 * bh231 + al229 * bl232;
|
|
526
|
+
const u234 = e233 + qkm1l * BIGINV;
|
|
527
|
+
const s235 = p226 + u234;
|
|
528
|
+
const e236 = u234 - (s235 - p226);
|
|
529
|
+
qkm1h = s235;
|
|
530
|
+
qkm1l = e236;
|
|
531
|
+
}
|
|
532
|
+
if (Math.abs(s165) < BIGINV || Math.abs(s142) < BIGINV) {
|
|
533
|
+
const p237 = pkm2h * BIG;
|
|
534
|
+
const t238 = SPLITTER * pkm2h;
|
|
535
|
+
const ah239 = t238 - (t238 - pkm2h);
|
|
536
|
+
const al240 = pkm2h - ah239;
|
|
537
|
+
const t241 = SPLITTER * BIG;
|
|
538
|
+
const bh242 = t241 - (t241 - BIG);
|
|
539
|
+
const bl243 = BIG - bh242;
|
|
540
|
+
const e244 = ah239 * bh242 - p237 + ah239 * bl243 + al240 * bh242 + al240 * bl243;
|
|
541
|
+
const u245 = e244 + pkm2l * BIG;
|
|
542
|
+
const s246 = p237 + u245;
|
|
543
|
+
const e247 = u245 - (s246 - p237);
|
|
544
|
+
pkm2h = s246;
|
|
545
|
+
pkm2l = e247;
|
|
546
|
+
const p248 = pkm1h * BIG;
|
|
547
|
+
const t249 = SPLITTER * pkm1h;
|
|
548
|
+
const ah250 = t249 - (t249 - pkm1h);
|
|
549
|
+
const al251 = pkm1h - ah250;
|
|
550
|
+
const t252 = SPLITTER * BIG;
|
|
551
|
+
const bh253 = t252 - (t252 - BIG);
|
|
552
|
+
const bl254 = BIG - bh253;
|
|
553
|
+
const e255 = ah250 * bh253 - p248 + ah250 * bl254 + al251 * bh253 + al251 * bl254;
|
|
554
|
+
const u256 = e255 + pkm1l * BIG;
|
|
555
|
+
const s257 = p248 + u256;
|
|
556
|
+
const e258 = u256 - (s257 - p248);
|
|
557
|
+
pkm1h = s257;
|
|
558
|
+
pkm1l = e258;
|
|
559
|
+
const p259 = qkm2h * BIG;
|
|
560
|
+
const t260 = SPLITTER * qkm2h;
|
|
561
|
+
const ah261 = t260 - (t260 - qkm2h);
|
|
562
|
+
const al262 = qkm2h - ah261;
|
|
563
|
+
const t263 = SPLITTER * BIG;
|
|
564
|
+
const bh264 = t263 - (t263 - BIG);
|
|
565
|
+
const bl265 = BIG - bh264;
|
|
566
|
+
const e266 = ah261 * bh264 - p259 + ah261 * bl265 + al262 * bh264 + al262 * bl265;
|
|
567
|
+
const u267 = e266 + qkm2l * BIG;
|
|
568
|
+
const s268 = p259 + u267;
|
|
569
|
+
const e269 = u267 - (s268 - p259);
|
|
570
|
+
qkm2h = s268;
|
|
571
|
+
qkm2l = e269;
|
|
572
|
+
const p270 = qkm1h * BIG;
|
|
573
|
+
const t271 = SPLITTER * qkm1h;
|
|
574
|
+
const ah272 = t271 - (t271 - qkm1h);
|
|
575
|
+
const al273 = qkm1h - ah272;
|
|
576
|
+
const t274 = SPLITTER * BIG;
|
|
577
|
+
const bh275 = t274 - (t274 - BIG);
|
|
578
|
+
const bl276 = BIG - bh275;
|
|
579
|
+
const e277 = ah272 * bh275 - p270 + ah272 * bl276 + al273 * bh275 + al273 * bl276;
|
|
580
|
+
const u278 = e277 + qkm1l * BIG;
|
|
581
|
+
const s279 = p270 + u278;
|
|
582
|
+
const e280 = u278 - (s279 - p270);
|
|
583
|
+
qkm1h = s279;
|
|
584
|
+
qkm1l = e280;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
return ansh + ansl;
|
|
588
|
+
}
|
|
589
|
+
/** continuedFractionCore with calls to the double-double helpers (also for huge parameters and double-precision mode) */
|
|
590
|
+
function continuedFractionCoreOps(a, b, xd, xcd, second) {
|
|
137
591
|
// #1: coefficients use x; #2: coefficients use z = x/(1-x)
|
|
138
592
|
const z = second ? ddDiv(xd, xcd) : xd;
|
|
139
593
|
const huge = Math.max(a, b) >= 2 ** 52;
|
|
@@ -310,12 +764,32 @@ function betaIncCore(a, b, xd, xcd, lower, wantLog) {
|
|
|
310
764
|
const e = ddAdd(ddMulNum(ddLog(sx), sa), [lgammaDiff(sa, sb) - lgamma1p(sa), 0]);
|
|
311
765
|
const lt = e[0] + e[1]; // log of the smaller tail (the lower tail if small)
|
|
312
766
|
const own = small === lower;
|
|
767
|
+
const v = Math.exp(e[0]) * (1 + e[1]);
|
|
313
768
|
if (own)
|
|
314
|
-
return [lt,
|
|
315
|
-
|
|
769
|
+
return [lt, v];
|
|
770
|
+
// The log of the other tail from v, not from exp(lt): lt rounded to a double is off by up to ε |lt| (|lt| > 700),
|
|
771
|
+
// which would become the relative error of the result
|
|
772
|
+
return [wantLog ? Math.log1p(-v) : NaN, -Math.expm1(lt)];
|
|
773
|
+
}
|
|
774
|
+
// Both parameters large and x near the mean: the uniform asymptotic expansion, whose cost does not grow with
|
|
775
|
+
// the parameters (the continued fraction needs about sqrt(a + b) steps there)
|
|
776
|
+
if (a >= TEMME_MIN_M && b >= TEMME_MIN_M) {
|
|
777
|
+
const t = betaIncTemme(a, b, xd, xcd, lower, wantLog);
|
|
778
|
+
if (t !== undefined)
|
|
779
|
+
return t;
|
|
316
780
|
}
|
|
317
781
|
const [pa, pb, px, pxc] = lower ? [a, b, xd, xcd] : [b, a, xcd, xd];
|
|
318
782
|
const [oa, ob, ox, oxc] = lower ? [b, a, xcd, xd] : [a, b, xd, xcd];
|
|
783
|
+
// One parameter large and the other small: where the continued fraction would be used below, the expansion for
|
|
784
|
+
// large a (incbetLargeA.ts) instead, in the frame of the large parameter. The length of the continued fraction
|
|
785
|
+
// stops growing with the large parameter, but in the bulk it takes 30 to 170 double-double steps; the expansion
|
|
786
|
+
// takes a few terms
|
|
787
|
+
const largeA = Math.max(a, b) >= LARGE_A_MIN && Math.min(a, b) <= SMALL_B_MAX;
|
|
788
|
+
const viaLargeA = (low, log) => {
|
|
789
|
+
if (!largeA)
|
|
790
|
+
return undefined;
|
|
791
|
+
return a >= b ? betaIncLargeA(a, b, xd, xcd, low, log) : betaIncLargeA(b, a, xcd, xd, !low, log);
|
|
792
|
+
};
|
|
319
793
|
// The log of a value near 1 is built with log1p from a direct computation of the other side
|
|
320
794
|
const finish = (v, other) => {
|
|
321
795
|
if (!wantLog)
|
|
@@ -334,12 +808,13 @@ function betaIncCore(a, b, xd, xcd, lower, wantLog) {
|
|
|
334
808
|
if (pseriesOk(pa, pb, px[0])) {
|
|
335
809
|
const v = pseriesComplement(pa, pb, px, false);
|
|
336
810
|
// Cancellation check as for the requested tail (see below)
|
|
337
|
-
if (pa * Math.abs(Math.log(px[0])) > 32 * v && cfOk(oa, ob, ox[0]))
|
|
338
|
-
return continuedFraction(oa, ob, ox, oxc, false);
|
|
811
|
+
if (pa * Math.abs(Math.log(px[0])) > 32 * v && cfOk(oa, ob, ox[0])) {
|
|
812
|
+
return viaLargeA(!lower, false)?.[1] ?? continuedFraction(oa, ob, ox, oxc, false);
|
|
813
|
+
}
|
|
339
814
|
return v;
|
|
340
815
|
}
|
|
341
816
|
if (cfOk(oa, ob, ox[0]))
|
|
342
|
-
return continuedFraction(oa, ob, ox, oxc, false);
|
|
817
|
+
return viaLargeA(!lower, false)?.[1] ?? continuedFraction(oa, ob, ox, oxc, false);
|
|
343
818
|
return undefined;
|
|
344
819
|
};
|
|
345
820
|
// A directly computed value close to subnormal has few significant digits, so recompute the log on the spot
|
|
@@ -358,6 +833,9 @@ function betaIncCore(a, b, xd, xcd, lower, wantLog) {
|
|
|
358
833
|
// instead (a lower threshold would also send cases where the series is accurate, e.g. most of pt near 0, to the
|
|
359
834
|
// slower continued fraction)
|
|
360
835
|
if (oa * Math.abs(Math.log(ox[0])) > 32 * v && cfOk(pa, pb, px[0])) {
|
|
836
|
+
const e = viaLargeA(lower, wantLog);
|
|
837
|
+
if (e !== undefined)
|
|
838
|
+
return e;
|
|
361
839
|
const w = continuedFraction(pa, pb, px, pxc, false);
|
|
362
840
|
if (wantLog && w < TINY)
|
|
363
841
|
return [continuedFraction(pa, pb, px, pxc, true), w];
|
|
@@ -365,6 +843,9 @@ function betaIncCore(a, b, xd, xcd, lower, wantLog) {
|
|
|
365
843
|
}
|
|
366
844
|
return finish(v, () => pseries(oa, ob, ox, oxc, false));
|
|
367
845
|
}
|
|
846
|
+
const e = viaLargeA(lower, wantLog);
|
|
847
|
+
if (e !== undefined)
|
|
848
|
+
return e;
|
|
368
849
|
if (cfOk(pa, pb, px[0])) {
|
|
369
850
|
const v = continuedFraction(pa, pb, px, pxc, false);
|
|
370
851
|
if (wantLog && v < TINY)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type DD } from "./dd.js";
|
|
2
|
+
/**
|
|
3
|
+
* Region where the expansion is used (the caller tries it where it would otherwise use the continued fraction):
|
|
4
|
+
* a >= LARGE_A_MIN, b <= SMALL_B_MAX, y = 1 - x <= Y_MAX, u <= U_MAX, and on the J side u >= U_MIN_J (below,
|
|
5
|
+
* J_0 would need more than 1000 terms of its continued fraction). Chosen by measurement against mpmath
|
|
6
|
+
* (scripts/mpmath/smallb.py) and against the time of the continued fraction (docs/performance.md)
|
|
7
|
+
*/
|
|
8
|
+
export declare const LARGE_A_MIN = 15;
|
|
9
|
+
export declare const SMALL_B_MAX = 40;
|
|
10
|
+
/**
|
|
11
|
+
* I_x(a, b) (lower) or 1 - I_x(a, b) by the expansion for large a, as [log, linear] (log NaN unless wantLog).
|
|
12
|
+
* x and y = 1 - x are given in double-double. Returns undefined outside the region above (assumes a >= LARGE_A_MIN
|
|
13
|
+
* and b <= SMALL_B_MAX)
|
|
14
|
+
*/
|
|
15
|
+
export declare function betaIncLargeA(a: number, b: number, xd: DD, yd: DD, lower: boolean, wantLog: boolean): [number, number] | undefined;
|