TorchLean API

NN.Proofs.Autograd.Runtime.Link.HigherOrder

Higher-order graph evaluation #

The real and nested-dual executions use the existing GraphData representation. A local jet-preservation law for each pair of nodes propagates through the graph, including its saved intermediates. Selecting any output then gives mathlib's iterated Fréchet derivative.

The auxiliary environment is held fixed. These results concern exact-real forward evaluation; they do not assume that node JVP/VJP fields are correct merely because the forward maps agree.

def TorchLean.TensorPack.JetRelated {E : Type u_1} [NormedAddCommGroup E] [NormedSpace E] {n : } (directions : Fin nE) (x : E) {shapes : List Spec.Shape} :

Each saved tensor is smooth and its nested-dual value contains its mixed derivatives.

Instances For
    theorem TorchLean.TensorPack.JetRelated.const {E : Type u_1} [NormedAddCommGroup E] [NormedSpace E] {n : } {shapes : List Spec.Shape} (directions : Fin nE) (x : E) (state : TensorPack shapes) :
    JetRelated directions x (fun (x : E) => state) (map (fun {shape : Spec.Shape} => Tensor.map (Runtime.Autograd.Model.Dual.Nested.ofPrimal n)) state)

    Fixed model state has zero mixed derivatives and uses the runtime constant embedding.

    theorem TorchLean.TensorPack.JetRelated.singleton_seed {n : } {shape : Spec.Shape} (directions : Fin nTensor shape) (input : Tensor shape) :
    JetRelated directions input (fun (x : Tensor shape) => singleton x) (singleton (Runtime.Autograd.Model.Dual.Nested.seedTensor directions input))

    The model's seeded input tensor satisfies the context relation at every derivative order.

    theorem TorchLean.TensorPack.JetRelated.append {E : Type u_1} [NormedAddCommGroup E] [NormedSpace E] {n : } {left right : List Spec.Shape} {directions : Fin nE} {x : E} {f : ETensorPack left} {g : ETensorPack right} {fv : TensorPack (Runtime.Autograd.Model.Dual.Nested n) left} {gv : TensorPack (Runtime.Autograd.Model.Dual.Nested n) right} (hf : JetRelated directions x f fv) (hg : JetRelated directions x g gv) :
    JetRelated directions x (fun (y : E) => (f y).append (g y)) (fv.append gv)

    Join separately certified input families, for example fixed state and varying model inputs.

    theorem TorchLean.TensorPack.JetRelated.cast {E : Type u_1} [NormedAddCommGroup E] [NormedSpace E] {n : } {shapes target : List Spec.Shape} {directions : Fin nE} {x : E} {f : ETensorPack shapes} {values : TensorPack (Runtime.Autograd.Model.Dual.Nested n) shapes} (h : JetRelated directions x f values) (hs : shapes = target) :
    JetRelated directions x (fun (y : E) => TensorPack.cast hs (f y)) (TensorPack.cast hs values)

    Shape-list transport changes neither smoothness nor stored derivative coefficients.

    theorem TorchLean.TensorPack.JetRelated.snoc {E : Type u_1} [NormedAddCommGroup E] [NormedSpace E] {n : } {shapes : List Spec.Shape} {shape : Spec.Shape} {directions : Fin nE} {x : E} {f : ETensorPack shapes} {values : TensorPack (Runtime.Autograd.Model.Dual.Nested n) shapes} (h : JetRelated directions x f values) {g : ETensor shape} (hg : ContDiff (↑n) g) :
    JetRelated directions x (fun (y : E) => (f y).snoc (g y)) (values.snoc (Runtime.Autograd.Model.DualTensor.jet directions g x))

    Appending a proved node output extends the relation for the saved context.

    theorem TorchLean.TensorPack.JetRelated.get {E : Type u_1} [NormedAddCommGroup E] [NormedSpace E] {n : } {shapes : List Spec.Shape} {shape : Spec.Shape} {directions : Fin nE} {x : E} {f : ETensorPack shapes} {values : TensorPack (Runtime.Autograd.Model.Dual.Nested n) shapes} (h : JetRelated directions x f values) (index : Proofs.Idx shapes shape) :
    (ContDiff n fun (y : E) => Proofs.getIdx (f y) index) Proofs.getIdx values index = Runtime.Autograd.Model.DualTensor.jet directions (fun (y : E) => Proofs.getIdx (f y) index) x

    A typed context lookup retrieves a smooth tensor and its complete jet.

    theorem TorchLean.TensorPack.JetRelated.of_get {E : Type u_1} [NormedAddCommGroup E] [NormedSpace E] {n : } {shapes : List Spec.Shape} {directions : Fin nE} {x : E} {f : ETensorPack shapes} {values : TensorPack (Runtime.Autograd.Model.Dual.Nested n) shapes} (h : ∀ {shape : Spec.Shape} (index : Proofs.Idx shapes shape), (ContDiff n fun (y : E) => Proofs.getIdx (f y) index) Proofs.getIdx values index = Runtime.Autograd.Model.DualTensor.jet directions (fun (y : E) => Proofs.getIdx (f y) index) x) :
    JetRelated directions x f values

    Coordinatewise certificates determine the complete heterogeneous context relation.

    A pair of forward maps preserves smooth input families and their full mixed-derivative jets. Reverse-mode correctness is a separate obligation.

    Instances For
      theorem Proofs.Autograd.Algebra.NodeData.PreservesJet.get {E : Type u_1} [NormedAddCommGroup E] [NormedSpace E] {n : } {Δ : Type} {Γ : List Spec.Shape} {shape : Spec.Shape} (index : Idx Γ shape) :
      PreservesJet E n (fun (ctx : TorchLean.TensorPack Γ) (x : Δ) => getIdx ctx index) fun (ctx : TorchLean.TensorPack (Runtime.Autograd.Model.Dual.Nested n) Γ) (x : Δ) => getIdx ctx index

      Reading an existing context entry preserves its smoothness and all derivative coefficients.

      theorem Proofs.Autograd.Algebra.NodeData.PreservesJet.map {E : Type u_1} [NormedAddCommGroup E] [NormedSpace E] {n : } {Δ : Type} {Γ : List Spec.Shape} {shape : Spec.Shape} (index : Idx Γ shape) (f : ) (lifted : Runtime.Autograd.Model.Dual.Nested nRuntime.Autograd.Model.Dual.Nested n) (hf : ContDiff (↑n) f) (hjet : ∀ (directions : Fin nE) (g : E), ContDiff (↑n) g∀ (x : E), Runtime.Autograd.Model.Dual.jet directions (fun (y : E) => f (g y)) x = lifted (Runtime.Autograd.Model.Dual.jet directions g x)) :
      PreservesJet E n (fun (inputs : TorchLean.TensorPack Γ) (x : Δ) => TorchLean.Tensor.map f (getIdx inputs index)) fun (values : TorchLean.TensorPack (Runtime.Autograd.Model.Dual.Nested n) Γ) (x : Δ) => TorchLean.Tensor.map lifted (getIdx values index)

      Lift a scalar jet rule through an elementwise graph operation reading a saved tensor.

      theorem Proofs.Autograd.Algebra.NodeData.PreservesJet.map2 {E : Type u_1} [NormedAddCommGroup E] [NormedSpace E] {n : } {Δ : Type} {Γ : List Spec.Shape} {shape : Spec.Shape} (left right : Idx Γ shape) (f : ) (lifted : Runtime.Autograd.Model.Dual.Nested nRuntime.Autograd.Model.Dual.Nested nRuntime.Autograd.Model.Dual.Nested n) (hf : ContDiff n fun (p : × ) => f p.1 p.2) (hjet : ∀ (directions : Fin nE) (g h : E), ContDiff (↑n) gContDiff (↑n) h∀ (x : E), Runtime.Autograd.Model.Dual.jet directions (fun (y : E) => f (g y) (h y)) x = lifted (Runtime.Autograd.Model.Dual.jet directions g x) (Runtime.Autograd.Model.Dual.jet directions h x)) :
      PreservesJet E n (fun (inputs : TorchLean.TensorPack Γ) (x : Δ) => TorchLean.Tensor.map2Spec f (getIdx inputs left) (getIdx inputs right)) fun (values : TorchLean.TensorPack (Runtime.Autograd.Model.Dual.Nested n) Γ) (x : Δ) => TorchLean.Tensor.map2Spec lifted (getIdx values left) (getIdx values right)

      Lift a binary scalar jet rule through any pair of saved tensors of the same shape.

      Node-local jet laws on a pair of existing executable graphs, in their recorded order.

      Instances For
        theorem Proofs.Autograd.Algebra.GraphData.PreservesJet.eval {E : Type u_1} [NormedAddCommGroup E] [NormedSpace E] {n : } {Δ : Type} {Γ shapes : List Spec.Shape} {real : GraphData Δ Γ shapes} {nested : GraphData (Runtime.Autograd.Model.Dual.Nested n) Δ Γ shapes} (h : PreservesJet E n real nested) (directions : Fin nE) (x : E) (inputs : ETorchLean.TensorPack Γ) (values : TorchLean.TensorPack (Runtime.Autograd.Model.Dual.Nested n) Γ) (data : Δ) (hinputs : TorchLean.TensorPack.JetRelated directions x inputs values) :
        TorchLean.TensorPack.JetRelated directions x (fun (y : E) => real.eval (inputs y) data) (nested.eval values data)

        Graph evaluation preserves the jet relation for the entire saved context.

        theorem Proofs.Autograd.Algebra.GraphData.PreservesJet.tangent_eval {E : Type u_1} [NormedAddCommGroup E] [NormedSpace E] {n : } {Δ : Type} {Γ shapes : List Spec.Shape} {real : GraphData Δ Γ shapes} {nested : GraphData (Runtime.Autograd.Model.Dual.Nested n) Δ Γ shapes} (h : PreservesJet E n real nested) (directions : Fin nE) (x : E) (inputs : ETorchLean.TensorPack Γ) (values : TorchLean.TensorPack (Runtime.Autograd.Model.Dual.Nested n) Γ) (data : Δ) (hinputs : TorchLean.TensorPack.JetRelated directions x inputs values) {shape : Spec.Shape} (output : Idx (Γ ++ shapes) shape) :
        Runtime.Autograd.Model.Dual.Nested.tangentTensor (getIdx (nested.eval values data) output) = (iteratedFDeriv n (fun (y : E) => getIdx (real.eval (inputs y) data) output) x) directions

        Extracting all tangent coefficients at any graph output computes its iterated derivative.