Shape Erasure #
Bridge lemmas between the proved typed context (TensorPack) and the runtime tape representation
(Spec.SomeTensor stored in Arrays).
The conversion preserves order and stores each erased shape in the resulting SomeTensor.
Every (pid, tensor) produced by toIndexedShapeErasedArray ts start satisfies
pid < start + ss.length.
This is bookkeeping used to prove runtime backward only references earlier nodes.
toShapeErasedArray ignores type-level casts of the shape list.
toShapeErasedArray has the same size as the underlying shape list.
Recovering a typed pack ignores array entries before and after its encoded segment.
Recovering a typed pack after an untouched array prefix and shape erasure is lossless.
Recovering the expected typed pack immediately after shape erasure is lossless.
Splitting a typed context splits its erased array at the same boundary.
Recover just the typed input prefix of a complete runtime context.
Shape-erasing conversions #
The lemmas below show that these conversions preserve length and order and interact well with
TorchLean.TensorPack.snoc and TorchLean.TensorPack.get. They are used later to relate runtime
node ids to positions in the typed proof context Γ ++ ss.
toShapeErasedArray commutes with appending a value.
toShapeErasedArray of a cons context is array cons/append of the head element.
Array lookup through toShapeErasedArray corresponds to TorchLean.TensorPack.get after
erasing the result's shape from its type.
This is the key lemma that lets us connect runtime indexing (arr[i]) to proof indexing (get xs i).