Runtime Gradient Accumulation Link #
This file connects the executable dense-gradient array used by the runtime tape to the typed context
addition used in the proved autograd algebra. The main lemmas show that folding runtime gradient
updates over indexed tensors agrees with the proof-level TList accumulation operation.
Key accumulation lemma for the runtime dense gradient array:
Folding Tape.addGradAll over the contributions corresponding to a TList (via toIndexedAnyList)
is equivalent to pointwise addition of the typed contexts (TList.add), embedded back into the
array layout pref ++ seed ++ suffix.
This is the “runtime accumulation matches proved addition” bridge.
Tape.addGradAll never changes the size of the dense gradient array in the .ok case.
This is a structural property needed to show the runtime reverse loop preserves array sizes.
If addGradAll returns .ok grads', then grads'.size = grads.size.
If one step of the runtime dense backward loop succeeds, it preserves the accumulator array size.
This is proved by showing the internal foldlM addGradAll preserves size, then splitting on the
control flow of backwardDenseFromStep.