Table of Contents

Class MathExpressionExtensions

Namespace
Utils.Mathematics.Expressions
Assembly
Utils.Mathematics.dll

Provides helper methods to derive lambda expressions using ExpressionDerivation<T>.

public static class MathExpressionExtensions
Inheritance
MathExpressionExtensions
Inherited Members

Methods

Derivate(LambdaExpression)

Computes the derivative of a single-parameter lambda expression with respect to its declared parameter. The scalar type is inferred from that parameter's CLR type instead of assuming double.

public static LambdaExpression Derivate(this LambdaExpression e)

Parameters

e LambdaExpression

Lambda expression to differentiate.

Returns

LambdaExpression

A lambda expression representing the derivative.

Derivate(LambdaExpression, ParameterExpression)

Computes the derivative of a lambda expression with respect to the exact declared parameter instance. Unlike the name-based overload, this resolves the differentiation variable unambiguously even when the parameter's Name is null or shared with another, unrelated parameter (see TODO-pass4 item #47). The scalar type is inferred from parameter's own CLR type instead of assuming double.

public static LambdaExpression Derivate(this LambdaExpression e, ParameterExpression parameter)

Parameters

e LambdaExpression

Lambda expression to differentiate.

parameter ParameterExpression

The exact parameter instance used as the differentiation variable.

Returns

LambdaExpression

A lambda expression representing the derivative.

Exceptions

NotSupportedException

Thrown when parameter's CLR type does not implement IFloatingPoint<TSelf>.

Derivate(LambdaExpression, string)

Computes the derivative of a lambda expression with respect to the specified parameter name. The scalar type is inferred from that parameter's CLR type instead of assuming double.

public static LambdaExpression Derivate(this LambdaExpression e, string paramName)

Parameters

e LambdaExpression

Lambda expression to differentiate.

paramName string

Name of the parameter used as the differentiation variable.

Returns

LambdaExpression

A lambda expression representing the derivative.

Exceptions

NotSupportedException

Thrown when paramName's CLR type does not implement IFloatingPoint<TSelf>.

Derivate<T>(LambdaExpression, ParameterExpression)

Computes the derivative of a lambda expression with respect to the exact declared parameter instance.

public static LambdaExpression Derivate<T>(this LambdaExpression e, ParameterExpression parameter) where T : IFloatingPoint<T>

Parameters

e LambdaExpression

Lambda expression to differentiate.

parameter ParameterExpression

The exact parameter instance used as the differentiation variable.

Returns

LambdaExpression

A lambda expression representing the derivative.

Type Parameters

T

Floating-point type used by derivative rules.

Derivate<T>(LambdaExpression, string)

Computes the derivative of a lambda expression with respect to the specified parameter name.

public static LambdaExpression Derivate<T>(this LambdaExpression e, string paramName) where T : IFloatingPoint<T>

Parameters

e LambdaExpression

Lambda expression to differentiate.

paramName string

Name of the parameter used as the differentiation variable.

Returns

LambdaExpression

A lambda expression representing the derivative.

Type Parameters

T

Floating-point type used by derivative rules.

Gradient(LambdaExpression)

Computes the gradient of a multi-parameter lambda expression as an array of partial-derivative expressions. Each entry i is the partial derivative with respect to the i-th parameter. All parameters must share the same CLR type, which is inferred instead of assuming double.

public static LambdaExpression[] Gradient(this LambdaExpression e)

Parameters

e LambdaExpression

Lambda expression to differentiate.

Returns

LambdaExpression[]

Array of lambda expressions representing each partial derivative; shares the same parameter list as e.

Exceptions

NotSupportedException

Thrown when e's parameters do not share a single CLR type, or that type does not implement IFloatingPoint<TSelf>.

Gradient<T>(LambdaExpression, params IEnumerable<ParameterExpression>)

