Real Tensor Proof Toolkit #
This file is the ℝ-specialized proof-facing companion to the spec tensor layer.
The tensor proof folder has two layers:
NN.Proofs.Tensor.Algebrais backend-generic and proves semiring facts about recursive 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 (Shape.size s) → ℝview ofTensor ℝ s.- lemmas relate
toVecviews toadd_spec,scale_spec, etc.
We re-export selected generic helpers from NN.Proofs.Tensor.Algebra into the Spec.* namespace so
downstream proof files can use one consistent tensor vocabulary (Spec.toVec, Spec.ofVec,
Spec.finRange_foldl_add_eq_finset_sum) through shared fold and vector lemmas.
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 toShape.size. https://pytorch.org/docs/stable/generated/torch.Tensor.numel.html
Algebraic instances for small tensor shapes #
Additive commutative monoid structure on scalar-shaped real tensors, transported by equivalence.
Additive commutative monoid structure on 1D real tensors (transported via an equiv).
Scalar tensors inherit an ℝ-module structure when their entries do, transported by equivalence.
Tensor α (dim n scalar) inherits an ℝ-module structure when α is an ℝ-module (via an
equiv).
Noncomputable ℝ-module instance on scalar real tensors (for calculus proofs).
Noncomputable ℝ-module instance on 1D real tensors (for calculus proofs).
1D helpers #
Flatten a tensor of shape s into a 1D view Fin (Shape.size s) → ℝ.
This is the proof-facing counterpart of Spec.Tensor.flatten_spec 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 (Shape.size s) → ℝ back into a tensor of shape s.
This is the proof-facing counterpart of Spec.Tensor.unflatten_spec specialized to ℝ, and is
intended to round-trip with flattenR under the spec lemmas in
NN/Spec/Core/TensorReductionShape.lean.