Dual Number¶
A dual number is a number of the form \(a + b \epsilon\), where \(a\) and \(b\) are real numbers, and \(\epsilon\) is a symbol that satisfies \(\epsilon^2 = 0\). The dual number system is an extension of the real numbers that is useful for performing automatic differentiation. Sometimes related to homogeneous transformation in robotics.
Conjugate & Norm¶
The norm of a dual number is defined as the square of the self with conjugated self. The conjugate of a dual number is the same as the original number.
Addition & Subtraction¶
Dual number addition & subtraction are defined as follows:
Multiplication¶
Dual number multiplication is defined as follows:
Inverse & Division¶
The inverse of a dual number is defined as the reciprocal of the dual number.
Division is defined as the multiplication of the first number by the inverse of the second number.
Square Root¶
The square root of a dual number is defined as follows:
Dual Number Class¶
/// initializer
DualNumber<float> d1{1.f, 2.f}; // Re, Du
DualNumber<float> d2{{1.f, 2.f}};
// type alias
DualNumberf d3 = d1;
// cast to other objects (2 x 1)
Vector2f v = d1.cast2Vector();
Matrix2f m = d1.cast2Matrix();
// accessor
float re = d1.Re();
float du = d1.Du();
d1.Re() = re;
d1.Du() = du;
// conjugate, norm
DualNumber<float> d4 = d1.conjugated();
float norm = d1.norm();
// inverse
DualNumber<float> d5 = d1.inversed();
// operators
DualNumber<float> d6 = d1 + d2;
DualNumber<float> d7 = d1 - d2;
DualNumber<float> d8 = d1 * d2; // Dual number multiplication
DualNumber<float> d9 = d1 / d2; // Dual number division
// result type casting
Vector2f v = SquareMatrix2f{} * d1; // matrix multiplication
// to multiplication matrix
SquareMatrix2f m = d1.toMatrix();
// | Re() 0 |
// | Du() Re() |