Table of Contents

Class ChebyshevSpline

Namespace
ChebyshevSharp
Assembly
ChebyshevSharp.dll

Piecewise Chebyshev interpolation with user-specified knots. Partitions the domain into sub-intervals at interior knots and builds an independent ChebyshevApproximation on each piece. Query points are routed to the appropriate piece for evaluation.

public class ChebyshevSpline
Inheritance
ChebyshevSpline
Inherited Members

Remarks

This is the correct approach when the target function has known singularities (kinks, discontinuities) at specific locations: place knots at those locations so that each piece is smooth, restoring spectral convergence.

Constructors

ChebyshevSpline(Func<double[], object?, double>, int, double[][], int[], double[][], int)

Create a new ChebyshevSpline.

public ChebyshevSpline(Func<double[], object?, double> function, int numDimensions, double[][] domain, int[] nNodes, double[][] knots, int maxDerivativeOrder = 2)

Parameters

function Func<double[], object, double>

Function to approximate: f(point, data) -> double.

numDimensions int

Number of input dimensions.

domain double[][]

Bounds for each dimension as double[ndim][2].

nNodes int[]

Number of Chebyshev nodes per dimension per piece.

knots double[][]

Interior knots for each dimension. Empty array for no knots.

maxDerivativeOrder int

Maximum derivative order to support (default 2).

Properties

BuildTime

Wall-clock time (seconds) for the most recent Build() call.

public double BuildTime { get; }

Property Value

double

Built

Whether Build() has been called.

public bool Built { get; }

Property Value

bool

Domain

Domain bounds for each dimension, as list of [lo, hi].

public double[][] Domain { get; }

Property Value

double[][]

Function

The function to approximate. Null after load or from_values.

public Func<double[], object?, double>? Function { get; }

Property Value

Func<double[], object, double>

Knots

Interior knots per dimension. Each sub-array is sorted ascending.

public double[][] Knots { get; }

Property Value

double[][]

MaxDerivativeOrder

Maximum supported derivative order.

public int MaxDerivativeOrder { get; }

Property Value

int

NNodes

Number of Chebyshev nodes per dimension per piece.

public int[] NNodes { get; }

Property Value

int[]

NumDimensions

Number of input dimensions.

public int NumDimensions { get; }

Property Value

int

NumPieces

Total number of pieces (Cartesian product of per-dimension intervals).

public int NumPieces { get; }

Property Value

int

TotalBuildEvals

Total number of function evaluations used during build.

public int TotalBuildEvals { get; }

Property Value

int

Methods

Build(bool)

Build all pieces by evaluating the function on each sub-domain.

public void Build(bool verbose = true)

Parameters

verbose bool

If true, print build progress.

ErrorEstimate()

Estimate the supremum-norm interpolation error. Returns the maximum error estimate across all pieces.

public double ErrorEstimate()

Returns

double

Eval(double[], int[])

Evaluate the spline approximation at a point.

public double Eval(double[] point, int[] derivativeOrder)

Parameters

point double[]

Evaluation point in the full domain.

derivativeOrder int[]

Derivative order for each dimension (0 = function value).

Returns

double

Approximated function value or derivative.

EvalBatch(double[][], int[])

Evaluate at multiple points, grouping by piece for efficiency.

public double[] EvalBatch(double[][] points, int[] derivativeOrder)

Parameters

points double[][]

Evaluation points (N x numDimensions).

derivativeOrder int[]

Derivative order for each dimension.

Returns

double[]

Approximated values at each point.

EvalMulti(double[], int[][])

Evaluate multiple derivative orders at one point, sharing weights.

public double[] EvalMulti(double[] point, int[][] derivativeOrders)

Parameters

point double[]

Evaluation point in the full domain.

derivativeOrders int[][]

Each inner array specifies derivative order per dimension.

Returns

double[]

One result per derivative order.

Extrude(params (int dimIndex, double[] bounds, int nNodes)[])

Add new dimensions where the function is constant.

public ChebyshevSpline Extrude(params (int dimIndex, double[] bounds, int nNodes)[] extrudeParams)

Parameters

extrudeParams (int dimIndex, double[] bounds, int nNodes)[]

Tuples of (dimIndex, bounds, nNodes).

Returns

ChebyshevSpline

A new, higher-dimensional spline (already built).

FromValues(double[][], int, double[][], int[], double[][], int)

Create a spline from pre-computed function values on each piece.

public static ChebyshevSpline FromValues(double[][] pieceValues, int numDimensions, double[][] domain, int[] nNodes, double[][] knots, int maxDerivativeOrder = 2)

Parameters

pieceValues double[][]

Function values for each piece. Length must equal total pieces.

numDimensions int

Number of dimensions.

domain double[][]

Lower and upper bounds for each dimension.

