Real Tensor Proof Toolkit #
This file is the ℝ-specialized proof layer companion to the spec tensor layer.
The tensor proof folder has two layers:
NN.Proofs.Tensor.Algebrais backend-generic and proves semiring facts about tensor dot products and executable folds.- this file works in
Specoverℝ, where calculus, norms, Frobenius products, and model-analysis lemmas live.
The statements use PyTorch-shaped names where that helps readers:
flattenR/unflattenRgive aFin (Spec.Shape.size s) → ℝview ofTensor ℝ s.- lemmas relate
getScalarviews toaddSpec,scaleSpec, etc.
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 #
- Flatten / reshape:
torch.flatten,torch.reshape, andTensor.view. https://pytorch.org/docs/stable/generated/torch.flatten.html https://pytorch.org/docs/stable/generated/torch.reshape.html https://pytorch.org/docs/stable/generated/torch.Tensor.view.html - “numel”:
tensor.numel()corresponds toSpec.Shape.size. https://pytorch.org/docs/stable/generated/torch.Tensor.numel.html
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 #
Mapping a scalar tensor and then extracting it is the same as mapping its scalar value.
Coordinate extraction commutes with a tensor map on vectors.
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.