Table of Contents

Class ExpressionIntegration<T>

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

Provides integration rules for mathematical expression trees.

public class ExpressionIntegration<T> : ExpressionTransformer where T : IFloatingPoint<T>

Type Parameters

T
Inheritance
ExpressionIntegration<T>
Derived
Inherited Members
Extension Methods

Constructors

ExpressionIntegration(ParameterExpression)

Initializes a new instance of the ExpressionIntegration<T> class that integrates with respect to a specific ParameterExpression instance rather than a name. Unlike the name-based constructor, this identifies the integration variable unambiguously even when parameter's Name is null or shared by another, unrelated parameter in the same lambda (see TODO-2026-07-11-pass4.md item #47).

public ExpressionIntegration(ParameterExpression parameter)

Parameters

parameter ParameterExpression

The exact parameter instance to integrate against.

ExpressionIntegration(string)

Initializes a new instance of the ExpressionIntegration<T> class.

public ExpressionIntegration(string parameterName)

Parameters

parameterName string

The name of the parameter serving as the integration variable.

Properties

ParameterName

Gets the name of the parameter used as the integration variable.

public string ParameterName { get; }

Property Value

string

Methods

Add(BinaryExpression, Expression, Expression)

Integrates a sum by integrating each operand individually.

[ExpressionSignature(ExpressionType.Add)]
public Expression Add(BinaryExpression e, Expression left, Expression right)

Parameters

e BinaryExpression

The binary expression representing the addition.

left Expression

The left operand of the addition.

right Expression

The right operand of the addition.

Returns

Expression

The integral of the sum expression.

Constant(ConstantExpression, object)

Integrates a numeric constant by multiplying it with the integration parameter.

[ExpressionSignature(ExpressionType.Constant)]
public Expression Constant(ConstantExpression e, object value)

Parameters

e ConstantExpression

The constant expression being transformed.

value object

The numeric value stored by the constant expression.

Returns

Expression

The integral expression for the constant value.

Convert(UnaryExpression, Expression)

Integrates the wrapped operand and re-applies the conversion's declared result type when the integral's type does not already match it, so the result expression stays type-consistent with the original conversion node.

[ExpressionSignature(ExpressionType.Convert)]
public Expression Convert(UnaryExpression e, Expression operand)

Parameters

e UnaryExpression

The conversion expression.

operand Expression

The wrapped operand.

Returns

Expression

The integral of the wrapped operand, converted back to e.Type if needed.

ConvertChecked(UnaryExpression, Expression)

Integrates the wrapped operand through a checked conversion. Checked conversions exist specifically to guard against narrowing/overflow, which has no well-defined symbolic integral; only a trivial same-type checked conversion is passed through, anything else is rejected instead of silently stripped.

[ExpressionSignature(ExpressionType.ConvertChecked)]
public Expression ConvertChecked(UnaryExpression e, Expression operand)

Parameters

e UnaryExpression

The checked conversion expression.

operand Expression

The wrapped operand.

Returns

Expression

The integral of the wrapped operand when the checked conversion is a same-type no-op.

Exceptions

NotSupportedException

Thrown when the checked conversion actually changes the type (a narrowing or otherwise non-trivial conversion), since integrating through it is not well-defined.

Cos(MethodCallExpression, BinaryExpression)

Integrates a cosine call whose argument is a scaled integration parameter.

[ExpressionCallSignature(typeof(double), "Cos")]
public Expression? Cos(MethodCallExpression e, BinaryExpression be)

Parameters

e MethodCallExpression

The method call expression representing double.Cos.

be BinaryExpression

The binary multiplication composing the cosine argument.

Returns

Expression

The integral of the cosine call when the pattern matches; otherwise, null.

Cos(MethodCallExpression, ParameterExpression)

Integrates a cosine call that directly uses the integration parameter.

[ExpressionCallSignature(typeof(double), "Cos")]
public Expression? Cos(MethodCallExpression e, ParameterExpression op)

Parameters

e MethodCallExpression

The method call expression representing double.Cos.

op ParameterExpression

The parameter passed to the cosine function.

Returns

