TorchLean API

NN.Proofs.Tensor.Basic.Algebra

Tensor Algebra Lemmas #

This file collects foundational algebraic lemmas for TorchLean.Tensor: extensionality, map/fold rewrites, and pointwise arithmetic facts used throughout the autograd and runtime-correctness proof files.

theorem Spec.tensor_ext {α : Type} [TorchLean.Storage α] {s : Shape} {x y : TorchLean.Tensor α s} :
(∀ (idxs : List ), getSpec x idxs = getSpec y idxs)x = y

Tensor extensionality over a generic element type: equal getSpec views imply equal tensors.

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.

theorem Spec.option_zero_add (o : Option ) :
Option.map (fun (x : ) => 0 + x) o = o

Mapping 0 + · over an Option is the identity.

@[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.