TorchLean API

NN.Proofs.Tensor.Algebra

Tensor algebra proofs #

Backend-generic algebraic lemmas for TorchLean's single packed tensor type. Proofs observe tensors through item, unstack, and typed indexing; they do not depend on the physical buffer selected by Storage.

def Proofs.TensorAlgebra.dot {α : Type} [TorchLean.Storage α] [Zero α] [Add α] [Mul α] {shape : Spec.Shape} :
TorchLean.Tensor α shape → TorchLean.Tensor α shape → α

Multiply matching scalar entries and add them in row-major shape order.

Instances For

    Dot-product algebra #

    @[simp]

    The dot product of two scalars is their product: the base case of the recursion.

    theorem Proofs.TensorAlgebra.dot_scale_right {α : Type} [TorchLean.Storage α] [CommSemiring α] {s : Spec.Shape} (left right : TorchLean.Tensor α s) (scalar : α) :
    dot left (right.scaleSpec scalar) = dot left right * scalar

    Dot is multiplicative with scalar scaling in its right argument.

    theorem Proofs.TensorAlgebra.dot_comm {α : Type} [TorchLean.Storage α] [CommSemiring α] {s : Spec.Shape} (left right : TorchLean.Tensor α s) :
    dot left right = dot right left

    Dot is symmetric over a commutative semiring.

    theorem Proofs.TensorAlgebra.dot_scale_left {α : Type} [TorchLean.Storage α] [CommSemiring α] {s : Spec.Shape} (left right : TorchLean.Tensor α s) (scalar : α) :
    dot (left.scaleSpec scalar) right = dot left right * scalar

    Dot is multiplicative with scalar scaling in its left argument.

    theorem Proofs.TensorAlgebra.dot_add_left {α : Type} [TorchLean.Storage α] [CommSemiring α] {s : Spec.Shape} (left middle right : TorchLean.Tensor α s) :
    dot (left.addSpec middle) right = dot left right + dot middle right

    Dot distributes over addition in its left argument.

    theorem Proofs.TensorAlgebra.dot_add_right {α : Type} [TorchLean.Storage α] [CommSemiring α] {s : Spec.Shape} (left middle right : TorchLean.Tensor α s) :
    dot left (middle.addSpec right) = dot left middle + dot left right

    Dot distributes over addition in its right argument.

    The dot product with an all-zero tensor is zero.

    theorem Proofs.TensorAlgebra.dot_vec_eq_sum {α : Type} [TorchLean.Storage α] [CommSemiring α] {n : ℕ} (a b : TorchLean.Tensor α [n]) :
    dot a b = ∑ index : Fin n, a.getScalar index * b.getScalar index

    Vector dot is the ordinary finite sum of matching scalar coordinates.

    Indexing and matrix/vector bridges #

    theorem Proofs.TensorAlgebra.get2_eq {α : Type} [TorchLean.Storage α] {m n : ℕ} (A : TorchLean.Tensor α [m, n]) (i : Fin m) (j : Fin n) :
    Spec.get2 A i j = ((A.unstack i).unstack j).item

    Matrix indexing is two successive packed leading-axis selections.

    theorem Proofs.TensorAlgebra.get_eq {α : Type} [TorchLean.Storage α] {m : ℕ} {shape : Spec.Shape} (t : TorchLean.Tensor α (Spec.Shape.dim m shape)) (i : Fin m) :

    Spec.get is the public spelling of packed leading-axis selection.

    Coordinate expansion of matrix-vector multiplication.

    Coordinate expansion of vector-matrix multiplication.

    theorem Proofs.TensorAlgebra.dot_mat_linear_adjoint {α : Type} [TorchLean.Storage α] [CommSemiring α] {inDim outDim : ℕ} (W : TorchLean.Tensor α [outDim, inDim]) (dLdy : TorchLean.Tensor α [outDim]) (dx : TorchLean.Tensor α [inDim]) :

    Matrix-vector and vector-matrix multiplication are adjoint under dot.