brain

tamnd's digital brain — notes, problems, research

43815 notes

Computational Fluid Dynamics

Computational fluid dynamics studies fluid motion by solving discretized forms of the governing equations. Automatic differentiation enters CFD when we want gradients of...

autodiffbook
Neural Network Training

Neural network training is the repeated application of three operations: evaluate a model, differentiate a scalar loss, and update parameters. Automatic differentiation...

autodiffbook
AD in C and C++

C and C++ are important targets for automatic differentiation because much scientific, engineering, graphics, finance, and machine learning infrastructure is written in these...

autodiffbook
SSA Form

Static single assignment form, or SSA, is an intermediate representation where each variable is assigned exactly once.

autodiffbook
Linear Algebra Primitives

Linear algebra primitives are tensor operations with algebraic structure: matrix multiplication, triangular solves, factorizations, inverses, determinants, norms, and spectral...

autodiffbook
Dynamic Graphs

A dynamic graph is a computation graph built while the program runs. Its structure depends on ordinary runtime values: branches, loop counts, recursive calls, tensor shapes,...

autodiffbook
Higher-Order Reverse Mode

Reverse mode is efficient for scalar-output functions because it propagates one adjoint backward through the computation and produces a full gradient. For

autodiffbook
Truncated Polynomial Algebras

Dual numbers capture first-order derivatives because the infinitesimal element satisfies

autodiffbook
Reverse Accumulation Algorithms

Reverse accumulation is the operational core of reverse mode automatic differentiation. The forward pass evaluates a program and records dependency information. The reverse...

autodiffbook
Jacobian-Vector Products

The natural output of forward mode automatic differentiation is a Jacobian-vector product. Instead of constructing the full Jacobian matrix explicitly, forward mode computes...

autodiffbook
Reverse Accumulation

Reverse accumulation is the reverse-mode form of automatic differentiation. It propagates derivative information backward from outputs to inputs.

autodiffbook
Control Flow

Control flow determines which operations a program executes. Straight-line programs have a fixed sequence of operations, but ordinary programs contain branches, loops,...

autodiffbook
Chain Rule as Composition Algebra

The chain rule is the central theorem behind automatic differentiation. Every useful AD algorithm is a disciplined way of applying the chain rule to a program.

autodiffbook
Automatic Differentiation

Automatic differentiation computes derivatives by applying the chain rule to the operations of a program. The input is ordinary code that computes a value. The output is code,...

autodiffbook
TensorFlow Autograd

TensorFlow Autograd refers to TensorFlow’s automatic differentiation system, mainly exposed through tf.GradientTape. It is a reverse-mode AD system designed for tensor...

autodiffbook
TensorFlow Autograd

TensorFlow Autograd refers to TensorFlow’s automatic differentiation system, mainly exposed through tf.GradientTape. It is a reverse-mode AD system designed for tensor...

autodiffbook
Graph Representation

A graph representation makes the structure of a differentiated computation explicit. In reverse mode, this structure is required because the backward pass must know which...

autodiffbook
Categorical Semantics

Algebraic semantics describes differentiation through derivations, tangent maps, and linear structure. Categorical semantics goes further. It studies differentiation as a...

autodiffbook
Differentiable Optimization Layers

An optimization layer is a program component whose output is the solution of an optimization problem. Instead of computing

autodiffbook
Overflow and Underflow

Floating point systems represent numbers within a finite range. When a computed value exceeds the largest representable magnitude, overflow occurs. When a value becomes too...

autodiffbook
Differentiable Rendering

Differentiable rendering is the process of computing derivatives of rendered images with respect to scene parameters. A renderer becomes part of the computational graph rather...

autodiffbook
Inverse Problems

An inverse problem asks for causes from effects. A forward model predicts observations from parameters. An inverse model tries to recover parameters from observations.

autodiffbook
Backpropagation

Backpropagation is reverse mode automatic differentiation applied to neural networks. In most machine learning writing, the term refers to the whole training procedure: run a...

autodiffbook
Differentiable Programming

Differentiable programming treats differentiation as a general programming-language feature. A program can contain numerical kernels, control flow, data structures, solvers,...

autodiffbook
Intermediate Representations

An intermediate representation, or IR, is the internal program form used by a compiler or AD system after parsing and before final code generation.

autodiffbook
Broadcasting Semantics

