brain
tamnd's digital brain — notes, problems, research
42768 notes
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...
For a scalar function
The defining feature of dual numbers is the existence of a nonzero element whose square vanishes:
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...
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...
Automatic differentiation reduces differentiation to a finite collection of elementary operations. Every program, regardless of complexity, is decomposed into primitive...
Intermediate variables are the named values created between program inputs and program outputs. They make automatic differentiation mechanical.
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...
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...
ADIFOR, short for Automatic Differentiation of Fortran, is one of the classical source-transformation systems for automatic differentiation. It was designed for numerical...
ADIFOR, short for Automatic Differentiation of Fortran, is one of the classical source-transformation systems for automatic differentiation. It was designed for numerical...
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...
Automatic differentiation is often described by a simple rule:
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.
Automatic differentiation computes derivatives by executing arithmetic. On a real machine, arithmetic uses finite precision. This means AD gives the derivative of the...
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....
Differential equations are one of the main reasons automatic differentiation matters in scientific computing. Many scientific models are not written as closed-form functions....
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...
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...
Source transformation is an implementation strategy for automatic differentiation in which a program that computes a function is rewritten into another program that computes...
Matrix calculus is the notation and rule system used to differentiate functions whose inputs, outputs, or intermediate values are vectors, matrices, or tensors. Automatic...
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...
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...
Dual numbers give the cleanest algebraic model of forward mode automatic differentiation. They extend ordinary real numbers with a formal infinitesimal part. Instead of...
Reverse mode automatic differentiation computes derivatives by propagating sensitivities backward through a computation. In forward mode, each intermediate value carries a...
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...
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...
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,...
Automatic differentiation begins with a simple object: a function.
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...
A clear explanation of building all word squares using backtracking with prefix pruning.
A clear explanation of finding the minimum heater radius by sorting positions and matching each house to its nearest heater.
A clear explanation of finding the longest substring that can become all one letter using a sliding window.
A clear explanation of solving the largest subset problem as a two-dimensional 0/1 knapsack over zero and one counts.
A clear explanation of reconstructing digits from shuffled English words using character frequency counts and unique identifying letters.
A clear explanation of deciding whether matchsticks can form a square using backtracking, sorting, and pruning.
A clear explanation of filtering words that can be typed using only one row of an American keyboard.
A clear explanation of finding all words that can be formed by concatenating at least two shorter words from the same list.
Delete a node from a binary search tree while preserving the BST property using recursive search and inorder successor replacement.
A clear explanation of finding the nth digit in the infinite integer sequence using digit groups and arithmetic.
A clear explanation of solving division equations using graph traversal and weighted edges.
A clear explanation of finding the minimum guaranteed cost using interval dynamic programming.
A clear explanation of finding the shortest rolling-ball path to the hole using Dijkstra with lexicographic tie-breaking.
A clear explanation of interval dynamic programming for encoding a string into the shortest k[encoded_string] form.
Serialize a binary search tree compactly with preorder traversal and rebuild it using BST value bounds.
A clear explanation of checking whether rows and columns read the same using direct index comparison.
A clear explanation of picking a uniformly random index for a target value using reservoir sampling, with an alternative hash map approach.
A clear explanation of finding the picked number using binary search and the guess API.
A clear explanation of returning matrix elements in diagonal zigzag order by grouping cells with the same row plus column index.
A clear explanation of finding the k smallest pair sums from two sorted arrays using a min heap and best-first search.
A clear explanation of generating a uniform random integer from 1 to 10 using only rand7 and rejection sampling.
Find all missing numbers from 1 to n in O(n) time using in-place index marking.
A clear explanation of finding the maximum XOR of two numbers using greedy bit prefixes.
A clear explanation of reducing an integer to 1 with the fewest operations using greedy bit decisions.
A clear explanation of computing large modular exponentiation using fast power, modular arithmetic, and digit decomposition.
A clear explanation of Maximum Size Subarray Sum Equals k using prefix sums and earliest-index hashing.
A clear explanation of Wiggle Sort II using sorting, median splitting, and virtual indexing.
A clear explanation of maximizing the rotation function using a recurrence instead of simulating every rotation.
A clear explanation of counting connected components using Union-Find and graph traversal.
A clear explanation of checking whether ordered points form a convex polygon using cross products.
Count ordered boomerang tuples by fixing each point as the center and grouping other points by squared distance.
A clear explanation of uniformly picking an integer point from non-overlapping rectangles using prefix sums and binary search.
A clear explanation of checking the minimum edits needed to make a password strong using greedy handling of length, missing character types, and repeated runs.
A clear explanation of adding two integers without using plus or minus by using XOR, AND, carry, and a 32-bit mask.
A clear explanation of Intersection of Two Arrays II using frequency counting.
A clear explanation of Coin Change using dynamic programming for minimum coin count.
A clear explanation of finding the next greater element using a monotonic decreasing stack and hash map.
A clear explanation of counting battleships in a board using one-pass observation without modifying the grid.
A clear explanation of Create Maximum Number using monotonic stacks for subsequences and greedy merging.
A clear explanation of calculating total poisoned duration by merging overlapping attack intervals.
A clear explanation of validating IPv4 and IPv6 addresses by checking segment count, length, characters, range, and leading-zero rules.
Count arithmetic subsequences of length at least three using dynamic programming with one hash map per ending index.
A clear explanation of fitting a sentence onto a screen using cyclic string simulation and greedy row transitions.
A clear explanation of finding the longest substring where every character appears at least k times using divide and conquer.
A clear explanation of applying many range updates efficiently using a difference array and prefix sums.
A clear explanation of Intersection of Two Arrays using hash sets for uniqueness and fast lookup.
A clear explanation of Generalized Abbreviation using backtracking to choose whether each character is kept or abbreviated.
A dynamic programming and patience sorting solution for finding the longest strictly increasing subsequence in an array.
A clear explanation of counting sign assignments that reach a target using recursion first, then subset-sum dynamic programming.
A clear explanation of finding cells that can flow to both oceans using reverse graph traversal from the borders.
A clear explanation of counting unique substrings that appear in the infinite alphabet wraparound string using dynamic programming by ending character.
A clear explanation of Bulb Switcher using divisor parity and perfect squares.
A counting solution for producing the Bulls and Cows hint while handling duplicate digits correctly.
Add two numbers stored in forward-order linked lists using stacks and carry propagation.
A clear explanation of Design Tic-Tac-Toe using row, column, and diagonal counters for constant-time winner checks.
A clear explanation of decoding nested repeat expressions using a stack.
A clear explanation of adding one to a number stored as a linked list using the rightmost non-nine digit.
A clear explanation of counting pairs where nums[i] is greater than twice nums[j] using merge sort.
A clear explanation of Maximum Product of Word Lengths using bit masks to test disjoint character sets efficiently.
A clear explanation of deciding whether an array can be split into two equal-sum subsets using 0/1 knapsack dynamic programming.
A clear explanation of validating a byte sequence as UTF-8 using bit masks and a continuation-byte counter.
Check whether nums is the unique shortest supersequence of given subsequences using topological sorting.
A clear explanation of counting how many repeated copies of one string can be obtained as a subsequence of another repeated string.
A clear explanation of finding the largest subset where every pair is divisible using sorting, dynamic programming, and parent reconstruction.
A clear explanation of finding rectangle dimensions with a fixed area and the smallest length-width difference.
A clear explanation of Top K Frequent Elements using frequency counting and bucket sort.
A DFS solution for finding the longest parent-to-child path where each node value increases by exactly one.
A preorder DFS codec for converting a binary tree to a string and reconstructing the same tree from that string.
A clear explanation of implementing a LIFO stack using only FIFO queue operations.
Compress a character array in-place using two pointers and grouped character counting.