TorchLean API

NN.Proofs.Tensor.Basic.Algebra

Tensor Algebra Lemmas #

This file collects foundational algebraic lemmas for TorchLean.Tensor over ℝ: pointwise arithmetic identities, linearity of matrix-vector multiplication, and the scalar-fold bridge used throughout the autograd and runtime-correctness proof files.

theorem Spec.add_spec_assoc {s : Shape} (a b c : TorchLean.Tensor ℝ s) :
(a.addSpec b).addSpec c = a.addSpec (b.addSpec c)

Elementwise addition is associative (over $\mathbb R$ tensors).

Elementwise subtraction distributes over addition on the right.

theorem Spec.mul_spec_add_right {s : Shape} (a b c : TorchLean.Tensor ℝ s) :
a.mulSpec (b.addSpec c) = (a.mulSpec b).addSpec (a.mulSpec c)

Elementwise multiplication distributes over addition on the right.

theorem Spec.mul_spec_add_left {s : Shape} (a b c : TorchLean.Tensor ℝ s) :
(a.addSpec b).mulSpec c = (a.mulSpec c).addSpec (b.mulSpec c)

Elementwise multiplication distributes over addition on the left.

Bias cancellation for tensor subtraction: (a + c) - (b + c) = a - b.

Linearity of matrix-vector multiplication in the vector argument (addition).

Linearity of matrix-vector multiplication in the vector argument (scaling).

Full linearity of matrix-vector multiplication in the vector argument.

@[simp]

Left identity for addSpec: adding the all-zero tensor does nothing.

@[simp]

Right identity for addSpec: adding the all-zero tensor does nothing.

@[simp]

Left identity for mulSpec: multiplying by the all-ones tensor does nothing.

@[simp]

Right identity for mulSpec: multiplying by the all-ones tensor does nothing.

theorem Spec.foldl_add_scalar {ι : Type} (values : ι → TorchLean.Tensor ℝ Shape.scalar) (items : List ι) (initial : ℝ) :
List.foldl (fun (total : TorchLean.Tensor ℝ Shape.scalar) (item : ι) => total + values item) (TorchLean.Tensor.scalar initial) items = TorchLean.Tensor.scalar (List.foldl (fun (total : ℝ) (item : ι) => total + (values item).item) initial items)

Adding scalar tensors in a left fold agrees with folding their scalar values.