Expression

The integral of the cosine call when the parameter matches; otherwise, null.

Cosh(MethodCallExpression, BinaryExpression)

Integrates a hyperbolic cosine call whose argument is a scaled integration parameter.

[ExpressionCallSignature(typeof(double), "Cosh")]
public Expression? Cosh(MethodCallExpression e, BinaryExpression be)

Parameters

e MethodCallExpression

The method call expression representing double.Cosh.

be BinaryExpression

The binary multiplication composing the hyperbolic cosine argument.

Returns

Expression

The integral of the hyperbolic cosine call when the pattern matches; otherwise, null.

Cosh(MethodCallExpression, ParameterExpression)

Integrates a hyperbolic cosine call that directly uses the integration parameter.

[ExpressionCallSignature(typeof(double), "Cosh")]
public Expression? Cosh(MethodCallExpression e, ParameterExpression op)

Parameters

e MethodCallExpression

The method call expression representing double.Cosh.

op ParameterExpression

The parameter passed to the hyperbolic cosine function.

Returns

Expression

The integral of the hyperbolic cosine call when the parameter matches; otherwise, null.

Divide(BinaryExpression, ConstantExpression, BinaryExpression)

Integrates a constant divided by a power expression representing x raised to n.

[ExpressionSignature(ExpressionType.Divide)]
public Expression? Divide(BinaryExpression e, ConstantExpression left, BinaryExpression right)

Parameters

e BinaryExpression

The division expression being transformed.

left ConstantExpression

The constant factor in the numerator.

right BinaryExpression

The power expression in the denominator.

Returns

Expression

The integral of the quotient when the pattern matches; otherwise, null.

Divide(BinaryExpression, ConstantExpression, MethodCallExpression)

Integrates a constant divided by a square root method call of the integration parameter.

[ExpressionSignature(ExpressionType.Divide)]
public Expression? Divide(BinaryExpression e, ConstantExpression left, MethodCallExpression right)

Parameters

e BinaryExpression

The division expression being transformed.

left ConstantExpression

The constant factor in the numerator.

right MethodCallExpression

The method call expected to represent double.Sqrt.

Returns

Expression

The integral of the expression when the pattern matches; otherwise, null.

Divide(BinaryExpression, ConstantExpression, ParameterExpression)

Integrates a constant divided by a parameter by applying the logarithm rule.

[ExpressionSignature(ExpressionType.Divide)]
public Expression? Divide(BinaryExpression e, ConstantExpression left, ParameterExpression right)

Parameters

e BinaryExpression

The division expression being transformed.

left ConstantExpression

The constant expression in the numerator.

right ParameterExpression

The parameter in the denominator.

Returns

Expression

The integral of the quotient expression.

Divide(BinaryExpression, Expression, ConstantExpression)

Integrates a quotient whose denominator is a constant by integrating the numerator.

[ExpressionSignature(ExpressionType.Divide)]
public Expression Divide(BinaryExpression e, Expression left, ConstantExpression right)

Parameters

e BinaryExpression

The binary expression representing the division.

left Expression

The expression in the numerator.

right ConstantExpression

The constant expression in the denominator.

Returns

Expression

The integral of the division expression.

Divide(BinaryExpression, UnaryExpression, BinaryExpression)

Integrates a converted numeric constant divided by a power expression in the denominator.

[ExpressionSignature(ExpressionType.Divide)]
public Expression? Divide(BinaryExpression e, UnaryExpression left, BinaryExpression right)

Parameters

e BinaryExpression

The division expression being transformed.

left UnaryExpression

The converted numeric constant in the numerator.

right BinaryExpression

The power expression in the denominator.

Returns

Expression

The integral of the quotient when the pattern matches; otherwise, null.

Divide(BinaryExpression, UnaryExpression, MethodCallExpression)

Integrates a converted numeric constant divided by a method call denominator.

[ExpressionSignature(ExpressionType.Divide)]
public Expression? Divide(BinaryExpression e, UnaryExpression left, MethodCallExpression right)

Parameters

e BinaryExpression

The division expression being transformed.

left UnaryExpression

