Analytic upgrade of the runtime link: reverse mode computes (fderiv eval)† #
Two independent developments meet in this file.
- The runtime link (
Runtime/Link/BackwardGraph.lean) proves that the tape engine's dense reverse pass (Tape.backwardDenseFrom) agrees with the algebraic model's full backpropagationbackpropAllCtx, over any commutative semiring carrier and an arbitrary non-differentiable environmentΔ. - The analytic tape model (
Tape/Core/FDeriv.lean) proves that reverse-mode accumulation computes the adjoint of the Fréchet derivative of the forward evaluation, overℝ.
The two developments are stated on different graph types: the algebraic
Algebra.Graph (α := α) Δ Γ ss versus the ℝ-monomorphic, environment-free
Proofs.Autograd.Graph Γ ss. Their contexts already coincide (TList Γ is by definition
Algebra.TList ℝ Γ), and their eval/jvpCtx/backpropCtx recursions mirror each other
node for node — what has been missing is the formal connection. This file supplies it:
- The real, environment-free slice.
Algebra.Node.toReal/Algebra.Graph.toRealspecialize an algebraic graph atα := ℝand a fixed environmentd : Δto an analytic graph;Node.toAlgebra/Graph.toAlgebraembed an analytic graph back as theΔ := Unitslice, and both round trips are identities on that slice (toAlgebra_toRealandtoReal_toAlgebra). The analytic model is therefore exactly the environment-freeℝslice of the algebraic model. The commutation lemmastoReal_eval,toReal_jvpCtx,toReal_backpropCtxshow the specialization preserves all three semantics. - Input-prefix extraction.
TList.takeLeftreads the input (Γ-prefix) block out of a full context, andtakeLeft_backpropAllCtx(also inGraphDataform) identifies the input block of the full backpropagation with the inputs-onlybackpropCtx— the missing lemma relating the runtime-facingbackpropAllCtxto the proof-facingbackpropCtx. - Vectorization transport. The
flattenCtx_*lemmas commute context vectorization withcast/snoc/unsnoc/add, so theTList-level graph semantics coincide with the EuclideanCtxVecsemantics:evalVec_flattenCtx,jvpVec_flattenCtx,backpropVec_flattenCtx. - The composed endpoints.
backpropCtx_eq_adjoint_fderivupgrades the algebraic backpropagation atℝto the Fréchet-adjoint characterization, andbackwardDenseFrom_compileAux_adjoint_fderivcombines it with the runtime link: the tape model's dense reverse pass on a compiled graph, instantiated atα := ℝ, succeeds with the full backpropagation context, whose input prefix is exactly(fderiv ℝ eval x)† seed. The_atvariants assume differentiability only at the actual execution point (GraphFDerivCorrectAt), covering graphs with non-smooth primitives (relu,abs,min/max,log,sqrt, …).
Throughout, "reverse pass" means the exact tape model: the Tape.backwardDenseFrom program of
Runtime/Autograd instantiated at the exact carrier α := ℝ. Nothing in this file is a
statement about the native Float evaluation or the CUDA execution path; relating those to the
exact model is a separate (approximation) concern.
The analytic context inner product (Spec.dot-based) agrees with the algebraic one
(TensorAlgebra.dot-based) at ℝ.
Both recursions are the same sum of per-entry tensor dots; the entries agree by
dot_eq_tensorAlgebra_dot.
flattenCtx commutes with casting a context along a shape-list equality.
Vectorization is additive: toVecT maps addSpec to vector addition.
flattenCtx maps context addition to vector addition.
flattenCtx maps TList.snoc to snocCtx.
flattenCtx maps TList.unsnoc to unsnocCtx.
The vectorized forward map, evaluated on a flattened context.
The vectorized JVP, evaluated on flattened contexts.
The vectorized VJP, evaluated on a flattened context and a vectorized cotangent.
The Euclidean graph evaluation is the flattening of the TList evaluation.
The Euclidean graph JVP is the flattening of the TList JVP.
The Euclidean reverse pass is the flattening of the TList reverse pass.
Embed an analytic node as an algebraic node over ℝ with a trivial environment.
Instances For
Embed an analytic graph as an algebraic graph over ℝ with a trivial environment.
Instances For
Specialize an algebraic node at carrier ℝ and a fixed environment d : Δ to an analytic
node. The adjointness law transports along dot_eq_tensorAlgebra_dot.
Instances For
Specialize an algebraic graph at carrier ℝ and a fixed environment to an analytic graph.
Instances For
The round trip through the algebraic model is the identity on analytic nodes.
Specializing an algebraic node with a trivial environment and embedding it back is the identity.
The round trip through the algebraic model is the identity on analytic graphs.
Specialization preserves the reverse pass.
Read the input (Γ-prefix) block out of a full context over Γ ++ ss.
Instances For
Push a cast along a cons cell.
takeLeft ignores a snoc-ed final block (after reassociating the context).
The input (Γ-prefix) block of the full backpropagation is the inputs-only backpropagation.
This identifies the link-facing backpropAllCtx (which retains a cotangent for every
value, mirroring the tape engine's dense reverse pass) with the proof-facing backpropCtx
on the input block.
GraphData version of Graph.takeLeft_backpropAllCtx.
Analytic upgrade of the algebraic reverse pass. At carrier ℝ and a fixed environment,
the inputs-only backpropagation computes the adjoint of the Fréchet derivative of the graph's
(vectorized) forward evaluation.
Pointwise variant of backpropCtx_eq_adjoint_fderiv: differentiability is assumed only at the
values actually encountered, admitting non-smooth primitives away from their kinks.
The function differentiated in the endpoints is the graph's own forward evaluation.
Tape-model reverse pass = adjoint of the Fréchet derivative. Running the tape engine's
dense reverse pass (Tape.backwardDenseFrom) on a compiled graph — the exact tape model
instantiated at α := ℝ, not the native Float or CUDA execution path — succeeds and returns
the full backpropagation context, whose input (Γ-prefix) block is exactly the adjoint of the
Fréchet derivative of the graph's forward evaluation applied to the seed.
This composes the runtime link (backwardDenseFrom_compileAux_eq_backpropAllCtx) with the
analytic upgrade above.
Pointwise variant of backwardDenseFrom_compileAux_adjoint_fderiv.