TorchLean API

NN.Proofs.Autograd.FDeriv.PrimitiveCoordinates

Tensor coordinates for primitive derivatives #

Flattening preserves the coordinate formulas of pointwise tensor operations. These lemmas connect the actual tensor functions to the diagonal calculus in PrimitiveSpecs, without restricting the tensor to one axis. A binary operation with a captured right argument then needs only the scalar derivative with respect to its left argument.

@[simp]
theorem Proofs.Autograd.PrimitiveSpecs.coordinatewise_apply {n : } (f : Fin n) (x : Vec n) (i : Fin n) :
(coordinatewise f x).ofLp i = f i (x.ofLp i)

Coordinate evaluation removes the Euclidean wrapper around a pointwise function.

@[simp]

Row-major flattening commutes with a unary pointwise map.

@[simp]

Both operands of a binary pointwise map use the same flattened coordinate.

@[simp]

Every coordinate of a filled tensor is its fill value.

@[simp]

Elementwise multiplication becomes multiplication of the corresponding real coordinates.

theorem Proofs.Autograd.PrimitiveSpecs.binaryElemOp_hasFDerivAt {s : Spec.Shape} (rhs : TorchLean.Tensor s) (f df : ) (x : Vec s.size) (hf : ∀ (i : Fin s.size), HasDerivAt (fun (z : ) => f z ((tensorToVec rhs).ofLp i)) (df (x.ofLp i) ((tensorToVec rhs).ofLp i)) (x.ofLp i)) :
HasFDerivAt (fun (y : Vec s.size) => tensorToVec ((Spec.binaryElemOp rhs f df).forward (vecToTensor y))) (coordinateDeriv fun (i : Fin s.size) => df (x.ofLp i) ((tensorToVec rhs).ofLp i)) x

The captured-right constructor differentiates its actual tensor forward function.

theorem Proofs.Autograd.PrimitiveSpecs.binaryElemOp_backward_eq_adjoint {s : Spec.Shape} (rhs : TorchLean.Tensor s) (f df : ) (x : Vec s.size) (hf : ∀ (i : Fin s.size), HasDerivAt (fun (z : ) => f z ((tensorToVec rhs).ofLp i)) (df (x.ofLp i) ((tensorToVec rhs).ofLp i)) (x.ofLp i)) (δ : TorchLean.Tensor s) :

Scalar derivative evidence certifies the stored captured-right backward formula.