6 #ifndef THEORETICA_DUAL2_H
7 #define THEORETICA_DUAL2_H
9 #ifndef THEORETICA_NO_PRINT
14 #include "../core/error.h"
15 #include "../core/constants.h"
16 #include "../algebra/algebra_types.h"
41 : a(real_part), b(dual1_part), c(dual2_part) {}
45 : a(real_part), b(dual1_part), c(0) {}
49 : a(real_part), b(0), c(0) {}
101 return dual2(a, -b, -c);
117 return dual2(a, b, c);
122 return dual2(a + other.a, b + other.b, c + other.c);
127 return dual2(a + r, b, c);
132 return dual2(-a, -b, -c);
137 return dual2(a - other.a, b - other.b, c - other.c);
142 return dual2(a - r, b, c);
147 return dual2(a * other.a,
148 a * other.b + b * other.a,
149 a * other.c + 2 * b * other.b + c * other.a);
154 return dual2(a * r, b * r, c * r);
170 return dual2(a / r, b / r, c / r);
201 b = (a * other.b) + (b * other.a);
202 c = (a * other.c) + (2 * b * other.b) + (c * other.a);
242 return (a == other.a) && (b == other.b) && (c == other.c);
279 return dual2(a, 0, 0) / d;
283 #ifndef THEORETICA_NO_PRINT
291 std::stringstream res;
294 res << (b >= 0 ?
" + " :
" - ");
299 res << (c >= 0 ?
" + " :
" - ");
Second order dual number class.
Definition: dual2.h:29
dual2 & operator/=(real r)
Divide a dual number by a real number.
Definition: dual2.h:221
dual2 & operator*=(real r)
Multiply this dual number by a real number.
Definition: dual2.h:207
dual2(real real_part, real dual1_part)
Initialize from two real numbers.
Definition: dual2.h:44
friend std::ostream & operator<<(std::ostream &out, const dual2 &obj)
Stream the dual number in string representation to an output stream (std::ostream)
Definition: dual2.h:316
dual2 & operator=(const vec3 &v)
Initialize a dual number from a vec3.
Definition: dual2.h:61
dual2 operator*(const dual2 &other) const
Multiply two dual numbers.
Definition: dual2.h:146
dual2 conjugate() const
Get the dual conjugate.
Definition: dual2.h:100
dual2 operator+(real r) const
Sum a real number to a dual number.
Definition: dual2.h:126
dual2 operator+(const dual2 &other) const
Sum two dual numbers.
Definition: dual2.h:121
dual2 & operator-=(real r)
Subtract a real number from this dual number.
Definition: dual2.h:191
dual2 operator/(const dual2 &other) const
Dual division.
Definition: dual2.h:158
vec3 to_vec() const
Convert a dual number to a vector.
Definition: dual2.h:247
std::string to_string(const std::string &epsilon1="e1", const std::string &epsilon2="e2") const
Convert the dual number to string representation.
Definition: dual2.h:288
dual2 inverse() const
Get the inverse of a dual number.
Definition: dual2.h:105
dual2 operator/(real r) const
Divide a dual number by a real number.
Definition: dual2.h:163
dual2()
Default constructor, initialize with null values.
Definition: dual2.h:37
dual2 operator-(const dual2 &other) const
Subtract two dual numbers.
Definition: dual2.h:136
dual2 & operator+=(real r)
Sum a real number to this dual number.
Definition: dual2.h:175
dual2 & operator=(const std::array< real, 3 > &v)
Initialize a dual number from a std::array.
Definition: dual2.h:77
dual2(const vec3 &v)
Initialize from a vec3.
Definition: dual2.h:54
dual2 & operator-=(const dual2 &other)
Subtract a real number from this one.
Definition: dual2.h:182
dual2(real real_part)
Initialize from a real number.
Definition: dual2.h:48
dual2 & operator=(real x)
Initialize a dual number from a real number.
Definition: dual2.h:69
real Dual2() const
Return second order dual part.
Definition: dual2.h:95
void from_vec(const vec3 &v)
Initialize from a vector.
Definition: dual2.h:256
dual2 operator*(real r) const
Multiply a dual number by a real number.
Definition: dual2.h:153
dual2 & operator/=(const dual2 &other)
Divide this dual number by another one.
Definition: dual2.h:215
dual2 & operator*=(const dual2 &other)
Multiply this dual number by another one.
Definition: dual2.h:198
dual2 operator-(real r) const
Subtract a real number from a dual number.
Definition: dual2.h:141
dual2(real real_part, real dual1_part, real dual2_part)
Initialize from two real numbers.
Definition: dual2.h:40
dual2 operator-() const
Get the opposite of a dual number.
Definition: dual2.h:131
real Re() const
Return real part.
Definition: dual2.h:85
dual2 operator+() const
Identity (for consistency)
Definition: dual2.h:116
bool operator==(const dual2 &other)
Check whether two dual numbers have the same real and dual parts.
Definition: dual2.h:241
real Dual1() const
Return first order dual part.
Definition: dual2.h:90
A statically allocated N-dimensional vector with elements of the given type.
Definition: vec.h:88
Type get(unsigned int i) const
Getters and setters.
Definition: vec.h:322
Type & at(unsigned int i)
Access i-th element.
Definition: vec.h:316
#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION)
TH_MATH_ERROR is a macro which throws exceptions or modifies errno (depending on which compiling opti...
Definition: error.h:219
std::string string(size_t length)
Generate a random string made of human-readable ASCII characters.
Definition: random.h:102
Main namespace of the library which contains all functions and objects.
Definition: algebra.h:27
double real
A real number, defined as a floating point type.
Definition: constants.h:188
dual2 abs(dual2 x)
Compute the absolute value of a second order dual number.
Definition: dual2_functions.h:183
dual2 square(dual2 x)
Return the square of a second order dual number.
Definition: dual2_functions.h:23
real nan()
Return a quiet NaN number in floating point representation.
Definition: error.h:54
dual2 cube(dual2 x)
Return the cube of a second order dual number.
Definition: dual2_functions.h:29