Vathek training frame, derivative certificates, state, and runs
DefinitionVathekStateThe training-state vocabulary. A frame bundles the shared differentiable computation , the per-occurrence loss maps , the fixed reduction coefficients , and the finite occurrence set ; all discrete choices are fixed during one logical update. A derivative-certificate package at a pre-update point supplies the shared derivative with the certificate that it really is the derivative of , and for each occurrence the value, direct gradient, and shared cotangent — each certified as the genuine mathematical derivative of the stated map (no uninterpreted gradient oracle). A training state carries the parameters, both optimizer moment slots, and the step counter; a structural snapshot is the real-valued coordinate-list encoding of exactly that state, with a total decoder (restore). The monolithic gradient monoGrad is the Riesz representation of the derivative of the whole logical objective. The tiled run and monolithic run schedule one masked, clipped optimizer application per logical step, and runFrom iterates a step function over step indices.
import Definitions.Def_VathekFrame
/-!
# VathekProof — training frame, derivative certificates, state, and runs (§4.2–4.5, §5)
-/
namespace VathekProof
/-- §4.2–4.3: one *training frame* — the shared differentiable computation `h`, the
per-occurrence loss maps `f`, the fixed reduction coefficients `α`, and the finite
occurrence set `I`. All discrete choices of the frame are fixed during one logical
update. -/
structure Frame (d m : ℕ) (ι : Type*) where
/-- shared computation: source encoding, all-slot interaction, shared projections -/
h : EuclideanSpace ℝ (Fin d) → EuclideanSpace ℝ (Fin m)
/-- per-occurrence loss maps `fᵢ : W × V → ℝ` -/
f : ι → EuclideanSpace ℝ (Fin d) × EuclideanSpace ℝ (Fin m) → ℝ
/-- fixed reduction coefficients (`αᵢ ≥ 0` in the product objective) -/
α : ι → ℝ
/-- finite occurrence set of this frame -/
I : Finset ι
/-- §4.4: derivative certificates for one frame at the pre-update point `w₀` — the
shared derivative, and for each occurrence the value, direct partial gradient, and
shared partial cotangent, each certified as the genuine mathematical value or
derivative of the stated map (no uninterpreted `gradient` oracle). -/
structure FrameDeriv (d m : ℕ) (ι : Type*) (ξ : Frame d m ι)
(w₀ : EuclideanSpace ℝ (Fin d)) where
/-- the derivative of the shared map at `w₀` -/
h' : EuclideanSpace ℝ (Fin d) →L[ℝ] EuclideanSpace ℝ (Fin m)
/-- certificate: `h'` really is the derivative of `ξ.h` at `w₀` -/
hh : HasFDerivAt ξ.h h' w₀
/-- per-occurrence values `fᵢ (w₀, h (w₀))` -/
val : ι → ℝ
/-- certificate: `val i` really is the value `fᵢ (w₀, h (w₀))` -/
hval : ∀ i ∈ ξ.I, val i = ξ.f i (w₀, ξ.h w₀)
/-- per-occurrence direct parameter gradients `∇₁ fᵢ (w₀, h₀)` -/
direct : ι → EuclideanSpace ℝ (Fin d)
/-- per-occurrence shared-state cotangents `∇₂ fᵢ (w₀, h₀)` -/
shared : ι → EuclideanSpace ℝ (Fin m)
/-- certificate: `direct i` is the gradient of `w ↦ fᵢ (w, h (w₀))` at `w₀` -/
hdirect : ∀ i ∈ ξ.I, HasGradientAt (fun w => ξ.f i (w, ξ.h w₀)) (direct i) w₀
/-- certificate: `shared i` is the gradient of `v ↦ fᵢ (w₀, v)` at `h (w₀)` -/
hshared : ∀ i ∈ ξ.I, HasGradientAt (fun v => ξ.f i (w₀, v)) (shared i) (ξ.h w₀)
/-- certificate: `fᵢ` is differentiable at the point used `(w₀, h (w₀))` -/
hdiff : ∀ i ∈ ξ.I, DifferentiableAt ℝ (ξ.f i) (w₀, ξ.h w₀)
/-- §4.5: a *training state* — logical parameters, the two optimizer moment slots, and
the step counter. (`TrainState` is the minimal transition-relevant state of the
mission; a production state carries more slots with the same discipline.) -/
structure TrainState (d : ℕ) where
/-- logical parameters `w` -/
w : EuclideanSpace ℝ (Fin d)
/-- first-moment slots -/
mom1 : EuclideanSpace ℝ (Fin d)
/-- second-moment slots -/
mom2 : EuclideanSpace ℝ (Fin d)
/-- step counter `t` -/
t : ℕ
/-- §5 (checkpoint): the structural snapshot of a `TrainState` — real-valued slots as
coordinate lists plus the counter. This is a *real-valued mathematical* snapshot; a
finite-byte codec is a separate refinement (§9.4, §12.2). -/
structure TrainSnap (d : ℕ) where
/-- serialized parameters -/
w : List ℝ
/-- serialized first moments -/
mom1 : List ℝ
/-- serialized second moments -/
mom2 : List ℝ
/-- step counter -/
t : ℕ
/-- Encode a real vector as its coordinate list (length `d`). -/
def listOfVec {d : ℕ} (x : EuclideanSpace ℝ (Fin d)) : List ℝ :=
List.ofFn (fun j => x j)
/-- Decode a coordinate list back to a real vector (total: missing coordinates
default to `0`; a round trip never has them). -/
def vecOfList {d : ℕ} (l : List ℝ) : EuclideanSpace ℝ (Fin d) :=
WithLp.toLp 2 (fun j => l.getD j.val 0)
/-- §5: the structural snapshot of a complete training state. -/
def snap {d : ℕ} (S : TrainState d) : TrainSnap d where
w := listOfVec S.w
mom1 := listOfVec S.mom1
mom2 := listOfVec S.mom2
t := S.t
/-- §5: reconstruction of a training state from its snapshot. -/
def restore {d : ℕ} (P : TrainSnap d) : TrainState d where
w := vecOfList P.w
mom1 := vecOfList P.mom1
mom2 := vecOfList P.mom2
t := P.t
/-- The monolithic evaluator's gradient vector at `w₀`: the Riesz representation of
the derivative of the whole logical objective. Well defined wherever the objective is
differentiable; under the frame's certificates it is the mathematical gradient. -/
noncomputable def monoGrad {d m : ℕ} {ι : Type*} (ξ : Frame d m ι) (w₀ : EuclideanSpace ℝ (Fin d)) :
EuclideanSpace ℝ (Fin d) :=
(fderiv ℝ (frameLoss ξ.h ξ.f ξ.α ξ.I) w₀).adjoint 1
/-- §5: the tiled evaluator's run — at logical step `k`, every tile of the partition
`𝔅 k` reads the same pre-update parameters `S.w` (through the certificates `Dof k S`),
the full gradient is accumulated, projected, clipped, and the optimizer `U` runs once. -/
noncomputable def tiledRun (d m : ℕ) (ι : Type*) [DecidableEq ι] (ξ : ℕ → Frame d m ι)
(𝔅 : ℕ → List (Finset ι))
(Dof : ∀ (k : ℕ) (S : TrainState d), FrameDeriv d m ι (ξ k) S.w)
(T : Finset (Fin d)) (c : ℝ)
(U : TrainState d → EuclideanSpace ℝ (Fin d) → TrainState d) :
TrainState d → ℕ → TrainState d :=
fun S k => U S (clipVec c (coordMask T
(tiledGrad (ξ k).α (Dof k S).val (Dof k S).direct (Dof k S).shared (Dof k S).h' (𝔅 k))))
/-- §5: the monolithic evaluator's run — one full loss and one full derivative per
logical step, then the same projection, clipping, and single optimizer application. -/
noncomputable def monoRun (d m : ℕ) (ι : Type*) (ξ : ℕ → Frame d m ι) (T : Finset (Fin d)) (c : ℝ)
(U : TrainState d → EuclideanSpace ℝ (Fin d) → TrainState d) :
TrainState d → ℕ → TrainState d :=
fun S k => U S (clipVec c (coordMask T (monoGrad (ξ k) S.w)))
/-- §5: run the first `n` logical steps of a schedule. -/
def runFrom {σ : Type*} (step : σ → ℕ → σ) : ℕ → σ → σ
| 0, S => S
| n + 1, S => runFrom step n (step S n)
end VathekProof
Read-back
What the Lean code literally says, in plain math · glm-5.3 (independent auditor subagent)
{'text': '{\n "type": "result",\n "data": "Throughout, denotes -dimensional real coordinate space with the standard Euclidean inner product and norm ; a vector is viewed as its coordinate function on . A derivative is always a Fréchet derivative: is the derivative of at means with a continuous linear map. For real-valued , \" is the gradient of at \" means .\n\n**Frame.** For arbitrary natural numbers and an arbitrary type (a type of occurrence labels; no assumption of any kind is placed on ), a frame is a record with four data fields:\n\n- a map ;\n- an -indexed family of loss maps , one for each ;\n- an -indexed family of real coefficients — no sign or other condition is imposed (negative and zero coefficients are permitted);\n- a finite occurrence set .\n\nNo regularity (continuity, differentiability) is required of or of any . The quantification silently includes the degenerate cases or (the corresponding space is a single point), , and infinite (only is required finite).\n\n**FrameDeriv.** For arbitrary , an arbitrary type , a frame as above, and a point , a frame-derivative certificate at is a record with the following data fields and proof fields (all must be supplied to give an element):\n\n- data: a continuous linear map h\' : \\\\mathbb{R}^d \\\\to \\\\mathbb{R}^m;\n- certificate hh (unconditional): h\' is the derivative of at ;\n- data: a function ;\n- certificate hval: for every , ;\n- data: a function ;\n- data: a function ;\n- certificate hdirect: for every , is the gradient at of the partially applied map (second argument frozen at the pre-update shared state );\n- certificate hshared: for every , is the gradient at of the map (first argument frozen at );\n- certificate hdiff: for every , is differentiable (as a map on the product ) at the single point .\n\nAll certificates except hh quantify only over : outside the functions , , are unconstrained arbitrary data. If these four conditions are vacuous, and the only substantive requirement is that be differentiable at (so the existence of such a record always forces differentiability of at , but forces nothing about the when ).\n\n**TrainState.** For every , a training state is a record of four data fields: three vectors and a step counter . No conditions are imposed on any field.\n\n**TrainSnap.** For every , a training snapshot is a record of four data fields: three lists of reals and a step counter . The lengths of the lists are in no way tied to ; snapshots with empty, short, or long lists are all legitimate elements.\n\n**listOfVec.** For every (implicit) and every , this is the list of reals of length exactly whose -th entry is the coordinate , for . For it is the empty list.\n\n**vecOfList.** For every (implicit) and every list of reals, this is the vector in whose -th coordinate is the -th entry of if the list has an entry at position , and otherwise. The function is total: a list shorter than is padded with zeros in the missing coordinates, and entries at positions are ignored.\n\n**snap.** For every (implicit), this maps a training state to its snapshot: each of the three vectors is encoded by listOfVec (so each list has length exactly ), and the counter is copied unchanged.\n\n**restore.** For every (implicit), this maps a snapshot back to a training state: each of the three lists is decoded by vecOfList (with the zero-padding / entry-ignoring behavior above when a list's length differs from ), and is copied unchanged.\n\n**monoGrad.** For all , all types (implicit), every frame , and every , this defines a vector in . Write the monolithic objective\n
\nThen is obtained by taking the Fréchet derivative of L_\\\\xi at — read through the total derivative operator, which returns the zero map at any point where L_\\\\xi fails to be differentiable — and applying its adjoint (Riesz representation) to the scalar . Equivalently, \\\\mathrm{monoGrad}(\\\\xi, w_0) = \\\\big(DL_\\\\xi(w_0)\\\\big)^{T} \\\\cdot 1: it is the gradient \\\\nabla L_\\\\xi(w_0) wherever L_\\\\xi is differentiable at , and the zero vector at every point where it is not. The definition itself assumes no differentiability; it is total for every frame, including frames with non-differentiable or .\n\n**tiledRun.** For all and every type carrying decidable equality, given\n\n- a frame schedule , one frame per logical step ;\n- a tiling schedule , each a finite list of finite subsets (\"tiles\") of ;\n- a certificate oracle assigning to every step and every training state a full frame-derivative certificate for the frame at the point ;\n- a finite set of trainable coordinates;\n- a real clipping radius ;\n- an optimizer map from states and vectors to states,\n\nthis defines a one-step transition on (state, step index): the state at logical step is sent to , where the gradient is computed as follows. Unfolding the tiled gradient: with \\\\mathrm{val}, \\\\mathrm{direct}, \\\\mathrm{shared}, h\' the data fields of the certificate at , an accumulator is built by traversing the tile list from left to right starting from , each tile adding\n
\n(the same fold also maintains a running scalar loss per tile, which the gradient does not read), and then\n
\n denoting the adjoint of the shared-derivative certificate h\'. Next, is the coordinate projection keeping for and zeroing for ; finally is\n
\\\\mathrm{clip}_c(g) = \\\\begin{cases} g, & \\\\lVert g\\\\rVert \\\\le c,\\\\\\\\[2pt] \\\\dfrac{c}{\\\\lVert g\\\\rVert}\\\\, g, & \\\\lVert g\\\\rVert > c.\\\\end{cases}\nThe optimizer is applied exactly once, to the pre-update state and the processed gradient; a single certificate, at the point , supplies every tile's data. The definition imposes no relation between the tile lists and the frame's occurrence set : tiles may be empty, overlap, repeat (a repeated tile contributes twice), or contain indices outside , and the certificate data are only certified on while the sums run over the tiles as given; an empty tile list yields . The clipping is total for every real (real division satisfies ); note sends every to , and negative makes the branch condition fail for every , producing — a vector of norm pointing opposite to (and when ). Note also that supplying the certificate oracle at all states entails, through the unconditional hh field, differentiability of each at every parameter vector .\n\n**monoRun.** For all and every type (no decidable-equality assumption here), given a frame schedule , a finite trainable-coordinate set , a real clipping radius , and an optimizer , this defines the one-step transition sending the state at logical step to\n
\nthat is: the monolithic gradient of at the current parameters (zero by convention wherever is not differentiable there), followed by the same coordinate projection and the same clipping as in tiledRun, then a single application of . No certificates, tiles, or differentiability hypotheses are involved; the definition is total for every schedule.\n\n**runFrom.** For an arbitrary type (implicit) and an arbitrary step function (a map taking a state and a natural step index to a new state), this defines a function by recursion on the number of steps:\n\n- ;\n- .\n\nThus applies exactly times, the applications receiving the step indices in that order:\n
\nAt the state is returned unchanged. The definition is generic in ; it is not tied to training states, frames, or any particular step function."\n}', 'details': {'resolvedPath': '/home/ajax/.omp/agent/sessions/-math/2026-09-22T19-31-08-510Z_01a0ca99-be5e-7000-93c6-dac7c74cc004/RB2-VathekState.md', 'contentType': 'text/markdown', 'totalLines': 4, 'displayContent': {'text': '{\n "type": "result",\n "data": "Throughout, denotes -dimensional real coordinate space with the standard Euclidean inner product and norm ; a vector is viewed as its coordinate function on . A derivative is always a Fréchet derivative: is the derivative of at means with a continuous linear map. For real-valued , \" is the gradient of at \" means .\n\n**Frame.** For arbitrary natural numbers and an arbitrary type (a type of occurrence labels; no assumption of any kind is placed on ), a frame is a record with four data fields:\n\n- a map ;\n- an -indexed family of loss maps , one for each ;\n- an -indexed family of real coefficients — no sign or other condition is imposed (negative and zero coefficients are permitted);\n- a finite occurrence set .\n\nNo regularity (continuity, differentiability) is required of or of any . The quantification silently includes the degenerate cases or (the corresponding space is a single point), , and infinite (only is required finite).\n\n**FrameDeriv.** For arbitrary , an arbitrary type , a frame as above, and a point , a frame-derivative certificate at is a record with the following data fields and proof fields (all must be supplied to give an element):\n\n- data: a continuous linear map h\' : \\\\mathbb{R}^d \\\\to \\\\mathbb{R}^m;\n- certificate hh (unconditional): h\' is the derivative of at ;\n- data: a function ;\n- certificate hval: for every , ;\n- data: a function ;\n- data: a function ;\n- certificate hdirect: for every , is the gradient at of the partially applied map (second argument frozen at the pre-update shared state );\n- certificate hshared: for every , is the gradient at of the map (first argument frozen at );\n- certificate hdiff: for every , is differentiable (as a map on the product ) at the single point .\n\nAll certificates except hh quantify only over : outside the functions , , are unconstrained arbitrary data. If these four conditions are vacuous, and the only substantive requirement is that be differentiable at (so the existence of such a record always forces differentiability of at , but forces nothing about the when ).\n\n**TrainState.** For every , a training state is a record of four data fields: three vectors and a step counter . No conditions are imposed on any field.\n\n**TrainSnap.** For every , a training snapshot is a record of four data fields: three lists of reals and a step counter . The lengths of the lists are in no way tied to ; snapshots with empty, short, or long lists are all legitimate elements.\n\n**listOfVec.** For every (implicit) and every , this is the list of reals of length exactly whose -th entry is the coordinate , for . For it is the empty list.\n\n**vecOfList.** For every (implicit) and every list of reals, this is the vector in whose -th coordinate is the -th entry of if the list has an entry at position , and otherwise. The function is total: a list shorter than is padded with zeros in the missing coordinates, and entries at positions are ignored.\n\n**snap.** For every (implicit), this maps a training state to its snapshot: each of the three vectors is encoded by listOfVec (so each list has length exactly ), and the counter is copied unchanged.\n\n**restore.** For every (implicit), this maps a snapshot back to a training state: each of the three lists is decoded by vecOfList (with the zero-padding / entry-ignoring behavior above when a list's length differs from ), and is copied unchanged.\n\n**monoGrad.** For all , all types (implicit), every frame , and every , this defines a vector in . Write the monolithic objective\n
\nThen is obtained by taking the Fréchet derivative of L_\\\\xi at — read through the total derivative operator, which returns the zero map at any point where L_\\\\xi fails to be differentiable — and applying its adjoint (Riesz representation) to the scalar . Equivalently, \\\\mathrm{monoGrad}(\\\\xi, w_0) = \\\\big(DL_\\\\xi(w_0)\\\\big)^{T} \\\\cdot 1: it is the gradient \\\\nabla L_\\\\xi(w_0) wherever L_\\\\xi is differentiable at , and the zero vector at every point where it is not. The definition itself assumes no differentiability; it is total for every frame, including frames with non-differentiable or .\n\n**tiledRun.** For all and every type carrying decidable equality, given\n\n- a frame schedule , one frame per logical step ;\n- a tiling schedule , each a finite list of finite subsets (\"tiles\") of ;\n- a certificate oracle assigning to every step and every training state a full frame-derivative certificate for the frame at the point ;\n- a finite set of trainable coordinates;\n- a real clipping radius ;\n- an optimizer map from states and vectors to states,\n\nthis defines a one-step transition on (state, step index): the state at logical step is sent to , where the gradient is computed as follows. Unfolding the tiled gradient: with \\\\mathrm{val}, \\\\mathrm{direct}, \\\\mathrm{shared}, h\' the data fields of the certificate at , an accumulator is built by traversing the tile list from left to right starting from , each tile adding\n
\n(the same fold also maintains a running scalar loss per tile, which the gradient does not read), and then\n
\n denoting the adjoint of the shared-derivative certificate h\'. Next, is the coordinate projection keeping for and zeroing for ; finally is\n
\\\\mathrm{clip}_c(g) = \\\\begin{cases} g, & \\\\lVert g\\\\rVert \\\\le c,\\\\\\\\[2pt] \\\\dfrac{c}{\\\\lVert g\\\\rVert}\\\\, g, & \\\\lVert g\\\\rVert > c.\\\\end{cases}\nThe optimizer is applied exactly once, to the pre-update state and the processed gradient; a single certificate, at the point , supplies every tile's data. The definition imposes no relation between the tile lists and the frame's occurrence set : tiles may be empty, overlap, repeat (a repeated tile contributes twice), or contain indices outside , and the certificate data are only certified on while the sums run over the tiles as given; an empty tile list yields . The clipping is total for every real (real division satisfies ); note sends every to , and negative makes the branch condition fail for every , producing — a vector of norm pointing opposite to (and when ). Note also that supplying the certificate oracle at all states entails, through the unconditional hh field, differentiability of each at every parameter vector .\n\n**monoRun.** For all and every type (no decidable-equality assumption here), given a frame schedule , a finite trainable-coordinate set , a real clipping radius , and an optimizer , this defines the one-step transition sending the state at logical step to\n
\nthat is: the monolithic gradient of at the current parameters (zero by convention wherever is not differentiable there), followed by the same coordinate projection and the same clipping as in tiledRun, then a single application of . No certificates, tiles, or differentiability hypotheses are involved; the definition is total for every schedule.\n\n**runFrom.** For an arbitrary type (implicit) and an arbitrary step function (a map taking a state and a natural step index to a new state), this defines a function by recursion on the number of steps:\n\n- ;\n- .\n\nThus applies exactly times, the applications receiving the step indices in that order:\n
\nAt the state is returned unchanged. The definition is generic in ; it is not tied to training states, frames, or any particular step function."\n}', 'startLine': 1, 'lineNumbers': [1, 2, 3, 4]}, 'meta': {'source': {'type': 'internal', 'value': 'agent://RB2-VathekState'}}}}
Confirmed by the mission captain (proposal self-audit).