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
parameterParameterExpressionThe exact parameter instance to integrate against.
ExpressionIntegration(string)
Initializes a new instance of the ExpressionIntegration<T> class.
public ExpressionIntegration(string parameterName)
Parameters
parameterNamestringThe 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
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
eBinaryExpressionThe binary expression representing the addition.
leftExpressionThe left operand of the addition.
rightExpressionThe 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
eConstantExpressionThe constant expression being transformed.
valueobjectThe 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
eUnaryExpressionThe conversion expression.
operandExpressionThe wrapped operand.
Returns
- Expression
The integral of the wrapped operand, converted back to
e.Typeif 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
eUnaryExpressionThe checked conversion expression.
operandExpressionThe 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
eMethodCallExpressionThe method call expression representing
double.Cos.beBinaryExpressionThe 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
eMethodCallExpressionThe method call expression representing
double.Cos.opParameterExpressionThe 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
eMethodCallExpressionThe method call expression representing
double.Cosh.beBinaryExpressionThe 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
eMethodCallExpressionThe method call expression representing
double.Cosh.opParameterExpressionThe 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
eBinaryExpressionThe division expression being transformed.
leftConstantExpressionThe constant factor in the numerator.
rightBinaryExpressionThe 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
eBinaryExpressionThe division expression being transformed.
leftConstantExpressionThe constant factor in the numerator.
rightMethodCallExpressionThe 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
eBinaryExpressionThe division expression being transformed.
leftConstantExpressionThe constant expression in the numerator.
rightParameterExpressionThe 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
eBinaryExpressionThe binary expression representing the division.
leftExpressionThe expression in the numerator.
rightConstantExpressionThe 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
eBinaryExpressionThe division expression being transformed.
leftUnaryExpressionThe converted numeric constant in the numerator.
rightBinaryExpressionThe 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
eBinaryExpressionThe division expression being transformed.
leftUnaryExpressionThe converted numeric constant in the numerator.
rightMethodCallExpressionThe 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
eBinaryExpressionThe division expression being transformed.
leftUnaryExpressionThe converted numeric constant in the numerator.
rightParameterExpressionThe 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
eMethodCallExpressionThe method call expression representing
double.Exp.beBinaryExpressionThe 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
eMethodCallExpressionThe method call expression representing
double.Exp.opParameterExpressionThe 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
eExpressionThe expression that could not be integrated.
parametersExpression[]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
eLambdaExpressionThe 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 ofe'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
eMethodCallExpressionThe method call expression representing
double.Log.pParameterExpressionThe 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
eMethodCallExpressionThe method call expression representing
double.Log10.pParameterExpressionThe 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
eBinaryExpressionThe binary expression representing the multiplication.
leftConstantExpressionThe constant factor on the left side.
rightExpressionThe 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
eBinaryExpressionThe binary expression representing the multiplication.
leftExpressionThe non-constant expression on the left side.
rightConstantExpressionThe 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
eUnaryExpressionThe unary expression representing the negation.
operandExpressionThe 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
eParameterExpressionThe 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
eBinaryExpressionThe power expression being transformed.
pParameterExpressionThe parameter expression that serves as the base.
expoConstantExpressionThe 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
eBinaryExpressionThe power expression being transformed.
pParameterExpressionThe parameter expression that serves as the base.
expoUnaryExpressionThe 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
eMethodCallExpressionThe method call expression representing
Math.Pow.pParameterExpressionThe parameter expression that serves as the base.
expoConstantExpressionThe 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
eMethodCallExpressionThe method call expression representing
Math.Pow.pParameterExpressionThe parameter expression that serves as the base.
expoUnaryExpressionThe 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
eMethodCallExpressionThe method call expression representing
double.Sin.beBinaryExpressionThe 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
eMethodCallExpressionThe method call expression representing
double.Sin.opParameterExpressionThe 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
eMethodCallExpressionThe method call expression representing
double.Sinh.beBinaryExpressionThe 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
eMethodCallExpressionThe method call expression representing
double.Sinh.opParameterExpressionThe 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
eBinaryExpressionThe binary expression representing the subtraction.
leftExpressionThe expression on the left side of the operator.
rightExpressionThe 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
eMethodCallExpressionThe method call expression representing
double.Tan.beBinaryExpressionThe 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
eMethodCallExpressionThe method call expression representing
double.Tan.opParameterExpressionThe 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
eMethodCallExpressionThe method call expression representing
double.Tanh.beBinaryExpressionThe 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
eMethodCallExpressionThe method call expression representing
double.Tanh.opParameterExpressionThe parameter passed to the hyperbolic tangent function.
Returns
- Expression
The integral of the hyperbolic tangent call when the parameter matches; otherwise, null.