Calculus

Computation Graphs

A computation graph breaks a calculation into nodes so values flow forward and sensitivities flow backward.

status: publishedimportance: criticaldifficulty 2/5math: undergraduateread: 13mlive demo
Editorial autodiff illustration of computation graph nodes with forward value flow and backward sensitivity arrows.

Concept Structure

Computation Graphs

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

1prerequisites
1next concepts
1related links

Learning map

Computation Graphs
BeforeChain RuleNow4/4 sections readyTryManipulate one control and predict the visible change.NextReverse-Mode Automatic Differentiation

Object flow

4/4 sections readyAsk about thisResearch room
ConceptComputation GraphsCalculus
1 source attachedLocal snapshot ready
concept:calculus/computation-graphs

Conceptual Bridge

What should feel connected as you move through this page.

Carry inChain Rule

Bring the mental model from Chain Rule; this page will reuse it instead of restarting from zero.

Work hereComputation Graphs

A computation graph breaks a calculation into nodes so values flow forward and sensitivities flow backward.

Carry outReverse-Mode Automatic Differentiation

The next edge should feel earned: use the demo prediction here before following Reverse-Mode Automatic Differentiation.

Test the linkManipulate one control and predict the visible change.Then continue to Reverse-Mode Automatic Differentiation
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

Suppose one intermediate value gets used twice. If a=xya=xy, b=sin(a)b=\sin(a), and c=a+bc=a+b, then aa affects cc directly and also through bb. How should the derivative remember both uses without differentiating one huge expanded formula by hand?

A computation graph makes that bookkeeping visible.

Instead of treating a function as one large expression, we split it into small operations: multiply here, apply a nonlinearity, add there, reuse an intermediate value. Each operation becomes a node, and each dependency becomes an edge.

A computation graph is not just an expression tree. The expanded expression xy+sin(xy)xy+\sin(xy) repeats xyxy. The graph stores a=xya=xy once and records that two later operations depend on that same value.

This matters because the graph gives backpropagation a route. Values move forward through the graph to produce an output or loss. Derivatives move backward through the same graph, using local slopes on each edge. The chain rule stops feeling like one giant symbolic derivative and becomes bookkeeping over small local changes.

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

In this first example, every node is scalar. Let x,yRx,y\in\mathbb R, and draw edges from inputs to the values that depend on them. The graph for one forward pass is a directed acyclic graph: later nodes depend on earlier nodes, not the other way around.

Consider the scalar computation

a=xy,b=sin(a),c=a+b.a = xy,\qquad b = \sin(a),\qquad c = a + b.

The graph has inputs x,yx,y, intermediate nodes a,ba,b, and output cc. The forward pass stores each node value. The important detail is reuse: aa is stored once, but two later uses depend on it. The backward pass asks how a small change in each node would affect the output.

For any node vv, write

vˉ=cv.\bar v = \frac{\partial c}{\partial v}.

The output seed is cˉ=1\bar c=1. The final add node c=a+bc=a+b sends one unit of sensitivity to both inputs:

aˉ+=cˉcadirect=1,bˉ+=cˉcb=1.\bar a \mathrel{+}= \bar c\frac{\partial c}{\partial a}\Big|_{\text{direct}} = 1,\qquad \bar b \mathrel{+}= \bar c\frac{\partial c}{\partial b} = 1.

The sine branch also sends a local contribution into the same stored node aa. The important invariant is local: a node's cotangent is the sum of contributions from each immediate downstream use. The demo hides the sine-branch contribution until you predict whether it will lower, preserve, or raise the direct baseline.

The backward pass does not expand every symbolic path; each downstream node has already summarized everything beyond it.

For vector or tensor nodes, the same idea uses Jacobians or local vector-Jacobian product rules. With column-vector cotangents, if vj=f(vi)v_j=f(v_i) and Jji=vj/viJ_{ji}=\partial v_j/\partial v_i, the reverse update is

vˉi+=JjiTvˉj.\bar v_i \mathrel{+}= J_{ji}^{\mathsf T}\bar v_j.

Reverse-mode autodiff is the automated version of this bookkeeping: save forward values, then run local backward rules in reverse topological order.

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
import math

x, y = 2.0, 3.0

# Forward pass: store intermediate node values.
a = x * y
b = math.sin(a)
c = a + b

# Reverse pass bookkeeping: every downstream use appends one local contribution.
bar_c = 1.0
bar_a = 0.0
bar_b = 0.0
bar_x = 0.0
bar_y = 0.0

# c = a + b sends one unit to both inputs.
bar_a += bar_c * 1.0
bar_b += bar_c * 1.0

# b = sin(a) sends another contribution into reused node a.
bar_a += bar_b * math.cos(a)

