21 / 90

Day 21: Computational graphs and the backpropagation connection (review)

This is a consolidation and review day: walk a computational graph forward and backward by hand, prove that shared nodes accumulate gradient, and re-verify the block's results with one finite-difference harness. Retrieval and review are part of the 480-minute ledger.

AI Mathematics & Calculus 480 active minutes (8 hours focused study)
01 120 min

Computational graphs: local derivatives and backward accumulation

Assistance allowed only after prediction and observed evidence are recorded.

Prerequisites

Days 19-20 chain rule and gradient drills; if any step is shaky, open the day-level recovery link first.

Learning Objective

Decompose a scalar expression into a computational graph, compute each node's forward value, then propagate derivatives backward by multiplying local chain-rule factors.

Instructions

Take L = (a*b + c)^2 with a = 2, b = 3, c = 1. Forward: n1 = a*b = 6, n2 = n1 + c = 7, L = n2^2 = 49. Backward: dL/dn2 = 2*n2 = 14; dL/dn1 = 14 * ∂n2/∂n1 = 14 * 1 = 14; dL/dc = 14 * ∂n2/∂c = 14; dL/da = 14 * ∂n1/∂a = 14 * b = 42; dL/db = 14 * ∂n1/∂b = 14 * a = 28. Every step is the Day 19-20 chain rule applied to one local edge. Predict dL/da before perturbing a in code.

Practice & Prediction Log

Draw the graph for L = (a*b + c)^2 at (2, 3, 1), fill in forward values 6, 7, 49, then compute all input gradients by hand. Verify dL/da, dL/db, dL/dc against central finite differences and record agreement.

Independent Mastery Criterion

You reproduce forward values 6, 7, 49 and backward values 42, 28, 14 unaided, name the local derivative on every edge, and your finite-difference run agrees with each hand gradient.

Authoritative Source Resources & Provenance

linking MIT

micrograd: A tiny scalar-valued autograd engine

Author: Andrej Karpathy | Original Source Link ↗

Relevant Section / Range: micrograd/engine.py: class Value (_backward closures and backward() topological sort); README 'Example usage'

Verified Version & Date: 2022 (verified 2026-10-30)

Selection Rationale:

The scalar computational graph in this lesson is exactly the micrograd engine walkthrough; it previews the autograd project without importing any material.

Source Prerequisites:

Chain rule and partial derivatives (Study Days 19-20).

Safe Fallback (Offline Resilience):

The full forward and backward pass is derived locally with numeric verification; no video is required.

Compared Candidate Sources & Selection Analysis (2)
PyTorch Autograd Internals ↗ compared_alternative [Modified BSD]

Normative production documentation, but micrograd's pure Python implementation provides far superior initial clarity.

3Blue1Brown: What is Backpropagation? ↗ compared_alternative [3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions]

High visual quality, pairs cleanly as optional supplementary visual reference.

linking CC BY-NC-SA 4.0 attribution noncommercial share-alike

OpenStax Calculus Volume 3

Author: OpenStax, Rice University (Gilbert Strang, Edwin Herman, et al.) | Original Source Link ↗

Relevant Section / Range: Section 4.5: tree-diagram rule used to justify backward accumulation

Verified Version & Date: OpenStax Calculus Volume 3 web edition (verified 2026-10-30)

Selection Rationale:

Provides the formal chain rule statement that the graph walkthrough applies node by node.

Source Prerequisites:

Scalar chain rule (day-19) and partial derivatives (day-20).

Safe Fallback (Offline Resilience):

The derivation uses only local rules already proven on Days 19-20.

Compared Candidate Sources & Selection Analysis (2)

Selected as the lecture-depth companion for partial derivatives; OpenStax Volume 3 remains the written primary reference.

Khan Academy: Multivariable Calculus ↗ compared_alternative [CC BY-NC-SA 4.0]

Strong visual coverage of gradients, but the OpenStax text better matches the lesson's theorem-plus-hand-check structure.

02 120 min

Shared nodes: why gradient contributions accumulate

Independent practice: predict first and preserve the recorded unaided attempt; any later help is a separate assisted-recovery phase, and a fresh equivalent unaided check is required before the idea counts as independent evidence.

Prerequisites

Complete the previous activity; use the listed recovery link if blocked.

Learning Objective

Prove that when one node feeds two consumers its total gradient is the sum of both contributions, and verify the reusable-variable counterexample by direct substitution.

Instructions

Case 1: L = (a + 1)^2 with a = 2. Write it as L = u * v where u = a + 1 and v = a + 1 — the variable a is shared by both factors, so it reaches L along two paths. Path view: the u-path contributes v * du/da = u * 1 = u, the v-path contributes u * dv/da = u, total dL/da = 2u = 6 at a = 2. The single-path answer 3 is the counterexample error. Case 2: w = (u + v)^2 with u = x^2, v = 2x at x = 1: dw/dx = 2(u + v) * (2x + 2) = 2 * 3 * 4 = 24. If you use help after the preserved attempt, treat it as assisted recovery: keep the original attempt unchanged, and pass a fresh equivalent unaided check before calling the idea remediated.

