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
-
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
.-
property
constant_cf
¶ Constant term of the polynomial
-
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()
.
-
evaluate
((gdual_double)arg1, (dict)arg2) → float :¶ Evaluates the Taylor polynomial
- C++ signature :
double evaluate(audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> >,boost::python::dict)
-
extend_symbol_set
((gdual_double)arg1, (object)arg2) → None :¶ Extends the symbol set
- C++ signature :
void extend_symbol_set(audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > {lvalue},boost::python::api::object)
-
extract_terms
((gdual_double)arg1, (int)arg2) → gdual_double :¶ returns a new gdual containing only terms of a given order
- C++ signature :
audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > extract_terms(audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > {lvalue},unsigned int)
-
find_cf
((gdual_double)arg1, (object)arg2) → float :¶ Finds the coefficient of the Taylor expansion
- C++ signature :
double find_cf(audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> >,boost::python::api::object)
-
get_derivative
((gdual_double)arg1, (object)arg2) → float :¶ Finds the derivative (i.e. the coefficient of the Taylor expansion discounted by the factorial factor
- C++ signature :
double get_derivative(audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> >,boost::python::api::object)
- get_derivative( (gdual_double)arg1, (dict)arg2) -> float :
Finds the derivative (i.e. the coefficient of the Taylor expansion discounted by the factorial factor
- C++ signature :
double get_derivative(audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> >,boost::python::dict)
-
integrate
((gdual_double)arg1, (str)arg2) → gdual_double :¶ Integrate with respect to argument
- C++ signature :
audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > integrate(audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > {lvalue},std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)
-
is_zero
((gdual_double)arg1, (float)arg2) → bool :¶ checks if all coefficients of the gdual are zero within a tolerance
- C++ signature :
bool is_zero(audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > {lvalue},double)
-
property
order
¶ truncation order (>= degree)
-
partial
((gdual_double)arg1, (str)arg2) → gdual_double :¶ Partial derivative with respect to argument
- C++ signature :
audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > partial(audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > {lvalue},std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)
-
subs
((gdual_double)arg1, (str)arg2, (float)arg3) → gdual_double :¶ Substitutes a symbol with a value (does not remove symbol from symbol set)
- C++ signature :
audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > subs(audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > {lvalue},std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >,double)
- subs( (gdual_double)arg1, (str)arg2, (gdual_double)arg3) -> gdual_double :
Substitutes a symbol with a gdual
- C++ signature :
audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > subs(audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > {lvalue},std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >,audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> >)
-
trim
((gdual_double)arg1, (float)arg2) → gdual_double :¶ returns a new gdual removing all coefficients that are smaller than a tolerance
- C++ signature :
audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > trim(audi::gdual<double, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > {lvalue},double)
-
property
-
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
.-
property
constant_cf
¶ Constant term of the polynomial
-
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()
.
-
evaluate
((gdual_vdouble)arg1, (dict)arg2) → object :¶ Evaluates the Taylor polynomial
- C++ signature :
audi::vectorized<double> evaluate(audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> >,boost::python::dict)
-
extend_symbol_set
((gdual_vdouble)arg1, (object)arg2) → None :¶ Extends the symbol set
- C++ signature :
void extend_symbol_set(audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > {lvalue},boost::python::api::object)
-
extract_terms
((gdual_vdouble)arg1, (int)arg2) → gdual_vdouble :¶ returns a new gdual containing only terms of a given order
- C++ signature :
audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > extract_terms(audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > {lvalue},unsigned int)
-
find_cf
((gdual_vdouble)arg1, (object)arg2) → object :¶ Finds the coefficient of the Taylor expansion
- C++ signature :
audi::vectorized<double> find_cf(audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> >,boost::python::api::object)
-
get_derivative
((gdual_vdouble)arg1, (object)arg2) → object :¶ Finds the derivative (i.e. the coefficient of the Taylor expansion discounted by the factorial factor
- C++ signature :
audi::vectorized<double> get_derivative(audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> >,boost::python::api::object)
- get_derivative( (gdual_vdouble)arg1, (dict)arg2) -> object :
Finds the derivative (i.e. the coefficient of the Taylor expansion discounted by the factorial factor
- C++ signature :
audi::vectorized<double> get_derivative(audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> >,boost::python::dict)
-
integrate
((gdual_vdouble)arg1, (str)arg2) → gdual_vdouble :¶ Integrate with respect to argument
- C++ signature :
audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > integrate(audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > {lvalue},std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)
-
is_zero
((gdual_vdouble)arg1, (float)arg2) → bool :¶ checks if all coefficients of the gdual are zero within a tolerance
- C++ signature :
bool is_zero(audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > {lvalue},double)
-
property
order
¶ truncation order (>= degree)
-
partial
((gdual_vdouble)arg1, (str)arg2) → gdual_vdouble :¶ Partial derivative with respect to argument
- C++ signature :
audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > partial(audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > {lvalue},std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)
-
subs
((gdual_vdouble)arg1, (str)arg2, (object)arg3) → gdual_vdouble :¶ Substitutes a symbol with a value (does not remove symbol from symbol set)
- C++ signature :
audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > subs(audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > {lvalue},std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >,boost::python::api::object)
- subs( (gdual_vdouble)arg1, (str)arg2, (gdual_vdouble)arg3) -> gdual_vdouble :
Substitutes a symbol with a gdual
- C++ signature :
audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > subs(audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > {lvalue},std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >,audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> >)
-
trim
((gdual_vdouble)arg1, (float)arg2) → gdual_vdouble :¶ returns a new gdual removing all coefficients that are smaller than a tolerance
- C++ signature :
audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > trim(audi::gdual<audi::vectorized<double>, obake::polynomials::d_packed_monomial<unsigned long long, 8u, void> > {lvalue},double)
-
property