@danielsimonjr/mathts-functions 0.75.0 → 0.75.1
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/index.js
CHANGED
|
@@ -45879,24 +45879,85 @@ function legendrePair(n, x) {
|
|
|
45879
45879
|
}
|
|
45880
45880
|
return [pCurr, pPrev];
|
|
45881
45881
|
}
|
|
45882
|
+
const SPLIT = 134217729;
|
|
45883
|
+
function legendreWeightTermsDD(n, x) {
|
|
45884
|
+
const cx = SPLIT * x;
|
|
45885
|
+
const xh = cx - (cx - x);
|
|
45886
|
+
const xl = x - xh;
|
|
45887
|
+
let ph = 1;
|
|
45888
|
+
let pl = 0;
|
|
45889
|
+
let ch = x;
|
|
45890
|
+
let cl = 0;
|
|
45891
|
+
for (let k = 2; k <= n; k++) {
|
|
45892
|
+
const a = 2 * k - 1;
|
|
45893
|
+
let uh = ch * a;
|
|
45894
|
+
let ul = cl * a + twoProdErr(ch, a, uh);
|
|
45895
|
+
let s = uh + ul;
|
|
45896
|
+
ul = ul - (s - uh);
|
|
45897
|
+
uh = s;
|
|
45898
|
+
let vh = uh * x;
|
|
45899
|
+
let vl = ul * x + twoProdErrSplit(uh, vh, xh, xl);
|
|
45900
|
+
s = vh + vl;
|
|
45901
|
+
vl = vl - (s - vh);
|
|
45902
|
+
vh = s;
|
|
45903
|
+
const m = -(k - 1);
|
|
45904
|
+
const wh = ph * m;
|
|
45905
|
+
const wl = pl * m + twoProdErr(ph, m, wh);
|
|
45906
|
+
const sh = vh + wh;
|
|
45907
|
+
const bb = sh - vh;
|
|
45908
|
+
let sl = vh - (sh - bb) + (wh - bb) + vl + wl;
|
|
45909
|
+
const th = sh + sl;
|
|
45910
|
+
sl = sl - (th - sh);
|
|
45911
|
+
const q1 = th / k;
|
|
45912
|
+
const ph2 = q1 * k;
|
|
45913
|
+
const q2 = (th - ph2 - twoProdErr(q1, k, ph2) + sl) / k;
|
|
45914
|
+
const nh = q1 + q2;
|
|
45915
|
+
const nl = q2 - (nh - q1);
|
|
45916
|
+
ph = ch;
|
|
45917
|
+
pl = cl;
|
|
45918
|
+
ch = nh;
|
|
45919
|
+
cl = nl;
|
|
45920
|
+
}
|
|
45921
|
+
const yh = ch * x;
|
|
45922
|
+
const yl = cl * x + twoProdErrSplit(ch, yh, xh, xl);
|
|
45923
|
+
const s = ph - yh;
|
|
45924
|
+
const bb = s - ph;
|
|
45925
|
+
const tl = ph - (s - bb) + (-yh - bb) + pl - yl;
|
|
45926
|
+
return [ch + cl, s + tl];
|
|
45927
|
+
}
|
|
45928
|
+
function twoProdErr(a, b, p) {
|
|
45929
|
+
const ca = SPLIT * a;
|
|
45930
|
+
const ah = ca - (ca - a);
|
|
45931
|
+
const al = a - ah;
|
|
45932
|
+
const cb = SPLIT * b;
|
|
45933
|
+
const bh = cb - (cb - b);
|
|
45934
|
+
const bl = b - bh;
|
|
45935
|
+
return ah * bh - p + ah * bl + al * bh + al * bl;
|
|
45936
|
+
}
|
|
45937
|
+
function twoProdErrSplit(a, p, xh, xl) {
|
|
45938
|
+
const ca = SPLIT * a;
|
|
45939
|
+
const ah = ca - (ca - a);
|
|
45940
|
+
const al = a - ah;
|
|
45941
|
+
return ah * xh - p + ah * xl + al * xh + al * xl;
|
|
45942
|
+
}
|
|
45882
45943
|
function rootsLegendre(n) {
|
|
45883
45944
|
if (!Number.isInteger(n) || n < 1) throw new Error("rootsLegendre: n must be a positive integer");
|
|
45884
45945
|
const nodes = [];
|
|
45885
45946
|
const weights = [];
|
|
45886
45947
|
for (let i = 0; i < n; i++) {
|
|
45887
45948
|
let x = Math.cos(Math.PI * (i + .75) / (n + .5));
|
|
45888
|
-
let pn;
|
|
45889
|
-
let dpn = 0;
|
|
45890
45949
|
for (let iter = 0; iter < NEWTON_MAX_ITERATIONS; iter++) {
|
|
45891
45950
|
const [pCurr, pPrev] = legendrePair(n, x);
|
|
45892
|
-
|
|
45893
|
-
dpn = n * (x * pCurr - pPrev) / (x * x - 1);
|
|
45894
|
-
const dx = pn / dpn;
|
|
45951
|
+
const dx = pCurr / (n * (x * pCurr - pPrev) / (x * x - 1));
|
|
45895
45952
|
x -= dx;
|
|
45896
45953
|
if (Math.abs(dx) < NEWTON_TOLERANCE) break;
|
|
45897
45954
|
}
|
|
45898
45955
|
nodes.push(x);
|
|
45899
|
-
|
|
45956
|
+
const [pn, t] = legendreWeightTermsDD(n, x);
|
|
45957
|
+
const om = (1 - x) * (1 + x);
|
|
45958
|
+
const d = n * t / om;
|
|
45959
|
+
const w0 = 2 / (om * d * d);
|
|
45960
|
+
weights.push(w0 * (1 + 2 * x * pn / (om * d)));
|
|
45900
45961
|
}
|
|
45901
45962
|
nodes.reverse();
|
|
45902
45963
|
weights.reverse();
|
|
@@ -21,7 +21,9 @@ export interface RootsLegendreResult {
|
|
|
21
21
|
*
|
|
22
22
|
* Nodes are the roots of the degree-n Legendre polynomial P_n, refined by
|
|
23
23
|
* Newton's method from the standard asymptotic initial guess
|
|
24
|
-
* `cos(pi*(i+0.75)/(n+0.5))`. Weights are `2 / ((1-x_i^2) * P'_n(x_i)^2)
|
|
24
|
+
* `cos(pi*(i+0.75)/(n+0.5))`. Weights are `2 / ((1-x_i^2) * P'_n(x_i)^2)`,
|
|
25
|
+
* evaluated in double-double at the final node and corrected to the exact
|
|
26
|
+
* root, so each weight is within 1e-15 relative for n up to 64.
|
|
25
27
|
*
|
|
26
28
|
* @param n - Number of quadrature points (positive integer)
|
|
27
29
|
* @returns Nodes (ascending) and matching weights
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gauss-nodes.d.ts","sourceRoot":"","sources":["../../src/numeric/gauss-nodes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,yFAAyF;AACzF,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;
|
|
1
|
+
{"version":3,"file":"gauss-nodes.d.ts","sourceRoot":"","sources":["../../src/numeric/gauss-nodes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,yFAAyF;AACzF,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAsGD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAmC5D"}
|
package/package.json
CHANGED