functions¶
Uniform interface for functions working on both symbolic and numeric inputs.
- class parityos.utils.functions.NamedFunction(name: str, sympy: Callable[[Expr], Expr], math: Callable[[float], float], cmath: Callable[[complex], FloatComplexT])¶
Bases:
Generic[FloatComplexT]A wrapper class for symbolic, numerical, and complex-valued implementations of a specific named function.
This class provides a uniform interface for functions that have three implementations:
A SymPy symbolic implementation
A standard math implementation for floats
A complex math implementation for complex numbers
Instantiations are callables that take an argument and dispatch it to the relevant implementation.
- sympy: Callable[[Expr], Expr]¶
A callable that takes a SymPy expression and returns a SymPy expression.
- cmath: Callable[[complex], FloatComplexT]¶
A callable that takes a complex number and returns either a float or complex.
- __call__(arg: float) float¶
- __call__(arg: complex) FloatComplexT
- __call__(arg: Symbolic) ParameterExpression
Apply the underlying function to argument.
Disambiguates to correct implementation (real, complex, symbolic) based on input type.
- Parameters:
arg – Argument to the underlying function.
- Returns:
The underlying function applied to
arg.- Raises:
ParityOSNotSupportedError – If the underlying function is not implemented for the type of
arg.
- parityos.utils.functions.exp = NamedFunction(name='exp', sympy=exp, math=<built-in function exp>, cmath=<built-in function exp>)¶
Compute the exponential of a symbolic or numerical
Coefficient.
- parityos.utils.functions.log = NamedFunction(name='log', sympy=log, math=<built-in function log>, cmath=<built-in function log>)¶
Compute the natural logarithm symbolic or numerical
Coefficient.
- parityos.utils.functions.sqrt = NamedFunction(name='sqrt', sympy=<function sqrt>, math=<built-in function sqrt>, cmath=<built-in function sqrt>)¶
Compute the square root symbolic or numerical
Coefficient.
- parityos.utils.functions.cos = NamedFunction(name='cos', sympy=cos, math=<built-in function cos>, cmath=<built-in function cos>)¶
Compute the cosine symbolic or numerical
Coefficient.
- parityos.utils.functions.sin = NamedFunction(name='sin', sympy=sin, math=<built-in function sin>, cmath=<built-in function sin>)¶
Compute the sine symbolic or numerical
Coefficient.
- parityos.utils.functions.tan = NamedFunction(name='tan', sympy=tan, math=<built-in function tan>, cmath=<built-in function tan>)¶
Compute the tangent symbolic or numerical
Coefficient.
- parityos.utils.functions.acos = NamedFunction(name='acos', sympy=acos, math=<built-in function acos>, cmath=<built-in function acos>)¶
Compute the inverse cosine symbolic or numerical
Coefficient.
- parityos.utils.functions.asin = NamedFunction(name='asin', sympy=asin, math=<built-in function asin>, cmath=<built-in function asin>)¶
Compute the inverse sine symbolic or numerical
Coefficient.
- parityos.utils.functions.atan = NamedFunction(name='atan', sympy=atan, math=<built-in function atan>, cmath=<built-in function atan>)¶
Compute the inverse tangent symbolic or numerical
Coefficient.
- parityos.utils.functions.cosh = NamedFunction(name='cosh', sympy=cosh, math=<built-in function cosh>, cmath=<built-in function cosh>)¶
Compute the hyperbolic cosine symbolic or numerical
Coefficient.
- parityos.utils.functions.sinh = NamedFunction(name='sinh', sympy=sinh, math=<built-in function sinh>, cmath=<built-in function sinh>)¶
Compute the hyperbolic sine symbolic or numerical
Coefficient.
- parityos.utils.functions.tanh = NamedFunction(name='tanh', sympy=tanh, math=<built-in function tanh>, cmath=<built-in function tanh>)¶
Compute the hyperbolic tangent symbolic or numerical
Coefficient.
- parityos.utils.functions.acosh = NamedFunction(name='acosh', sympy=acosh, math=<built-in function acosh>, cmath=<built-in function acosh>)¶
Compute the inverse hyperbolic cosine symbolic or numerical
Coefficient.
- parityos.utils.functions.asinh = NamedFunction(name='asinh', sympy=asinh, math=<built-in function asinh>, cmath=<built-in function asinh>)¶
Compute the inverse hyperbolic sine symbolic or numerical
Coefficient.
- parityos.utils.functions.atanh = NamedFunction(name='atanh', sympy=atanh, math=<built-in function atanh>, cmath=<built-in function atanh>)¶
Compute the inverse hyperbolic tangent symbolic or numerical
Coefficient.
- parityos.utils.functions.abs_squared = NamedFunction(name='abs_squared', sympy=<function <lambda>>, math=<function <lambda>>, cmath=<function <lambda>>)¶
Compute the squared absolute value symbolic or numerical
Coefficient. Always returns a real valued result.