Broadcasting is the rule system that allows tensor operations between arrays of different shapes without explicitly materializing expanded copies. It is one of the most...

autodiffbook
Recursion

Recursion is control flow where a function calls itself. In automatic differentiation, recursion behaves like a loop with a call stack. Each recursive call contributes one...

autodiffbook
Hessian-Vector Products

A Hessian-vector product computes

autodiffbook
Geometric Interpretation

Dual numbers provide an algebraic mechanism for differentiation, but they also have a precise geometric meaning. A dual number represents a point together with an...

autodiffbook
Vector-Jacobian Products

Reverse mode automatic differentiation fundamentally computes vector-Jacobian products. The gradient of a scalar function is a special case of this more general operation.

autodiffbook
Forward Evaluation Rules

Forward mode automatic differentiation works by replacing each primitive operation with an extended operation on pairs:

autodiffbook
Forward Accumulation

Forward accumulation is the forward-mode form of automatic differentiation. It propagates derivative information in the same order as ordinary program evaluation. Each...

autodiffbook
Dependency Graphs

A dependency graph describes how values in a computation depend on earlier values. Automatic differentiation operates on these dependencies.

autodiffbook
Jacobians and Hessians

The gradient is enough when a function has many inputs and one scalar output. More general programs need more general derivative objects. Two of the most important are the...

autodiffbook
Symbolic Differentiation

Symbolic differentiation computes derivatives by manipulating expressions. The input is a formula. The output is another formula.

autodiffbook
Tapenade

Tapenade is a source-transformation automatic differentiation system developed at INRIA. Like ADIFOR, it takes an existing program and produces a new differentiated program....

autodiffbook
Tapenade

Tapenade is a source-transformation automatic differentiation system developed at INRIA. Like ADIFOR, it takes an existing program and produces a new differentiated program....

autodiffbook
Minimal Reverse Mode Engine

Reverse mode automatic differentiation computes derivatives by traversing the program backward after evaluation. Unlike forward mode, which propagates tangents alongside...

autodiffbook
Algebraic Semantics

Automatic differentiation is often introduced operationally. A program executes elementary operations, and derivative information propagates alongside the computation. This...

autodiffbook
Differentiating Through Solvers

A solver is a program that computes a value by search, iteration, or factorization. Instead of evaluating a closed-form expression, it finds a value that satisfies a condition.

autodiffbook
Stability of Reverse Mode

Reverse mode automatic differentiation computes gradients by propagating adjoint values backward through a computational graph. In exact arithmetic, the reverse accumulation...

autodiffbook
Differentiable Databases

A differentiable database is a data system whose operations participate in gradient-based optimization. Instead of treating storage and querying as external infrastructure,...

autodiffbook
Sensitivity Analysis

Sensitivity analysis studies how changes in inputs affect the outputs of a system. In differential equations, optimization, simulation, and machine learning, the main object...

autodiffbook
Stochastic Optimization

Stochastic optimization studies optimization when the objective is accessed through samples, noisy estimates, or partial observations. In machine learning, this is the normal...

autodiffbook
Functional Languages

Functional programming languages provide a natural semantic foundation for automatic differentiation. Programs are expressed as compositions of functions, immutable values,...

autodiffbook
Operator Overloading

Operator overloading implements automatic differentiation by changing the meaning of ordinary arithmetic operations for special numeric objects.

autodiffbook
Tensor Operations

Tensor operations generalize scalar, vector, and matrix operations to arrays with arbitrary rank. In automatic differentiation, a tensor is usually treated as a typed array...

autodiffbook
forward

A loop repeats a computation until a condition fails or a fixed iteration count is reached. In automatic differentiation, loops are important because many numerical algorithms...

autodiffbook
Hessian Computation

For a scalar function

autodiffbook
Nilpotent Elements

The defining feature of dual numbers is the existence of a nonzero element whose square vanishes:

autodiffbook
Reverse Computational Graphs

Reverse mode automatic differentiation operates on a computational graph. The forward pass evaluates the graph from inputs to outputs. The reverse pass traverses the same...

autodiffbook
Dual Numbers

Dual numbers give forward mode automatic differentiation a compact algebraic form. Instead of storing a value and a tangent as two unrelated fields, we package them into one...

autodiffbook
Elementary Operations

Automatic differentiation reduces differentiation to a finite collection of elementary operations. Every program, regardless of complexity, is decomposed into primitive...

