Mathematical functions and numerical integration

The escape.core.math module provides mathematical functions and numerical integration capabilities for working with functors, parameters, and variables.

Mathematical Functions

The module includes common mathematical functions that can operate on various input types (float, int, parameter_obj, functor_obj, cplx_functor_obj, or variable_obj):

  • Trigonometric: sin, cos, tan

  • Hyperbolic: sinh, cosh, tanh

  • Exponential and Logarithmic: exp, log, log10

  • Other: sqrt, abs, erf

  • Special Functions: tgamma, gamma_p, gamma_q, cyl_bessel_j

Each function returns an appropriate type (parameter_obj, functor_obj, or cplx_functor_obj) based on the input type.

Numerical Integration

The module provides numerical integration capabilities through the integral() function, which supports:

  • Definite integration with fixed or variable limits

  • Gauss-Kronrod quadrature with configurable points (7, 15, 21, 31, 51, or 61)

  • Adaptive integration with error control

  • Integration of both real and complex functions

Interpolation

Linear interpolation is available through the linterp() function, which creates piecewise linear interpolants from discrete data points.

Examples

Basic mathematical operations: >>> x = Variable(‘x’) >>> f = sin(x) # Creates a functor representing sin(x) >>> g = exp(x) # Creates a functor representing exp(x)

Integration: >>> result = integral(f, x, 0, 1) # Integrates sin(x) from 0 to 1

See Also

escape.core.functor : Core functor functionality escape.core.objects : Basic object definitions

escape.core.math.abs(obj: Union[float, int, parameter_obj, functor_obj, cplx_functor_obj, variable_obj]) Union[parameter_obj, functor_obj]

Returns a functor or parameter which computes an absolute value.

Args:

obj: Input argument - can be float, int, parameter_obj, functor_obj, cplx_functor_obj or variable

Returns:

parameter_obj or functor_obj depending on input type

Raises:

TypeError: If obj is not one of the supported types

escape.core.math.arg(obj: Union[functor_obj, cplx_functor_obj, variable_obj]) functor_obj

Returns a functor which computes the arg value.

Args:

obj: Input argument - can be functor_obj, cplx_functor_obj or variable

Returns:

functor_obj

Raises:

TypeError: If obj is not one of the supported types

escape.core.math.conj(obj: Union[functor_obj, cplx_functor_obj, variable_obj]) cplx_functor_obj

Returns a functor which computes conjugate of obj.

Args:

obj: Input argument - can be functor_obj, cplx_functor_obj or variable

Returns:

cplx_functor_obj

Raises:

TypeError: If obj is not one of the supported types

escape.core.math.cos(obj: Union[float, int, parameter_obj, functor_obj, cplx_functor_obj, variable_obj]) Union[parameter_obj, functor_obj, cplx_functor_obj]

Returns a functor or parameter which computes a cosine value.

Args:

obj: Input argument - can be float, int, parameter_obj, functor_obj, cplx_functor_obj or variable

Returns:

parameter_obj, functor_obj or cplx_functor_obj depending on input type

Raises:

TypeError: If obj is not one of the supported types

escape.core.math.cosh(obj: Union[float, int, parameter_obj, functor_obj, cplx_functor_obj, variable_obj]) Union[parameter_obj, functor_obj, cplx_functor_obj]

Returns a functor or parameter which computes a hyperbolic cosine value.

Args:

obj: Input argument - can be float, int, parameter_obj, functor_obj, cplx_functor_obj or variable

Returns:

parameter_obj, functor_obj or cplx_functor_obj depending on input type

Raises:

TypeError: If obj is not one of the supported types

escape.core.math.cyl_bessel_j(a: Union[float, parameter_obj], z: Union[float, int, parameter_obj, functor_obj, variable_obj, str]) Union[parameter_obj, functor_obj]

Returns a functor or parameter which computes the cylindrical Bessel function of the first kind.

Args:

a: Order of the Bessel function - can be float or parameter_obj z: Input argument - can be float, int, parameter_obj, functor_obj, variable_obj or str

Returns:

parameter_obj or functor_obj depending on input type

Raises:

TypeError: If inputs are not of supported types

escape.core.math.erf(obj: Union[float, int, parameter_obj, functor_obj, variable_obj]) Union[parameter_obj, functor_obj]

Returns a functor or parameter which computes an error function value.

Args:

obj: Input argument - can be float, int, parameter_obj, functor_obj or variable

Returns:

parameter_obj or functor_obj depending on input type

Raises:

TypeError: If obj is not one of the supported types

escape.core.math.exp(obj: Union[float, int, parameter_obj, functor_obj, cplx_functor_obj, variable_obj]) Union[parameter_obj, functor_obj, cplx_functor_obj]

Returns a functor or parameter which computes an exponential function value.

Args:

obj: Input argument - can be float, int, parameter_obj, functor_obj, cplx_functor_obj or variable

Returns:

parameter_obj, functor_obj or cplx_functor_obj depending on input type

Raises:

TypeError: If obj is not one of the supported types

escape.core.math.gamma_p(a: Union[float, parameter_obj], z: Union[float, int, parameter_obj, functor_obj, variable_obj, str], normalized: bool = True) Union[parameter_obj, functor_obj]

Returns a functor or parameter which computes the lower incomplete gamma function.

Args:

a: Parameter a - can be float or parameter_obj z: Input argument - can be float, int, parameter_obj, functor_obj, variable_obj or str normalized: If True, output is normalized to [0,1] range

Returns:

parameter_obj or functor_obj depending on input type

Raises:

TypeError: If inputs are not of supported types

escape.core.math.gamma_q(a: Union[float, parameter_obj], z: Union[float, int, parameter_obj, functor_obj, variable_obj, str], normalized: bool = True) Union[parameter_obj, functor_obj]

Returns a functor or parameter which computes the upper incomplete gamma function.

Args:

a: Parameter a - can be float or parameter_obj z: Input argument - can be float, int, parameter_obj, functor_obj, variable_obj or str normalized: If True, output is normalized to [0,1] range

Returns:

parameter_obj or functor_obj depending on input type

Raises:

TypeError: If inputs are not of supported types

escape.core.math.imag(obj: Union[functor_obj, cplx_functor_obj, variable_obj]) functor_obj

Returns a functor which computes imaginary part of obj.

Args:

obj: Input argument - can be functor_obj, cplx_functor_obj or variable

Returns:

functor_obj

Raises:

TypeError: If obj is not one of the supported types

escape.core.math.integral(fun: Union[functor_obj, parameter_obj], x: Union[variable_obj, parameter_obj], a: Union[int, float, parameter_obj], b: Union[int, float, parameter_obj], numpoints: int = 7, epsabs: Optional[float] = None, epsrel: Optional[float] = None, maxiter: Optional[int] = None) Union[functor_obj, parameter_obj]

Returns functor which computes a result of definite integral.

Computes the definite integral:

\[I = \int_a^b f(x)dx\]

where x is a variable or parameter.

Args:

fun: The function to integrate - functor_obj or parameter_obj with variable/parameter x x: Integration variable - variable_obj or parameter_obj a: Lower integration limit - parameter_obj, functor_obj, variable_obj or numeric value b: Upper integration limit - parameter_obj, functor_obj, variable_obj or numeric value numpoints: Number of points for Gauss-Kronrod quadrature (7, 15, 21, 31, 51, or 61) epsabs: Absolute error tolerance for adaptive integration (default 1e-5) epsrel: Relative error tolerance for adaptive integration (default 0) maxiter: Maximum iterations for adaptive integration (default None = no adaptive integration)

Returns:

functor_obj or parameter_obj depending on input types

Raises:

TypeError: If inputs have unsupported types ValueError: If numpoints is not a supported value

escape.core.math.linterp(x: Union[variable_obj, functor_obj], xp: np.ndarray, yp: np.ndarray) functor_obj

One-dimensional linear interpolation functor.

Creates a piecewise linear interpolant from discrete data points (xp, yp), evaluated at values returned by x.

Args:

x: The points to interpolate at - functor_obj or variable_obj xp: Array of x-coordinates of data points, must be sorted ascending yp: Array of y-coordinates of data points

Returns:

functor_obj representing the interpolated function

Raises:

TypeError: If x has unsupported type

New in version 0.9.1.

escape.core.math.log(obj: Union[float, int, parameter_obj, functor_obj, variable_obj]) Union[parameter_obj, functor_obj]

Returns a functor or parameter which computes a natural logarithm value.

Args:

obj: Input argument - can be float, int, parameter_obj, functor_obj or variable

Returns:

parameter_obj or functor_obj depending on input type

Raises:

TypeError: If obj is not one of the supported types

escape.core.math.log10(obj: Union[float, int, parameter_obj, functor_obj, variable_obj]) Union[parameter_obj, functor_obj]

Returns a functor or parameter which computes a decimal logarithm value.

Args:

obj: Input argument - can be float, int, parameter_obj, functor_obj or variable

Returns:

parameter_obj or functor_obj depending on input type

Raises:

TypeError: If obj is not one of the supported types

escape.core.math.max(obj1: Union[float, int, parameter_obj, functor_obj, variable_obj], obj2: Union[float, int, parameter_obj, functor_obj, variable_obj]) Union[parameter_obj, functor_obj]

Returns a functor or parameter which computes the largest value for two arguments.

Args:

obj1: Input argument 1 - can be float, int, parameter_obj, functor_obj or variable obj2: Input argument 2 - can be float, int, parameter_obj, functor_obj or variable

Returns:

parameter_obj or functor_obj depending on input types

Raises:

TypeError: If obj1 or obj2 are not one of the supported types

escape.core.math.min(obj1: Union[float, int, parameter_obj, functor_obj, variable_obj], obj2: Union[float, int, parameter_obj, functor_obj, variable_obj]) Union[parameter_obj, functor_obj]

Returns a functor or parameter which computes the smallest value for two arguments.

Args:

obj1: Input argument 1 - can be float, int, parameter_obj, functor_obj or variable obj2: Input argument 2 - can be float, int, parameter_obj, functor_obj or variable

Returns:

parameter_obj or functor_obj depending on input types

Raises:

TypeError: If obj1 or obj2 are not one of the supported types

escape.core.math.norm(obj: Union[functor_obj, cplx_functor_obj, variable_obj]) functor_obj

Returns a functor which computes the norm value.

Args:

obj: Input argument - can be functor_obj, cplx_functor_obj or variable

Returns:

functor_obj

Raises:

TypeError: If obj is not one of the supported types

escape.core.math.pow(obj1: Union[float, int, parameter_obj, functor_obj, variable_obj], obj2: Union[float, int, parameter_obj, functor_obj, variable_obj]) Union[parameter_obj, functor_obj]

Returns a functor or parameter which computes the value of base obj1 raised to the power obj2.

Args:

obj1: Base - can be float, int, parameter_obj, functor_obj or variable obj2: Exponent - can be float, int, parameter_obj, functor_obj or variable

Returns:

parameter_obj or functor_obj depending on input types

Raises:

TypeError: If obj1 or obj2 are not one of the supported types

escape.core.math.real(obj: Union[functor_obj, cplx_functor_obj, variable_obj]) functor_obj

Returns a functor which computes real part of obj.

Args:

obj: Input argument - can be functor_obj, cplx_functor_obj or variable

Returns:

functor_obj

Raises:

TypeError: If obj is not one of the supported types

escape.core.math.sin(obj: Union[float, int, parameter_obj, functor_obj, cplx_functor_obj, variable_obj]) Union[parameter_obj, functor_obj, cplx_functor_obj]

Returns a functor or parameter which computes a sine value.

Args:

obj: Input argument - can be float, int, parameter_obj, functor_obj, cplx_functor_obj or variable

Returns:

parameter_obj, functor_obj or cplx_functor_obj depending on input type

Raises:

TypeError: If obj is not one of the supported types

escape.core.math.sinh(obj: Union[float, int, parameter_obj, functor_obj, cplx_functor_obj, variable_obj]) Union[parameter_obj, functor_obj, cplx_functor_obj]

Returns a functor or parameter which computes a hyperbolic sine value.

Args:

obj: Input argument - can be float, int, parameter_obj, functor_obj, cplx_functor_obj or variable

Returns:

parameter_obj, functor_obj or cplx_functor_obj depending on input type

Raises:

TypeError: If obj is not one of the supported types

escape.core.math.sqrt(obj: Union[float, int, parameter_obj, functor_obj, cplx_functor_obj, variable_obj]) Union[parameter_obj, functor_obj, cplx_functor_obj]

Returns a functor or parameter which computes a square root value.

Args:

obj: Input argument - can be float, int, parameter_obj, functor_obj, cplx_functor_obj or variable

Returns:

parameter_obj, functor_obj or cplx_functor_obj depending on input type

Raises:

TypeError: If obj is not one of the supported types

escape.core.math.tan(obj: Union[float, int, parameter_obj, functor_obj, cplx_functor_obj, variable_obj]) Union[parameter_obj, functor_obj, cplx_functor_obj]

Returns a functor or parameter which computes a tangent value.

Args:

obj: Input argument - can be float, int, parameter_obj, functor_obj, cplx_functor_obj or variable

Returns:

parameter_obj, functor_obj or cplx_functor_obj depending on input type

Raises:

TypeError: If obj is not one of the supported types

escape.core.math.tanh(obj: Union[float, int, parameter_obj, functor_obj, cplx_functor_obj, variable_obj]) Union[parameter_obj, functor_obj, cplx_functor_obj]

Returns a functor or parameter which computes a hyperbolic tangent value.

Args:

obj: Input argument - can be float, int, parameter_obj, functor_obj, cplx_functor_obj or variable

Returns:

parameter_obj, functor_obj or cplx_functor_obj depending on input type

Raises:

TypeError: If obj is not one of the supported types

escape.core.math.tgamma(z: Union[float, int, parameter_obj, functor_obj, variable_obj, str]) Union[parameter_obj, functor_obj]

Returns a functor or parameter which computes the true gamma function.

Args:

z: Input argument - can be float, int, parameter_obj, functor_obj, variable_obj or str

Returns:

parameter_obj or functor_obj depending on input type

Raises:

TypeError: If z is not one of the supported types