Practice & Prediction Log

Compute and verify: (a) dL/da at a = 2 for L = (a + 1)^2 — show both path contributions and the wrong single-path value; (b) dw/dx at x = 1 for w = (u + v)^2, u = x^2, v = 2x — by the tree rule and by expanding (x^2 + 2x)^2.

Independent Mastery Criterion

Unaided, you identify every path into the shared node, produce 6 and 24 with an independent check for each, and explain why dropping a path undercounts by exactly that path's contribution.

Authoritative Source Resources & Provenance

linking MIT

micrograd: A tiny scalar-valued autograd engine

Author: Andrej Karpathy | Original Source Link ↗

Relevant Section / Range: micrograd/engine.py: class Value (_backward closures and backward() topological sort); README 'Example usage'

Verified Version & Date: 2022 (verified 2026-10-30)

Selection Rationale:

The reusable-variable counterexample in this activity mirrors the accumulation behavior a correct engine must implement.

Source Prerequisites:

Computational graph walkthrough (day-21-act-01).

Safe Fallback (Offline Resilience):

The counterexample is proven locally by direct substitution and a finite-difference check.

Compared Candidate Sources & Selection Analysis (2)
PyTorch Autograd Internals ↗ compared_alternative [Modified BSD]

Normative production documentation, but micrograd's pure Python implementation provides far superior initial clarity.

3Blue1Brown: What is Backpropagation? ↗ compared_alternative [3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions]

High visual quality, pairs cleanly as optional supplementary visual reference.

linking CC BY-NC-SA 4.0 attribution noncommercial share-alike

OpenStax Calculus Volume 3

Author: OpenStax, Rice University (Gilbert Strang, Edwin Herman, et al.) | Original Source Link ↗

Relevant Section / Range: Section 4.5: sum over all dependency paths when a variable is reused

Verified Version & Date: OpenStax Calculus Volume 3 web edition (verified 2026-10-30)

Selection Rationale:

States the rule that total derivatives add contributions along every path, which the counterexample verifies.

Source Prerequisites:

Scalar chain rule (day-19) and partial derivatives (day-20).

Safe Fallback (Offline Resilience):

The proof reduces the composition to a single-variable expansion, independent of the external source.

Compared Candidate Sources & Selection Analysis (2)

Selected as the lecture-depth companion for partial derivatives; OpenStax Volume 3 remains the written primary reference.

Khan Academy: Multivariable Calculus ↗ compared_alternative [CC BY-NC-SA 4.0]

Strong visual coverage of gradients, but the OpenStax text better matches the lesson's theorem-plus-hand-check structure.

03 120 min

Finite-difference verification harness and retrieval review

Assistance allowed only after prediction and observed evidence are recorded.

Prerequisites

Complete the previous activity; use the listed recovery link if blocked.

Learning Objective

Consolidate Days 16-20 by writing one reusable central-difference helper that re-verifies this block's key numbers, then run a closed-book retrieval pass over the block's definitions.

Instructions

Write the helper def central_fd(f, x, h=1e-5): return (f(x + h) - f(x - h)) / (2 * h) and predict each row before running: d/dx (3x + 1)^2 at x = 1 -> 24; d/dx (5x - 2)^3 at x = 1 -> 135; d/dx (x^2 + 1)^2 at x = 2 -> 40; ∂/∂x and ∂/∂y of x^2 y + 3y - x at (2, 1) -> 3 and 7; gradient norm of x^2 + y^2 at (3, 4) -> 10; and dL/da, dL/db, dL/dc for L = (a*b + c)^2 at (2, 3, 1) -> 42, 28, 14.

Practice & Prediction Log

Run the harness for all six rows, then close the notes and retrieve from memory: the limit definition of the derivative, the chain rule statement, the partial derivative definition, the gradient norm property, and the path-sum rule for shared variables. Mark anything missed.

Independent Mastery Criterion

All harness rows agree with the predicted values to four decimals, and your retrieval list reproduces all five statements with no more than one marked miss plus a recovery plan for it.

Authoritative Source Resources & Provenance

linking PSF License Version 2

The Python Tutorial: Numbers and Expressions

Author: Python Software Foundation | Original Source Link ↗

Relevant Section / Range: Section 3.1.1 Numbers: arithmetic used by the verification harness

Verified Version & Date: Python 3.12 documentation (verified 2026-10-30)

Selection Rationale:

Reference for the arithmetic in the central finite-difference helper reused across the block.

Source Prerequisites:

Able to run a short Python file from the terminal.

Safe Fallback (Offline Resilience):

The harness listing is embedded and runs on a standard Python install.

Compared Candidate Sources & Selection Analysis (2)
math — Mathematical functions ↗ compared_alternative [PSF License Version 2]

Extends the operator set to transcendental functions; kept as a follow-on once the arithmetic expressions are fluent.