The converted numeric constant in the numerator.

right MethodCallExpression

The method call denominator.

Returns

Expression

The integral of the quotient when the pattern matches; otherwise, null.

Divide(BinaryExpression, UnaryExpression, ParameterExpression)

Integrates a converted numeric constant divided by the integration parameter. This covers inputs where numeric normalization introduces a Convert node.

[ExpressionSignature(ExpressionType.Divide)]
public Expression? Divide(BinaryExpression e, UnaryExpression left, ParameterExpression right)

Parameters

e BinaryExpression

The division expression being transformed.

left UnaryExpression

The converted numeric constant in the numerator.

right ParameterExpression

The parameter in the denominator.

Returns

Expression

The integral of the quotient when the pattern matches; otherwise, null.

Exp(MethodCallExpression, BinaryExpression)

Integrates an exponential call whose argument is a scaled integration parameter.

[ExpressionCallSignature(typeof(double), "Exp")]
public Expression? Exp(MethodCallExpression e, BinaryExpression be)

Parameters

e MethodCallExpression

The method call expression representing double.Exp.

be BinaryExpression

The binary multiplication composing the exponential argument.

Returns

Expression

The integral of the exponential call when the pattern matches; otherwise, null.

Exp(MethodCallExpression, ParameterExpression)

Integrates an exponential call that directly uses the integration parameter.

[ExpressionCallSignature(typeof(double), "Exp")]
public Expression? Exp(MethodCallExpression e, ParameterExpression op)

Parameters

e MethodCallExpression

The method call expression representing double.Exp.

op ParameterExpression

The parameter passed to the exponential function.

Returns

Expression

The integral of the exponential call when the parameter matches; otherwise, null.

FinalizeExpression(Expression, Expression[])

Called when no integration rule matches the current node. Replaces the base transformer's generic Exception with a specific, node-tagged NotSupportedException, so a failed integration is distinguishable as "not integrable" (see TODO-2026-07-11-pass3.md item #42) and TryIntegrate<T>(LambdaExpression, string) can surface the offending node.

protected override Expression FinalizeExpression(Expression e, Expression[] parameters)

Parameters

e Expression

The expression that could not be integrated.

parameters Expression[]

Prepared child expressions (unused; no rule consumed them).

Returns

Expression

Never returns; always throws.

Exceptions

NotSupportedException

Always thrown, tagged with e.

Integrate(LambdaExpression)

Integrates a lambda expression with respect to the configured parameter.

public Expression Integrate(LambdaExpression e)

Parameters

e LambdaExpression

The lambda expression to integrate.

Returns

Expression

The integrated expression tree.

Exceptions

InvalidOperationException

Thrown when this instance was constructed with a parameter name and no parameter named ParameterName is found in e, or more than one distinct parameter shares that name (an ambiguous match that cannot be resolved by name alone). When this instance was instead constructed with an exact ParameterExpression instance, thrown when that instance is not one of e's declared parameters.

Log(MethodCallExpression, ParameterExpression)

Integrates a natural logarithm call whose argument is the integration parameter.

[ExpressionCallSignature(typeof(double), "Log")]
public Expression? Log(MethodCallExpression e, ParameterExpression p)

Parameters

e MethodCallExpression

The method call expression representing double.Log.

p ParameterExpression

The parameter passed to the logarithm.

Returns

Expression

The integral of the logarithm when the parameter matches; otherwise, null.

Log10(MethodCallExpression, ParameterExpression)

Integrates a base-10 logarithm call that uses the integration parameter.

[ExpressionCallSignature(typeof(double), "Log10")]
public Expression? Log10(MethodCallExpression e, ParameterExpression p)

Parameters

e MethodCallExpression

The method call expression representing double.Log10.

p ParameterExpression

The parameter passed to the logarithm.

Returns

Expression

The integral of the logarithm when the parameter matches; otherwise, null.

Multiply(BinaryExpression, ConstantExpression, Expression)

Integrates a product of a constant and an expression by treating the constant as a factor.

[ExpressionSignature(ExpressionType.Multiply)]
public Expression Multiply(BinaryExpression e, ConstantExpression left, Expression right)

