@danielsimonjr/mathts-functions 0.32.0 → 0.34.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/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2182 -583
- package/dist/numbertheory/extra.d.ts +142 -0
- package/dist/numbertheory/extra.d.ts.map +1 -0
- package/dist/numeric/gauss-nodes.d.ts +35 -0
- package/dist/numeric/gauss-nodes.d.ts.map +1 -0
- package/dist/signal/conv.d.ts +113 -0
- package/dist/signal/conv.d.ts.map +1 -0
- package/dist/signal/fft-helpers.d.ts +56 -0
- package/dist/signal/fft-helpers.d.ts.map +1 -0
- package/dist/signal/fft.d.ts +136 -0
- package/dist/signal/fft.d.ts.map +1 -0
- package/dist/signal/fir-smoothing.d.ts +62 -0
- package/dist/signal/fir-smoothing.d.ts.map +1 -0
- package/dist/signal/iir-design.d.ts +94 -0
- package/dist/signal/iir-design.d.ts.map +1 -0
- package/dist/signal/spectral-peaks.d.ts +115 -0
- package/dist/signal/spectral-peaks.d.ts.map +1 -0
- package/dist/signal/wavelets.d.ts +55 -0
- package/dist/signal/wavelets.d.ts.map +1 -0
- package/dist/signal-filter-extra.d.ts +42 -3
- package/dist/signal-filter-extra.d.ts.map +1 -1
- package/dist/special/hypergeometric.d.ts +91 -0
- package/dist/special/hypergeometric.d.ts.map +1 -0
- package/dist/special/jacobi-elliptic.d.ts +60 -0
- package/dist/special/jacobi-elliptic.d.ts.map +1 -0
- package/dist/special/polygamma-orthopoly.d.ts +79 -0
- package/dist/special/polygamma-orthopoly.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/** Options for {@link findPeaks}. */
|
|
2
|
+
export interface FindPeaksOptions {
|
|
3
|
+
/** Minimum peak value to keep. */
|
|
4
|
+
height?: number;
|
|
5
|
+
/** Minimum index separation between kept peaks (greedily keeps the taller peak). */
|
|
6
|
+
distance?: number;
|
|
7
|
+
/** Minimum topographic prominence to keep (see {@link peakWidths} for the definition). */
|
|
8
|
+
prominence?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Find strict local-maxima peak indices in `x` (`x[i-1] < x[i] > x[i+1]`), then
|
|
12
|
+
* optionally filter by minimum `height`, minimum index `distance` (greedily keeping
|
|
13
|
+
* the taller peak of any too-close pair), and/or minimum topographic `prominence` —
|
|
14
|
+
* `scipy.signal.find_peaks`.
|
|
15
|
+
*
|
|
16
|
+
* @param x - Input signal
|
|
17
|
+
* @param opts - `{ height?, distance?, prominence? }`
|
|
18
|
+
* @returns Ascending indices of the surviving peaks
|
|
19
|
+
*/
|
|
20
|
+
export declare function findPeaks(x: readonly number[], opts?: FindPeaksOptions): number[];
|
|
21
|
+
/**
|
|
22
|
+
* Width (in samples) of each peak at `relHeight` down from the peak toward its
|
|
23
|
+
* topographic base (see {@link peakProminence}), with linearly-interpolated crossing
|
|
24
|
+
* points — `scipy.signal.peak_widths`.
|
|
25
|
+
*
|
|
26
|
+
* @param x - Input signal
|
|
27
|
+
* @param peaks - Peak indices (e.g. from {@link findPeaks})
|
|
28
|
+
* @param relHeight - Fraction of the prominence to descend (default 0.5, i.e. FWHM-style)
|
|
29
|
+
* @returns Width per peak, same order as `peaks`
|
|
30
|
+
*/
|
|
31
|
+
export declare function peakWidths(x: readonly number[], peaks: readonly number[], relHeight?: number): number[];
|
|
32
|
+
/** Options shared by {@link csd} and {@link coherence}. */
|
|
33
|
+
export interface CsdOptions {
|
|
34
|
+
/** Segment length (default `min(256, x.length, y.length)`). */
|
|
35
|
+
nperseg?: number;
|
|
36
|
+
/** Samples of overlap between segments (default `floor(nperseg/2)`). */
|
|
37
|
+
noverlap?: number;
|
|
38
|
+
/** Window applied to each segment (default `'hann'`) — see {@link windowFunction}. */
|
|
39
|
+
window?: string;
|
|
40
|
+
/** Sample rate in Hz, used to scale frequencies and power (default 1). */
|
|
41
|
+
fs?: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Cross-spectral density of `x` and `y` via Welch's overlapped-segment-averaging
|
|
45
|
+
* method (segment, window, FFT, average `X·conj(Y)`) — `scipy.signal.csd`.
|
|
46
|
+
*
|
|
47
|
+
* @param x - First signal
|
|
48
|
+
* @param y - Second signal
|
|
49
|
+
* @param opts - `{ nperseg?, noverlap?, window?, fs? }`
|
|
50
|
+
* @returns `{ frequencies, power }` — `power` is the magnitude of the averaged
|
|
51
|
+
* cross spectrum at each frequency bin
|
|
52
|
+
*/
|
|
53
|
+
export declare function csd(x: readonly number[], y: readonly number[], opts?: CsdOptions): {
|
|
54
|
+
frequencies: number[];
|
|
55
|
+
power: number[];
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Magnitude-squared coherence between `x` and `y`: `|Pxy|² / (Pxx·Pyy)`, per Welch
|
|
59
|
+
* frequency bin — `scipy.signal.coherence`. Values lie in `[0, 1]`.
|
|
60
|
+
*
|
|
61
|
+
* @param x - First signal
|
|
62
|
+
* @param y - Second signal
|
|
63
|
+
* @param opts - `{ nperseg?, noverlap?, window?, fs? }`
|
|
64
|
+
* @returns `{ frequencies, coherence }`
|
|
65
|
+
*/
|
|
66
|
+
export declare function coherence(x: readonly number[], y: readonly number[], opts?: CsdOptions): {
|
|
67
|
+
frequencies: number[];
|
|
68
|
+
coherence: number[];
|
|
69
|
+
};
|
|
70
|
+
/** Options for {@link stft} / {@link istft} — must match between the two calls. */
|
|
71
|
+
export interface StftOptions {
|
|
72
|
+
/** Frame length (default 256). */
|
|
73
|
+
nperseg?: number;
|
|
74
|
+
/** Samples of overlap between frames (default `floor(nperseg/2)`). */
|
|
75
|
+
noverlap?: number;
|
|
76
|
+
/** Window applied to each frame (default `'hann'`) — see {@link windowFunction}. */
|
|
77
|
+
window?: string;
|
|
78
|
+
}
|
|
79
|
+
/** `stft`'s output: one row per frame, one column per (non-redundant-truncated) frequency bin. */
|
|
80
|
+
export interface StftResult {
|
|
81
|
+
re: number[][];
|
|
82
|
+
im: number[][];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Short-time Fourier transform: windowed, overlapping frames, each FFT'd independently
|
|
86
|
+
* — `scipy.signal.stft` (magnitude/phase convention; frames are not scaled).
|
|
87
|
+
*
|
|
88
|
+
* @param x - Input signal
|
|
89
|
+
* @param opts - `{ nperseg?, noverlap?, window? }`
|
|
90
|
+
* @returns `{ re, im }`, each `number[frame][bin]`
|
|
91
|
+
*/
|
|
92
|
+
export declare function stft(x: readonly number[], opts?: StftOptions): StftResult;
|
|
93
|
+
/**
|
|
94
|
+
* Inverse short-time Fourier transform via overlap-add: each frame is inverse-FFT'd
|
|
95
|
+
* back to `nperseg` samples, re-windowed, and accumulated; the accumulation is
|
|
96
|
+
* normalized by the running sum of squared window values (the standard
|
|
97
|
+
* constant-overlap-add / COLA normalization), so reconstruction is exact in the
|
|
98
|
+
* interior wherever the window's overlap sum is nonzero — `scipy.signal.istft`.
|
|
99
|
+
*
|
|
100
|
+
* @param S - `{ re, im }` as returned by {@link stft}
|
|
101
|
+
* @param opts - `{ nperseg?, noverlap?, window? }` — must match the `stft` call
|
|
102
|
+
* @returns Reconstructed signal
|
|
103
|
+
*/
|
|
104
|
+
export declare function istft(S: StftResult, opts?: StftOptions): number[];
|
|
105
|
+
/**
|
|
106
|
+
* Downsample `x` by an integer factor `q`: apply a Butterworth anti-alias lowpass
|
|
107
|
+
* (order 4, cutoff `min(0.8/q, 0.99)` of Nyquist) with zero-phase `filtfilt`, then
|
|
108
|
+
* take every `q`-th sample — `scipy.signal.decimate` (IIR mode).
|
|
109
|
+
*
|
|
110
|
+
* @param x - Input signal
|
|
111
|
+
* @param q - Downsampling factor (positive integer)
|
|
112
|
+
* @returns Downsampled signal, length `ceil(x.length / q)`
|
|
113
|
+
*/
|
|
114
|
+
export declare function decimate(x: readonly number[], q: number): number[];
|
|
115
|
+
//# sourceMappingURL=spectral-peaks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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EAAE,CAAC;IAAC,SAAS,EAAE,MAAM,EAAE,CAAA;CAAE,CAahD;AAMD,mFAAmF;AACnF,MAAM,WAAW,WAAW;IAC1B,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sEAAsE;IACtE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oFAAoF;IACpF,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,kGAAkG;AAClG,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC;IACf,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,UAAU,CAoBzE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,EAAE,CA6BjE;AAMD;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAclE"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 6 Task 4 — inverse DWT, multilevel wavedec/waverec (perfect
|
|
3
|
+
* reconstruction), and the continuous wavelet transform (CWT).
|
|
4
|
+
*
|
|
5
|
+
* `idwt`/`wavedec`/`waverec` must invert the existing `dwt` (`../typed/signal.ts`)
|
|
6
|
+
* exactly, so they match its Haar convention bit-for-bit: analysis filters
|
|
7
|
+
* scaled by `s = 1/sqrt(2)`, `approx[i] = s*(x[2i]+x[2i+1])`,
|
|
8
|
+
* `detail[i] = s*(x[2i]-x[2i+1])`. Haar's synthesis (reconstruction) filters
|
|
9
|
+
* are the time-reverse of its analysis filters — for a symmetric 2-tap filter
|
|
10
|
+
* that reversal is a no-op, so the closed-form inverse below is exact:
|
|
11
|
+
* `x[2i] = s*(approx[i]+detail[i])`, `x[2i+1] = s*(approx[i]-detail[i])`.
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Inverse single-level discrete wavelet transform. Upsamples `approx`/`detail`
|
|
17
|
+
* and combines them with the Haar synthesis filters, exactly inverting `dwt`.
|
|
18
|
+
*
|
|
19
|
+
* @param approx - Approximation (low-pass) coefficients
|
|
20
|
+
* @param detail - Detail (high-pass) coefficients, same length as `approx`
|
|
21
|
+
* @param wavelet - Wavelet name (currently only 'haar'/'db1', matching `dwt`)
|
|
22
|
+
* @returns Reconstructed signal, length `2 * approx.length`
|
|
23
|
+
*/
|
|
24
|
+
export declare function idwt(approx: number[], detail: number[], wavelet?: string): number[];
|
|
25
|
+
/**
|
|
26
|
+
* Multilevel discrete wavelet decomposition: repeatedly applies `dwt` to the
|
|
27
|
+
* approximation coefficients.
|
|
28
|
+
*
|
|
29
|
+
* @param x - Input signal
|
|
30
|
+
* @param wavelet - Wavelet name (passed through to `dwt`)
|
|
31
|
+
* @param level - Number of decomposition levels (>= 1)
|
|
32
|
+
* @returns `[cA_level, cD_level, cD_{level-1}, ..., cD_1]` (pywt order)
|
|
33
|
+
*/
|
|
34
|
+
export declare function wavedec(x: number[], wavelet?: string, level?: number): number[][];
|
|
35
|
+
/**
|
|
36
|
+
* Inverse of `wavedec`: repeatedly applies `idwt` from the coarsest level
|
|
37
|
+
* (`coeffs[0]` = cA_level) up to the finest detail (`coeffs[coeffs.length-1]`
|
|
38
|
+
* = cD_1), reconstructing the original signal.
|
|
39
|
+
*
|
|
40
|
+
* @param coeffs - Coefficient arrays as returned by `wavedec`
|
|
41
|
+
* @param wavelet - Wavelet name (passed through to `idwt`)
|
|
42
|
+
* @returns Reconstructed signal
|
|
43
|
+
*/
|
|
44
|
+
export declare function waverec(coeffs: number[][], wavelet?: string): number[];
|
|
45
|
+
/**
|
|
46
|
+
* Continuous wavelet transform: convolves `x` with a discretized, normalized
|
|
47
|
+
* wavelet at each requested scale.
|
|
48
|
+
*
|
|
49
|
+
* @param x - Input signal
|
|
50
|
+
* @param scales - Wavelet scales to evaluate (each > 0)
|
|
51
|
+
* @param wavelet - 'ricker' (Mexican-hat, default) or 'morlet'
|
|
52
|
+
* @returns `scales.length` x `x.length` matrix, row `i` = CWT at `scales[i]`
|
|
53
|
+
*/
|
|
54
|
+
export declare function cwt(x: number[], scales: number[], wavelet?: string): number[][];
|
|
55
|
+
//# sourceMappingURL=wavelets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wavelets.d.ts","sourceRoot":"","sources":["../../src/signal/wavelets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,MAAe,GAAG,MAAM,EAAE,CAgB3F;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,MAAe,EAAE,KAAK,GAAE,MAAU,GAAG,MAAM,EAAE,EAAE,CAc5F;AAED;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,GAAE,MAAe,GAAG,MAAM,EAAE,CAU9E;AA2BD;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,MAAiB,GAAG,MAAM,EAAE,EAAE,CAYzF"}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Digital filter design + application (Wave D / remaining). FIR window design
|
|
3
|
+
* (`firwin`), IIR Butterworth design (`butter`), the direct-form filter (`lfilter`),
|
|
4
|
+
* and zero-phase filtering (`filtfilt`). Matches `scipy.signal`. `butter` reuses the
|
|
5
|
+
* core `Complex` type for the analog-pole bilinear-transform pipeline.
|
|
6
|
+
*/
|
|
7
|
+
import { Complex } from '@danielsimonjr/mathts-core';
|
|
1
8
|
type Vec = readonly number[] | Float64Array;
|
|
9
|
+
export declare const sinc: (x: number) => number;
|
|
2
10
|
/**
|
|
3
11
|
* FIR lowpass filter coefficients by the windowed-sinc method (Hamming window,
|
|
4
12
|
* normalized to unit DC gain) — `scipy.signal.firwin(numtaps, cutoff)` with the
|
|
@@ -22,12 +30,43 @@ export declare function lfilterZi(b: Vec, a: Vec): number[];
|
|
|
22
30
|
* magnitude response is applied with no phase distortion.
|
|
23
31
|
*/
|
|
24
32
|
export declare function filtfilt(b: Vec, a: Vec, x: Vec): number[];
|
|
33
|
+
export declare const cAdd: (p: Complex, q: Complex) => Complex;
|
|
34
|
+
export declare const cSub: (p: Complex, q: Complex) => Complex;
|
|
35
|
+
export declare const cMul: (p: Complex, q: Complex) => Complex;
|
|
36
|
+
export declare const cDiv: (p: Complex, q: Complex) => Complex;
|
|
37
|
+
/** Scale a Complex by a real number (`Complex.mul` only accepts `Scalar`, not `number`). */
|
|
38
|
+
export declare const cScale: (p: Complex, s: number) => Complex;
|
|
39
|
+
/** Real polynomial coefficients (highest degree first) of ∏(x − rₖ). */
|
|
40
|
+
export declare function polyFromRoots(roots: Complex[]): number[];
|
|
41
|
+
/** Analog lowpass prototype: zeros, poles, gain (cutoff normalized to 1 rad/s). */
|
|
42
|
+
export interface AnalogProto {
|
|
43
|
+
z: Complex[];
|
|
44
|
+
p: Complex[];
|
|
45
|
+
k: number;
|
|
46
|
+
}
|
|
47
|
+
export type FilterBtype = 'low' | 'high' | 'bandpass' | 'bandstop';
|
|
48
|
+
/** zpk → transfer-function coefficients (scipy `zpk2tf`). */
|
|
49
|
+
export declare function zpkToTf(z: Complex[], p: Complex[], k: number): {
|
|
50
|
+
b: number[];
|
|
51
|
+
a: number[];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Digital IIR filter design pipeline shared by butter/cheby1/cheby2/ellip:
|
|
55
|
+
* pre-warp `Wn` → frequency-transform the analog lowpass prototype (`proto`,
|
|
56
|
+
* cutoff normalized to 1 rad/s) to the requested `btype` → bilinear transform →
|
|
57
|
+
* zpk2tf. Matches `scipy.signal.iirfilter`'s internal pipeline (fs = 2 convention).
|
|
58
|
+
*/
|
|
59
|
+
export declare function analogToDigital(proto: AnalogProto, Wn: number | readonly number[], btype: FilterBtype): {
|
|
60
|
+
b: number[];
|
|
61
|
+
a: number[];
|
|
62
|
+
};
|
|
25
63
|
/**
|
|
26
64
|
* Butterworth IIR filter design — returns `{ b, a }` transfer-function coefficients.
|
|
27
|
-
* `N` is the order, `Wn` the cutoff
|
|
28
|
-
* (`btype
|
|
65
|
+
* `N` is the order, `Wn` the cutoff (scalar) or `[low, high]` band edges, normalized
|
|
66
|
+
* to Nyquist (0..1). `btype` defaults to `'low'` (matches the original 2-arg call
|
|
67
|
+
* unchanged). Matches `scipy.signal.butter(N, Wn, btype)`.
|
|
29
68
|
*/
|
|
30
|
-
export declare function butter(N: number, Wn: number): {
|
|
69
|
+
export declare function butter(N: number, Wn: number | readonly number[], btype?: FilterBtype): {
|
|
31
70
|
b: number[];
|
|
32
71
|
a: number[];
|
|
33
72
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signal-filter-extra.d.ts","sourceRoot":"","sources":["../src/signal-filter-extra.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signal-filter-extra.d.ts","sourceRoot":"","sources":["../src/signal-filter-extra.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAMrD,KAAK,GAAG,GAAG,SAAS,MAAM,EAAE,GAAG,YAAY,CAAC;AAG5C,eAAO,MAAM,IAAI,GAAI,GAAG,MAAM,KAAG,MAA+D,CAAC;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AgB,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG;IAAE,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAE3F;AAgBD;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,WAAW,EAClB,EAAE,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,EAC9B,KAAK,EAAE,WAAW,GACjB;IAAE,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAgB9B;AAaD;;;;;GAKG;AACH,wBAAgB,MAAM,CACpB,CAAC,EAAE,MAAM,EACT,EAAE,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,EAC9B,KAAK,GAAE,WAAmB,GACzB;IAAE,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAG9B"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hypergeometric functions.
|
|
3
|
+
*
|
|
4
|
+
* Implements the generalized hypergeometric series pFq via the ascending
|
|
5
|
+
* Pochhammer-ratio method: each term is generated from the previous one by
|
|
6
|
+
* multiplying by the ratio of rising factorials,
|
|
7
|
+
*
|
|
8
|
+
* term_{n+1} / term_n = ( prod_i (a_i + n) / prod_j (b_j + n) ) * z / (n + 1)
|
|
9
|
+
*
|
|
10
|
+
* accumulating until the term becomes negligible relative to the running sum
|
|
11
|
+
* (|term| < 1e-16 * |sum|) or a hard iteration cap is hit. This incremental
|
|
12
|
+
* form avoids recomputing factorials/Pochhammer symbols from scratch at each
|
|
13
|
+
* order and is numerically well-behaved for the convergent regimes documented
|
|
14
|
+
* per function below.
|
|
15
|
+
*
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Generalized hypergeometric function pFq(a; b; z), computed via the
|
|
20
|
+
* ascending Pochhammer-ratio series:
|
|
21
|
+
*
|
|
22
|
+
* pFq(a_1..a_p; b_1..b_q; z) = sum_{n=0}^inf
|
|
23
|
+
* ( prod_i (a_i)_n / prod_j (b_j)_n ) * z^n / n!
|
|
24
|
+
*
|
|
25
|
+
* This is the generic engine that hyp0f1/hyp1f1/hyp2f1 delegate to. No
|
|
26
|
+
* convergence-region check is performed here (that is the caller's
|
|
27
|
+
* responsibility, see hyp2f1's |z| < 1 guard) — the series is simply summed
|
|
28
|
+
* until it converges to machine precision or MAX_TERMS is reached.
|
|
29
|
+
*
|
|
30
|
+
* @param a - Upper (numerator) parameters
|
|
31
|
+
* @param b - Lower (denominator) parameters
|
|
32
|
+
* @param z - Argument
|
|
33
|
+
* @returns pFq(a; b; z)
|
|
34
|
+
*/
|
|
35
|
+
export declare function pFq(a: number[], b: number[], z: number): number;
|
|
36
|
+
/**
|
|
37
|
+
* Confluent hypergeometric limit function 0F1(; b; z):
|
|
38
|
+
*
|
|
39
|
+
* hyp0f1(b, z) = sum_{n=0}^inf z^n / ((b)_n n!)
|
|
40
|
+
*
|
|
41
|
+
* Entire in z (converges for all finite z, real or otherwise real-valued
|
|
42
|
+
* here); related to the Bessel functions.
|
|
43
|
+
*
|
|
44
|
+
* @param b - Parameter
|
|
45
|
+
* @param z - Argument
|
|
46
|
+
* @returns 0F1(; b; z)
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* hyp0f1(2, 0.5) // ~1.2717234563
|
|
50
|
+
*/
|
|
51
|
+
export declare function hyp0f1(b: number, z: number): number;
|
|
52
|
+
/**
|
|
53
|
+
* Kummer's confluent hypergeometric function 1F1(a; b; z) (Kummer's M):
|
|
54
|
+
*
|
|
55
|
+
* hyp1f1(a, b, z) = sum_{n=0}^inf ( (a)_n / (b)_n ) * z^n / n!
|
|
56
|
+
*
|
|
57
|
+
* Entire in z. The direct ascending series targets moderate |z| — for large
|
|
58
|
+
* |z| the series requires many terms and loses accuracy to cancellation
|
|
59
|
+
* (particularly when a and b have opposite signs); an asymptotic expansion
|
|
60
|
+
* would be needed for large |z| but is not implemented here.
|
|
61
|
+
*
|
|
62
|
+
* @param a - Numerator parameter
|
|
63
|
+
* @param b - Denominator parameter
|
|
64
|
+
* @param z - Argument
|
|
65
|
+
* @returns 1F1(a; b; z)
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* hyp1f1(1, 2, 0.5) // ~1.2974425414
|
|
69
|
+
*/
|
|
70
|
+
export declare function hyp1f1(a: number, b: number, z: number): number;
|
|
71
|
+
/**
|
|
72
|
+
* Gauss's hypergeometric function 2F1(a, b; c; z):
|
|
73
|
+
*
|
|
74
|
+
* hyp2f1(a, b, c, z) = sum_{n=0}^inf ( (a)_n (b)_n / (c)_n ) * z^n / n!
|
|
75
|
+
*
|
|
76
|
+
* The ascending series converges only for |z| < 1. Analytic continuation
|
|
77
|
+
* beyond the unit disk (e.g. via connection formulas or a transformation to
|
|
78
|
+
* 1-z) is not yet implemented.
|
|
79
|
+
*
|
|
80
|
+
* @param a - First numerator parameter
|
|
81
|
+
* @param b - Second numerator parameter
|
|
82
|
+
* @param c - Denominator parameter
|
|
83
|
+
* @param z - Argument, must satisfy |z| < 1
|
|
84
|
+
* @returns 2F1(a, b; c; z)
|
|
85
|
+
* @throws {Error} If |z| >= 1
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* hyp2f1(1, 2, 3, 0.5) // ~1.5451774445
|
|
89
|
+
*/
|
|
90
|
+
export declare function hyp2f1(a: number, b: number, c: number, z: number): number;
|
|
91
|
+
//# sourceMappingURL=hypergeometric.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hypergeometric.d.ts","sourceRoot":"","sources":["../../src/special/hypergeometric.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAQH;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAgB/D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAKzE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jacobi elliptic functions sn, cn, dn.
|
|
3
|
+
*
|
|
4
|
+
* Uses the parameter convention `m = k^2` (matching scipy's
|
|
5
|
+
* `scipy.special.ellipj(u, m)` and mpmath's `ellipfun(..., u, m)`), not the
|
|
6
|
+
* modulus-angle convention some texts use.
|
|
7
|
+
*
|
|
8
|
+
* Computed via the descending Landen transformation / arithmetic-geometric
|
|
9
|
+
* mean (AGM) method (Abramowitz & Stegun 16.4, the Bulirsch algorithm):
|
|
10
|
+
* build the AGM sequences
|
|
11
|
+
*
|
|
12
|
+
* a_0 = 1, b_0 = sqrt(1 - m), c_0 = sqrt(m)
|
|
13
|
+
* a_{i+1} = (a_i + b_i) / 2
|
|
14
|
+
* b_{i+1} = sqrt(a_i * b_i)
|
|
15
|
+
* c_{i+1} = (a_i - b_i) / 2
|
|
16
|
+
*
|
|
17
|
+
* until c_N is negligible, then descend the amplitude
|
|
18
|
+
*
|
|
19
|
+
* phi_N = 2^N * a_N * u
|
|
20
|
+
* phi_{i-1} = (phi_i + asin((c_i / a_i) * sin(phi_i))) / 2 for i = N..1
|
|
21
|
+
*
|
|
22
|
+
* so that sn(u,m) = sin(phi_0), cn(u,m) = cos(phi_0),
|
|
23
|
+
* dn(u,m) = sqrt(1 - m * sn^2(u,m)).
|
|
24
|
+
*
|
|
25
|
+
* @packageDocumentation
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Jacobi elliptic function sn(u, m), parameter convention m = k^2.
|
|
29
|
+
*
|
|
30
|
+
* @param u - Argument
|
|
31
|
+
* @param m - Parameter m = k^2, must be in [0, 1]
|
|
32
|
+
* @returns sn(u, m)
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* jacobiSN(0.5, 0.3) // ~0.4742156227
|
|
36
|
+
*/
|
|
37
|
+
export declare function jacobiSN(u: number, m: number): number;
|
|
38
|
+
/**
|
|
39
|
+
* Jacobi elliptic function cn(u, m), parameter convention m = k^2.
|
|
40
|
+
*
|
|
41
|
+
* @param u - Argument
|
|
42
|
+
* @param m - Parameter m = k^2, must be in [0, 1]
|
|
43
|
+
* @returns cn(u, m)
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* jacobiCN(0.5, 0.3) // ~0.8804087364
|
|
47
|
+
*/
|
|
48
|
+
export declare function jacobiCN(u: number, m: number): number;
|
|
49
|
+
/**
|
|
50
|
+
* Jacobi elliptic function dn(u, m), parameter convention m = k^2.
|
|
51
|
+
*
|
|
52
|
+
* @param u - Argument
|
|
53
|
+
* @param m - Parameter m = k^2, must be in [0, 1]
|
|
54
|
+
* @returns dn(u, m)
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* jacobiDN(0.5, 0.3) // ~0.9656789647
|
|
58
|
+
*/
|
|
59
|
+
export declare function jacobiDN(u: number, m: number): number;
|
|
60
|
+
//# sourceMappingURL=jacobi-elliptic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jacobi-elliptic.d.ts","sourceRoot":"","sources":["../../src/special/jacobi-elliptic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAwDH;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAErD"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Polygamma functions and classical orthogonal polynomials.
|
|
3
|
+
*
|
|
4
|
+
* `polygamma(n, x)` is the n-th derivative of the digamma function,
|
|
5
|
+
* ψ^(n)(x) = d^n/dx^n ψ(x). It is computed by shifting the argument up via
|
|
6
|
+
* the standard recurrence
|
|
7
|
+
*
|
|
8
|
+
* ψ^(n)(x) = ψ^(n)(x + m) + (-1)^(n+1) n! * sum_{k=0}^{m-1} 1/(x+k)^(n+1)
|
|
9
|
+
*
|
|
10
|
+
* until x + m is large enough (>= SHIFT_THRESHOLD) for the asymptotic
|
|
11
|
+
* (Bernoulli) expansion (DLMF 5.15.8) to converge to machine precision:
|
|
12
|
+
*
|
|
13
|
+
* psi^(n)(X) ~ (-1)^(n-1) * [ (n-1)!/X^n + n!/(2 X^(n+1))
|
|
14
|
+
* + sum_j B_{2j} * (2j+n-1)! / ((2j)! * X^(2j+n)) ]
|
|
15
|
+
*
|
|
16
|
+
* Since (-1)^(n+1) = (-1)^(n-1), both pieces share the same overall sign.
|
|
17
|
+
*
|
|
18
|
+
* `jacobiP` and `gegenbauerC` are evaluated with their standard stable
|
|
19
|
+
* three-term recurrences (DLMF 18.9.2 and 18.9.1 respectively), matching the
|
|
20
|
+
* pattern already used for `chebyshevT` / `hermiteH` / `laguerreL` /
|
|
21
|
+
* `legendreP`.
|
|
22
|
+
*
|
|
23
|
+
* @packageDocumentation
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Polygamma function ψ^(n)(x): the n-th derivative of the digamma function.
|
|
27
|
+
*
|
|
28
|
+
* `polygamma(0, x)` delegates to `digamma(x)`. For `n >= 1`, x is shifted up
|
|
29
|
+
* via the standard recurrence until it is large enough for the Bernoulli
|
|
30
|
+
* asymptotic expansion to converge.
|
|
31
|
+
*
|
|
32
|
+
* @param n - Derivative order (nonnegative integer)
|
|
33
|
+
* @param x - Argument (must not be a nonpositive integer, where ψ^(n) has poles)
|
|
34
|
+
* @returns ψ^(n)(x)
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* polygamma(1, 2) // ~0.6449340668 (trigamma(2))
|
|
38
|
+
* polygamma(2, 1) // ~-2.4041138063
|
|
39
|
+
*/
|
|
40
|
+
export declare function polygamma(n: number, x: number): number;
|
|
41
|
+
/**
|
|
42
|
+
* Trigamma function ψ'(x) = ψ^(1)(x): the first derivative of the digamma
|
|
43
|
+
* function. Equivalent to `polygamma(1, x)`.
|
|
44
|
+
*
|
|
45
|
+
* @param x - Argument
|
|
46
|
+
* @returns ψ'(x)
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* trigamma(2) // ~0.6449340668 (= zeta(2) - 1 = pi^2/6 - 1)
|
|
50
|
+
*/
|
|
51
|
+
export declare function trigamma(x: number): number;
|
|
52
|
+
/**
|
|
53
|
+
* Jacobi polynomial P_n^(alpha,beta)(x), evaluated via the standard
|
|
54
|
+
* three-term recurrence (DLMF 18.9.2).
|
|
55
|
+
*
|
|
56
|
+
* @param n - Degree (nonnegative integer)
|
|
57
|
+
* @param alpha - Parameter alpha (> -1)
|
|
58
|
+
* @param beta - Parameter beta (> -1)
|
|
59
|
+
* @param x - Evaluation point
|
|
60
|
+
* @returns P_n^(alpha,beta)(x)
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* jacobiP(2, 1, 1, 0.5) // 0.1875
|
|
64
|
+
*/
|
|
65
|
+
export declare function jacobiP(n: number, alpha: number, beta: number, x: number): number;
|
|
66
|
+
/**
|
|
67
|
+
* Gegenbauer (ultraspherical) polynomial C_n^(alpha)(x), evaluated via the
|
|
68
|
+
* standard three-term recurrence (DLMF 18.9.1).
|
|
69
|
+
*
|
|
70
|
+
* @param n - Degree (nonnegative integer)
|
|
71
|
+
* @param alpha - Parameter alpha (> -1/2, alpha != 0)
|
|
72
|
+
* @param x - Evaluation point
|
|
73
|
+
* @returns C_n^(alpha)(x)
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* gegenbauerC(2, 1, 1) // 3 (C_2^(1)(x) = 4x^2 - 1)
|
|
77
|
+
*/
|
|
78
|
+
export declare function gegenbauerC(n: number, alpha: number, x: number): number;
|
|
79
|
+
//# sourceMappingURL=polygamma-orthopoly.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polygamma-orthopoly.d.ts","sourceRoot":"","sources":["../../src/special/polygamma-orthopoly.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAiBH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAkCtD;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAqBjF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAgBvE"}
|
package/package.json
CHANGED