Worked examples — Computational graphs and autograd
We first draw the scenario matrix: the complete list of structural situations a computational graph can throw at you. Then every example is tagged with the cell it covers.
The scenario matrix
Every computational-graph problem is some combination of these structural situations. A "cell" is one row here.
| # | Cell (structural situation) | Why it's tricky | Covered by |
|---|---|---|---|
| A | Single path input → output | The plain chain rule, no summing | Ex 1 |
| B | Fan-out (one node feeds ≥2 children) | Must accumulate () adjoints | Ex 2 |
| C | Dead branch (a node not on any path to output) | Its adjoint must be 0 | Ex 3 |
| D | Multiplication node with equal inputs () | Both edges carry gradient, easy to halve by mistake | Ex 4 |
| E | Zero / degenerate input killing a gradient | A factor becomes , gradient vanishes | Ex 5 |
| F | Full neuron chain (loss → sigmoid → linear) | Real backprop, several primitives stacked | Ex 6 |
| G | Broadcast / vector sum (one input, many outputs summed) | Adjoints from every output add | Ex 7 |
| H | Limiting behaviour (saturated sigmoid, ) | Gradient , "vanishing gradient" | Ex 8 |
| I | Word problem (real-world sensitivity) | Translate story → graph → adjoint | Ex 9 |
| J | Exam twist (branch that cancels: ) | Adjoints from two paths cancel to | Ex 10 |
We reuse the adjoint rule throughout:
Below, the small diagram shows the reading direction: values flow right (forward), blame flows left (backward).
Example 1 — Single path (Cell A)
Forecast: guess first — is bigger or smaller than ? Write your guess.
- Forward, store values. ; ; . Why this step? Local derivatives need these numbers (e.g. needs ).
- Seed . Why? by definition.
- Edge : . Why? so the local slope is .
- Edge : . Why? , evaluated at the stored .
- Edge : . Why? is linear, slope .
Answer: .
Verify: analytically , so , at gives . ✓ (Single path = one product of slopes, no summing needed.)
Example 2 — Fan-out, must accumulate (Cell B)
Forecast: how many paths does take to reach ? Guess the count before continuing.

Look at the figure: the amber node splits into two cyan edges — one to , one to . That split is the fan-out. Both branches must contribute blame.
- Forward. ; ; . Why? Store — the product's local derivatives are the other factor.
- Seed .
- Edge : . Why? .
- Edge : . Why? symmetric, .
- Edge : . Why? , slope . First contribution.
- Edge : . Why? , slope ; accumulate — this is the second path. → .
Answer: .
Verify: , so ; at : . ✓ If you had overwritten instead of accumulating you'd get — wrong. This is the classic mistake.
Example 3 — Dead branch (Cell C)
Forecast: does affect at all? Guess .
- Forward. ; is computed but unused by . Why? We evaluate the whole program, but only what feeds matters for blame.
- Seed .
- Edge : . Why? , at is .
- Node : it has no child on the path to , so . Why? Blame only flows backward from the output; received no seed and no adjoint from any child.
- Edge : .
Answer: .
Verify: contains no , so for all . ✓ (Autograd sets adjoints of unreachable nodes to zero automatically — they simply never get pushed.)
Example 4 — Multiply a node by itself (Cell D)
Forecast: slope of is . Will autograd give or accidentally ?
- Forward. Treat the two inputs of the multiply as and where . . Why? A multiply node has two input slots; both happen to be fed by — that is a fan-out.
- Seed .
- Left leg : . Why? .
- Right leg : . Why? .
- Edge : .
- Edge : . Accumulate. → .
Answer: .
Verify: , at . ✓ The factor of comes entirely from summing both legs — the derivative rule for is autograd's fan-out at work.
Example 5 — Zero input kills the gradient (Cell E)
Forecast: one of these adjoints will be zero. Which one, and why?
- Forward. ; ; .
- Seed .
- Edge : . Why? here.
- Edge : . Why? .
- ; .
Answer: .
Verify: and at . ✓ A zero value on one input zeroes the other input's gradient — a degenerate but perfectly valid case. Frameworks handle it with no special code.
Example 6 — Full neuron chain (Cell F)
Forecast: since and , the loss wants to decrease . Will be positive or negative?
- Forward. ; ; . Why store ? needs ; the linear slope needs .
- Seed .
- Edge : . Why? .
- Edge : . Why? , the sigmoid identity.
- Edge : . Why? , so .
Answer: (positive).
Verify: positive gradient means Gradient descent will decrease , lowering , lowering toward — exactly what we want. Numerically the closed form gives the same . ✓
Example 7 — Broadcast / summed outputs (Cell G)
Forecast: , so the answer is obviously — but watch how the adjoints stack.
- Forward. ; .
- Seed .
- Sum node: for each term. So . Why? Derivative of a sum w.r.t. each summand is .
- Edge : .
- Edge : .
- Edge : . → .
Answer: .
Verify: , . ✓ Broadcasting one variable into many summed uses = sum the adjoints from every use — the general form of the fan-out rule (this is exactly how a bias reused across a batch gets its gradient in PyTorch autograd / TensorFlow GradientTape).
Example 8 — Limiting behaviour: saturated sigmoid (Cell H)
Forecast: the sigmoid is nearly flat far from the origin. Guess: will be near or near ?

The figure shows flattening: at the curve is almost horizontal, so a wiggle in barely moves .
- Forward. .
- Local slope . Why? Sigmoid identity again.
- Edge : .
Answer: — essentially zero.
Verify: as , , , so . Same as (). ✓ This is the vanishing-gradient case: saturated neurons pass almost no blame backward — a real reason deep nets stall, and why alternatives to sigmoid exist (Sigmoid and activation functions).
Example 9 — Word problem: cost sensitivity (Cell I)
Forecast: guess whether cutting the price or the count gives more cost reduction per unit nudge.
- Model as a graph. (multiply), (add). Why? Translate the story into add/multiply primitives.
- Forward. ; .
- Seed (we ask sensitivity of total cost).
- Edge : ; also . Why? Add node passes blame unchanged.
- Edge : . Why? .
- Edge : . Why? .
Answer: dollars-per-(dollar-of-price), dollars-per-part.
Verify: dropping price by $1 saves $100 (all 100 parts get cheaper); dropping count by 1 saves $3 (one part's price). Cutting price moves cost far faster. Units check: has units $/($/part)·... = dollars saved per unit price change. ✓ This is exactly a gradient in cost space.
Example 10 — Exam twist: branches that cancel (Cell J)
Forecast: always. But do the intermediate adjoints vanish, or do they cancel at the end? Guess.
- Forward. ; ; .
- Seed .
- Edge : . Why? .
- Edge : . Why? — the sign matters.
- Edge : .
- Edge : . Accumulate. → .
Answer: .
Verify: identically, so . ✓ Note the adjoints did not vanish individually (); they cancelled at the accumulation step. This is the subtractive twin of Example 2 — same fan-out, opposite signs — and shows why keeping edge signs correct is critical.
Recall Self-test on the cells
Which cell is ? ::: Cell D — fan-out in disguise, both legs summed to give . Why is Example 10's answer zero even though ? ::: The two path adjoints ( and ) cancel at the accumulation step. In Example 8, what physical phenomenon does represent? ::: The vanishing gradient of a saturated sigmoid. In the word problem, why is ? ::: (many parts share the price) while .