@ac-kit/math-analysis 0.2.0 → 0.3.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 +89 -0
- package/README.md +85 -2
- package/dist/differentiation/finite-difference.d.ts +41 -0
- package/dist/differentiation/finite-difference.d.ts.map +1 -0
- package/dist/differentiation/finite-difference.js +53 -0
- package/dist/differentiation/finite-difference.js.map +1 -0
- package/dist/differentiation/gradient.d.ts +73 -0
- package/dist/differentiation/gradient.d.ts.map +1 -0
- package/dist/differentiation/gradient.js +167 -0
- package/dist/differentiation/gradient.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -1
- package/dist/interpolation/barycentric-interpolator.d.ts +29 -0
- package/dist/interpolation/barycentric-interpolator.d.ts.map +1 -0
- package/dist/interpolation/barycentric-interpolator.js +94 -0
- package/dist/interpolation/barycentric-interpolator.js.map +1 -0
- package/dist/legendre/_legendre-kernel.d.ts +22 -0
- package/dist/legendre/_legendre-kernel.d.ts.map +1 -0
- package/dist/legendre/_legendre-kernel.js +232 -0
- package/dist/legendre/_legendre-kernel.js.map +1 -0
- package/dist/legendre/legendre-fully-normalized.d.ts +52 -0
- package/dist/legendre/legendre-fully-normalized.d.ts.map +1 -0
- package/dist/legendre/legendre-fully-normalized.js +62 -0
- package/dist/legendre/legendre-fully-normalized.js.map +1 -0
- package/dist/legendre/legendre-index.d.ts +27 -0
- package/dist/legendre/legendre-index.d.ts.map +1 -0
- package/dist/legendre/legendre-index.js +31 -0
- package/dist/legendre/legendre-index.js.map +1 -0
- package/dist/legendre/legendre-schmidt.d.ts +37 -0
- package/dist/legendre/legendre-schmidt.d.ts.map +1 -0
- package/dist/legendre/legendre-schmidt.js +47 -0
- package/dist/legendre/legendre-schmidt.js.map +1 -0
- package/dist/ode/runge-kutta4.d.ts +46 -0
- package/dist/ode/runge-kutta4.d.ts.map +1 -0
- package/dist/ode/runge-kutta4.js +85 -0
- package/dist/ode/runge-kutta4.js.map +1 -0
- package/dist/optimize/_more-thuente.d.ts +95 -0
- package/dist/optimize/_more-thuente.d.ts.map +1 -0
- package/dist/optimize/_more-thuente.js +333 -0
- package/dist/optimize/_more-thuente.js.map +1 -0
- package/dist/optimize/_wolfe-line-search.d.ts +85 -0
- package/dist/optimize/_wolfe-line-search.d.ts.map +1 -0
- package/dist/optimize/_wolfe-line-search.js +193 -0
- package/dist/optimize/_wolfe-line-search.js.map +1 -0
- package/dist/optimize/bfgs.d.ts +262 -0
- package/dist/optimize/bfgs.d.ts.map +1 -0
- package/dist/optimize/bfgs.js +418 -0
- package/dist/optimize/bfgs.js.map +1 -0
- package/dist/optimize/lbfgs.d.ts +199 -0
- package/dist/optimize/lbfgs.d.ts.map +1 -0
- package/dist/optimize/lbfgs.js +383 -0
- package/dist/optimize/lbfgs.js.map +1 -0
- package/dist/optimize/levenberg-marquardt.d.ts +78 -0
- package/dist/optimize/levenberg-marquardt.d.ts.map +1 -0
- package/dist/optimize/levenberg-marquardt.js +204 -0
- package/dist/optimize/levenberg-marquardt.js.map +1 -0
- package/dist/optimize/nelder-mead.d.ts +68 -0
- package/dist/optimize/nelder-mead.d.ts.map +1 -0
- package/dist/optimize/nelder-mead.js +198 -0
- package/dist/optimize/nelder-mead.js.map +1 -0
- package/dist/quadrature/adaptive-quadrature.d.ts +53 -0
- package/dist/quadrature/adaptive-quadrature.d.ts.map +1 -0
- package/dist/quadrature/adaptive-quadrature.js +175 -0
- package/dist/quadrature/adaptive-quadrature.js.map +1 -0
- package/dist/quadrature/gauss-legendre.d.ts +27 -0
- package/dist/quadrature/gauss-legendre.d.ts.map +1 -0
- package/dist/quadrature/gauss-legendre.js +111 -0
- package/dist/quadrature/gauss-legendre.js.map +1 -0
- package/dist/quadrature/simpsons-rule.d.ts +27 -0
- package/dist/quadrature/simpsons-rule.d.ts.map +1 -0
- package/dist/quadrature/simpsons-rule.js +44 -0
- package/dist/quadrature/simpsons-rule.js.map +1 -0
- package/dist/roots/_grown.d.ts.map +1 -1
- package/dist/roots/_grown.js +0 -1
- package/dist/roots/_grown.js.map +1 -1
- package/dist/roots/_level-search.d.ts +19 -2
- package/dist/roots/_level-search.d.ts.map +1 -1
- package/dist/roots/_level-search.js +47 -23
- package/dist/roots/_level-search.js.map +1 -1
- package/dist/roots/find-level-bands.js +1 -1
- package/dist/roots/find-level-bands.js.map +1 -1
- package/dist/roots/find-level-crossings.d.ts +4 -2
- package/dist/roots/find-level-crossings.d.ts.map +1 -1
- package/dist/roots/find-level-crossings.js +4 -10
- package/dist/roots/find-level-crossings.js.map +1 -1
- package/dist/roots/newton-raphson.d.ts +31 -0
- package/dist/roots/newton-raphson.d.ts.map +1 -0
- package/dist/roots/newton-raphson.js +69 -0
- package/dist/roots/newton-raphson.js.map +1 -0
- package/dist/series/sum-series.d.ts +43 -0
- package/dist/series/sum-series.d.ts.map +1 -0
- package/dist/series/sum-series.js +70 -0
- package/dist/series/sum-series.js.map +1 -0
- package/package.json +8 -7
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,0CAA0C,CAAC;AACzD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kCAAkC,CAAC;AACjD,cAAc,yCAAyC,CAAC;AACxD,cAAc,mCAAmC,CAAC;AAClD,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wCAAwC,CAAC;AACvD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,6CAA6C,CAAC;AAC5D,cAAc,0CAA0C,CAAC;AACzD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,yCAAyC,CAAC;AACxD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mCAAmC,CAAC;AAClD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qCAAqC,CAAC;AACpD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,yCAAyC,CAAC;AACxD,cAAc,mCAAmC,CAAC;AAClD,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The polynomial through the points `(xs[i], ys[i])`, evaluated by the
|
|
3
|
+
* barycentric formula of the second kind (Berrut and Trefethen, "Barycentric
|
|
4
|
+
* Lagrange Interpolation", 2004): `p(x) = Σ wᵢ yᵢ / (x − xᵢ) / Σ wᵢ / (x −
|
|
5
|
+
* xᵢ)`.
|
|
6
|
+
*
|
|
7
|
+
* The numerically stable form of Lagrange interpolation: forward stable for any
|
|
8
|
+
* node set with a good Lebesgue constant (Chebyshev points), O(n) per
|
|
9
|
+
* evaluation once the weights are computed in O(n²), and exact at the nodes.
|
|
10
|
+
* The weights are scaled by their largest magnitude, so they neither overflow
|
|
11
|
+
* nor underflow for hundreds of nodes. The interpolant is a polynomial of
|
|
12
|
+
* degree `n − 1`, so equally spaced nodes still suffer Runge's phenomenon: that
|
|
13
|
+
* is the nodes' fault, not the formula's.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const p = createBarycentricInterpolator([0, 1, 2], [1, 3, 7]); // x² + x + 1
|
|
18
|
+
* p(3); // 13
|
|
19
|
+
* p(1); // 3 — exact at a node
|
|
20
|
+
* ```;
|
|
21
|
+
*
|
|
22
|
+
* @param xs The nodes, distinct.
|
|
23
|
+
* @param ys The values at the nodes, as many.
|
|
24
|
+
* @returns The interpolant; `NaN` for a `NaN` argument.
|
|
25
|
+
* @throws {RangeError} When the arrays are empty or of different lengths, a
|
|
26
|
+
* node is not finite, or two nodes are equal.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createBarycentricInterpolator(xs: ArrayLike<number>, ys: ArrayLike<number>): (x: number) => number;
|
|
29
|
+
//# sourceMappingURL=barycentric-interpolator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barycentric-interpolator.d.ts","sourceRoot":"","sources":["../../src/interpolation/barycentric-interpolator.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,6BAA6B,CAC5C,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,EACrB,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,GACnB,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CA0EvB"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { describeValue } from "@ac-kit/core";
|
|
2
|
+
/**
|
|
3
|
+
* The polynomial through the points `(xs[i], ys[i])`, evaluated by the
|
|
4
|
+
* barycentric formula of the second kind (Berrut and Trefethen, "Barycentric
|
|
5
|
+
* Lagrange Interpolation", 2004): `p(x) = Σ wᵢ yᵢ / (x − xᵢ) / Σ wᵢ / (x −
|
|
6
|
+
* xᵢ)`.
|
|
7
|
+
*
|
|
8
|
+
* The numerically stable form of Lagrange interpolation: forward stable for any
|
|
9
|
+
* node set with a good Lebesgue constant (Chebyshev points), O(n) per
|
|
10
|
+
* evaluation once the weights are computed in O(n²), and exact at the nodes.
|
|
11
|
+
* The weights are scaled by their largest magnitude, so they neither overflow
|
|
12
|
+
* nor underflow for hundreds of nodes. The interpolant is a polynomial of
|
|
13
|
+
* degree `n − 1`, so equally spaced nodes still suffer Runge's phenomenon: that
|
|
14
|
+
* is the nodes' fault, not the formula's.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const p = createBarycentricInterpolator([0, 1, 2], [1, 3, 7]); // x² + x + 1
|
|
19
|
+
* p(3); // 13
|
|
20
|
+
* p(1); // 3 — exact at a node
|
|
21
|
+
* ```;
|
|
22
|
+
*
|
|
23
|
+
* @param xs The nodes, distinct.
|
|
24
|
+
* @param ys The values at the nodes, as many.
|
|
25
|
+
* @returns The interpolant; `NaN` for a `NaN` argument.
|
|
26
|
+
* @throws {RangeError} When the arrays are empty or of different lengths, a
|
|
27
|
+
* node is not finite, or two nodes are equal.
|
|
28
|
+
*/
|
|
29
|
+
export function createBarycentricInterpolator(xs, ys) {
|
|
30
|
+
const count = xs.length;
|
|
31
|
+
if (count === 0 || ys.length !== count) {
|
|
32
|
+
throw new RangeError(`createBarycentricInterpolator: ${count} nodes and ${ys.length} values`);
|
|
33
|
+
}
|
|
34
|
+
const nodes = Float64Array.from(xs);
|
|
35
|
+
const values = Float64Array.from(ys);
|
|
36
|
+
const weights = new Float64Array(count);
|
|
37
|
+
const exponents = new Float64Array(count);
|
|
38
|
+
for (let i = 0; i < count; i++) {
|
|
39
|
+
const node = nodes[i];
|
|
40
|
+
if (node - node !== 0) {
|
|
41
|
+
throw new RangeError(`createBarycentricInterpolator: node ${i} is ${describeValue(node)}`);
|
|
42
|
+
}
|
|
43
|
+
// wᵢ = 1 / Πⱼ≠ᵢ (xᵢ − xⱼ), accumulated as a product of scaled factors
|
|
44
|
+
// with the exponent kept apart so it cannot overflow.
|
|
45
|
+
let product = 1;
|
|
46
|
+
let exponent = 0;
|
|
47
|
+
for (let j = 0; j < count; j++) {
|
|
48
|
+
if (j === i) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const difference = node - nodes[j];
|
|
52
|
+
if (difference === 0) {
|
|
53
|
+
throw new RangeError(`createBarycentricInterpolator: nodes ${j} and ${i} are both ${node}`);
|
|
54
|
+
}
|
|
55
|
+
product *= difference;
|
|
56
|
+
const magnitude = Math.abs(product);
|
|
57
|
+
if (magnitude > 2 ** 500 || magnitude < 2 ** -500) {
|
|
58
|
+
const shift = Math.round(Math.log2(magnitude));
|
|
59
|
+
product /= 2 ** shift;
|
|
60
|
+
exponent += shift;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
weights[i] = 1 / product;
|
|
64
|
+
exponents[i] = -exponent;
|
|
65
|
+
}
|
|
66
|
+
// Bring every weight to the largest exponent: the formula is invariant
|
|
67
|
+
// under a common factor.
|
|
68
|
+
let largest = -Infinity;
|
|
69
|
+
for (let i = 0; i < count; i++) {
|
|
70
|
+
largest = Math.max(largest, exponents[i] + Math.log2(Math.abs(weights[i])));
|
|
71
|
+
}
|
|
72
|
+
const common = Math.round(largest);
|
|
73
|
+
for (let i = 0; i < count; i++) {
|
|
74
|
+
weights[i] = weights[i] * 2 ** (exponents[i] - common);
|
|
75
|
+
}
|
|
76
|
+
return (x) => {
|
|
77
|
+
if (x !== x) {
|
|
78
|
+
return Number.NaN;
|
|
79
|
+
}
|
|
80
|
+
let numerator = 0;
|
|
81
|
+
let denominator = 0;
|
|
82
|
+
for (let i = 0; i < count; i++) {
|
|
83
|
+
const difference = x - nodes[i];
|
|
84
|
+
if (difference === 0) {
|
|
85
|
+
return values[i];
|
|
86
|
+
}
|
|
87
|
+
const term = weights[i] / difference;
|
|
88
|
+
numerator += term * values[i];
|
|
89
|
+
denominator += term;
|
|
90
|
+
}
|
|
91
|
+
return numerator / denominator;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=barycentric-interpolator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barycentric-interpolator.js","sourceRoot":"","sources":["../../src/interpolation/barycentric-interpolator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,6BAA6B,CAC5C,EAAqB,EACrB,EAAqB;IAErB,MAAM,KAAK,GAAG,EAAE,CAAC,MAAM,CAAC;IACxB,IAAI,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;QACxC,MAAM,IAAI,UAAU,CACnB,kCAAkC,KAAK,cAAc,EAAE,CAAC,MAAM,SAAS,CACvE,CAAC;IACH,CAAC;IACD,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpC,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACrC,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;IACxC,MAAM,SAAS,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;IAC1C,KAAK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AG,MAAM,CAAC,CAAC,CAAE,CAAC;YAC/B,WAAW,IAAI,IAAI,CAAC;QACrB,CAAC;QACD,OAAO,SAAS,GAAG,WAAW,CAAC;IAChC,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The colatitude of the call in progress: the public functions store it here
|
|
3
|
+
* and the kernel reads it, so no double crosses a call the engine may not
|
|
4
|
+
* inline (V8 boxes one in a heap number there).
|
|
5
|
+
*/
|
|
6
|
+
export declare const LEGENDRE_COLATITUDE_: Float64Array<ArrayBuffer>;
|
|
7
|
+
/** Fills `values[0 … length)` (and `derivatives`) with `NaN`. */
|
|
8
|
+
export declare function legendreFillNaN_(values: Float64Array, derivatives: Float64Array | undefined, length: number): void;
|
|
9
|
+
/**
|
|
10
|
+
* Writes the table of fully normalised (or, with `schmidt`, Schmidt
|
|
11
|
+
* semi-normalised) associated Legendre functions of `cos θ` up to `maxDegree`
|
|
12
|
+
* into `values`, and their derivatives with respect to the colatitude `θ` into
|
|
13
|
+
* `derivatives`, `θ` read from {@link LEGENDRE_COLATITUDE_}. Arguments are
|
|
14
|
+
* checked by the caller: `θ` is in `[0, π]`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function legendreKernel_(values: Float64Array, derivatives: Float64Array | undefined, maxDegree: number, schmidt: boolean): void;
|
|
17
|
+
/**
|
|
18
|
+
* Checks the arguments common to both normalisations, the colatitude read from
|
|
19
|
+
* {@link LEGENDRE_COLATITUDE_}; returns the table length.
|
|
20
|
+
*/
|
|
21
|
+
export declare function legendreCheck_(name: string, values: Float64Array, derivatives: Float64Array | undefined, maxDegree: number): number;
|
|
22
|
+
//# sourceMappingURL=_legendre-kernel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_legendre-kernel.d.ts","sourceRoot":"","sources":["../../src/legendre/_legendre-kernel.ts"],"names":[],"mappings":"AA6CA;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,2BAAsB,CAAC;AAExD,iEAAiE;AACjE,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,YAAY,EACpB,WAAW,EAAE,YAAY,GAAG,SAAS,EACrC,MAAM,EAAE,MAAM,GACZ,IAAI,CAGN;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC9B,MAAM,EAAE,YAAY,EACpB,WAAW,EAAE,YAAY,GAAG,SAAS,EACrC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,OAAO,GACd,IAAI,CAsHN;AAwCD;;;GAGG;AACH,wBAAgB,cAAc,CAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,YAAY,EACpB,WAAW,EAAE,YAAY,GAAG,SAAS,EACrC,SAAS,EAAE,MAAM,GACf,MAAM,CAoCR"}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { binaryExponent, scaleByPowerOfTwoInPlace } from "@ac-kit/core";
|
|
2
|
+
// The modified forward column method of Holmes and Featherstone (2002): for
|
|
3
|
+
// each order m, the column P̄ₙₘ / sinᵐθ, which is a polynomial in cos θ and
|
|
4
|
+
// never underflows, is run up in degree from a seed scaled by 2⁻⁹³⁰, then
|
|
5
|
+
// multiplied back by sinᵐθ kept as a mantissa and a binary exponent. The
|
|
6
|
+
// scaled column stays below 2⁶⁰⁰ to degree 2190 and beyond (its largest value,
|
|
7
|
+
// at the pole, is about 10⁴⁵⁶ before scaling), and the scaling back is by a
|
|
8
|
+
// power of two, rounded once: values below the normal range underflow as they
|
|
9
|
+
// should (within a unit of the smallest subnormal) rather than taking the
|
|
10
|
+
// column with them.
|
|
11
|
+
const SEED_EXPONENT_ = 930;
|
|
12
|
+
const SEED_SCALE_ = 2 ** -SEED_EXPONENT_;
|
|
13
|
+
// sinᵐθ's mantissa is kept in [1, 2³⁰), so its product with the scaled
|
|
14
|
+
// column stays finite as long as the column stays below 2⁹⁹⁰.
|
|
15
|
+
const POWER_LIMIT_ = 2 ** 30;
|
|
16
|
+
const POWER_STEP_ = 2 ** -30;
|
|
17
|
+
const POWER_STEP_EXPONENT_ = 30;
|
|
18
|
+
/** Below this scale (sinᵐθ · 2⁹³⁰ < 2⁻²²⁰⁰) a whole column underflows to 0. */
|
|
19
|
+
const ZERO_EXPONENT_ = -2200;
|
|
20
|
+
/** The least exponent of a normal power of two, a factor computed once. */
|
|
21
|
+
const MIN_NORMAL_EXPONENT_ = -1022;
|
|
22
|
+
const HALF_ = 0.5;
|
|
23
|
+
/** Where sin θ is scaled to its mantissa, so no double crosses a call. */
|
|
24
|
+
const SINE_ = new Float64Array(1);
|
|
25
|
+
let roots_ = new Float64Array(0);
|
|
26
|
+
let inverseRoots_ = new Float64Array(0);
|
|
27
|
+
/** Grows the tables of √k and 1/√k to cover `0 … count − 1`. */
|
|
28
|
+
function ensureRoots_(count) {
|
|
29
|
+
if (roots_.length >= count) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const length = Math.max(count, 2 * roots_.length, 64);
|
|
33
|
+
const roots = new Float64Array(length);
|
|
34
|
+
const inverseRoots = new Float64Array(length);
|
|
35
|
+
for (let k = 0; k < length; k++) {
|
|
36
|
+
roots[k] = Math.sqrt(k);
|
|
37
|
+
inverseRoots[k] = k === 0 ? 0 : 1 / roots[k];
|
|
38
|
+
}
|
|
39
|
+
roots_ = roots;
|
|
40
|
+
inverseRoots_ = inverseRoots;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The colatitude of the call in progress: the public functions store it here
|
|
44
|
+
* and the kernel reads it, so no double crosses a call the engine may not
|
|
45
|
+
* inline (V8 boxes one in a heap number there).
|
|
46
|
+
*/
|
|
47
|
+
export const LEGENDRE_COLATITUDE_ = new Float64Array(1);
|
|
48
|
+
/** Fills `values[0 … length)` (and `derivatives`) with `NaN`. */
|
|
49
|
+
export function legendreFillNaN_(values, derivatives, length) {
|
|
50
|
+
values.fill(Number.NaN, 0, length);
|
|
51
|
+
derivatives?.fill(Number.NaN, 0, length);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Writes the table of fully normalised (or, with `schmidt`, Schmidt
|
|
55
|
+
* semi-normalised) associated Legendre functions of `cos θ` up to `maxDegree`
|
|
56
|
+
* into `values`, and their derivatives with respect to the colatitude `θ` into
|
|
57
|
+
* `derivatives`, `θ` read from {@link LEGENDRE_COLATITUDE_}. Arguments are
|
|
58
|
+
* checked by the caller: `θ` is in `[0, π]`.
|
|
59
|
+
*/
|
|
60
|
+
export function legendreKernel_(values, derivatives, maxDegree, schmidt) {
|
|
61
|
+
ensureRoots_(2 * maxDegree + 4);
|
|
62
|
+
const roots = roots_;
|
|
63
|
+
const inverseRoots = inverseRoots_;
|
|
64
|
+
const colatitude = LEGENDRE_COLATITUDE_[0];
|
|
65
|
+
const cosine = Math.cos(colatitude);
|
|
66
|
+
const sine = Math.sin(colatitude);
|
|
67
|
+
// Near a pole cos θ = ±(1 − 2 sin²(θ/2)) (or ±(1 − 2 cos²(θ/2))) has lost
|
|
68
|
+
// the low bits of θ, and Pₙₘ at degree n amplifies that loss n² times: the
|
|
69
|
+
// recursion takes t as lead − offset, the offset computed from the half
|
|
70
|
+
// angle to full relative accuracy.
|
|
71
|
+
let lead = cosine;
|
|
72
|
+
let offset = 0;
|
|
73
|
+
if (cosine > HALF_) {
|
|
74
|
+
const half = Math.sin(colatitude * HALF_);
|
|
75
|
+
lead = 1;
|
|
76
|
+
offset = 2 * half * half;
|
|
77
|
+
}
|
|
78
|
+
else if (cosine < -HALF_) {
|
|
79
|
+
const half = Math.cos(colatitude * HALF_);
|
|
80
|
+
lead = -1;
|
|
81
|
+
offset = -2 * half * half;
|
|
82
|
+
}
|
|
83
|
+
// sin θ = mantissa · 2^exponent, the mantissa in [1, 2), exactly.
|
|
84
|
+
let sineExponent = 0;
|
|
85
|
+
let sineMantissa = 0;
|
|
86
|
+
if (sine > 0) {
|
|
87
|
+
sineExponent = binaryExponent(sine) | 0;
|
|
88
|
+
SINE_[0] = sine;
|
|
89
|
+
scaleByPowerOfTwoInPlace(SINE_, 0, -sineExponent | 0);
|
|
90
|
+
sineMantissa = SINE_[0];
|
|
91
|
+
}
|
|
92
|
+
// sinᵐθ = power · 2^powerExponent, power in [1, 2³⁰).
|
|
93
|
+
let power = 1;
|
|
94
|
+
let powerExponent = 0;
|
|
95
|
+
let sectoral = SEED_SCALE_;
|
|
96
|
+
let order = 0;
|
|
97
|
+
for (; order <= maxDegree; order++) {
|
|
98
|
+
if (order > 0) {
|
|
99
|
+
if (sine === 0) {
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
// P̄ₘₘ / sinᵐθ = √((2m + 1) / 2m) · P̄ₘ₋₁,ₘ₋₁ / sinᵐ⁻¹θ, and √3 from
|
|
103
|
+
// P̄₀₀ = 1, the (2 − δₘ₀) of the normalisation entering there.
|
|
104
|
+
sectoral *=
|
|
105
|
+
order === 1
|
|
106
|
+
? roots[3]
|
|
107
|
+
: roots[2 * order + 1] * inverseRoots[2 * order];
|
|
108
|
+
power *= sineMantissa;
|
|
109
|
+
powerExponent += sineExponent;
|
|
110
|
+
if (power >= POWER_LIMIT_) {
|
|
111
|
+
power *= POWER_STEP_;
|
|
112
|
+
powerExponent += POWER_STEP_EXPONENT_;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const exponent = (SEED_EXPONENT_ + powerExponent) | 0;
|
|
116
|
+
if (exponent + POWER_STEP_EXPONENT_ < ZERO_EXPONENT_) {
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
// sinᵐθ · 2⁹³⁰ = power · 2^exponent. A normal 2^exponent is one factor
|
|
120
|
+
// for the column; below, the column is scaled entry by entry once it is
|
|
121
|
+
// written, so a result below the normal range is rounded once.
|
|
122
|
+
const isFactorNormal = exponent >= MIN_NORMAL_EXPONENT_;
|
|
123
|
+
const factor = isFactorNormal ? 2 ** exponent : 1;
|
|
124
|
+
let previous = 0;
|
|
125
|
+
let current = sectoral;
|
|
126
|
+
for (let degree = order; degree <= maxDegree; degree++) {
|
|
127
|
+
if (degree > order) {
|
|
128
|
+
// P̄ₙₘ = aₙₘ t P̄ₙ₋₁,ₘ − bₙₘ P̄ₙ₋₂,ₘ, with
|
|
129
|
+
// aₙₘ = √((2n − 1)(2n + 1) / ((n − m)(n + m))) and
|
|
130
|
+
// bₙₘ = √((2n + 1)(n + m − 1)(n − m − 1) / ((n − m)(n + m)(2n − 3))),
|
|
131
|
+
// t written lead − offset (see above).
|
|
132
|
+
const denominator = inverseRoots[degree - order] * inverseRoots[degree + order];
|
|
133
|
+
const a = roots[2 * degree - 1] * roots[2 * degree + 1] * denominator;
|
|
134
|
+
let next = a * lead * current;
|
|
135
|
+
if (degree > order + 1) {
|
|
136
|
+
const b = roots[2 * degree + 1] *
|
|
137
|
+
roots[degree + order - 1] *
|
|
138
|
+
roots[degree - order - 1] *
|
|
139
|
+
inverseRoots[2 * degree - 3] *
|
|
140
|
+
denominator;
|
|
141
|
+
next -= b * previous;
|
|
142
|
+
}
|
|
143
|
+
next -= a * offset * current;
|
|
144
|
+
previous = current;
|
|
145
|
+
current = next;
|
|
146
|
+
}
|
|
147
|
+
const index = (degree * (degree + 1)) / 2 + order;
|
|
148
|
+
let scaled = current * power;
|
|
149
|
+
if (schmidt) {
|
|
150
|
+
scaled *= inverseRoots[2 * degree + 1];
|
|
151
|
+
}
|
|
152
|
+
values[index] = scaled * factor;
|
|
153
|
+
}
|
|
154
|
+
if (!isFactorNormal) {
|
|
155
|
+
for (let degree = order; degree <= maxDegree; degree++) {
|
|
156
|
+
scaleByPowerOfTwoInPlace(values, (degree * (degree + 1)) / 2 + order, exponent);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// The orders left underflow whole (or vanish with sin θ).
|
|
161
|
+
for (; order <= maxDegree; order++) {
|
|
162
|
+
for (let degree = order; degree <= maxDegree; degree++) {
|
|
163
|
+
values[(degree * (degree + 1)) / 2 + order] = 0;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (derivatives !== undefined) {
|
|
167
|
+
derivativesFromValues_(values, derivatives, maxDegree);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* DP̄ₙₘ/dθ from the neighbouring orders of the same degree, the same for both
|
|
172
|
+
* normalisations (they differ by a factor of the degree alone), with no
|
|
173
|
+
* division by sin θ, so exact at the poles:
|
|
174
|
+
*
|
|
175
|
+
* - DP̄ₙ₀/dθ = −√(n(n + 1) / 2) P̄ₙ₁
|
|
176
|
+
* - DP̄ₙ₁/dθ = ½ (√(2n(n + 1)) P̄ₙ₀ − √((n + 2)(n − 1)) P̄ₙ₂)
|
|
177
|
+
* - DP̄ₙₘ/dθ = ½ (√((n + m)(n − m + 1)) P̄ₙ,ₘ₋₁ − √((n − m)(n + m + 1)) P̄ₙ,ₘ₊₁)
|
|
178
|
+
*/
|
|
179
|
+
function derivativesFromValues_(values, derivatives, maxDegree) {
|
|
180
|
+
derivatives[0] = 0;
|
|
181
|
+
for (let degree = 1; degree <= maxDegree; degree++) {
|
|
182
|
+
const base = (degree * (degree + 1)) / 2;
|
|
183
|
+
const product = degree * (degree + 1);
|
|
184
|
+
derivatives[base] = -Math.sqrt(product * HALF_) * values[base + 1];
|
|
185
|
+
// The coupling √((n − m)(n + m + 1)) of orders m and m + 1, which is
|
|
186
|
+
// also √((n + m')(n − m' + 1)) for m' = m + 1: one root per entry.
|
|
187
|
+
let coupling = degree >= 2 ? Math.sqrt((degree - 1) * (degree + 2)) : 0;
|
|
188
|
+
let first = Math.sqrt(2 * product) * values[base];
|
|
189
|
+
if (degree >= 2) {
|
|
190
|
+
first -= coupling * values[base + 2];
|
|
191
|
+
}
|
|
192
|
+
derivatives[base + 1] = HALF_ * first;
|
|
193
|
+
for (let order = 2; order <= degree; order++) {
|
|
194
|
+
let sum = coupling * values[base + order - 1];
|
|
195
|
+
if (order < degree) {
|
|
196
|
+
coupling = Math.sqrt((degree - order) * (degree + order + 1));
|
|
197
|
+
sum -= coupling * values[base + order + 1];
|
|
198
|
+
}
|
|
199
|
+
derivatives[base + order] = HALF_ * sum;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Checks the arguments common to both normalisations, the colatitude read from
|
|
205
|
+
* {@link LEGENDRE_COLATITUDE_}; returns the table length.
|
|
206
|
+
*/
|
|
207
|
+
export function legendreCheck_(name, values, derivatives, maxDegree) {
|
|
208
|
+
const colatitude = LEGENDRE_COLATITUDE_[0];
|
|
209
|
+
if (!Number.isSafeInteger(maxDegree) || maxDegree < 0) {
|
|
210
|
+
throw new RangeError(`${name}: maxDegree must be a non-negative integer, got ${maxDegree}`);
|
|
211
|
+
}
|
|
212
|
+
const length = ((maxDegree + 1) * (maxDegree + 2)) / 2;
|
|
213
|
+
if (values.length < length) {
|
|
214
|
+
throw new RangeError(`${name}: out holds ${values.length} entries, degree ${maxDegree} needs ${length}`);
|
|
215
|
+
}
|
|
216
|
+
if (derivatives !== undefined) {
|
|
217
|
+
if (derivatives.length < length) {
|
|
218
|
+
throw new RangeError(`${name}: derivativesOut holds ${derivatives.length} entries, degree ${maxDegree} needs ${length}`);
|
|
219
|
+
}
|
|
220
|
+
if (derivatives.buffer === values.buffer &&
|
|
221
|
+
derivatives.byteOffset < values.byteOffset + 8 * length &&
|
|
222
|
+
values.byteOffset < derivatives.byteOffset + 8 * length) {
|
|
223
|
+
throw new RangeError(`${name}: out and derivativesOut overlap`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (!(colatitude >= 0 && colatitude <= Math.PI) &&
|
|
227
|
+
colatitude === colatitude) {
|
|
228
|
+
throw new RangeError(`${name}: colatitude must be in [0, π] radians, got ${colatitude}`);
|
|
229
|
+
}
|
|
230
|
+
return length;
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=_legendre-kernel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_legendre-kernel.js","sourceRoot":"","sources":["../../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G,CAAC,CAAC;IACvD,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;QAC5B,MAAM,IAAI,UAAU,CACnB,GAAG,IAAI,eAAe,MAAM,CAAC,MAAM,oBAAoB,SAAS,UAAU,MAAM,EAAE,CAClF,CAAC;IACH,CAAC;IACD,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC/B,IAAI,WAAW,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;YACjC,MAAM,IAAI,UAAU,CACnB,GAAG,IAAI,0BAA0B,WAAW,CAAC,MAAM,oBAAoB,SAAS,UAAU,MAAM,EAAE,CAClG,CAAC;QACH,CAAC;QACD,IACC,WAAW,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM;YACpC,WAAW,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,GAAG,CAAC,GAAG,MAAM;YACvD,MAAM,CAAC,UAAU,GAAG,WAAW,CAAC,UAAU,GAAG,CAAC,GAAG,MAAM,EACtD,CAAC;YACF,MAAM,IAAI,UAAU,CAAC,GAAG,IAAI,kCAAkC,CAAC,CAAC;QACjE,CAAC;IACF,CAAC;IACD,IACC,CAAC,CAAC,UAAU,IAAI,CAAC,IAAI,UAAU,IAAI,IAAI,CAAC,EAAE,CAAC;QAC3C,UAAU,KAAK,UAAU,EACxB,CAAC;QACF,MAAM,IAAI,UAAU,CACnB,GAAG,IAAI,+CAA+C,UAAU,EAAE,CAClE,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes the fully normalised associated Legendre functions `P̄ₙₘ(cos θ)` of
|
|
3
|
+
* every degree `n ≤ maxDegree` and order `0 ≤ m ≤ n` into `out`, in the order
|
|
4
|
+
* of {@link legendreIndex}, and their derivatives `dP̄ₙₘ/dθ` with respect to the
|
|
5
|
+
* colatitude `θ` into `derivativesOut` when given. Returns `out`.
|
|
6
|
+
*
|
|
7
|
+
* The normalisation of geodesy and gravity field models (EGM2008, the geoid):
|
|
8
|
+
* `P̄ₙₘ = √((2 − δₘ₀)(2n + 1)(n − m)! / (n + m)!) Pₙₘ`, so that the mean of
|
|
9
|
+
* `(P̄ₙₘ(cos θ) cos mλ)²` over the sphere is `1`, without the Condon–Shortley
|
|
10
|
+
* phase `(−1)ᵐ`. It is {@link legendreSchmidt}'s times `√(2n + 1)`.
|
|
11
|
+
*
|
|
12
|
+
* Stable to degree 2190 (EGM2008's) and beyond, at every colatitude: the
|
|
13
|
+
* recursion is Holmes and Featherstone's modified forward column method, each
|
|
14
|
+
* order's column run as `P̄ₙₘ / sinᵐθ` with a scaled seed and multiplied back
|
|
15
|
+
* by `sinᵐθ` with its exponent kept apart, so no intermediate overflows to
|
|
16
|
+
* degree 2700 (past about 2850 the scaled columns do, near the poles), and a
|
|
17
|
+
* value too small for binary64 (high orders near the poles) underflows to the
|
|
18
|
+
* subnormal range or to `0` instead of corrupting its column. The derivatives
|
|
19
|
+
* come from the neighbouring orders, with no division by `sin θ`, so they are
|
|
20
|
+
* exact at the poles too. Measured against 60-digit references, the error of a
|
|
21
|
+
* degree-n entry stays below `10⁻¹¹ √(2n + 1)` to degree 2190, and below `10⁻¹³
|
|
22
|
+
* √(2n + 1)` to degree 100; the cosine near a pole is taken from the half
|
|
23
|
+
* angle, so a colatitude of `10⁻⁶` loses nothing to `cos θ` rounding to within
|
|
24
|
+
* `10⁻¹⁶` of `1`. Near `θ = π` a double holds the colatitude itself only to
|
|
25
|
+
* `2⁻⁵² π` absolute; evaluate a southern point at `π − θ` and apply `P̄ₙₘ(−t) =
|
|
26
|
+
* (−1)ⁿ⁺ᵐ P̄ₙₘ(t)` when that matters.
|
|
27
|
+
*
|
|
28
|
+
* O(maxDegree²) time; O(maxDegree) memory for a table of integer square roots
|
|
29
|
+
* kept between calls, which grows to the largest degree asked for. Nothing is
|
|
30
|
+
* allocated once that table is large enough.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const length = legendreTableLength(2190);
|
|
35
|
+
* const values = new Float64Array(length);
|
|
36
|
+
* const derivatives = new Float64Array(length);
|
|
37
|
+
* legendreFullyNormalized(values, 2190, colatitude, derivatives);
|
|
38
|
+
* values[legendreIndex(2190, 1000)]; // P̄₂₁₉₀,₁₀₀₀(cos θ)
|
|
39
|
+
* ```;
|
|
40
|
+
*
|
|
41
|
+
* @param out Receives the values; entries past {@link legendreTableLength}
|
|
42
|
+
* `(maxDegree)` are left alone.
|
|
43
|
+
* @param maxDegree The highest degree, a non-negative integer.
|
|
44
|
+
* @param colatitude `θ`, radians in `[0, π]`; `NaN` fills both tables with
|
|
45
|
+
* `NaN`.
|
|
46
|
+
* @param derivativesOut Receives `dP̄ₙₘ/dθ`; must not overlap `out`.
|
|
47
|
+
* @throws {RangeError} When `maxDegree` is not a non-negative integer, a table
|
|
48
|
+
* is too short for it, the tables overlap or `colatitude` is outside `[0,
|
|
49
|
+
* π]`; nothing is written.
|
|
50
|
+
*/
|
|
51
|
+
export declare function legendreFullyNormalized(out: Float64Array, maxDegree: number, colatitude: number, derivativesOut?: Float64Array): Float64Array;
|
|
52
|
+
//# sourceMappingURL=legendre-fully-normalized.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legendre-fully-normalized.d.ts","sourceRoot":"","sources":["../../src/legendre/legendre-fully-normalized.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAgB,uBAAuB,CACtC,GAAG,EAAE,YAAY,EACjB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,cAAc,CAAC,EAAE,YAAY,GAC3B,YAAY,CAcd"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { LEGENDRE_COLATITUDE_, legendreCheck_, legendreFillNaN_, legendreKernel_, } from "./_legendre-kernel.js";
|
|
2
|
+
/**
|
|
3
|
+
* Writes the fully normalised associated Legendre functions `P̄ₙₘ(cos θ)` of
|
|
4
|
+
* every degree `n ≤ maxDegree` and order `0 ≤ m ≤ n` into `out`, in the order
|
|
5
|
+
* of {@link legendreIndex}, and their derivatives `dP̄ₙₘ/dθ` with respect to the
|
|
6
|
+
* colatitude `θ` into `derivativesOut` when given. Returns `out`.
|
|
7
|
+
*
|
|
8
|
+
* The normalisation of geodesy and gravity field models (EGM2008, the geoid):
|
|
9
|
+
* `P̄ₙₘ = √((2 − δₘ₀)(2n + 1)(n − m)! / (n + m)!) Pₙₘ`, so that the mean of
|
|
10
|
+
* `(P̄ₙₘ(cos θ) cos mλ)²` over the sphere is `1`, without the Condon–Shortley
|
|
11
|
+
* phase `(−1)ᵐ`. It is {@link legendreSchmidt}'s times `√(2n + 1)`.
|
|
12
|
+
*
|
|
13
|
+
* Stable to degree 2190 (EGM2008's) and beyond, at every colatitude: the
|
|
14
|
+
* recursion is Holmes and Featherstone's modified forward column method, each
|
|
15
|
+
* order's column run as `P̄ₙₘ / sinᵐθ` with a scaled seed and multiplied back
|
|
16
|
+
* by `sinᵐθ` with its exponent kept apart, so no intermediate overflows to
|
|
17
|
+
* degree 2700 (past about 2850 the scaled columns do, near the poles), and a
|
|
18
|
+
* value too small for binary64 (high orders near the poles) underflows to the
|
|
19
|
+
* subnormal range or to `0` instead of corrupting its column. The derivatives
|
|
20
|
+
* come from the neighbouring orders, with no division by `sin θ`, so they are
|
|
21
|
+
* exact at the poles too. Measured against 60-digit references, the error of a
|
|
22
|
+
* degree-n entry stays below `10⁻¹¹ √(2n + 1)` to degree 2190, and below `10⁻¹³
|
|
23
|
+
* √(2n + 1)` to degree 100; the cosine near a pole is taken from the half
|
|
24
|
+
* angle, so a colatitude of `10⁻⁶` loses nothing to `cos θ` rounding to within
|
|
25
|
+
* `10⁻¹⁶` of `1`. Near `θ = π` a double holds the colatitude itself only to
|
|
26
|
+
* `2⁻⁵² π` absolute; evaluate a southern point at `π − θ` and apply `P̄ₙₘ(−t) =
|
|
27
|
+
* (−1)ⁿ⁺ᵐ P̄ₙₘ(t)` when that matters.
|
|
28
|
+
*
|
|
29
|
+
* O(maxDegree²) time; O(maxDegree) memory for a table of integer square roots
|
|
30
|
+
* kept between calls, which grows to the largest degree asked for. Nothing is
|
|
31
|
+
* allocated once that table is large enough.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const length = legendreTableLength(2190);
|
|
36
|
+
* const values = new Float64Array(length);
|
|
37
|
+
* const derivatives = new Float64Array(length);
|
|
38
|
+
* legendreFullyNormalized(values, 2190, colatitude, derivatives);
|
|
39
|
+
* values[legendreIndex(2190, 1000)]; // P̄₂₁₉₀,₁₀₀₀(cos θ)
|
|
40
|
+
* ```;
|
|
41
|
+
*
|
|
42
|
+
* @param out Receives the values; entries past {@link legendreTableLength}
|
|
43
|
+
* `(maxDegree)` are left alone.
|
|
44
|
+
* @param maxDegree The highest degree, a non-negative integer.
|
|
45
|
+
* @param colatitude `θ`, radians in `[0, π]`; `NaN` fills both tables with
|
|
46
|
+
* `NaN`.
|
|
47
|
+
* @param derivativesOut Receives `dP̄ₙₘ/dθ`; must not overlap `out`.
|
|
48
|
+
* @throws {RangeError} When `maxDegree` is not a non-negative integer, a table
|
|
49
|
+
* is too short for it, the tables overlap or `colatitude` is outside `[0,
|
|
50
|
+
* π]`; nothing is written.
|
|
51
|
+
*/
|
|
52
|
+
export function legendreFullyNormalized(out, maxDegree, colatitude, derivativesOut) {
|
|
53
|
+
LEGENDRE_COLATITUDE_[0] = colatitude;
|
|
54
|
+
const length = legendreCheck_("legendreFullyNormalized", out, derivativesOut, maxDegree);
|
|
55
|
+
if (colatitude !== colatitude) {
|
|
56
|
+
legendreFillNaN_(out, derivativesOut, length);
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
legendreKernel_(out, derivativesOut, maxDegree, false);
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=legendre-fully-normalized.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legendre-fully-normalized.js","sourceRoot":"","sources":["../../src/legendre/legendre-fully-normalized.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAChB,eAAe,GACf,MAAM,uBAAuB,CAAC;AAE/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,MAAM,UAAU,uBAAuB,CACtC,GAAiB,EACjB,SAAiB,EACjB,UAAkB,EAClB,cAA6B;IAE7B,oBAAoB,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC;IACrC,MAAM,MAAM,GAAG,cAAc,CAC5B,yBAAyB,EACzB,GAAG,EACH,cAAc,EACd,SAAS,CACT,CAAC;IACF,IAAI,UAAU,KAAK,UAAU,EAAE,CAAC;QAC/B,gBAAgB,CAAC,GAAG,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;QAC9C,OAAO,GAAG,CAAC;IACZ,CAAC;IACD,eAAe,CAAC,GAAG,EAAE,cAAc,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IACvD,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The position of degree `degree` and order `order` in a triangular table of
|
|
3
|
+
* associated Legendre functions, as {@link legendreSchmidt} and
|
|
4
|
+
* {@link legendreFullyNormalized} write it: degree by degree, each degree's
|
|
5
|
+
* orders `0` to `degree` in turn, so `(0, 0)` is at `0`, `(1, 0)` at `1`, `(1,
|
|
6
|
+
* 1)` at `2`, `(2, 0)` at `3`. The index is `degree (degree + 1) / 2 + order`.
|
|
7
|
+
*
|
|
8
|
+
* Not checked: `degree` and `order` are integers with `0 ≤ order ≤ degree`.
|
|
9
|
+
* O(1).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* legendreIndex(2, 1); // 4
|
|
14
|
+
* legendreIndex(12, 12); // 90, the last entry of a degree-12 table
|
|
15
|
+
* ```;
|
|
16
|
+
*/
|
|
17
|
+
export declare function legendreIndex(degree: number, order: number): number;
|
|
18
|
+
/**
|
|
19
|
+
* The number of entries of a triangular table up to degree `maxDegree`, every
|
|
20
|
+
* order of every degree from `0`: `(maxDegree + 1)(maxDegree + 2) / 2`. A
|
|
21
|
+
* degree-12 table (the World Magnetic Model) has 91 entries, a degree-2190 one
|
|
22
|
+
* (EGM2008) 2 401 336.
|
|
23
|
+
*
|
|
24
|
+
* Not checked: `maxDegree` is a non-negative integer. O(1).
|
|
25
|
+
*/
|
|
26
|
+
export declare function legendreTableLength(maxDegree: number): number;
|
|
27
|
+
//# sourceMappingURL=legendre-index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legendre-index.d.ts","sourceRoot":"","sources":["../../src/legendre/legendre-index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE7D"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The position of degree `degree` and order `order` in a triangular table of
|
|
3
|
+
* associated Legendre functions, as {@link legendreSchmidt} and
|
|
4
|
+
* {@link legendreFullyNormalized} write it: degree by degree, each degree's
|
|
5
|
+
* orders `0` to `degree` in turn, so `(0, 0)` is at `0`, `(1, 0)` at `1`, `(1,
|
|
6
|
+
* 1)` at `2`, `(2, 0)` at `3`. The index is `degree (degree + 1) / 2 + order`.
|
|
7
|
+
*
|
|
8
|
+
* Not checked: `degree` and `order` are integers with `0 ≤ order ≤ degree`.
|
|
9
|
+
* O(1).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* legendreIndex(2, 1); // 4
|
|
14
|
+
* legendreIndex(12, 12); // 90, the last entry of a degree-12 table
|
|
15
|
+
* ```;
|
|
16
|
+
*/
|
|
17
|
+
export function legendreIndex(degree, order) {
|
|
18
|
+
return (degree * (degree + 1)) / 2 + order;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The number of entries of a triangular table up to degree `maxDegree`, every
|
|
22
|
+
* order of every degree from `0`: `(maxDegree + 1)(maxDegree + 2) / 2`. A
|
|
23
|
+
* degree-12 table (the World Magnetic Model) has 91 entries, a degree-2190 one
|
|
24
|
+
* (EGM2008) 2 401 336.
|
|
25
|
+
*
|
|
26
|
+
* Not checked: `maxDegree` is a non-negative integer. O(1).
|
|
27
|
+
*/
|
|
28
|
+
export function legendreTableLength(maxDegree) {
|
|
29
|
+
return ((maxDegree + 1) * (maxDegree + 2)) / 2;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=legendre-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legendre-index.js","sourceRoot":"","sources":["../../src/legendre/legendre-index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,KAAa;IAC1D,OAAO,CAAC,MAAM,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAC5C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,SAAiB;IACpD,OAAO,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes the Schmidt semi-normalised associated Legendre functions `Pₙᵐ(cos θ)`
|
|
3
|
+
* of every degree `n ≤ maxDegree` and order `0 ≤ m ≤ n` into `out`, in the
|
|
4
|
+
* order of {@link legendreIndex}, and their derivatives `dPₙᵐ/dθ` with respect
|
|
5
|
+
* to the colatitude `θ` into `derivativesOut` when given. Returns `out`.
|
|
6
|
+
*
|
|
7
|
+
* The normalisation of geomagnetism (the World Magnetic Model, the IGRF): `Pₙᵐ
|
|
8
|
+
* = √((2 − δₘ₀)(n − m)! / (n + m)!) Pₙₘ`, so that `Σₘ (Pₙᵐ)² = 1` for every
|
|
9
|
+
* degree, without the Condon–Shortley phase `(−1)ᵐ`. It is
|
|
10
|
+
* {@link legendreFullyNormalized}'s divided by `√(2n + 1)`, and shares its
|
|
11
|
+
* recursion, so it is as stable: to degree 2190 and beyond (2700) at every
|
|
12
|
+
* colatitude, and with derivatives exact at the poles.
|
|
13
|
+
*
|
|
14
|
+
* O(maxDegree²) time; O(maxDegree) memory for a table of integer square roots
|
|
15
|
+
* kept between calls. Nothing is allocated once that table is large enough.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const values = new Float64Array(legendreTableLength(12));
|
|
20
|
+
* const derivatives = new Float64Array(legendreTableLength(12));
|
|
21
|
+
* legendreSchmidt(values, 12, Math.PI / 3, derivatives);
|
|
22
|
+
* values[legendreIndex(1, 1)]; // sin θ = 0.8660254037844386
|
|
23
|
+
* derivatives[legendreIndex(1, 0)]; // −sin θ
|
|
24
|
+
* ```;
|
|
25
|
+
*
|
|
26
|
+
* @param out Receives the values; entries past {@link legendreTableLength}
|
|
27
|
+
* `(maxDegree)` are left alone.
|
|
28
|
+
* @param maxDegree The highest degree, a non-negative integer.
|
|
29
|
+
* @param colatitude `θ`, radians in `[0, π]`; `NaN` fills both tables with
|
|
30
|
+
* `NaN`.
|
|
31
|
+
* @param derivativesOut Receives `dPₙᵐ/dθ`; must not overlap `out`.
|
|
32
|
+
* @throws {RangeError} When `maxDegree` is not a non-negative integer, a table
|
|
33
|
+
* is too short for it, the tables overlap or `colatitude` is outside `[0,
|
|
34
|
+
* π]`; nothing is written.
|
|
35
|
+
*/
|
|
36
|
+
export declare function legendreSchmidt(out: Float64Array, maxDegree: number, colatitude: number, derivativesOut?: Float64Array): Float64Array;
|
|
37
|
+
//# sourceMappingURL=legendre-schmidt.d.ts.map
|