THE DUAL NUMBER differentiate a program for free, exactly
Adjoin a new unit ε with ε² = 0 (not −1 like i, not 0). A dual number is a + bε: a value carrying a shadow. Do arithmetic on the pair and the shadow obeys the calculus by itself — because (a+bε)(c+dε) = ac + (ad+bc)ε is exactly the product rule. Evaluate any program on x + 1·ε and the ε-part that falls out is f′(x) — exact, no step size, no symbolic blowup. This is forward-mode automatic differentiation, and the whole thing is one small duality.
THE TECHNIQUE a + bε, ε²=0 ; evaluate f on x+ε → f(x)+f′(x)ε
Pick x and a cubic; evaluate it on the dual x + 1ε using only value/shadow arithmetic. The shadow that comes back is the exact derivative — check it against the hand-computed f′: live demo
HISTORY & CREDIT Clifford 1873 · Wengert 1964
“A computer gets derivatives one of two ways: symbolically (exact but the expression explodes) or numerically (a finite h, so roundoff and truncation fight).” — there is a third way with neither flaw. Carry the derivative as the ε-component; the chain and product rules are forced by ε²=0. Exact to the last bit, no h, no symbolic tree. cited
1873 · William Kingdon Clifford — introduces “dual quantities” a+bε, ε²=0, alongside his biquaternions. 1903 · Eduard Study — dual numbers and dual angles become the algebra of lines and screw motion in kinematics. 1964 · R. E. Wengert — “A simple automatic derivative evaluation program”: the forward mode of automatic differentiation, the dual number put to work.
The value and its shadow ride together through every operation, and neither is approximated. It is the cleanest duality in the batch: a number and its rate of change, computed at once, for the cost of one. Clifford 1873
RECOMMEND FOR I-13 exact derivative from dual arithmetic, computed
On the canonical compiler, a dual number is a two-cell array and f runs on [x, 1]. For f(x)=x³−2x+1 at x=2 the shadow is the exact derivative 3x²−2 = 10:
$ i13 run dual.i13 # f(x)=x^3-2x+1 evaluated on the dual [2,1]
val = 5 -- f(2) = 8 - 4 + 1
der = 10 -- f'(2) = 3*4 - 2, the eps-component, EXACT (no step size)
Recommend: the dual number is LIT and a keeper-grade fit for I-13 — verified f(x)=x³−2x+1 on the dual [2,1] returns [5, 10]: value and exact derivative in one pass, via [a,b]·[c,d]=[ac, ad+bc] and nothing else. No h, no symbolic tree — the derivative is carried, not approximated. The literal duality engine.