Parameters

e BinaryExpression

The binary expression representing the multiplication.

left ConstantExpression

The constant factor on the left side.

right Expression

The expression on the right side.

Returns

Expression

The integral of the product.

Multiply(BinaryExpression, Expression, ConstantExpression)

Integrates a product of an expression and a constant by treating the constant as a factor.

[ExpressionSignature(ExpressionType.Multiply)]
public Expression Multiply(BinaryExpression e, Expression left, ConstantExpression right)

Parameters

e BinaryExpression

The binary expression representing the multiplication.

left Expression

The non-constant expression on the left side.

right ConstantExpression

The constant factor on the right side.

Returns

Expression

The integral of the product.

Negate(UnaryExpression, Expression)

Integrates a negated expression by negating the integral of its operand.

[ExpressionSignature(ExpressionType.Negate)]
public Expression Negate(UnaryExpression e, Expression operand)

Parameters

e UnaryExpression

The unary expression representing the negation.

operand Expression

The operand that is being negated.

Returns

Expression

The integral of the negated expression.

Parameter(ParameterExpression)

Integrates a parameter expression, returning x^2/2 when it matches the integration variable.

[ExpressionSignature(ExpressionType.Parameter)]
public Expression Parameter(ParameterExpression e)

Parameters

e ParameterExpression

The parameter expression that may match the integration variable.

Returns

Expression

The integral of the parameter expression.

Power(BinaryExpression, ParameterExpression, ConstantExpression)

Integrates a power expression whose base is the integration parameter.

[ExpressionSignature(ExpressionType.Power)]
public Expression? Power(BinaryExpression e, ParameterExpression p, ConstantExpression expo)

Parameters

e BinaryExpression

The power expression being transformed.

p ParameterExpression

The parameter expression that serves as the base.

expo ConstantExpression

The constant exponent applied to the base.

Returns

Expression

The integral of the power expression when the pattern matches; otherwise, null.

Power(BinaryExpression, ParameterExpression, UnaryExpression)

Integrates a power expression whose exponent is wrapped in a numeric conversion.

[ExpressionSignature(ExpressionType.Power)]
public Expression? Power(BinaryExpression e, ParameterExpression p, UnaryExpression expo)

Parameters

e BinaryExpression

The power expression being transformed.

p ParameterExpression

The parameter expression that serves as the base.

expo UnaryExpression

The converted exponent expression.

Returns

Expression

The integral of the power expression when the pattern matches; otherwise, null.

PowerMathCall(MethodCallExpression, ParameterExpression, ConstantExpression)

Integrates a Pow(double, double) call whose base is the integration parameter and exponent is a numeric constant.

[ExpressionCallSignature(typeof(Math), "Pow")]
public Expression? PowerMathCall(MethodCallExpression e, ParameterExpression p, ConstantExpression expo)

Parameters

e MethodCallExpression

The method call expression representing Math.Pow.

p ParameterExpression

The parameter expression that serves as the base.

expo ConstantExpression

The constant numeric exponent.

Returns

Expression

The integral of the power expression when the pattern matches; otherwise, null.

PowerMathCall(MethodCallExpression, ParameterExpression, UnaryExpression)

Integrates a Pow(double, double) call whose base is the integration parameter and exponent is a convert-wrapped numeric constant.

[ExpressionCallSignature(typeof(Math), "Pow")]
public Expression? PowerMathCall(MethodCallExpression e, ParameterExpression p, UnaryExpression expo)

Parameters

e MethodCallExpression

The method call expression representing Math.Pow.

p ParameterExpression

The parameter expression that serves as the base.

expo UnaryExpression

The converted exponent expression.

Returns

Expression

The integral of the power expression when the pattern matches; otherwise, null.

Sin(MethodCallExpression, BinaryExpression)

Integrates a sine call whose argument is a scaled integration parameter.

[ExpressionCallSignature(typeof(double), "Sin")]
public Expression? Sin(MethodCallExpression e, BinaryExpression be)

Parameters

e MethodCallExpression

The method call expression representing double.Sin.

