TorchLean API

NN.Tensor.Internal.Elab.Transform.Index

Certified transform index compilation #

This module compiles the flat-index function of a checked rearrangement or repeat while elaborating the surrounding expression. The generated program contains only the resulting row-major arithmetic; parser data, axis lookup, and checked-plan interpretation remain in erased correctness proofs.

Symbolic dimensions remain symbolic arithmetic in the generated expression; the returned theorem still identifies that program with the independent coordinate semantics.

Build function composition as an explicit lambda.

Generated index maps are executable programs. Lambda form exposes their stored composition without unfolding checked-plan definitions.

Instances For

    Estimate the runtime cost of a generated flat-index map.

    Only value-level arithmetic contributes to the estimate. Dependent bounds, types, and correctness proofs are deliberately ignored because they are erased before execution. The estimate is used to choose between composing a shape-only chain and materializing its already-certified native result.

    Maximum inherited flat-index cost that remains cheaper to fuse than to materialize through the native transform kernel.

    The weighted estimate reflects native arithmetic cost: quotient and remainder are more expensive than addition or multiplication. The threshold is independent of tensor rank and transformation kind.

    Instances For

      Report whether an inherited flat-index map should remain fused.

      Instances For

        Compile a checked output-to-input flat projection.

        The executable result is specialized row-major arithmetic when the reflected plan reduces. Its proof connects that arithmetic directly to linearization of the plan's independent coordinate projection, without unfolding the checked plan's proof fields.

        Instances For