# a = x * y sends the accumulated sensitivity to x and y.
bar_x += bar_a * y
bar_y += bar_a * x

print("c:", round(c, 4))
print("stored a once:", a)
print("downstream uses of a:", ["direct add edge", "sine edge"])
print("bar_a:", round(bar_a, 4))
print("dc/dx:", round(bar_x, 4))
print("dc/dy:", round(bar_y, 4))

The code is deliberately manual. The += updates are the graph mechanism: a reused node collects every downstream local contribution before sending its accumulated sensitivity to its own inputs.

04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

Use the sliders to change xx and yy. In Forward mode, watch the stored value a=xya=xy feed both b=sin(a)b=\sin(a) and the final add node c=a+bc=a+b.

Before switching into the backward numbers, predict whether the hidden accumulated sensitivity at the reused node aa should land lower than, nearly equal to, or higher than the direct contribution from c=a+bc=a+b.

Use Case A and Case B as neutral graph states. Commit first, then reveal how the downstream paths combine before aa sends sensitivity back to xx and yy.

Live Concept Demo

Explore Computation Graphs

The stage is code-native and interactive. Use it to test the explanation against the mechanism.

difficulty 2/5undergraduatecode-aligned
Demo Prediction Checkpoint

Manipulate one control and predict the visible change.

Commit to what Computation Graphs should make visible before reading the result.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

A computation graph breaks a calculation into nodes so values flow forward and sensitivities flow backward.

Prediction open01 / Intuition
Editorial autodiff illustration of computation graph nodes with forward value flow and backward sensitivity arrows.
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Computation Graphs should make visible.

Visual Inquiry

Make the image answer a mathematical question

A computation graph breaks a calculation into nodes so values flow forward and sensitivities flow backward.

4/4 stages readyLive demo connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Computation Graphs easier to reason about before the page gives the answer.

Source Grounding

Canonical references for the mechanism on this page.

paper · 2018Automatic differentiation in machine learning: a surveyBaydin et al.

Grounds computation graphs as the program structure used by automatic differentiation systems.

Open source

Claim Review

A computation graph breaks a calculation into nodes so values flow forward and sensitivities flow backward.

Status1 substantive review recorded

Claims without a substantive review badge still need exact source-support review.

Sources1 reference

baydin-2018-ad-survey

Witnesses4 local objects

Use equation, code, and demo objects to check whether the source support is operational.

Substantively reviewedFor one executed differentiable program, a computation graph uses elementary-operation nodes and dependency edges, stores each reused intermediate node value once in the forward pass, and makes reverse-mode/backprop local: downstream sensitivities from every use accumulate at a node before being sent to its inputs.Claim metadata: source checked

Baydin et al. describe AD over evaluation traces of elementary operations, computational graphs for dependency relations, and reverse mode as a forward pass that populates intermediate variables/records graph dependencies followed by reverse adjoint propagation; the page example a=xy instantiates reuse and additive accumulation.

Sources: Automatic differentiation in machine learning: a surveyCovers differentiable primitives in one executed DAG/program trace and local scalar/vector-VJP teaching model, not symbolic simplification, mutation/aliasing, checkpointing policy, nonsmooth primitives, or every static/dynamic control-flow convention.A bounded review summary is present; still check caveats and exact source scope.

Checked Baydin et al. for one executed AD trace: programs become elementary-operation traces and graphs of intermediate-variable dependencies; reverse mode runs code forward, populates intermediates, records dependencies, then propagates adjoints backward; a reused variable's adjoint sums downstream contributions before input derivatives are obtained. Local math/code/demo instantiate a=xy,b=sin(a),c=a+b with one stored a, direct + sine-path cotangent accumulation, and propagation to x,y.

Reviewer: codex+oracle; reviewed 2026-05-07

Practice Loop

Try the idea before it explains itself

A computation graph breaks a calculation into nodes so values flow forward and sensitivities flow backward.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Computation Graphs.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Object research drawerClose
ConceptComputation GraphsCalculus

Research Room

Attach the question to an exact object

Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptCalculus

Computation Graphs

Anchored question

What is the smallest example that makes Computation Graphs click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays locally in this browser for concept:calculus/computation-graphs.

No local draft saved.
Evidence to inspect
  • Source ids to inspect: baydin-2018-ad-survey
  • Definition, prerequisite, and contrast concept links
  • The equation or code witness that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - Computation Graphs Object key: concept:calculus/computation-graphs Context: Calculus Anchor id: concept/concept-notebook/calculus/computation-graphs Open question: What is the smallest example that makes Computation Graphs click without losing the math? Evidence to inspect: - Source ids to inspect: baydin-2018-ad-survey - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

Open source object
concept/concept-notebook/calculus/computation-graphs concept:calculus/computation-graphs