be BinaryExpression

The binary multiplication composing the sine argument.

Returns

Expression

The integral of the sine call when the pattern matches; otherwise, null.

Sin(MethodCallExpression, ParameterExpression)

Integrates a sine call that directly uses the integration parameter.

[ExpressionCallSignature(typeof(double), "Sin")]
public Expression? Sin(MethodCallExpression e, ParameterExpression op)

Parameters

e MethodCallExpression

The method call expression representing double.Sin.

op ParameterExpression

The parameter passed to the sine function.

Returns

Expression

The integral of the sine call when the parameter matches; otherwise, null.

Sinh(MethodCallExpression, BinaryExpression)

Integrates a hyperbolic sine call whose argument is a scaled integration parameter.

[ExpressionCallSignature(typeof(double), "Sinh")]
public Expression? Sinh(MethodCallExpression e, BinaryExpression be)

Parameters

e MethodCallExpression

The method call expression representing double.Sinh.

be BinaryExpression

The binary multiplication composing the hyperbolic sine argument.

Returns

Expression

The integral of the hyperbolic sine call when the pattern matches; otherwise, null.

Sinh(MethodCallExpression, ParameterExpression)

Integrates a hyperbolic sine call that directly uses the integration parameter.

[ExpressionCallSignature(typeof(double), "Sinh")]
public Expression? Sinh(MethodCallExpression e, ParameterExpression op)

Parameters

e MethodCallExpression

The method call expression representing double.Sinh.

op ParameterExpression

The parameter passed to the hyperbolic sine function.

Returns

Expression

The integral of the hyperbolic sine call when the parameter matches; otherwise, null.

Subtract(BinaryExpression, Expression, Expression)

Integrates a subtraction by integrating both operands and subtracting the results.

[ExpressionSignature(ExpressionType.Subtract)]
public Expression Subtract(BinaryExpression e, Expression left, Expression right)

Parameters

e BinaryExpression

The binary expression representing the subtraction.

left Expression

The expression on the left side of the operator.

right Expression

The expression on the right side of the operator.

Returns

Expression

The integral of the subtraction expression.

Tan(MethodCallExpression, BinaryExpression)

Integrates a tangent call whose argument is a scaled integration parameter.

[ExpressionCallSignature(typeof(double), "Tan")]
public Expression? Tan(MethodCallExpression e, BinaryExpression be)

Parameters

e MethodCallExpression

The method call expression representing double.Tan.

be BinaryExpression

The binary multiplication composing the tangent argument.

Returns

Expression

The integral of the tangent call when the pattern matches; otherwise, null.

Tan(MethodCallExpression, ParameterExpression)

Integrates a tangent call that directly uses the integration parameter.

[ExpressionCallSignature(typeof(double), "Tan")]
public Expression? Tan(MethodCallExpression e, ParameterExpression op)

Parameters

e MethodCallExpression

The method call expression representing double.Tan.

op ParameterExpression

The parameter passed to the tangent function.

Returns

Expression

The integral of the tangent call when the parameter matches; otherwise, null.

Tanh(MethodCallExpression, BinaryExpression)

Integrates a hyperbolic tangent call whose argument is a scaled integration parameter.

[ExpressionCallSignature(typeof(double), "Tanh")]
public Expression? Tanh(MethodCallExpression e, BinaryExpression be)

Parameters

e MethodCallExpression

The method call expression representing double.Tanh.

be BinaryExpression

The binary multiplication composing the hyperbolic tangent argument.

Returns

Expression

The integral of the hyperbolic tangent call when the pattern matches; otherwise, null.

Tanh(MethodCallExpression, ParameterExpression)

Integrates a hyperbolic tangent call that directly uses the integration parameter.

[ExpressionCallSignature(typeof(double), "Tanh")]
public Expression? Tanh(MethodCallExpression e, ParameterExpression op)

Parameters

e MethodCallExpression

The method call expression representing double.Tanh.

op ParameterExpression

The parameter passed to the hyperbolic tangent function.

Returns

Expression

The integral of the hyperbolic tangent call when the parameter matches; otherwise, null.