Computes the partial derivatives of a lambda expression with respect to the specified exact parameter instances. Unlike the name-based overload, this resolves each differentiation variable unambiguously even when multiple targeted parameters share one name — including null for unnamed parameters (see TODO-pass4 item #47).

public static LambdaExpression[] Gradient<T>(this LambdaExpression e, params IEnumerable<ParameterExpression> parameters) where T : IFloatingPoint<T>

Parameters

e LambdaExpression

Lambda expression to differentiate.

parameters IEnumerable<ParameterExpression>

The exact parameter instances to differentiate with respect to.

Returns

LambdaExpression[]

Array of lambda expressions representing each partial derivative; shares the same parameter list as e.

Type Parameters

T

Floating-point type used by derivative rules.

Gradient<T>(LambdaExpression, params IEnumerable<string>)

Computes the partial derivatives of a lambda expression with respect to the specified parameter names.

public static LambdaExpression[] Gradient<T>(this LambdaExpression e, params IEnumerable<string> paramNames) where T : IFloatingPoint<T>

Parameters

e LambdaExpression

Lambda expression to differentiate.

paramNames IEnumerable<string>

Names of the parameters to differentiate with respect to.

Returns

LambdaExpression[]

Array of lambda expressions representing each partial derivative; shares the same parameter list as e.

Type Parameters

T

Floating-point type used by derivative rules.

Integrate(LambdaExpression)

Computes the integral of a single-parameter lambda expression with respect to its declared parameter. The scalar type is inferred from that parameter's CLR type instead of assuming double.

public static LambdaExpression Integrate(this LambdaExpression e)

Parameters

e LambdaExpression

Lambda expression to integrate.

Returns

LambdaExpression

A lambda expression representing the integral.

Exceptions

NotSupportedException

Thrown when the declared parameter's CLR type does not implement IFloatingPoint<TSelf>.

Integrate(LambdaExpression, ParameterExpression)

Computes the integral of a lambda expression with respect to the exact declared parameter instance. Unlike the name-based overload, this resolves the integration variable unambiguously even when the parameter's Name is null or shared with another, unrelated parameter (see TODO-pass4 item #47). The scalar type is inferred from parameter's own CLR type instead of assuming double.

public static LambdaExpression Integrate(this LambdaExpression e, ParameterExpression parameter)

Parameters

e LambdaExpression

Lambda expression to integrate.

parameter ParameterExpression

The exact parameter instance used as the integration variable.

Returns

LambdaExpression

A lambda expression representing the integral.

Exceptions

NotSupportedException

Thrown when parameter's CLR type does not implement IFloatingPoint<TSelf>.

Integrate<T>(LambdaExpression, ParameterExpression)

Computes the integral of a lambda expression with respect to the exact declared parameter instance.

public static LambdaExpression Integrate<T>(this LambdaExpression e, ParameterExpression parameter) where T : IFloatingPoint<T>

Parameters

e LambdaExpression

Lambda expression to integrate.

parameter ParameterExpression

The exact parameter instance used as the integration variable.

Returns

LambdaExpression

A lambda expression representing the integral.

Type Parameters

T

Floating-point type used by integration rules.

Integrate<T>(LambdaExpression, string)

Computes the integral of a lambda expression with respect to the specified parameter name.

public static LambdaExpression Integrate<T>(this LambdaExpression e, string paramName) where T : IFloatingPoint<T>

Parameters

e LambdaExpression

Lambda expression to integrate.

paramName string

Name of the parameter used as the integration variable.

Returns

LambdaExpression

A lambda expression representing the integral.

Type Parameters

T

Floating-point type used by integration rules.

TryDerivate<T>(LambdaExpression, string, bool)

Attempts to differentiate e with respect to the parameter named paramName without throwing, returning a structured SymbolicTransformationResult that distinguishes success (exact or numeric-fallback), unsupported expression, unsupported scalar operation, invalid input, and construction failure (see TODO-2026-07-11-pass3.md item #42). The throwing Derivate<T>(LambdaExpression, string) overload is unchanged.

public static SymbolicTransformationResult TryDerivate<T>(this LambdaExpression e, string paramName, bool allowNumericalFallback = false) where T : IFloatingPoint<T>

Parameters

e LambdaExpression

Lambda expression to differentiate.

paramName string

Name of the parameter used as the differentiation variable.

allowNumericalFallback bool

When true, unknown single-argument methods are approximated with a centered finite difference and the result reports IsExact as false; when false (default) such a method yields UnsupportedExpression.

Returns

SymbolicTransformationResult

A structured result describing the outcome.

Type Parameters

T

Floating-point type used by derivative rules.

TryIntegrate<T>(LambdaExpression, string)

Attempts to integrate e with respect to the parameter named paramName without throwing, returning a structured SymbolicTransformationResult (see TODO-2026-07-11-pass3.md item #42). A successful symbolic integral always reports IsExact as true (integration has no numeric fallback). The throwing Integrate<T>(LambdaExpression, string) overload is unchanged.

public static SymbolicTransformationResult TryIntegrate<T>(this LambdaExpression e, string paramName) where T : IFloatingPoint<T>

Parameters

e LambdaExpression

Lambda expression to integrate.

paramName string

Name of the parameter used as the integration variable.

Returns

SymbolicTransformationResult

A structured result describing the outcome.

Type Parameters

T

Floating-point type used by integration rules.