Generalized Dual numbers
The following instances of generalized dual numbers (and thus the corresponding algebra) are made available in the python module pyaudi:
gdual_double: basic type for computing on real numbers
gdual_vdouble: basic type for computing on vectors of real numbers
gdual_double
- class pyaudi.gdual_double
The generalized dual number class
This class represents a generalized dual number, in a nutshell, a truncated multivariate Taylor polynomial. A gdual is defined by its truncation order \(m\) as well as on its expansion point \(\mathbf a\). All arithmetic operators +,*,/,-,** are overloaded so that the Taylor expansion of arithmetic computations is obtained.
A basic example is:
gdual_double: \(m = 2\), \(\mathbf a = [1.2, -0.1]\), \(f = \frac{x1+x2}{x1-x2}\)
>>> from pyaudi import gdual_double as gdual >>> x1 = gdual(1.2, "x1", 2) >>> x2 = gdual(-0.1, "x2", 2) >>> f = (x1+x2) / (x1-x2) >>> print(f) 1.42012*dx2+0.118343*dx1+1.0924*dx2**2+0.846154-1.00137*dx1*dx2-0.0910332*dx1**2
gdual_vdouble: \(m = 2\), \(\mathbf a = [[1.2, 1.1], [-0.1, -0.2]]\), \(f = \frac{x1+x2}{x1-x2}\)
>>> from pyaudi import gdual_vdouble as gdual >>> x1 = gdual([1.2, 1.1], "x1", 2) >>> x2 = gdual([-0.1, -0.2], "x2", 2) >>> f = (x1+x2) / (x1-x2) >>> print(f) [1.42012, 1.30178]*dx2+[0.118343, 0.236686]*dx1+[1.0924, 1.00137]*dx2**2+[0.846154, 0.692308]+[-1.00137, -0.819299]*dx1*dx2+[-0.0910332, -0.182066]*dx1**2
gdual_real128: \(m = 2\), \(\mathbf a = [1.2, -0.1]\), \(f = \frac{x1+x2}{x1-x2}\)
>>> from pyaudi import gdual_real128 as gdual >>> x1 = gdual("1.2", "x1", 2) >>> x2 = gdual("-0.1", "x2", 2) >>> f = (x1+x2) / (x1-x2) >>> print(f) 1.42011834319526627218934911242603510e+00*dx2+1.18343195266272189349112426035503101e-01*dx1+1.09239872553482020937642239417387321e+00*dx2**2+8.46153846153846153846153846153845954e-01-1.00136549840691852526172052799271705e+00*dx1*dx2-9.10332271279016841147018661811561892e-02*dx1**2
Note
A gdual can operate on doubles (gdual_double), on vectorized doubles (gdual_vdouble) or on quadruple precision doubles (gdual_real128). The second case is immensely more efficient when applicable.
See also the docs of the C++ class
gdual.- abs(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Absolute value.
- acos(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Arc cosine.
- acosh(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Inverse hyperbolic cosine.
- arccos(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Arc cosine.
- arccosh(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Inverse hyperbolic cosine.
- arcsin(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Arc sine.
- arcsinh(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Inverse hyperbolic sine.
- arctan(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Arc tangent.
- arctanh(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Inverse hyperbolic arc tangent.
- asin(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Arc sine.
- asinh(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Inverse hyperbolic sine.
- atan(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Arc tangent.
- atanh(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Inverse hyperbolic arc tangent.
- cbrt(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Cubic root.
- property constant_cf
Constant term of the polynomial
- cos(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Cosine.
- cosh(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Hyperbolic cosine.
- property degree
The degree of the generalized dual number
Note
The degree and the order of a gdual can be different, the degree is always smaller or equal ot the order.
- Returns:
The degree of the underlying Taylor polynomial
>>> from pyaudi import gdual_double as gdual >>> x1 = gdual(1.2, "x1", 5) >>> f = x1**2 >>> print(f.degree) 2
See also the docs of the C++ method of the gdual
degree().
- erf(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Error function.
- erfc(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Error Function Complement
- evaluate(self: pyaudi.core.gdual_double, arg0: dict) float
Evaluates the Taylor polynomial
- exp(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Exponential.
- expm1(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
exp(x) - 1, inverse of log1p
- extend_symbol_set(self: pyaudi.core.gdual_double, arg0: collections.abc.Sequence[str]) None
Extends the symbol set
- extract_terms(self: pyaudi.core.gdual_double, arg0: SupportsInt) pyaudi.core.gdual_double
returns a new gdual containing only terms of a given order
- find_cf(self: pyaudi.core.gdual_double, arg0: collections.abc.Sequence[SupportsInt]) float
Find the coefficient of the Taylor expansion
- get_derivative(*args, **kwargs)
Overloaded function.
get_derivative(self: pyaudi.core.gdual_double, arg0: collections.abc.Sequence[typing.SupportsInt]) -> float
Finds the derivative (i.e. the coefficient of the Taylor expansion discounted of a factorial factor
get_derivative(self: pyaudi.core.gdual_double, arg0: collections.abc.Mapping[str, typing.SupportsInt]) -> float
Finds the derivative (i.e. the coefficient of the Taylor expansion discounted of a factorial factor
- info(self: pyaudi.core.gdual_double) str
Full information on the gdual
- integrate(self: pyaudi.core.gdual_double, arg0: str) pyaudi.core.gdual_double
Integrate with respect to argument
- is_zero(self: pyaudi.core.gdual_double, arg0: SupportsFloat) bool
checks if all coefficients of the gdual are zero within a tolerance
- log(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Natural logarithm.
- log10(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Base 10 Logarithm.
- log1p(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
log(x)+1, inverse of expm1
- log2(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Base 2 Logarithm.
- property order
truncation order (>= degree)
- partial(self: pyaudi.core.gdual_double, arg0: str) pyaudi.core.gdual_double
Partial derivative with respect to argument
- sin(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Sine.
- sinh(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Hyperbolic sine.
- sqrt(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Square root.
- subs(*args, **kwargs)
Overloaded function.
subs(self: pyaudi.core.gdual_double, arg0: str, arg1: typing.SupportsFloat) -> pyaudi.core.gdual_double
Substitutes a symbol with a value (does not remove symbol from symbol set)
subs(self: pyaudi.core.gdual_double, arg0: str, arg1: pyaudi.core.gdual_double) -> pyaudi.core.gdual_double
Substitutes a symbol with a gdual
- tan(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Tangent.
- tanh(self: pyaudi.core.gdual_double) pyaudi.core.gdual_double
Hyperbolic tangent.
- trim(self: pyaudi.core.gdual_double, arg0: SupportsFloat) pyaudi.core.gdual_double
returns a new gdual removing all coefficients that are smaller than a tolerance
gdual_vdouble
- class pyaudi.gdual_vdouble
The generalized dual number class
This class represents a generalized dual number, in a nutshell, a truncated multivariate Taylor polynomial. A gdual is defined by its truncation order \(m\) as well as on its expansion point \(\mathbf a\). All arithmetic operators +,*,/,-,** are overloaded so that the Taylor expansion of arithmetic computations is obtained.
A basic example is:
gdual_double: \(m = 2\), \(\mathbf a = [1.2, -0.1]\), \(f = \frac{x1+x2}{x1-x2}\)
>>> from pyaudi import gdual_double as gdual >>> x1 = gdual(1.2, "x1", 2) >>> x2 = gdual(-0.1, "x2", 2) >>> f = (x1+x2) / (x1-x2) >>> print(f) 1.42012*dx2+0.118343*dx1+1.0924*dx2**2+0.846154-1.00137*dx1*dx2-0.0910332*dx1**2
gdual_vdouble: \(m = 2\), \(\mathbf a = [[1.2, 1.1], [-0.1, -0.2]]\), \(f = \frac{x1+x2}{x1-x2}\)
>>> from pyaudi import gdual_vdouble as gdual >>> x1 = gdual([1.2, 1.1], "x1", 2) >>> x2 = gdual([-0.1, -0.2], "x2", 2) >>> f = (x1+x2) / (x1-x2) >>> print(f) [1.42012, 1.30178]*dx2+[0.118343, 0.236686]*dx1+[1.0924, 1.00137]*dx2**2+[0.846154, 0.692308]+[-1.00137, -0.819299]*dx1*dx2+[-0.0910332, -0.182066]*dx1**2
gdual_real128: \(m = 2\), \(\mathbf a = [1.2, -0.1]\), \(f = \frac{x1+x2}{x1-x2}\)
>>> from pyaudi import gdual_real128 as gdual >>> x1 = gdual("1.2", "x1", 2) >>> x2 = gdual("-0.1", "x2", 2) >>> f = (x1+x2) / (x1-x2) >>> print(f) 1.42011834319526627218934911242603510e+00*dx2+1.18343195266272189349112426035503101e-01*dx1+1.09239872553482020937642239417387321e+00*dx2**2+8.46153846153846153846153846153845954e-01-1.00136549840691852526172052799271705e+00*dx1*dx2-9.10332271279016841147018661811561892e-02*dx1**2
Note
A gdual can operate on doubles (gdual_double), on vectorized doubles (gdual_vdouble) or on quadruple precision doubles (gdual_real128). The second case is immensely more efficient when applicable.
See also the docs of the C++ class
gdual.- abs(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Absolute value.
- acos(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Arc cosine.
- acosh(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Inverse hyperbolic cosine.
- arccos(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Arc cosine.
- arccosh(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Inverse hyperbolic cosine.
- arcsin(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Arc sine.
- arcsinh(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Inverse hyperbolic sine.
- arctan(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Arc tangent.
- arctanh(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Inverse hyperbolic arc tangent.
- asin(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Arc sine.
- asinh(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Inverse hyperbolic sine.
- atan(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Arc tangent.
- atanh(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Inverse hyperbolic arc tangent.
- cbrt(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Cubic root.
- property constant_cf
Constant term of the polynomial
- cos(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Cosine.
- cosh(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Hyperbolic cosine.
- property degree
The degree of the generalized dual number
Note
The degree and the order of a gdual can be different, the degree is always smaller or equal ot the order.
- Returns:
The degree of the underlying Taylor polynomial
>>> from pyaudi import gdual_double as gdual >>> x1 = gdual(1.2, "x1", 5) >>> f = x1**2 >>> print(f.degree) 2
See also the docs of the C++ method of the gdual
degree().
- erf(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Error function.
- erfc(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Error Function Complement
- evaluate(self: pyaudi.core.gdual_vdouble, arg0: dict) vectorized<double>
Evaluates the Taylor polynomial
- exp(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Exponential.
- expm1(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
exp(x) - 1, inverse of log1p
- extend_symbol_set(self: pyaudi.core.gdual_vdouble, arg0: collections.abc.Sequence[str]) None
Extends the symbol set
- extract_terms(self: pyaudi.core.gdual_vdouble, arg0: SupportsInt) pyaudi.core.gdual_vdouble
returns a new gdual containing only terms of a given order
- find_cf(self: pyaudi.core.gdual_vdouble, arg0: collections.abc.Sequence[SupportsInt]) vectorized<double>
Find the coefficient of the Taylor expansion
- get_derivative(*args, **kwargs)
Overloaded function.
get_derivative(self: pyaudi.core.gdual_vdouble, arg0: collections.abc.Sequence[typing.SupportsInt]) -> vectorized<double>
Finds the derivative (i.e. the coefficient of the Taylor expansion discounted of a factorial factor
get_derivative(self: pyaudi.core.gdual_vdouble, arg0: collections.abc.Mapping[str, typing.SupportsInt]) -> vectorized<double>
Finds the derivative (i.e. the coefficient of the Taylor expansion discounted of a factorial factor
- info(self: pyaudi.core.gdual_vdouble) str
Full information on the gdual
- integrate(self: pyaudi.core.gdual_vdouble, arg0: str) pyaudi.core.gdual_vdouble
Integrate with respect to argument
- is_zero(self: pyaudi.core.gdual_vdouble, arg0: SupportsFloat) bool
checks if all coefficients of the gdual are zero within a tolerance
- log(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Natural logarithm.
- log10(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Base 10 Logarithm.
- log1p(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
log(x)+1, inverse of expm1
- log2(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Base 2 Logarithm.
- property order
truncation order (>= degree)
- partial(self: pyaudi.core.gdual_vdouble, arg0: str) pyaudi.core.gdual_vdouble
Partial derivative with respect to argument
- sin(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Sine.
- sinh(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Hyperbolic sine.
- sqrt(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Square root.
- subs(*args, **kwargs)
Overloaded function.
subs(self: pyaudi.core.gdual_vdouble, arg0: str, arg1: vectorized<double>) -> pyaudi.core.gdual_vdouble
Substitutes a symbol with a value (does not remove symbol from symbol set)
subs(self: pyaudi.core.gdual_vdouble, arg0: str, arg1: pyaudi.core.gdual_vdouble) -> pyaudi.core.gdual_vdouble
Substitutes a symbol with a gdual
- tan(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Tangent.
- tanh(self: pyaudi.core.gdual_vdouble) pyaudi.core.gdual_vdouble
Hyperbolic tangent.
- trim(self: pyaudi.core.gdual_vdouble, arg0: SupportsFloat) pyaudi.core.gdual_vdouble
returns a new gdual removing all coefficients that are smaller than a tolerance