/** * Interpolation Functions * * Provides polynomial and spline interpolation methods: * - linearInterp: Linear interpolation between data points * - lagrangeInterp: Lagrange polynomial interpolation * - cubicSpline: Natural cubic spline (returns evaluation function) * - hermiteInterp: Hermite interpolation with derivative data * - pchipInterp: Piecewise Cubic Hermite Interpolating Polynomial (shape-preserving) * - polyFit: Least-squares polynomial fitting * * These use plain exports since some return functions. * * The hot-loop tridiagonal solver used by `cubicSpline` is dispatched * through `functions/src/wasm/interpolation/wasm-bridge.ts` when the * knot count reaches the WASM_TRIDIAG_THRESHOLD (1024). * * @packageDocumentation */ import { WASM_INTERP_THRESHOLD } from '../wasm/interpolation/wasm-bridge.js'; /** * Linear interpolation between data points. * * Finds the interval containing x and linearly interpolates. * Extrapolates linearly outside the data range. * * @param xs - Sorted x-coordinates (ascending) * @param ys - Corresponding y-values * @param x - Point to interpolate at * @returns Interpolated value * * @example * linearInterp([0, 1], [0, 1], 0.5) // => 0.5 * linearInterp([0, 1, 2], [0, 1, 4], 1.5) // => 2.5 */ export declare function linearInterp(xs: number[], ys: number[], x: number): number; /** * Lagrange polynomial interpolation. * * Computes the unique polynomial of degree n-1 passing through n data points, * evaluated at x. * * When `xs.length >= WASM_INTERP_THRESHOLD` (256), the O(n²) * divided-difference table is computed via the AssemblyScript WASM kernel * and the result is evaluated in Newton form. * Below the threshold the classical direct Lagrange formula is used. * * @param xs - Distinct x-coordinates * @param ys - Corresponding y-values * @param x - Point to evaluate at * @returns Interpolated value * * @example * lagrangeInterp([0, 1, 2], [0, 1, 4], 1.5) // => 2.25 */ export declare function lagrangeInterp(xs: number[], ys: number[], x: number): number; /** * Newton's divided-difference polynomial interpolation. * * Evaluates the unique interpolating polynomial of degree n-1 at `x` using * Newton's divided-difference representation. Mathematically identical to * Lagrange interpolation but computed via a different (and more numerically * efficient) algorithm. * * When `xs.length >= WASM_INTERP_THRESHOLD` (256), the O(n²) * divided-difference table is dispatched to the WASM kernel; otherwise the * pure-JS path runs. * * @param xs - Distinct x-coordinates * @param ys - Corresponding y-values * @param x - Point to evaluate at * @returns Interpolated value * @throws RangeError when any two xs are equal (degenerate / duplicate nodes) * * @example * newtonInterp([0, 1, 2], [0, 1, 4], 1.5) // => 2.25 */ export declare function newtonInterp(xs: number[], ys: number[], x: number): number; /** * Re-export the WASM_INTERP_THRESHOLD constant for external consumers * that need to know the dispatch boundary. */ export { WASM_INTERP_THRESHOLD }; /** * Natural cubic spline interpolation. * * Computes spline coefficients and returns a function that evaluates * the spline at any point. Uses natural boundary conditions (second * derivative = 0 at endpoints). * * @param xs - Sorted x-coordinates (ascending, at least 3 points) * @param ys - Corresponding y-values * @returns Evaluation function * * @example * const spline = cubicSpline([0, 1, 2, 3], [0, 1, 4, 9]); * spline(1.5) // => ~2.25 */ export declare function cubicSpline(xs: number[], ys: number[]): (x: number) => number; /** * Hermite interpolation using function values and derivatives. * * Constructs the unique polynomial that matches both function values * and first derivatives at each data point. * * @param xs - Distinct x-coordinates * @param ys - Function values at xs * @param dys - Derivative values at xs * @param x - Point to evaluate at * @returns Interpolated value * * @example * hermiteInterp([0, 1], [0, 1], [1, 1], 0.5) // => 0.5 (linear) */ export declare function hermiteInterp(xs: number[], ys: number[], dys: number[], x: number): number; /** * Shape-preserving piecewise cubic Hermite interpolation (PCHIP). * * Unlike cubic splines, PCHIP preserves monotonicity and avoids overshoot. * Uses Fritsch-Carlson method to compute slopes. * * @param xs - Sorted x-coordinates (ascending, at least 2 points) * @param ys - Corresponding y-values * @param x - Point to interpolate at * @returns Interpolated value * * @example * pchipInterp([0, 1, 2, 3], [0, 1, 4, 9], 1.5) */ export declare function pchipInterp(xs: number[], ys: number[], x: number): number; /** * Least-squares polynomial fit. * * Fits a polynomial of given degree to data points using Vandermonde + QR. * Returns coefficients [a0, a1, ..., a_degree] where p(x) = a0 + a1*x + ... + a_d*x^d. * * When xs.length >= WASM_POLY_FIT_THRESHOLD (1024), the hot-loop is dispatched * to the AssemblyScript WASM backend. Below the threshold, a normal- * equation / Gaussian-elimination path runs in pure JS. * * @param xs - x-coordinates * @param ys - y-values * @param degree - Polynomial degree (must be < number of data points) * @returns Array of coefficients [a0, a1, ..., a_degree] * * @example * polyFit([0, 1, 2, 3], [0, 1, 4, 9], 2) // => ~[0, 0, 1] (x^2) */ export declare function polyFit(xs: number[], ys: number[], degree: number): number[]; /** * Fit a Chebyshev-series of given degree to data points. * * Returns coefficients [c0, c1, ..., c_degree] in the Chebyshev-T basis so * that f(x) ≈ c0·T_0(x) + c1·T_1(x) + ... + c_d·T_d(x). * * When xs.length >= WASM_POLY_FIT_THRESHOLD, the QR solve is dispatched * to WASM. Below the threshold, a normal-equation JS path is used. * * @param xs - x-coordinates (ideally in [-1, 1] for numerical stability) * @param ys - y-values * @param degree - Chebyshev degree * @returns Array of Chebyshev coefficients [c0, ..., c_degree] * * @example * // T_2(x) = 2x² - 1: coefficients should be approx [-1, 0, 2] (wait — basis order) * // T_0 = 1, T_1 = x, T_2 = 2x²-1 → recovery coefficients [0, 0, 1] for T_2 alone * chebyshevFit(xs, ys, 2) // ys = T_2(xs): => ~[0, 0, 1] */ export declare function chebyshevFit(xs: number[], ys: number[], degree: number): number[]; /** * Fit a Legendre-series of given degree to data points. * * Returns coefficients [c0, c1, ..., c_degree] in the Legendre-P basis so * that f(x) ≈ c0·P_0(x) + c1·P_1(x) + ... + c_d·P_d(x). * * When xs.length >= WASM_POLY_FIT_THRESHOLD, the QR solve is dispatched * to WASM. Below the threshold, a normal-equation JS path is used. * * @param xs - x-coordinates (ideally in [-1, 1] for numerical stability) * @param ys - y-values * @param degree - Legendre degree * @returns Array of Legendre coefficients [c0, ..., c_degree] * * @example * // P_2(x) = (3x² - 1)/2: recovery coefficients [0, 0, 1] for P_2 alone * legendreFit(xs, ys, 2) // ys = P_2(xs): => ~[0, 0, 1] */ export declare function legendreFit(xs: number[], ys: number[], degree: number): number[]; //# sourceMappingURL=interpolation.d.ts.map