Dual Types
- record dual
A dual number is a number in the form \(a + b\epsilon\), for which \(\epsilon^2 = 0\). Via the algebra induced by this definition one can show that \(f(a + b\epsilon) = f(a) + bf'(a)\epsilon\) and hence dual numbers can be used for forward mode automatic differentiation by operators overloading.
- var primalPart: real
primal part of the dual number
- var dualPart: real
dual part of the dual number
- record multidual
A multidual number is a number if the form \(a + \sum_{i=1}^nb_i\epsilon_i\), for which it holds \(\epsilon_i^2=0\) and \(\epsilon_i\epsilon_j=0\) for any indices \(i, j\).
- var dom: domain(1)
domain for the array of dual parts
- var primalPart: real
primal part
- var dualPart: [dom] real
dual parts
- proc todual(val: real, der: real)
Converts a pair of real numbers to dual number
- proc todual(val: real, grad: [?D])
Converts a real number and array of reals to a multidual number.
- proc isDualType(type t) param
Returns
true
ift
isdual
ormultidual
.
- proc isEitherDualType(type t, type s) param
Returns
true
if eithert
ors
is a dual type (dual
ormultidual
).
- proc primalPart(a)
For dual numbers, it returns the primal part. For real numbers, it returns the number itself.
- proc dualPart(a)
For dual numbers, it returns the dual part, for real numbers it returns zero.