nNodes int[]

Number of Chebyshev nodes per dimension per piece.

knots double[][]

Knot positions for each dimension.

maxDerivativeOrder int

Maximum derivative order (default 2).

Returns

ChebyshevSpline

A fully built spline with Function=null.

Integrate(int[]?, (double lo, double hi)[]?)

Integrate the spline over one or more dimensions.

public object Integrate(int[]? dims = null, (double lo, double hi)[]? bounds = null)

Parameters

dims int[]

Dimensions to integrate out. Null = all.

bounds (double lo, double hi)[]

Sub-interval bounds per dim. Null = full domain.

Returns

object

Scalar if all dims integrated, otherwise a lower-dimensional spline.

Load(string)

Load a previously saved spline from a file.

public static ChebyshevSpline Load(string path)

Parameters

path string

Path to the saved file.

Returns

ChebyshevSpline

The restored spline.

Maximize(int?, Dictionary<int, double>?)

Find the maximum value of the spline along a dimension.

public (double value, double location) Maximize(int? dim = null, Dictionary<int, double>? fixedDims = null)

Parameters

dim int?

Dimension along which to maximize.

fixedDims Dictionary<int, double>

For multi-D, dict of dim_index -> value for all other dims.

Returns

(double value, double location)

Tuple of (value, location).

Minimize(int?, Dictionary<int, double>?)

Find the minimum value of the spline along a dimension.

public (double value, double location) Minimize(int? dim = null, Dictionary<int, double>? fixedDims = null)

Parameters

dim int?

Dimension along which to minimize.

fixedDims Dictionary<int, double>

For multi-D, dict of dim_index -> value for all other dims.

Returns

(double value, double location)

Tuple of (value, location).

Nodes(int, double[][], int[], double[][])

Generate Chebyshev nodes for every piece without evaluating any function.

public static SplineNodeInfo Nodes(int numDimensions, double[][] domain, int[] nNodes, double[][] knots)

Parameters

numDimensions int

Number of dimensions.

domain double[][]

Lower and upper bounds for each dimension.

nNodes int[]

Number of Chebyshev nodes per dimension per piece.

knots double[][]

Knot positions for each dimension (may be empty).

Returns

SplineNodeInfo

A SplineNodeInfo with per-piece node info.

Roots(int?, Dictionary<int, double>?)

Find all roots of the spline along a specified dimension.

public double[] Roots(int? dim = null, Dictionary<int, double>? fixedDims = null)

Parameters

dim int?

Dimension along which to find roots.

fixedDims Dictionary<int, double>

For multi-D, dict of dim_index -> value for all other dims.

Returns

double[]

Sorted array of root locations.

Save(string)

Save the built spline to a file using JSON serialization.

public void Save(string path)

Parameters

path string

Destination file path.

Slice(params (int dimIndex, double value)[])

Fix one or more dimensions at given values, reducing dimensionality.

public ChebyshevSpline Slice(params (int dimIndex, double value)[] sliceParams)

Parameters

sliceParams (int dimIndex, double value)[]

Tuples of (dimIndex, value).

Returns

ChebyshevSpline

A new, lower-dimensional spline (already built).

ToReprString()

Compact string representation.

public string ToReprString()

Returns

string

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

Operators

operator +(ChebyshevSpline, ChebyshevSpline)

Add two splines with the same grid and knots.

public static ChebyshevSpline operator +(ChebyshevSpline a, ChebyshevSpline b)

Parameters

a ChebyshevSpline
b ChebyshevSpline

Returns

ChebyshevSpline

operator /(ChebyshevSpline, double)

Divide spline by a scalar.

public static ChebyshevSpline operator /(ChebyshevSpline a, double scalar)

Parameters

a ChebyshevSpline
scalar double

Returns

ChebyshevSpline

operator *(ChebyshevSpline, double)

Multiply spline by a scalar.

public static ChebyshevSpline operator *(ChebyshevSpline a, double scalar)

Parameters

a ChebyshevSpline
scalar double

Returns

ChebyshevSpline

operator *(double, ChebyshevSpline)

Multiply scalar by spline.

public static ChebyshevSpline operator *(double scalar, ChebyshevSpline a)

Parameters

scalar double
a ChebyshevSpline

Returns

ChebyshevSpline

operator -(ChebyshevSpline, ChebyshevSpline)

Subtract two splines with the same grid and knots.

public static ChebyshevSpline operator -(ChebyshevSpline a, ChebyshevSpline b)

Parameters

a ChebyshevSpline
b ChebyshevSpline

Returns

ChebyshevSpline

operator -(ChebyshevSpline)

Negate spline.

public static ChebyshevSpline operator -(ChebyshevSpline a)

Parameters

a ChebyshevSpline

Returns

ChebyshevSpline