Function Repository Resource:

DualNumber

Source Notebook

Represent a dual number

Contributed by: Jan Mangaldan

ResourceFunction["DualNumber"][a,b]

returns the dual number a+bε.

Details

Dual numbers are hypercomplex numbers of the form a+bε, where a and b are real numbers and ε satisfies the relation ε2=0.
Dual numbers work much like complex numbers.
Dual numbers are algebraically identical to the field of algebraic infinitesimals. They can be used in the field of nonstandard analysis.
Because of the similarities between dual numbers and complex numbers, this function imitates the Wolfram Languages treatment of complex numbers in many ways.
To provide a clear distinction between dual numbers and complex numbers, all dual numbers should be entered using the form ResourceFunction["DualNumber"][a,b], where a and b are real numbers.

Examples

Basic Examples (3) 

Get the dual number 1+2ε:

In[1]:=
ResourceFunction["DualNumber"][1, 2]
Out[1]=

Add two dual numbers:

In[2]:=
ResourceFunction["DualNumber"][1, 2] + ResourceFunction["DualNumber"][2, 3]
Out[2]=

Multiply two dual numbers:

In[3]:=
ResourceFunction["DualNumber"][2, -6]*
 ResourceFunction["DualNumber"][1, 4]
Out[3]=

Applications (5) 

A procedurally-defined function:

In[4]:=
f[x_] := Module[{c = 0},
  Do[c = c x + k,
   {k, 5}];
  c]

Evaluate at a dual number argument with unit dual part:

In[5]:=
res = f[ResourceFunction["DualNumber"][1.8, 1]]
Out[5]=

The real part is equal to the function evaluated at the real part of the argument:

In[6]:=
{Re[res], f[1.8]}
Out[6]=

The dual part is equal to the derivative of the function:

In[7]:=
ResourceFunction["DualPart"][res]
Out[7]=

Compare with a central difference approximation:

In[8]:=
With[{\[ScriptH] = Sqrt[$MachineEpsilon]}, (f[1.8 + \[ScriptH]] - f[1.8 - \[ScriptH]])/(2 \[ScriptH])]
Out[8]=

Properties and Relations (4) 

In the conjugate of a dual number, the sign of the dual part is reversed:

In[9]:=
d = Conjugate[ResourceFunction["DualNumber"][-4, -3]]
Out[9]=

Use Re and the resource function DualPart to extract the real and dual parts of a dual number:

In[10]:=
{Re[d], ResourceFunction["DualPart"][d]}
Out[10]=

The sign of a dual number is defined to be the sign of its real part:

In[11]:=
Sign[d]
Out[11]=

The absolute value of a dual number is the absolute value of its real part:

In[12]:=
Abs[d]
Out[12]=

Dual numbers have the following "polar form":

In[13]:=
d == Re[d] Exp[DualNumber[0, 1] ResourceFunction["DualPart"][d]/Re[d]]
Out[13]=

Use Norm to get the standard Euclidean length of a dual number:

In[14]:=
Norm[d]
Out[14]=

Evaluate the exponential of a dual number:

In[15]:=
Exp[ResourceFunction["DualNumber"][2, 3]]
Out[15]=

Raise a dual number to a dual number power:

In[16]:=
ResourceFunction["DualNumber"][2, 3]^ResourceFunction[
 "DualNumber"][1, -2]
Out[16]=

Just as with complex numbers, Mod works on dual numbers:

In[17]:=
Mod[ResourceFunction["DualNumber"][-5, 4], 3]
Out[17]=

Version History

  • 1.0.0 – 05 February 2021

Related Resources

Author Notes

The implementation is adapted from this Mathematica Stack Exchange post: https://mathematica.stackexchange.com/a/13926

License Information