TorchLean API

NN.Proofs.Tensor.Basic.Algebra

Tensor Algebra Lemmas #

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

theorem Spec.tensor_ext {α : Type} {s : Shape} {x y : 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 : Tensor s) :
(a.addSpec b).addSpec c = a.addSpec (b.addSpec c)

Elementwise addition is associative (over ℝ tensors).

theorem Spec.sub_spec_add_right {s : Shape} (a b c : Tensor s) :

Elementwise subtraction distributes over addition on the right.

theorem Spec.mul_spec_add_right {s : Shape} (a b c : 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 : Tensor s) :
(a.addSpec b).mulSpec c = (a.mulSpec c).addSpec (b.mulSpec c)

Elementwise multiplication distributes over addition on the left.

theorem Spec.sub_spec_bias_cancel {s : Shape} (a b c : Tensor s) :
(a.addSpec c).subSpec (b.addSpec c) = a.subSpec b

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]
theorem Spec.get_dim_scalar {n : } (f : Fin nTensor Shape.scalar) (i : Fin n) :
get (Tensor.dim f) i = f i

Simplification lemmas for common patterns. Useful for automated proof tactics.

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

Mapping 0 + · over an Option is the identity.

@[simp]
theorem Spec.add_spec_zero_left {s : Shape} (t : Tensor s) :
(fill 0 s).addSpec t = t

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

@[simp]
theorem Spec.add_spec_zero_right {s : Shape} (t : Tensor s) :
t.addSpec (fill 0 s) = t

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

@[simp]
theorem Spec.mul_spec_one_left {s : Shape} (t : Tensor s) :
(fill 1 s).mulSpec t = t

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

@[simp]
theorem Spec.mul_spec_one_right {s : Shape} (t : Tensor s) :
t.mulSpec (fill 1 s) = t

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