incomplete.fun/ dual numbers

ε² = 0, ε ≠ 0

dual numbers

A dual number is a + bε, where a,b ∈ R and the new infinitesimal unitε is nonzero but squares to zero. They are the smallest useful algebraic model of first-order change: values ride in the real part, derivatives ride in the ε part.

arithmetic playground

automatic differentiation

Evaluate f(x + sε) = f(x) + s f′(x)ε. Put s = 1 to read the derivative directly.

definition and arithmetic

The dual numbers form the commutative real algebra R[ε]/(ε²). Every element has the form a + bε.

operationrulecondition / note
equalitya+bε = c+dε ⇔ a=c and b=dε part is independent of real part
addition(a+bε)+(c+dε)=(a+c)+(b+d)εcomponentwise
multiplication(a+bε)(c+dε)=ac+(ad+bc)εthe bdε² term vanishes
powers(a+bε)ⁿ = aⁿ + n aⁿ⁻¹ bεinteger n; for negative n need a≠0
inverse(a+bε)⁻¹ = 1/a − b/a² εexists exactly when a≠0
division(a+bε)/(c+dε)=a/c + (bc-ad)/c² εrequires c≠0

algebraic facts

  • Not a field: every nonzero pure infinitesimal has no inverse.
  • Zero divisors: ε · ε = 0 although ε ≠ 0.
  • Units: a+bε is invertible iff its real part a is nonzero.
  • Local ring: the non-units form the maximal ideal (ε); the residue field is R.
  • Nilpotents: all elements of (ε) square to zero.
  • Conjugation: sometimes ¯(a+bε)=a-bε, but (a+bε)(a-bε)=a², not a norm that detects ε.

functions

If f is differentiable at a, the nilpotence of ε truncates the Taylor series after the linear term:

f(a+bε) = f(a) + b f′(a) ε

  • exp(a+bε)=eᵃ + b eᵃ ε
  • sin(a+bε)=sin a + b cos a ε
  • cos(a+bε)=cos a − b sin a ε
  • log(a+bε)=log a + b/a ε for a>0
  • sqrt(a+bε)=√a + b/(2√a) ε for a>0

why derivatives appear

Substituting x + ε into a polynomial forces exactly the first derivative to appear:(x+ε)³ = x³ + 3x²ε + 3xε² + ε³ = x³ + 3x²ε. For smooth functions this is the same Taylor-series phenomenon. No limiting process, symbolic simplification, or finite-difference step size is needed.

function square(x) { return x * x }

square(3 + 1ε) = 9 + 6ε
// value = 9, derivative at 3 = 6

geometry

A dual number can be read as a point plus a tangent vector. The real projection a+bε ↦ aforgets tangent information; the ε coefficient stores a direction and scale. In differential geometry, maps on manifolds send tangent vectors forward; dual numbers implement that idea algebraically in one dimension.

automatic differentiation

Forward-mode AD evaluates an ordinary program with dual-number arithmetic. Each elementary operation propagates both value and derivative by the chain rule. It gives machine-precision derivatives and is especially efficient for functions with few input variables and many outputs.

relatives and contrasts

  • Complex numbers: i²=-1 creates rotations; ε²=0 creates tangents.
  • Split-complex numbers: j²=+1 model hyperbolic geometry; dual numbers are the degenerate case between circular and hyperbolic behavior.
  • Truncated polynomials: R[ε]/(ε²) is the order-1 version; R[ε]/(εⁿ) carries higher derivatives up to order n-1.
  • Synthetic differential geometry: nilpotent infinitesimals are used axiomatically to reason about tangent spaces.