autodiffbook
Intermediate Variables

Intermediate variables are the named values created between program inputs and program outputs. They make automatic differentiation mechanical.

autodiffbook
Multivariate Calculus

Automatic differentiation is usually applied to functions with many inputs and many outputs. The calculus needed for this setting is multivariate calculus: the study of how a...

autodiffbook
Numerical Differentiation

Numerical differentiation estimates derivatives by evaluating a function at nearby input values. It treats the function as a black box. The method does not need access to the...

autodiffbook
Chapter 21. Major AD Systems

ADIFOR, short for Automatic Differentiation of Fortran, is one of the classical source-transformation systems for automatic differentiation. It was designed for numerical...

autodiffbook
Appendix

ADIFOR, short for Automatic Differentiation of Fortran, is one of the classical source-transformation systems for automatic differentiation. It was designed for numerical...

autodiffbook
Chapter 20. Building an AD Engine

A minimal forward mode automatic differentiation engine has one job: evaluate a program while carrying both a value and its derivative. The engine does not build a graph. It...

autodiffbook
Chapter 19. Theory and Foundations

Automatic differentiation is often described by a simple rule:

autodiffbook
Chapter 18. Advanced Topics

Many programs do not compute their output by applying a fixed sequence of explicit operations. Instead, they define the output as the solution of another problem.

autodiffbook
Chapter 17. Numerical and Systems Concerns

Automatic differentiation computes derivatives by executing arithmetic. On a real machine, arithmetic uses finite precision. This means AD gives the derivative of the...

autodiffbook
Chapter 15. Differentiable Systems Architecture

An end-to-end differentiable pipeline is a system whose final objective can send derivative information backward through every trainable or tunable stage of computation....

autodiffbook
Chapter 14. Scientific Computing Applications

Differential equations are one of the main reasons automatic differentiation matters in scientific computing. Many scientific models are not written as closed-form functions....

autodiffbook
Chapter 13. Optimization and Machine Learning

Gradient descent is the basic optimization procedure behind much of modern machine learning. It is simple enough to state in one line, but rich enough to expose many of the...

autodiffbook
Chapter 12. AD in Modern Programming Languages

Lisp is one of the natural homes of automatic differentiation. It treats programs as data, has a simple expression syntax, and supports macro systems that can transform code...

autodiffbook
Chapter 11. Compiler and Runtime Design

Source transformation is an implementation strategy for automatic differentiation in which a program that computes a function is rewritten into another program that computes...

autodiffbook
Chapter 10. Matrix and Tensor Differentiation

Matrix calculus is the notation and rule system used to differentiate functions whose inputs, outputs, or intermediate values are vectors, matrices, or tensors. Automatic...

autodiffbook
Chapter 9. Differentiation of Control Flow

A conditional is a program construct that chooses one computation among several possible computations. In ordinary code, this is written as if, else, switch, case, pattern...

autodiffbook
Chapter 8. Higher-Order Differentiation

First derivatives describe local rate of change. Second derivatives describe how that rate of change itself changes. In optimization, this is curvature. In dynamics, it is...

autodiffbook
Chapter 7. Dual Numbers and Algebraic Structures

Dual numbers give the cleanest algebraic model of forward mode automatic differentiation. They extend ordinary real numbers with a formal infinitesimal part. Instead of...

autodiffbook
Chapter 6. Reverse Mode Automatic Differentiation

Reverse mode automatic differentiation computes derivatives by propagating sensitivities backward through a computation. In forward mode, each intermediate value carries a...

autodiffbook
Chapter 5. Forward Mode Automatic Differentiation

Forward mode automatic differentiation computes derivatives by carrying two values through a program at the same time: the ordinary value and its tangent. The ordinary value...

autodiffbook
Chapter 4. Core Theory of Automatic Differentiation

Automatic differentiation is built on a simple observation: a complicated derivative can be computed by composing many small local derivatives. Instead of manipulating a full...

autodiffbook
Chapter 3. Programs as Mathematical Objects

A straight-line program is the simplest model of computation used in automatic differentiation. It is a program with a fixed sequence of assignments, no branches, no loops,...

autodiffbook
Chapter 2. Mathematical Foundations

Automatic differentiation begins with a simple object: a function.

autodiffbook
Chapter 1. Introduction

