Tensor Pullbacks, Reindexing, and Reshape #
Coordinate and flat-index pullbacks, broadcast, equivalence-based reindexing, row-major flattening, and zero-copy reshape.
Pull a tensor back along a row-major flat-index map.
This is the native execution form for coordinate programs whose compiler has already certified their linear-index behavior. It fills one output array and reads the source array directly, without constructing multidimensional coordinates in the scalar loop.
Instances For
A flat-index pullback equals its coordinate counterpart when both select the same source index for every row-major output index.
Successive flat-index pullbacks compose into one source-index calculation.
The first map selects entries from the original source, while the second map selects entries from the intermediate tensor.
Broadcast a tensor dimensionwise.
Source and target shapes have the same rank. In each dimension the source length must either equal the target length or be one; singleton dimensions are replicated without imposing any operation on the scalar type. Leading rank expansion can be represented explicitly by reshaping in singleton dimensions first, which is the normalization used by repeat lowering.
Instances For
Pullbacks compose in the reverse order of their coordinate maps.
This associativity-style law is intentionally not a global grind rule:
repeated e-matching can synthesize arbitrarily nested function compositions.
Two coordinate pullbacks are equal when their source coordinates have the same row-major index at every output index.
The premise is stated over linear output indices so reflected compilers can reduce composed coordinate programs to arithmetic without enumerating a tensor.
Reindexing by the identity coordinate equivalence leaves a tensor unchanged.
Successive coordinate equivalences compose to one reindexing operation.
The first equivalence is applied to the tensor, while the second is applied to the resulting tensor, so their coordinate maps compose in the opposite order from the tensor operations.
Reversing a reshape size equality reverses its coordinate equivalence.
Reshape a tensor while preserving its row-major scalar sequence.
The equality argument is proof data establishing that the source and target shapes have the same number of entries.
Instances For
Observing a zero-copy reshape applies the canonical row-major coordinate equivalence.
This is the proof-facing form of reshape_apply: execution reuses the source
array, while extensional arguments may reason about an ordinary coordinate
reindexing.
A zero-copy reshape is extensionally the corresponding coordinate reindexing.
The left side is the native implementation and allocates no array. The right side is used only as a mathematical description in compiler-correctness proofs.
Pointwise binary operations commute with reshaping both inputs by the same row-major size equality.