The Python Tutorial: Floating Point Arithmetic Issues ↗ compared_alternative [PSF License Version 2]

Explains binary float representation limits; deferred to the numerics days where tolerance reasoning is rehearsed.

linking CC BY-NC-SA 4.0 attribution noncommercial share-alike

OpenStax Calculus Volume 1

Author: OpenStax, Rice University (Gilbert Strang, Edwin Herman, et al.) | Original Source Link ↗

Relevant Section / Range: Sections 3.1-3.6 review scope for the block retrieval check

Verified Version & Date: OpenStax Calculus Volume 1 web edition (verified 2026-10-30)

Selection Rationale:

Optional drill source for extra derivative review during the consolidation block.

Source Prerequisites:

Derivative rules for powers and polynomials (Study Days 16-18).

Safe Fallback (Offline Resilience):

The retrieval checklist is self-contained in the lesson.

Compared Candidate Sources & Selection Analysis (3)
MIT OpenCourseWare 18.01SC Single Variable Calculus ↗ compared_selected_for_visual_practice [CC BY-NC-SA 4.0]

Strong exercises and transcripts, but the noncommercial share-alike terms and course navigation make OpenStax the primary stable text.

Paul's Online Math Notes: Calculus I ↗ compared_rejected_for_reuse [All Rights Reserved]

Useful reference, but rights and redistribution terms are less suitable for embedded recovery material.

SciPy Numerical Differentiation Documentation ↗ compared_selected_for_numerics [BSD-3-Clause]

A primary API reference for numerical derivative step-size behavior; it complements rather than replaces the hand derivation.

04 120 min

Block review assessment: graph gradient, edge cases, and recovery plan

Independent Mastery Check (no AI assistance).

Prerequisites

Complete the previous activity; use the listed recovery link if blocked.

Learning Objective

Independently compute all input gradients of a small computational graph, handle a nondifferentiable edge, and produce a recovery plan mapping each weak point to its review day.

Instructions

Closed book, no AI. Part 1: L = (a*b)^2 + c at a = 1, b = 2, c = 3. Forward: n1 = a*b = 2, n2 = n1^2 = 4, L = n2 + c = 7. Compute dL/da, dL/db, dL/dc backward by hand. Part 2: the ReLU node f(x) = max(0, x) at x = 0 has left slope 0 and right slope 1. State whether its derivative exists, what convention engines commonly choose, and why downstream gradients still need care. Part 3: write a recovery plan that maps any missed result to the day that taught it (Days 16-18 limits/derivatives, 19 chain rule, 20 gradients).

Practice & Prediction Log

Submit: the three gradients with forward node values, the ReLU edge-case verdict, and your recovery plan. Verify Part 1 numerically before submitting.

Independent Mastery Criterion

Unaided: forward values 2, 4, 7 and gradients 8, 4, 1 verified numerically; the ReLU verdict distinguishes 'undefined' from 'conventional 0'; and the recovery plan maps every miss to a concrete day.

Authoritative Source Resources & Provenance

linking MIT

micrograd: A tiny scalar-valued autograd engine

Author: Andrej Karpathy | Original Source Link ↗

Relevant Section / Range: micrograd/engine.py: class Value (_backward closures and backward() topological sort); README 'Example usage'

Verified Version & Date: 2022 (verified 2026-10-30)

Selection Rationale:

Optional preview of the autograd engine that the independent graph computation imitates.

Source Prerequisites:

All of Study Days 19-21 activities 1-3.

Safe Fallback (Offline Resilience):

The assessment is fully specified locally with a worked reference answer.

Compared Candidate Sources & Selection Analysis (2)
PyTorch Autograd Internals ↗ compared_alternative [Modified BSD]

Normative production documentation, but micrograd's pure Python implementation provides far superior initial clarity.

3Blue1Brown: What is Backpropagation? ↗ compared_alternative [3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions]

High visual quality, pairs cleanly as optional supplementary visual reference.

linking CC BY-NC-SA 4.0 attribution noncommercial share-alike

OpenStax Calculus Volume 3

Author: OpenStax, Rice University (Gilbert Strang, Edwin Herman, et al.) | Original Source Link ↗

Relevant Section / Range: Section 4.6: gradients exist only where partials exist; review scope for edge cases

Verified Version & Date: OpenStax Calculus Volume 3 web edition (verified 2026-10-30)

Selection Rationale:

Frames the ReLU kink edge case reviewed in the block assessment.

Source Prerequisites:

Partial derivatives and the multivariable chain rule.

Safe Fallback (Offline Resilience):

The edge case is resolved locally with left and right slopes.

Compared Candidate Sources & Selection Analysis (2)

Selected as the lecture-depth companion for partial derivatives; OpenStax Volume 3 remains the written primary reference.

Khan Academy: Multivariable Calculus ↗ compared_alternative [CC BY-NC-SA 4.0]

Strong visual coverage of gradients, but the OpenStax text better matches the lesson's theorem-plus-hand-check structure.