A derivative measures how an output changes when an input changes. That sentence is simple, but it is one of the main ideas behind numerical computing, optimization, machine...

autodiffbook
LeetCode 425: Word Squares

A clear explanation of building all word squares using backtracking with prefix pruning.

leetcodearraystringbacktrackingtriehash-table
LeetCode 475: Heaters

A clear explanation of finding the minimum heater radius by sorting positions and matching each house to its nearest heater.

leetcodearraysortingbinary-searchtwo-pointers
LeetCode 424: Longest Repeating Character Replacement

A clear explanation of finding the longest substring that can become all one letter using a sliding window.

leetcodestringsliding-windowtwo-pointershash-table
LeetCode 474: Ones and Zeroes

A clear explanation of solving the largest subset problem as a two-dimensional 0/1 knapsack over zero and one counts.

leetcodedynamic-programmingknapsackarraystring
LeetCode 423: Reconstruct Original Digits from English

A clear explanation of reconstructing digits from shuffled English words using character frequency counts and unique identifying letters.

leetcodestringhash-tablecounting
LeetCode 473: Matchsticks to Square

A clear explanation of deciding whether matchsticks can form a square using backtracking, sorting, and pruning.

leetcodearraybacktrackingdfsbitmask
LeetCode 500: Keyboard Row

A clear explanation of filtering words that can be typed using only one row of an American keyboard.

leetcodearrayhash-tablestringset
LeetCode 472: Concatenated Words

A clear explanation of finding all words that can be formed by concatenating at least two shorter words from the same list.

leetcodestringdynamic-programmingtriehash-set
LeetCode 450: Delete Node in a BST

Delete a node from a binary search tree while preserving the BST property using recursive search and inorder successor replacement.

leetcodetreebinary-search-treedfsrecursion
LeetCode 400: Nth Digit

A clear explanation of finding the nth digit in the infinite integer sequence using digit groups and arithmetic.

leetcodemathbinary-search
LeetCode 399: Evaluate Division

A clear explanation of solving division equations using graph traversal and weighted edges.

leetcodegraphdfsunion-findweighted-graph
LeetCode 375: Guess Number Higher or Lower II

A clear explanation of finding the minimum guaranteed cost using interval dynamic programming.

leetcodedynamic-programminginterval-dpgame-theoryminimax
LeetCode 499: The Maze III

A clear explanation of finding the shortest rolling-ball path to the hole using Dijkstra with lexicographic tie-breaking.

leetcodegraphdijkstraheapmatrixshortest-path
LeetCode 471: Encode String with Shortest Length

A clear explanation of interval dynamic programming for encoding a string into the shortest k[encoded_string] form.

leetcodestringdynamic-programminginterval-dp
LeetCode 449: Serialize and Deserialize BST

Serialize a binary search tree compactly with preorder traversal and rebuild it using BST value bounds.

leetcodetreebinary-search-treedfsdesignserialization
LeetCode 422: Valid Word Square

A clear explanation of checking whether rows and columns read the same using direct index comparison.

leetcodearraystringmatrixsimulation
LeetCode 398: Random Pick Index

A clear explanation of picking a uniformly random index for a target value using reservoir sampling, with an alternative hash map approach.

leetcodearrayhash-tablemathreservoir-samplingrandomized
LeetCode 374: Guess Number Higher or Lower

A clear explanation of finding the picked number using binary search and the guess API.

leetcodebinary-searchinteractive-api
LeetCode 498: Diagonal Traverse

A clear explanation of returning matrix elements in diagonal zigzag order by grouping cells with the same row plus column index.

leetcodearraymatrixsimulation
LeetCode 373: Find K Pairs with Smallest Sums

A clear explanation of finding the k smallest pair sums from two sorted arrays using a min heap and best-first search.

leetcodeheappriority-queuearraybest-first-search
LeetCode 470: Implement Rand10() Using Rand7()

A clear explanation of generating a uniform random integer from 1 to 10 using only rand7 and rejection sampling.

leetcodemathrandomizedrejection-sampling
LeetCode 448: Find All Numbers Disappeared in an Array

Find all missing numbers from 1 to n in O(n) time using in-place index marking.

leetcodearrayhashingin-place
LeetCode 421: Maximum XOR of Two Numbers in an Array

A clear explanation of finding the maximum XOR of two numbers using greedy bit prefixes.

leetcodearraybit-manipulationgreedytrie