Skip to content

Dual numbers and hyperdual space

Dual number theory

Dual numbers are a type of complex numbers. The ubiquitous set of complex numbers, C, may be defined as follows, where i is the imaginary number:

C=R[i]={z=a+bi | (a,b)R2,i2=1}

Similarly, we may define the set of dual numbers as follows, where ϵ is the dual number:

D=R[ϵ]={z=a+bϵ | (a,b)R2,ϵ2=0~and~ϵ0}

Moreover, for z=a+bϵ where zD, (a,b)R, let us define the real and dual parts of a dual number such as

{real(z)=adual(z)=b

An auto-differentiation property emerges from the addition of this nilpotent element, as is obvious from a Taylor series expansion. Evidently, this result is only valid for values of a where the function is differentiable.

f:DD ,(a,b)R2f(a+bε)=n=0f(n)(a)bnεnn!=f(a)+bdf(a)daε{real(f(a+bϵ))=f(a)dual(f(a+bϵ))=bdf(a)da

By choosing b=1, the first derivative comes out for free by simply evaluating the function f.

Hyperdual spaces

We can further extend the dual numbers to a hyperdual space. Let us define a hyperdual space of size 2 as follows, where ϵj is the j-th dual number:

D2=R[ϵx,ϵy]={z=a+bϵx+cϵy+dϵxϵy | (a,b,c,d)R4,ϵγ2=0, ϵγ0, γ{x,y}, ϵxϵy0}

This mathematical tool enables auto-differentiation of multi-variate functions as follows, where dualγ corresponds to the γ-th dual number, i.e. the number associated with ϵγ.

f:D2D2, (x,y)R2{real(f(x+ϵx, y+ϵy))=f(x,y)dualx(f(x+ϵx, y+ϵy))=xf(x,y)dualy(f(x+ϵx, y+ϵy))=yf(x,y)

Example

Let us detail a computation example of a smooth multivariate polynomial function defined over all reals.

f:RR, (x,y)R2f(x,y)=2x30.2y2+xxf(x,y)=6x2+1yf(x,y)=0.4y

Let us extend the definition of this function to D2.

g:DD, (x,y)R2g(x+ϵx, y+ϵy)=2(x+ϵx)30.2(y+ϵy)2+(x+ϵx)

Trivially,

(x+ϵx)2=x2+2xϵx(x+ϵx)3=x3+3x2ϵx

Hence, g may be written as follows:

g(x+ϵx, y+ϵy)=2(x+ϵx)30.2(y+ϵy)2+(x+ϵx)=2(x3+3x2ϵx)0.2(y2+2yϵy)+(x+ϵx)=(2x30.2y2+x)+(6x2+1)ϵx0.4yϵy

As expected, the dualx part of g corresponds to the partial of f with respect to x, the dualy part of g corresponds to the partial of f with respect to y, and the real part of the g corresponds to f.

Computation

All hyperdual computations are handled by the hyperdual Rust crate, co-authored by Chris Rabotin.