Table of Contents

Class ChebyshevSlider

Namespace
ChebyshevSharp
Assembly
ChebyshevSharp.dll

Chebyshev Sliding approximation for high-dimensional functions. Decomposes f(x₁, …, xₙ) into a sum of low-dimensional Chebyshev interpolants (slides) around a pivot point z: f(x) ≈ f(z) + Σᵢ [sᵢ(x_groupᵢ) - f(z)] where each slide sᵢ is a ChebyshevApproximation built on a subset of dimensions with the remaining dimensions fixed at z.

public class ChebyshevSlider
Inheritance
ChebyshevSlider
Inherited Members

Remarks

This trades accuracy for dramatically reduced build cost: instead of evaluating f at n₁ × n₂ × … × nₐ grid points (exponential), the slider evaluates the pivot once and then evaluates n₁ × n₂ + n₃ × n₄ + … slide-grid points (sum of products within each group). Reference: Ruiz & Zeron (2022), Ch. 7.

Constructors

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

Create a new ChebyshevSlider.

public ChebyshevSlider(Func<double[], object?, double> function, int numDimensions, double[][] domain, int[] nNodes, int[][] partition, double[] pivotPoint, int maxDerivativeOrder = 2, object? additionalData = null, int? nWorkers = null, IProgress<int>? progress = null)

Parameters

function Func<double[], object, double>

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

numDimensions int

Total number of input dimensions.

domain double[][]

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

nNodes int[]

Number of Chebyshev nodes per dimension.

partition int[][]

Grouping of dimension indices into slides. Each dimension must appear exactly once.

pivotPoint double[]

Reference point z around which slides are built.

maxDerivativeOrder int

Maximum derivative order to support (default 2).

additionalData object

Optional user data object threaded through every f(point, data) call during Build.

nWorkers int?

Number of parallel workers for function evaluation. null = sequential; -1 = ProcessorCount; positive = exact count.

progress IProgress<int>

Optional progress reporter; receives cumulative evaluation count across all slides.

Remarks

Thread safety: the user-supplied function must be thread-safe when nWorkers is non-null.

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 [lo, hi] pairs.

public double[][] Domain { get; }

Property Value

double[][]

Function

Function used by Build(bool). Null for objects restored from saved numerical state or created by transformation APIs.

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

Property Value

Func<double[], object, double>

MaxDerivativeOrder

Maximum supported derivative order.

public int MaxDerivativeOrder { get; }

Property Value

int

NNodes

Number of Chebyshev nodes per dimension.

public int[] NNodes { get; }

Property Value

int[]

NumDimensions

Number of input dimensions.

public int NumDimensions { get; }

Property Value

int

Partition

Grouping of dimension indices into slides.

public int[][] Partition { get; }

Property Value

int[][]

PivotPoint

Reference point z around which slides are built.

public double[] PivotPoint { get; }

Property Value

double[]

PivotValue

Function value at the pivot point: f(z).

public double PivotValue { get; }

Property Value

double

TotalBuildEvals

Total slide-grid evaluations used during build. Build(bool) also evaluates the pivot once.

public int TotalBuildEvals { get; }

Property Value

int

Methods

Build(bool)

Build all slides by evaluating the function at slide-specific grids. For each slide, dimensions outside the group are fixed at pivot values.

public void Build(bool verbose = true)

Parameters

verbose bool

If true, print build progress.

Exceptions

InvalidOperationException

If this object has no callable Function.

ArgumentException

If the function returns NaN or Infinity at the pivot or a slide grid point.

Clone()

Returns a deep copy of this slider. The source Function callable is not duplicated; clones cannot be rebuilt without re-supplying the function. All precomputed slides and state are deep-copied.

public ChebyshevSlider Clone()

Returns

ChebyshevSlider

A fully independent ChebyshevSlider with Function set to null.

ErrorEstimate()

Estimate the sliding approximation error. Returns the sum of per-slide Chebyshev error estimates. Note: this captures per-slide interpolation error only; cross-group interaction error inherent to the sliding decomposition is not included.

public double ErrorEstimate()

