Certified native finite loops #
Generated tensor kernels use these primitives when a static traversal length
fits every Lean target. The executable loops carry USize counters, while
their theorems identify the results with standard Fin.foldl and
Array.ofFn semantics.
This module is operation-independent. Rearrangement, repetition, reduction, packing, unpacking, and einsum all share the same traversal boundary.
Combine branch-local equality proofs for a generated runtime decision.
Native segmented kernels use this theorem to assemble arbitrary-length decision trees while keeping each leaf's semantic certificate local.
Combine proof-dependent branches that both compute the same semantic value.
The branch evidence erases in generated native code, while each branch may use it to certify subtraction, bounds, or direct buffer reads.
fin_foldl_push_eq_array_ofFn is not restated here. It is proved once in
NN.Tensor.Internal.Representation.Storage, which this file imports, and it used to have an exact
second copy at this spot. The uses below spell out the Storage. prefix rather than opening the
namespace, so a reader can see at a glance that the lemma comes from the storage layer.
Fill one array in increasing native-index order.
The callback's bound proof is erased, so the executable builder contains one
allocation and one USize loop.
Instances For
The native array builder equals Array.ofFn whenever its native callback
agrees pointwise with the semantic finite-index function.
Fill the physical buffer selected for α in increasing native-index order.
The storage dictionary is specialized at each scalar type. For Float, this
loop therefore allocates and pushes directly into an unboxed FloatArray.
Instances For
The native physical-buffer builder observes as Array.ofFn when its callback
agrees with the semantic finite-index function.
Fill a physical buffer by copying entries from another buffer.
The source-index callback never exposes α. Generic arrays can therefore
retain and transfer existing boxed values, while specialized scalar arrays
perform direct unboxed reads and writes.
Instances For
The native gather observes as Array.ofFn when every copied source entry
agrees with the semantic finite-index function.
The native gather creates the requested scalar count.
Fill a physical buffer with an executable update callback.
Unlike nativeBufferOfFn, the callback returns the updated physical buffer
instead of a scalar. Movement kernels can therefore copy boxed objects or
unboxed native entries without materializing a scalar at the callback ABI.
Instances For
A physical-update buffer fill observes as Array.ofFn when every update is
the corresponding semantic push.
A physical-update buffer fill creates the requested scalar count.