TorchLean API

NN.Proofs.Tensor.Basic.Core

Real Tensor Proof Toolkit #

This file is the -specialized proof layer companion to the spec tensor layer.

The tensor proof folder has two layers:

The statements use PyTorch-shaped names where that helps readers:

We re-export tensor-specific helpers from NN.Proofs.Tensor.Algebra into the Spec namespace. General list-fold lemmas retain their canonical List names.

PyTorch correspondence / citations #

Algebraic instances #

The pointwise AddCommGroup and Module instances on Tensor α s live in NN.Spec.Core.Tensor.Core; over they give Module ℝ (Tensor ℝ s) directly.

1D helpers #

@[simp]

Mapping a scalar tensor and then extracting it is the same as mapping its scalar value.

@[simp]
theorem Spec.getScalar_mapTensor {α β : Type} [TorchLean.Storage α] [TorchLean.Storage β] {n : } (f : αβ) (x : TorchLean.Tensor α [n]) (i : Fin n) :

Coordinate extraction commutes with a tensor map on vectors.

theorem Spec.getScalar_add_spec {n : } (x y : TorchLean.Tensor [n]) :
(x.addSpec y).getScalar = fun (i : Fin n) => x.getScalar i + y.getScalar i

getScalar distributes over pointwise addition (addSpec).

theorem Spec.getScalar_scale_spec {n : } (x : TorchLean.Tensor [n]) (c : ) :
(x.scaleSpec c).getScalar = fun (i : Fin n) => x.getScalar i * c

getScalar distributes over pointwise scaling (scaleSpec).

Flatten a tensor of shape s into a 1D view Fin (Spec.Shape.size s) → ℝ.

This is the proof layer counterpart of TorchLean.Tensor.flattenSpec specialized to . In PyTorch terms it is the functional analogue of flattening a tensor and then indexing it linearly (torch.flatten, tensor.view(-1)). See the spec file NN/Spec/Core/TensorReductionShape.lean for the definitional flatten/unflatten interface.

Citations: https://pytorch.org/docs/stable/generated/torch.flatten.html https://pytorch.org/docs/stable/generated/torch.Tensor.view.html

Instances For

    Unflatten a 1D view Fin (Spec.Shape.size s) → ℝ back into a tensor of shape s.

    This is the proof layer counterpart of TorchLean.Tensor.unflattenSpec specialized to , and is intended to round-trip with flattenR under the spec lemmas in NN/Spec/Core/TensorReductionShape.lean.

    Instances For

      Pointwise tensor algebra #