Returns

double

Estimated interpolation error (per-slide sum).

Eval(double[], int)

Evaluate at point using a previously-registered derivative id.

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

Parameters

point double[]

Evaluation point.

derivativeId int

Id returned by GetDerivativeId(int[]).

Returns

double

Interpolated value at the given derivative order.

Exceptions

ArgumentOutOfRangeException

Thrown when derivativeId has not been registered.

Eval(double[], int[])

Evaluate the slider approximation at a point. Uses Equation 7.5: f(x) ≈ f(z) + Σᵢ [sᵢ(x_groupᵢ) - f(z)]. For derivatives, only the slide containing that dimension contributes. Cross-group mixed partials are exactly zero.

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

Parameters

point double[]

Evaluation point inside the full declared domain.

derivativeOrder int[]

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

Returns

double

Approximated function value or derivative.

Exceptions

InvalidOperationException

If Build(bool) has not been called.

ArgumentException

If point or derivativeOrder has the wrong length.

ArgumentOutOfRangeException

If a point coordinate is outside the declared domain or a derivative order exceeds MaxDerivativeOrder.

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

Evaluate slider at multiple derivative orders for the same point.

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

Parameters

point double[]

Evaluation point inside the declared domain.

derivativeOrders int[][]

Each inner array specifies derivative order per dimension.

Returns

double[]

Results for each derivative order.

Exceptions

InvalidOperationException

If Build(bool) has not been called.

ArgumentException

If point or any derivative-order row has the wrong length.

ArgumentOutOfRangeException

If a point coordinate is outside the declared domain or a derivative order exceeds MaxDerivativeOrder.

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

Add new dimensions where the function is constant. Each new dimension becomes its own single-dim slide group with constant tensor values equal to PivotValue, so it contributes nothing to the sliding sum.

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

Parameters

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

Tuples of (dimIndex, bounds, nNodes).

Returns

ChebyshevSlider

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

GetAdditionalData()

Returns the user-supplied additionalData object passed to the constructor, or null if none was provided. Same value is threaded through every f(point, data) call during Build(bool).

public object? GetAdditionalData()

Returns

object

GetConstructorType()

Returns one of: "function" (Build), "load" (Load), or "clone" (Clone).

public string GetConstructorType()

Returns

string

GetDerivativeId(int[])

Register or look up a derivative-orders tuple. Returns a stable session-local int id for the same orders. Used in conjunction with the Eval(point, derivativeId) overload.

public int GetDerivativeId(int[] orders)

Parameters

orders int[]

Derivative order per dimension.

Returns

int

A stable int id for this orders tuple (0-based, assigned in registration order).

GetDescriptor()

Get the descriptor previously set via SetDescriptor(string); null if unset.

public string? GetDescriptor()

Returns

string

GetEvaluationPoints()

Flat row-major array of all slider evaluation points, expanded to full ndim using PivotPoint. Each slide's local coordinates are mapped to full-ndim space via the Partition and PivotPoint. Length is GetNumEvaluationPoints() * NumDimensions. Result is lazily built and cached internally.

public double[] GetEvaluationPoints()

Returns

double[]

A snapshot of full-ndim node coordinates, flattened in row-major order.

GetMaxDerivativeOrder()

Maximum derivative order this slider supports.

public int GetMaxDerivativeOrder()

Returns

int

GetNumEvaluationPoints()

Total number of evaluation points across all slides.

public int GetNumEvaluationPoints()

Returns

int

The sum of GetNumEvaluationPoints() from each slide.

GetUsedNs()

Per-dimension Chebyshev node counts actually used.

public int[] GetUsedNs()

Returns

int[]

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

Integrate the slider approximation over one or more dimensions. Uses the closed-form decomposition of the sliding sum: f(x) ≈ pv + Σ_i [s_i(x_{G_i}) - pv] Each slide's integral is computed via Integrate(int[]?, (double lo, double hi)[]?).

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

Parameters

dims int[]

Dimensions to integrate out. Null = all (full integration → scalar).

bounds (double lo, double hi)[]

