Lab · c18.s01.L1

Three ways to differentiate

The three routes to a gradient are priced by formula length, input count and operation count, so their costs cross over as the model grows.

Question: When do you use symbols, numbers or a program?

Three ways to differentiateLog–log chart of multiplications against model size, 3 weights to 1,000,000. Three lines: navy solid symbolic, russet dashed numeric, gold dotted automatic. The symbolic and numeric lines climb twice as steeply as the automatic line. A marker at 9 weights reads 63 multiplications for the formula route, 144 centred or 72 one-sided for the numeric route, and 24 for the program route. The formula route is cheapest up to 4 weights, the program route from 5.Three ways to differentiateL = w_1 * w_2 * ... * w_nelementary multiplications to produce all n partial derivatives110³10⁶10⁹10¹²3101001k10k100k1Mweights n (log scale)Symbolic differentiationpriced by formula lengthgrows as n²Numerical differentiationpriced by input countgrows as n²Automatic differentiationpriced by operation countgrows as na formula, exact for the functionan estimate, exact for nothingexact values for the coden = 9Formula cheapest to n = 4; program from n = 5.63 multiplications144 multiplications18 full evaluations24 multiplicationsAt 9 weights the formula route needs 63 multiplications, the numeric route 144 centred (72one-sided) and the program route 24.
Schematic Schematic: the counts are exact arithmetic for the toy program L = w_1 * w_2 * ... * w_n under stated counting rules — symbolic n(n-2), numeric 2n(n-1) centred and n(n-1) one-sided, automatic 3(n-1) multiplications — but they model work, not measured time. No stopwatch was run and no library was profiled. The chart plots those counts on log–log axes; the size control moves the marker and the numeric-step control halves that route.
Lab controls
9

Arrow keys move one size; Page Up/Down ten; Home 3; End 1,000,000

Centred, 2n(n-1)

Arrow keys switch between centred and one-sided

Frame 1 of 6: Three routes at n = 9At 9 weights the formula route needs 63 multiplications, the numeric route 144 centred (72 one-sided), and the program route 24. The vertical line marks this size; both axes are logarithmic.

Three routes at n = 9. At 9 weights the formula route needs 63 multiplications, the numeric route 144 centred (72 one-sided), and the program route 24. The vertical line marks this size; both axes are logarithmic.

Keyboard: Space plays or pauses, Left and Right step, Home goes to the first frame, End goes to the last frame.

Text description of this lab

Log–log chart of multiplications against model size, 3 weights to 1,000,000. Three lines: navy solid symbolic, russet dashed numeric, gold dotted automatic. The symbolic and numeric lines climb twice as steeply as the automatic line. A marker at 9 weights reads 63 multiplications for the formula route, 144 centred or 72 one-sided for the numeric route, and 24 for the program route. The formula route is cheapest up to 4 weights, the program route from 5.

Return to the section that hosts this lab

Caption status: schematic. Every lab declares one of published, re-simulated, schematic, synthetic or interpolated.