Documentation

ToCslib.Data.Fin.Cases

Direct compilation of finite case analysis #

The pinned core defines Fin.cases using induction. Strict evaluation may compute discarded induction hypotheses, which compounds for nested vector constructors: compiled code reads entry i of a chain of Fin.cons in time exponential in i. A proved compiler simplification selects the case directly, so the read takes time linear in i. The logical definition and its computation equations remain those of core.

A compiler simplification applies to the definitions compiled in the modules that import it. A library that compiles finite case analysis, Fin.cons or vector notation imports this module, as ToCslib.Data.Fin.MOfFn does.

def Fin.casesDirect {n : ℕ} {motive : Fin (n + 1) → Sort u} (zero : motive 0) (succ : (i : Fin n) → motive i.succ) (i : Fin (n + 1)) :
motive i

Finite case analysis with direct pattern matching on the underlying natural.

Equations
Instances For
    @[csimp]

    Compile finite case analysis without evaluating unused induction hypotheses.

    def Fin.consDirect {n : ℕ} {α : Fin (n + 1) → Sort u} (x : α 0) (xs : (i : Fin n) → α i.succ) (i : Fin (n + 1)) :
    α i

    Dependent tuple construction using direct case selection.

    Equations
    Instances For
      @[csimp]

      Rewriting the wrapper is necessary when its imported implementation is inlined later.

      def Matrix.vecConsDirect {α : Type u} {n : ℕ} (x : α) (xs : Fin n → α) :
      Fin (n + 1) → α

      Nondependent vector construction with direct case selection.

      Equations
      Instances For
        @[csimp]

        Compile vector notation without the imported induction-based wrapper.