Sub-interval bounds per dim (positional with sorted dims). Null = full domain.

Returns

object

A boxed double when every dim is integrated; otherwise a new ChebyshevSlider over surviving dims.

Exceptions

InvalidOperationException

If Build(bool) has not been called.

ArgumentException

If dims contains out-of-range indices, or bounds are invalid. Duplicate dims entries are silently deduplicated (matches Integrate(int[]?, (double lo, double hi)[]?)).

IsConstructionFinished()

True if Build(bool)/Load(string) completed.

public bool IsConstructionFinished()

Returns

bool

Load(string)

Load a previously saved slider from a JSON file.

public static ChebyshevSlider Load(string path)

Parameters

path string

Path to the saved file.

Returns

ChebyshevSlider

A fully functional slider with no callable source function attached.

Exceptions

InvalidDataException

If the file contains a malformed ChebyshevSlider state.

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

Find the maximum value of the slider along a specified dimension. See Minimize(int?, Dictionary<int, double>?) for parameter details.

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

Parameters

dim int?
fixedDims Dictionary<int, double>

Returns

(double lo, double hi)

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

Find the minimum value of the slider along a specified dimension. Reduces to a 1-D problem by slicing all other dimensions to their fixed values, then delegates to Minimize(int?, Dictionary<int, double>?).

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

Parameters

dim int?

Target dimension. For 1-D sliders, defaults to 0.

fixedDims Dictionary<int, double>

For multi-D, {dim_index: value} for all dims except dim.

Returns

(double lo, double hi)

Tuple (value, location) where value is the minimum and location is its coordinate in the target dimension.

Exceptions

InvalidOperationException

If Build(bool) has not been called.

ArgumentException

If validation fails.

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

Find all real roots of the slider along a specified dimension. Reduces to a 1-D problem by slicing all other dimensions to their fixed values, then delegates to Roots(int?, Dictionary<int, double>?).

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

Parameters

dim int?

Target dimension. For 1-D sliders, defaults to 0.

fixedDims Dictionary<int, double>

For multi-D sliders, {dim_index: value} for all dimensions except dim.

Returns

double[]

Sorted real root locations in the physical domain. Empty if no roots.

Exceptions

InvalidOperationException

If Build(bool) has not been called.

ArgumentException

If dim or fixedDims validation fails.

Save(string)

Save the built slider to a JSON file.

public void Save(string path)

Parameters

path string

Destination file path.

Exceptions

InvalidOperationException

If Build(bool) has not been called.

SetDescriptor(string)

Set a free-form descriptor string for this slider.

public void SetDescriptor(string descriptor)

Parameters

descriptor string

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

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

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

Parameters

sliceParams (int dimIndex, double value)[]

Tuples of (dimIndex, value).

Returns

ChebyshevSlider

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

ToReprString()

Compact repr string.

public string ToReprString()

Returns

string

ToString()

Multi-line display string.

public override string ToString()

Returns

string

Operators

operator +(ChebyshevSlider, ChebyshevSlider)

Pointwise addition of two sliders on the same grid.

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

Parameters

a ChebyshevSlider
b ChebyshevSlider

Returns

ChebyshevSlider

operator /(ChebyshevSlider, double)

Scalar division.

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

Parameters

a ChebyshevSlider
scalar double

Returns

ChebyshevSlider

operator *(ChebyshevSlider, double)

Scalar multiplication.

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

Parameters

a ChebyshevSlider
scalar double

Returns

ChebyshevSlider

operator *(double, ChebyshevSlider)

Scalar multiplication (scalar on left).

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

Parameters

scalar double
a ChebyshevSlider

Returns

ChebyshevSlider

operator -(ChebyshevSlider, ChebyshevSlider)

Pointwise subtraction of two sliders on the same grid.

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

Parameters

a ChebyshevSlider
b ChebyshevSlider

Returns

ChebyshevSlider

operator -(ChebyshevSlider)

Unary negation.

public static ChebyshevSlider operator -(ChebyshevSlider a)

Parameters

a ChebyshevSlider

Returns

ChebyshevSlider