Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Resource typing rules and bounded term rewrite systems

Definition
HofmannMoser_Typing

by kmehltretter82 · Oct 28, 2026 · Mathlib c5ea003 (Lean v4.30.0)

amortized-analysiscomplexityterm-rewritingtree-automatatype-systems

Resource-annotated signatures, the amortised resource typing judgment, and syntactic boundedness of term rewrite systems (Section 4, pp. 249–252).

An annotated signature (AnnotatedSignature C D, Definition 14, p. 249) assigns a relation between length-nnn input annotations QQQ and length-111 output annotations Q′Q'Q′ to each nnn-ary defined symbol f∈Dnf \in \mathcal{D}_nf∈Dn​. The structure AnnotatedSignatures C D bundles separate signature relations for charged (TypingMode.counted, ⊢\vdash⊢) and uncharged (TypingMode.costFree, ⊢cf\vdash^{\mathrm{cf}}⊢cf) derivations, and AnnotatedSignatureExtensional expresses invariance under coefficient-wise annotation equality (annotationEq, defined via annotationCoefficient).

The inductive judgment Γ:Q⊢(cf)t:Q′\Gamma : Q \vdash^{(\mathrm{cf})} t : Q'Γ:Q⊢(cf)t:Q′ (Typing S P F mode n xs Q t Q', Figure 2, p. 251) formalizes all eight typing rules of the paper:

  1. variable: typing a single variable x:Q⊢(cf)x:Qx : Q \vdash^{(\mathrm{cf})} x : Qx:Q⊢(cf)x:Q.
  2. defined: typing a flat defined call f(x1,…,xn)f(x_1, \dots, x_n)f(x1​,…,xn​) from (Q,Q′)∈F(mode)(f)(Q, Q') \in F(\text{mode})(f)(Q,Q′)∈F(mode)(f).
  3. constructor: typing a flat constructor application c(x1,…,xn)c(x_1, \dots, x_n)c(x1​,…,xn​) with input annotation ◃c(Q)\triangleleft_c(Q)◃c​(Q) and output annotation QQQ.
  4. weakenAnnotations: relaxing input and output annotations along pointwise coefficient inequality P0≤QP_0 \le QP0​≤Q and Q′≤P′Q' \le P'Q′≤P′ (annotationLe).
  5. exchange: simultaneously permuting context variables and annotation coordinates along a bijection ρ:Fin⁡(n)→Fin⁡(n)\rho : \operatorname{Fin}(n) \to \operatorname{Fin}(n)ρ:Fin(n)→Fin(n) (annotationReindex).
  6. weakenContext: dropping a trailing context variable by projecting the annotation at the canonical basic function ∅\emptyset∅ (annotationProject).
  7. share: contracting two distinct variables x,yx, yx,y into a fresh variable zzz via Υ(Q)\Upsilon(Q)Υ(Q) (annotationShare).
  8. composition: typing an application f(t0,…,tlast)f(t_0, \dots, t_{\text{last}})f(t0​,…,tlast​) of positive arity last+1\text{last} + 1last+1 across concatenated argument contexts (argumentContexts), governed by the coupling equations compositionCoefficients and the mode selector listPremiseMode (which uses counted mode for the all-canonical index ȷ⃗i=∅⃗\vec{\jmath}_i = \vec{\emptyset}​i​=∅​ inside a counted parent derivation and cost-free mode otherwise).

Finally, PatternExpansion and additiveShiftAt formalize iterated constructor pattern unfolding across rule left-hand sides, and Bounded / BoundedSignatures (Definition 15, p. 250) state that every rewrite rule f(l1,…,ln)→rf(l_1, \dots, l_n) \to rf(l1​,…,ln​)→r in RRR and every signature annotation (Q,Q′)(Q, Q')(Q,Q′) for fff expands to pattern variables (x1,…,xl)(x_1, \dots, x_l)(x1​,…,xl​) and an annotation P0P_0P0​ typing r:Q′r : Q'r:Q′ with P0+1=shiftedP_0 + 1 = \text{shifted}P0​+1=shifted in counted mode and P0=shiftedP_0 = \text{shifted}P0​=shifted in cost-free mode.

Definition code
import Definitions.Def_HofmannMoser_Syntax
import Definitions.Def_HofmannMoser_Potential

/-!
# Resource typing and bounded term rewrite systems for Hofmann–Moser

Definitions for Section 4 (Definitions 14 and 15, Figure 2) of Martin Hofmann and Georg Moser,
*Multivariate Amortised Resource Analysis for Term Rewrite Systems*, TLCA 2015, pp. 249–252,
<https://doi.org/10.4230/LIPIcs.TLCA.2015.241>.

Annotations are indexed by tuples of basic resource functions (`BasicFunction C`) with respect
to a fixed representative policy (`RepPolicy C`). The typing judgment `Typing` encodes the
inference rules of Figure 2 with counted and cost-free modes (`TypingMode`), separate
counted and cost-free annotated signatures (`AnnotatedSignatures`), simultaneous context
and annotation coordinate exchange, context weakening, annotation weakening (including the
empty context), sharing (`annotationShare`), and `n`-ary composition (`compositionCoefficients`).
`Bounded` and `BoundedSignatures` encode Definition 15 via concrete left-hand-side constructor
pattern expansion (`PatternExpansion`).
-/

namespace HofmannMoser

universe u

/-- Definition 14: an annotated signature assigns a collection of input/output annotation
pairs `(Q, Q')` to each `n`-ary defined function symbol `f ∈ D n`, where `Q` has length `n`
and `Q'` has length `1`. -/
abbrev AnnotatedSignature (C D : Nat → Type u) :=
  (n : Nat) → D n → Annotation C n → Annotation C 1 → Prop

/-- The two judgment modes occurring in Figure 2 (p. 251): charged (`counted`, `⊢`) and
uncharged (`costFree`, `⊢^{cf}`). -/
inductive TypingMode where
  | counted
  | costFree
  deriving DecidableEq

/-- Separate annotated signatures for charged (`counted`) and uncharged (`costFree`)
judgments (cf. p. 250 and the multiplication example on p. 252). -/
structure AnnotatedSignatures (C D : Nat → Type u) where
  counted : AnnotatedSignature C D
  costFree : AnnotatedSignature C D

/-- Select the annotated signature corresponding to a judgment mode. -/
def AnnotatedSignatures.get {C D : Nat → Type u} (F : AnnotatedSignatures C D) :
    TypingMode → AnnotatedSignature C D
  | .counted => F.counted
  | .costFree => F.costFree

/-- Reindex the coordinates of an annotation along `ρ`. When used in the exchange rule,
the same bijection reindexes both the context variables and every basic-function tuple. -/
def annotationReindex {C : Nat → Type u} {n : Nat} (ρ : Fin n → Fin n)
    (Q : Annotation C n) : Annotation C n :=
  Q.map fun entry ↦ (fun i ↦ entry.1 (ρ i), entry.2)

/-- The coefficient `q_{(p₁, …, p_n)}` of a basic-function tuple `index` in an annotation `Q`,
obtained by summing the weights of all entries in `Q` with key `index`. -/
noncomputable def annotationCoefficient {C : Nat → Type u} {n : Nat}
    (Q : Annotation C n) (index : Fin n → BasicFunction C) : Rat := by
  classical
  exact (Q.map fun entry ↦ if entry.1 = index then entry.2.1 else 0).sum

/-- Equality of annotations as finitely supported coefficient families over basic-function
tuples. -/
def annotationEq {C : Nat → Type u} {n : Nat} (P Q : Annotation C n) : Prop :=
  ∀ index, annotationCoefficient P index = annotationCoefficient Q index

/-- Pointwise comparison `P ≤ Q` of annotation coefficient families (§3, p. 249). -/
def annotationLe {C : Nat → Type u} {n : Nat} (P Q : Annotation C n) : Prop :=
  ∀ index, annotationCoefficient P index ≤ annotationCoefficient Q index

/-- An annotated signature on list representations is extensional when membership depends
only on the represented coefficient families (`annotationEq`). -/
def AnnotatedSignatureExtensional {C D : Nat → Type u} (F : AnnotatedSignature C D) : Prop :=
  ∀ n (f : D n) (P P' : Annotation C n) (Q Q' : Annotation C 1),
    annotationEq P P' → annotationEq Q Q' → (F n f P Q ↔ F n f P' Q')

/-- Read the coefficient of a basic-function tuple given as a list `indices` of length `n`.
Lists of length different from `n` return `0` and lie outside the length-guarded equations
of `compositionCoefficients`. -/
noncomputable def annotationCoefficientList {C : Nat → Type u} {n : Nat}
    (Q : Annotation C n) (indices : List (BasicFunction C)) : Rat := by
  classical
  exact if h : indices.length = n then
    annotationCoefficient Q (fun i ↦ indices.get ⟨i.val, by simp [h, i.isLt]⟩)
  else 0

/-- Total number of context variables across argument blocks in `[start, stop)`. -/
def contextWidth (lengths : Nat → Nat) (start stop : Nat) : Nat :=
  (((List.range (stop - start)).map fun k ↦ lengths (start + k))).sum

/-- The coefficient equations of the `n`-ary composition rule in Figure 2 (p. 251; see also
p. 250 and (8) on p. 253), for a positive number `last + 1` of arguments. For each argument
position `i`, `P i j` and `R i j` are the input and output annotations indexed by the list `j`
of `i` preceding output basic functions and `contextWidth lengths (i + 1) (last + 1)` following
context basic functions. -/
def compositionCoefficients {C : Nat → Type u} (last : Nat) (lengths : Nat → Nat)
    (Q : Annotation C (contextWidth lengths 0 (last + 1)))
    (S : Annotation C (last + 1))
    (P : (i : Nat) → List (BasicFunction C) → Annotation C (lengths i))
    (R : Nat → List (BasicFunction C) → Annotation C 1) : Prop :=
  (∀ first rest, first.length = lengths 0 →
    rest.length = contextWidth lengths 1 (last + 1) →
    annotationCoefficientList Q (first ++ rest) = annotationCoefficientList (P 0 rest) first) ∧
  (∀ i, i < last → ∀ before nextContext after output,
    before.length = i → nextContext.length = lengths (i + 1) →
    after.length = contextWidth lengths (i + 2) (last + 1) →
    annotationCoefficientList (P (i + 1) (before ++ [output] ++ after)) nextContext =
      annotationCoefficientList (R i (before ++ nextContext ++ after)) [output]) ∧
  (∀ before output, before.length = last →
    annotationCoefficientList S (before ++ [output]) =
      annotationCoefficientList (R last before) [output])

/-- Replace position `i` of a list `xs` by the list `children`, preserving the order of all
other entries. -/
def replaceAt {α : Type u} (xs : List α) (i : Nat) (children : List α) : List α :=
  xs.take i ++ children ++ xs.drop (i + 1)

/-- Replacing a valid index `i < xs.length` changes the list length by `children.length - 1`. -/
theorem replaceAt_length {α : Type u} (xs : List α) (i : Nat) (children : List α)
    (hi : i < xs.length) : (replaceAt xs i children).length = xs.length - 1 + children.length := by
  simp only [replaceAt, List.length_append, List.length_take, List.length_drop]
  simp only [Nat.min_eq_left (Nat.le_of_lt hi)]
  omega

/-- Expand the basic function at coordinate `pos` of an annotation `Q` at constructor `c`
using the transitions of its fixed representative `P.rep (entry.1 pos)`, replacing that
coordinate in place by the `k` rerooted child basic functions. -/
def additiveShiftAt {C : Nat → Type u} {n k : Nat}
    (P : RepPolicy C) (pos : Fin n) (c : C k) (Q : Annotation C n) :
    Annotation C (n - 1 + k) :=
  Q.flatMap fun entry ↦
    let A := P.rep (entry.1 pos)
    ((A.rules k c).filter fun tr ↦ tr.2 == A.final).map fun tr ↦
      let old := List.ofFn entry.1
      let children := List.ofFn fun i ↦ BasicFunction.reroot A (tr.1 i)
      let new := replaceAt old pos.val children
      have hlen : new.length = n - 1 + k := by
        rw [replaceAt_length old pos.val children (by simp [old, pos.isLt])]
        simp [old, children]
      (fun i ↦ new.get ⟨i.val, by simp [hlen, i.isLt]⟩, entry.2)

/-- Expanding a constructor pattern at `pos` changes the pattern list length by `k - 1`. -/
theorem replacePattern_length {C D : Nat → Type u} (patterns : List (Term C D))
    (pos : Fin patterns.length) {k : Nat} (args : Fin k → Term C D) :
    (replaceAt patterns pos.val (List.ofFn args)).length = patterns.length - 1 + k := by
  rw [replaceAt_length patterns pos.val (List.ofFn args) pos.isLt]
  simp

/-- Iterated constructor shift across a list of rule patterns (Definition 15, p. 250).
Each step expands a constructor subterm `c(t₁, …, t_k)` at coordinate `pos` and applies
`additiveShiftAt P pos c` at the same coordinate of the annotation, terminating when all
remaining pattern positions are variables `variables.map Term.var`. -/
inductive PatternExpansion {C D : Nat → Type u} (P : RepPolicy C) :
    (patterns : List (Term C D)) → Annotation C patterns.length →
      (variables : List Nat) → Annotation C variables.length → Prop
  | done (variables : List Nat) (Q : Annotation C variables.length) :
      PatternExpansion P (variables.map Term.var)
        ((List.length_map Term.var).symm ▸ Q) variables Q
  | step {k : Nat} (patterns : List (Term C D)) (pos : Fin patterns.length)
      (c : C k) (args : Fin k → Term C D) (hPattern : patterns.get pos = .func (.inl c) args)
      (Q : Annotation C patterns.length) (variables : List Nat)
      (Q' : Annotation C variables.length)
      (hNext : PatternExpansion P (replaceAt patterns pos.val (List.ofFn args))
        ((replacePattern_length patterns pos args).symm ▸ additiveShiftAt P pos c Q)
        variables Q') :
      PatternExpansion P patterns Q variables Q'

/-- Concatenate the argument contexts `Γ₁, …, Γ_{arity}` in order. -/
def argumentContexts (contexts : Nat → List Nat) (arity : Nat) : List Nat :=
  (List.range arity).flatMap contexts

/-- Total length of the concatenated argument contexts. -/
theorem argumentContexts_length (contexts : Nat → List Nat) (arity : Nat) :
    (argumentContexts contexts arity).length =
      contextWidth (fun i ↦ (contexts i).length) 0 arity := by
  simp [argumentContexts, contextWidth, List.length_flatMap]

/-- Figure 2's `⊢^{(cf)}` mode-selection convention (p. 251): inside a counted composition,
the all-canonical index `j⃗_i = ∅⃗` uses a counted premise (`counted`), and every other index
`j⃗_i ≠ ∅⃗` uses a cost-free premise (`costFree`). Inside a cost-free composition, all argument
premises are cost-free. -/
noncomputable def listPremiseMode {C : Nat → Type u} (S : FiniteConstructors C)
    (parent : TypingMode) (indices : List (BasicFunction C)) : TypingMode := by
  classical
  exact if parent = .costFree then .costFree
    else if ∀ p ∈ indices, p = BasicFunction.canonical S
      then .counted else .costFree

/-- The resource-analysis typing judgment `Γ : Q ⊢^{(cf)} t : Q'` of Figure 2 (p. 251),
parameterized by the finite constructor signature `S`, the representative policy `P`, and the
counted/cost-free annotated signatures `F`. -/
inductive Typing {C D : Nat → Type u} (S : FiniteConstructors C)
    (P : RepPolicy C) (F : AnnotatedSignatures C D) :
    TypingMode → (n : Nat) → (Fin n → Nat) → Annotation C n → Term C D →
      Annotation C 1 → Prop
  | variable (mode : TypingMode) (x : Nat) (Q : Annotation C 1) :
      Typing S P F mode 1 (fun _ ↦ x) Q (.var x) Q
  | defined (mode : TypingMode) {n : Nat} (f : D n) (xs : Fin n → Nat)
      (Q : Annotation C n) (Q' : Annotation C 1) (hDistinct : Function.Injective xs)
      (hannotated : F.get mode n f Q Q') :
      Typing S P F mode n xs Q (.func (.inr f) (fun i ↦ .var (xs i))) Q'
  | constructor (mode : TypingMode) {n : Nat} (c : C n) (xs : Fin n → Nat)
      (Q : Annotation C 1) (hDistinct : Function.Injective xs) :
      Typing S P F mode n xs (Nat.zero_add n ▸ additiveShift P (m := 0) c Q)
        (.func (.inl c) (fun i ↦ .var (xs i))) Q
  | weakenAnnotations (mode : TypingMode) {n : Nat} (xs : Fin n → Nat)
      (P₀ Q : Annotation C n) (P' Q' : Annotation C 1) (t : Term C D)
      (hDistinct : Function.Injective xs)
      (h : Typing S P F mode n xs P₀ t P') (hInput : annotationLe P₀ Q)
      (hOutput : annotationLe Q' P') : Typing S P F mode n xs Q t Q'
  | exchange (mode : TypingMode) {n : Nat} (xs : Fin n → Nat) (ρ : Fin n → Fin n)
      (hInjective : Function.Injective ρ) (hSurjective : Function.Surjective ρ)
      (Q : Annotation C n) (Q' : Annotation C 1) (t : Term C D)
      (h : Typing S P F mode n xs Q t Q') :
      Typing S P F mode n (fun i ↦ xs (ρ i)) (annotationReindex ρ Q) t Q'
  | weakenContext (mode : TypingMode) {n : Nat} (xs : Fin (n + 1) → Nat)
      (Q : Annotation C (n + 1)) (Q' : Annotation C 1) (t : Term C D)
      (hDistinct : Function.Injective xs)
      (h : Typing S P F mode n (fun i ↦ xs (Fin.castSucc i))
        (annotationProject Q (canonicalTuple S 1)) t Q') :
      Typing S P F mode (n + 1) xs Q t Q'
  | share (mode : TypingMode) {n : Nat} (xs : Fin n → Nat) (x y z : Nat)
      (Q : Annotation C (n + 2)) (Q' : Annotation C 1) (t : Term C D)
      (hContext : Function.Injective xs) (hDistinct : x ≠ y)
      (hFresh : ∀ i, xs i ≠ x ∧ xs i ≠ y ∧ xs i ≠ z)
      (hNew : z ≠ x ∧ z ≠ y ∧ z ∉ t.variables)
      (h : Typing S P F mode (n + 2)
        (Fin.addCases xs (fun i ↦ if i.val = 0 then x else y)) Q t Q') :
      Typing S P F mode (n + 1) (Fin.addCases xs (fun _ ↦ z))
        (annotationShare S P Q) (t.rename fun v ↦ if v = x ∨ v = y then z else v) Q'
  | composition (mode : TypingMode) (last : Nat) (f : C (last + 1) ⊕ D (last + 1))
      (contexts : Nat → List Nat) (terms : Nat → Term C D) (fresh : Fin (last + 1) → Nat)
      (Q : Annotation C (argumentContexts contexts (last + 1)).length)
      (S' : Annotation C (last + 1)) (Q' : Annotation C 1)
      (P_arg : (i : Nat) → List (BasicFunction C) → Annotation C (contexts i).length)
      (R_arg : Nat → List (BasicFunction C) → Annotation C 1)
      (hContexts : (argumentContexts contexts (last + 1)).Nodup)
      (hCoverage : ∀ i, i < last + 1 → ∀ x, x ∈ (terms i).variables → x ∈ contexts i)
      (hDistinct : Function.Injective fresh)
      (hFresh : ∀ i, fresh i ∉ argumentContexts contexts (last + 1) ∧
        ∀ j, j < last + 1 → fresh i ∉ (terms j).variables)
      (hCoefficients : compositionCoefficients last (fun i ↦ (contexts i).length)
        (argumentContexts_length contexts (last + 1) ▸ Q) S' P_arg R_arg)
      (hArguments : ∀ i, i < last + 1 → ∀ indices,
        indices.length = i + contextWidth (fun k ↦ (contexts k).length) (i + 1) (last + 1) →
        Typing S P F (listPremiseMode S mode indices) (contexts i).length
          (contexts i).get (P_arg i indices) (terms i) (R_arg i indices))
      (hFunction : Typing S P F mode (last + 1) fresh S'
        (.func f (fun i ↦ .var (fresh i))) Q') :
      Typing S P F mode (argumentContexts contexts (last + 1)).length
        (argumentContexts contexts (last + 1)).get Q
        (.func f (fun i ↦ terms i.val)) Q'

/-- One unit of rational potential. -/
def onePotential : {q : Rat // 0 ≤ q} := ⟨1, by decide⟩

/-- Definition 15 (p. 250): a TRS `R` is bounded (`mode = .counted`) or weakly bounded
(`mode = .costFree`) with respect to `F` if for every rule `f(l₁, …, l_n) → r` in `R` and
every annotation pair `(Q, Q')` in `F.get mode` for `f`, iteratively shifting `Q` across the
constructors of `l₁, …, l_n` yields an annotation `shifted` on the pattern variables
`variables = [x₁, …, x_l]` and an annotation `P₀` with `P₀ + 1 = shifted` (when `counted`)
or `P₀ = shifted` (when `costFree`) such that `x₁, …, x_l : P₀ ⊢^{(cf)} r : Q'` is derivable. -/
def Bounded {C D : Nat → Type u} (S : FiniteConstructors C) (P : RepPolicy C)
    (F : AnnotatedSignatures C D) (R : RewriteSystem C D) (mode : TypingMode) : Prop :=
  ∀ rule, R rule → ∀ (Q : Annotation C rule.arity) (Q' : Annotation C 1),
    F.get mode rule.arity rule.symbol Q Q' →
    ∃ (variables : List Nat) (P₀ shifted : Annotation C variables.length),
      PatternExpansion P (List.ofFn rule.patterns) ((List.length_ofFn).symm ▸ Q)
        variables shifted ∧
      (match mode with
       | .counted => annotationEq (addConstant S P₀ onePotential) shifted
       | .costFree => annotationEq P₀ shifted) ∧
      Typing S P F mode variables.length variables.get P₀ rule.rhs Q'

/-- Both boundedness obligations required when counted derivations invoke cost-free premises:
`R` is bounded with respect to `F.counted` and weakly bounded with respect to `F.costFree`. -/
def BoundedSignatures {C D : Nat → Type u} (S : FiniteConstructors C) (P : RepPolicy C)
    (F : AnnotatedSignatures C D) (R : RewriteSystem C D) : Prop :=
  Bounded S P F R .counted ∧ Bounded S P F R .costFree

end HofmannMoser
Source
Hofmann--Moser 2015, Multivariate Amortised Resource Analysis for Term Rewrite Systems, TLCA 2015, https://doi.org/10.4230/LIPIcs.TLCA.2015.241, Section 4, pp. 249--252, Definitions 14--15, Figure 2
Read-back

What the Lean code literally says, in plain math · gemini-2.5-pro

1. HofmannMoser.AnnotatedSignature

For a universe level uuu and two arity-indexed type families C,D:N→Type uC, D : \mathbb{N} \to \text{Type } uC,D:N→Type u (representing nnn-ary constructor symbols C(n)C(n)C(n) and nnn-ary defined function symbols D(n)D(n)D(n) for each n∈Nn \in \mathbb{N}n∈N), AnnotatedSignature C D is an abbreviation for the dependent relation type

Π(n:N),  D(n)→Annotation(C,n)→Annotation(C,1)→Prop.\Pi (n : \mathbb{N}),\; D(n) \to \text{Annotation}(C, n) \to \text{Annotation}(C, 1) \to \text{Prop}.Π(n:N),D(n)→Annotation(C,n)→Annotation(C,1)→Prop.

Here, for any k∈Nk \in \mathbb{N}k∈N, Annotation(C,k)\text{Annotation}(C, k)Annotation(C,k) is the list type List((Fin k→BasicFunction(C))×{q∈Q∣0≤q})\text{List}\big((\text{Fin } k \to \text{BasicFunction}(C)) \times \{q \in \mathbb{Q} \mid 0 \le q\}\big)List((Fin k→BasicFunction(C))×{q∈Q∣0≤q}), where:

  • Value(C)\text{Value}(C)Value(C) is the inductive type of finite ground constructor trees built via noden(c,children)\text{node}_n(c, \text{children})noden​(c,children) for n∈Nn \in \mathbb{N}n∈N, c∈C(n)c \in C(n)c∈C(n), and children:Fin n→Value(C)\text{children} : \text{Fin } n \to \text{Value}(C)children:Fin n→Value(C);
  • BasicFunction(C)={f:Value(C)→N∣∃A:TreeAutomaton(C),  A.basic=f}\text{BasicFunction}(C) = \{f : \text{Value}(C) \to \mathbb{N} \mid \exists A : \text{TreeAutomaton}(C),\; A.\text{basic} = f\}BasicFunction(C)={f:Value(C)→N∣∃A:TreeAutomaton(C),A.basic=f} is the subtype of functions on ground constructor values computed by the accepting run count A.basic(v)=A.runCount(v,A.final)A.\text{basic}(v) = A.\text{runCount}(v, A.\text{final})A.basic(v)=A.runCount(v,A.final) of some finite bottom-up tree automaton AAA; and
  • {q∈Q∣0≤q}\{q \in \mathbb{Q} \mid 0 \le q\}{q∈Q∣0≤q} is the subtype of non-negative rational weights.

An element F:AnnotatedSignature(C,D)F : \text{AnnotatedSignature}(C, D)F:AnnotatedSignature(C,D) is an arbitrary predicate relating an arity n∈Nn \in \mathbb{N}n∈N, a defined symbol f∈D(n)f \in D(n)f∈D(n), an nnn-ary input annotation P:Annotation(C,n)P : \text{Annotation}(C, n)P:Annotation(C,n), and a unary output annotation Q:Annotation(C,1)Q : \text{Annotation}(C, 1)Q:Annotation(C,1). No functionality, non-emptiness, or invariance under list reordering is imposed by the type itself (in particular, a symbol f∈D(n)f \in D(n)f∈D(n) may be related to zero, one, or multiple annotation pairs (P,Q)(P, Q)(P,Q), including when n=0n = 0n=0 or when PPP or QQQ is the empty list [][][]).


2. HofmannMoser.TypingMode

TypingMode is a two-element inductive enumeration type equipped with a derived decidable equality instance (DecidableEq\text{DecidableEq}DecidableEq), consisting of the two nullary constructors:

  • counted\text{counted}counted, and
  • costFree\text{costFree}costFree.

3. HofmannMoser.AnnotatedSignatures

For a universe level uuu and arity-indexed type families C,D:N→Type uC, D : \mathbb{N} \to \text{Type } uC,D:N→Type u, AnnotatedSignatures C D is a two-field structure bundling two annotated signature relations:

  • counted:AnnotatedSignature(C,D)\text{counted} : \text{AnnotatedSignature}(C, D)counted:AnnotatedSignature(C,D), and
  • costFree:AnnotatedSignature(C,D)\text{costFree} : \text{AnnotatedSignature}(C, D)costFree:AnnotatedSignature(C,D),

where each field has type Π(n:N),  D(n)→Annotation(C,n)→Annotation(C,1)→Prop\Pi (n : \mathbb{N}),\; D(n) \to \text{Annotation}(C, n) \to \text{Annotation}(C, 1) \to \text{Prop}Π(n:N),D(n)→Annotation(C,n)→Annotation(C,1)→Prop. The structure imposes no coupling or compatibility condition between counted\text{counted}counted and costFree\text{costFree}costFree.


4. HofmannMoser.AnnotatedSignatures.get

For implicit arity-indexed type families C,D:N→Type uC, D : \mathbb{N} \to \text{Type } uC,D:N→Type u, an explicit signature bundle F:AnnotatedSignatures(C,D)F : \text{AnnotatedSignatures}(C, D)F:AnnotatedSignatures(C,D), and an explicit mode mode:TypingMode\text{mode} : \text{TypingMode}mode:TypingMode, AnnotatedSignatures.get F mode projects the corresponding AnnotatedSignature(C,D)\text{AnnotatedSignature}(C, D)AnnotatedSignature(C,D) component of FFF:

get(F,mode)={F.countedif mode=counted,F.costFreeif mode=costFree.\text{get}(F, \text{mode}) = \begin{cases} F.\text{counted} & \text{if } \text{mode} = \text{counted}, \\ F.\text{costFree} & \text{if } \text{mode} = \text{costFree}. \end{cases}get(F,mode)={F.countedF.costFree​if mode=counted,if mode=costFree.​

5. HofmannMoser.annotationReindex

For an implicit constructor family C:N→Type uC : \mathbb{N} \to \text{Type } uC:N→Type u, an implicit arity n∈Nn \in \mathbb{N}n∈N, an explicit finite index map ρ:Fin n→Fin n\rho : \text{Fin } n \to \text{Fin } nρ:Fin n→Fin n, and an explicit annotation list Q:Annotation(C,n)Q : \text{Annotation}(C, n)Q:Annotation(C,n), annotationReindex ρ Q is the annotation of arity nnn obtained by mapping over the list Q=[(p⃗1,w1),…,(p⃗m,wm)]Q = [(\vec{p}_1, w_1), \dots, (\vec{p}_m, w_m)]Q=[(p​1​,w1​),…,(p​m​,wm​)] and precomposing each entry's tuple of basic functions with ρ\rhoρ:

annotationReindex(ρ,Q)=[(i∈Fin n↦p⃗1(ρ(i)), w1), …, (i∈Fin n↦p⃗m(ρ(i)), wm)].\text{annotationReindex}(\rho, Q) = \big[(i \in \text{Fin } n \mapsto \vec{p}_1(\rho(i)),\, w_1),\, \dots,\, (i \in \text{Fin } n \mapsto \vec{p}_m(\rho(i)),\, w_m)\big].annotationReindex(ρ,Q)=[(i∈Fin n↦p​1​(ρ(i)),w1​),…,(i∈Fin n↦p​m​(ρ(i)),wm​)].

The definition does not require ρ\rhoρ to be injective or surjective. If ρ\rhoρ collapses distinct tuples p⃗j≠p⃗k\vec{p}_j \ne \vec{p}_kp​j​=p​k​ into the same composite tuple p⃗j∘ρ=p⃗k∘ρ\vec{p}_j \circ \rho = \vec{p}_k \circ \rhop​j​∘ρ=p​k​∘ρ, both entries remain as separate elements in the resulting list without merging their weights. When n=0n = 0n=0 or Q=[]Q = []Q=[], the list is unchanged.


6. HofmannMoser.annotationCoefficient

For an implicit constructor family C:N→Type uC : \mathbb{N} \to \text{Type } uC:N→Type u, an implicit arity n∈Nn \in \mathbb{N}n∈N, an explicit annotation list Q:Annotation(C,n)Q : \text{Annotation}(C, n)Q:Annotation(C,n), and an explicit target tuple index:Fin n→BasicFunction(C)\text{index} : \text{Fin } n \to \text{BasicFunction}(C)index:Fin n→BasicFunction(C), annotationCoefficient Q index is a noncomputable rational number in Q\mathbb{Q}Q defined (using classical decidability of equality on Fin n→BasicFunction(C)\text{Fin } n \to \text{BasicFunction}(C)Fin n→BasicFunction(C)) as the sum of the underlying rational weights of all entries in QQQ whose first component equals index\text{index}index:

annotationCoefficient(Q,index)=∑(p⃗,w)∈Q{w.valif p⃗=index,0if p⃗≠index.\text{annotationCoefficient}(Q, \text{index}) = \sum_{(\vec{p}, w) \in Q} \begin{cases} w.\text{val} & \text{if } \vec{p} = \text{index}, \\ 0 & \text{if } \vec{p} \ne \text{index}. \end{cases}annotationCoefficient(Q,index)=(p​,w)∈Q∑​{w.val0​if p​=index,if p​=index.​

Because BasicFunction(C)\text{BasicFunction}(C)BasicFunction(C) is a subtype of Value(C)→N\text{Value}(C) \to \mathbb{N}Value(C)→N with a proof component in Prop\text{Prop}Prop, equality p⃗=index\vec{p} = \text{index}p​=index is extensional equality of the nnn underlying functions Value(C)→N\text{Value}(C) \to \mathbb{N}Value(C)→N at each coordinate i∈Fin ni \in \text{Fin } ni∈Fin n. If index\text{index}index does not occur in QQQ (in particular, if Q=[]Q = []Q=[]), the result is 0∈Q0 \in \mathbb{Q}0∈Q. If index\text{index}index occurs multiple times in QQQ, all matching weights are added together. Although every weight www satisfies 0≤w.val0 \le w.\text{val}0≤w.val, the return type is plain Q\mathbb{Q}Q rather than the non-negative subtype.


7. HofmannMoser.annotationEq

For an implicit constructor family C:N→Type uC : \mathbb{N} \to \text{Type } uC:N→Type u, an implicit arity n∈Nn \in \mathbb{N}n∈N, and two explicit annotations P,Q:Annotation(C,n)P, Q : \text{Annotation}(C, n)P,Q:Annotation(C,n), annotationEq P Q is the proposition asserting that PPP and QQQ assign the same total rational coefficient to every nnn-tuple of basic functions:

annotationEq(P,Q)  ⟺  ∀index:Fin n→BasicFunction(C),annotationCoefficient(P,index)=annotationCoefficient(Q,index).\text{annotationEq}(P, Q) \iff \forall \text{index} : \text{Fin } n \to \text{BasicFunction}(C),\quad \text{annotationCoefficient}(P, \text{index}) = \text{annotationCoefficient}(Q, \text{index}).annotationEq(P,Q)⟺∀index:Fin n→BasicFunction(C),annotationCoefficient(P,index)=annotationCoefficient(Q,index).

This equivalence identifies annotations that differ by list permutation, presence of zero-weight entries (p⃗,0)(\vec{p}, 0)(p​,0), or splitting of a tuple's weight across duplicate entries.


8. HofmannMoser.annotationLe

For an implicit constructor family C:N→Type uC : \mathbb{N} \to \text{Type } uC:N→Type u, an implicit arity n∈Nn \in \mathbb{N}n∈N, and two explicit annotations P,Q:Annotation(C,n)P, Q : \text{Annotation}(C, n)P,Q:Annotation(C,n), annotationLe P Q is the proposition asserting pointwise inequality of total rational coefficients across all nnn-tuples of basic functions:

annotationLe(P,Q)  ⟺  ∀index:Fin n→BasicFunction(C),annotationCoefficient(P,index)≤annotationCoefficient(Q,index).\text{annotationLe}(P, Q) \iff \forall \text{index} : \text{Fin } n \to \text{BasicFunction}(C),\quad \text{annotationCoefficient}(P, \text{index}) \le \text{annotationCoefficient}(Q, \text{index}).annotationLe(P,Q)⟺∀index:Fin n→BasicFunction(C),annotationCoefficient(P,index)≤annotationCoefficient(Q,index).

9. HofmannMoser.AnnotatedSignatureExtensional

For implicit arity-indexed type families C,D:N→Type uC, D : \mathbb{N} \to \text{Type } uC,D:N→Type u and an explicit annotated signature F:AnnotatedSignature(C,D)F : \text{AnnotatedSignature}(C, D)F:AnnotatedSignature(C,D), AnnotatedSignatureExtensional F is the proposition asserting that FFF respects coefficient-wise annotation equivalence (annotationEq\text{annotationEq}annotationEq) in both its input and output annotation arguments:

∀n:N,  ∀f:D(n),  ∀P,P′:Annotation(C,n),  ∀Q,Q′:Annotation(C,1),\forall n : \mathbb{N},\; \forall f : D(n),\; \forall P, P' : \text{Annotation}(C, n),\; \forall Q, Q' : \text{Annotation}(C, 1),∀n:N,∀f:D(n),∀P,P′:Annotation(C,n),∀Q,Q′:Annotation(C,1), annotationEq(P,P′)→annotationEq(Q,Q′)→(F(n,f,P,Q)  ⟺  F(n,f,P′,Q′)).\text{annotationEq}(P, P') \to \text{annotationEq}(Q, Q') \to \big(F(n, f, P, Q) \iff F(n, f, P', Q')\big).annotationEq(P,P′)→annotationEq(Q,Q′)→(F(n,f,P,Q)⟺F(n,f,P′,Q′)).

10. HofmannMoser.annotationCoefficientList

For an implicit constructor family C:N→Type uC : \mathbb{N} \to \text{Type } uC:N→Type u, an implicit arity n∈Nn \in \mathbb{N}n∈N, an explicit annotation Q:Annotation(C,n)Q : \text{Annotation}(C, n)Q:Annotation(C,n), and an explicit list of basic functions indices:List(BasicFunction(C))\text{indices} : \text{List}(\text{BasicFunction}(C))indices:List(BasicFunction(C)), annotationCoefficientList Q indices is a noncomputable rational number in Q\mathbb{Q}Q defined by:

annotationCoefficientList(Q,indices)={annotationCoefficient(Q, (i∈Fin n↦indices[i]))if ∣indices∣=n,0if ∣indices∣≠n.\text{annotationCoefficientList}(Q, \text{indices}) = \begin{cases} \text{annotationCoefficient}\big(Q,\, (i \in \text{Fin } n \mapsto \text{indices}[i])\big) & \text{if } |\text{indices}| = n, \\ 0 & \text{if } |\text{indices}| \ne n. \end{cases}annotationCoefficientList(Q,indices)={annotationCoefficient(Q,(i∈Fin n↦indices[i]))0​if ∣indices∣=n,if ∣indices∣=n.​

In the degenerate case where the length ∣indices∣|\text{indices}|∣indices∣ does not match the arity parameter nnn of QQQ, the function returns the fallback value 0∈Q0 \in \mathbb{Q}0∈Q.


11. HofmannMoser.contextWidth

For an explicit sequence of natural numbers lengths:N→N\text{lengths} : \mathbb{N} \to \mathbb{N}lengths:N→N and explicit bounds start,stop∈N\text{start}, \text{stop} \in \mathbb{N}start,stop∈N, contextWidth lengths start stop is the natural number computed by summing lengths(start+k)\text{lengths}(\text{start} + k)lengths(start+k) for kkk running over List.range(stop−start)=[0,1,…,(stop−start)−1]\text{List.range}(\text{stop} - \text{start}) = [0, 1, \dots, (\text{stop} - \text{start}) - 1]List.range(stop−start)=[0,1,…,(stop−start)−1]:

contextWidth(lengths,start,stop)=∑k=0(stop−start)−1lengths(start+k).\text{contextWidth}(\text{lengths}, \text{start}, \text{stop}) = \sum_{k=0}^{(\text{stop} - \text{start}) - 1} \text{lengths}(\text{start} + k).contextWidth(lengths,start,stop)=k=0∑(stop−start)−1​lengths(start+k).

Here stop−start\text{stop} - \text{start}stop−start is truncating natural number subtraction: whenever stop≤start\text{stop} \le \text{start}stop≤start, stop−start=0\text{stop} - \text{start} = 0stop−start=0, the range list is empty, and contextWidth(lengths,start,stop)=0\text{contextWidth}(\text{lengths}, \text{start}, \text{stop}) = 0contextWidth(lengths,start,stop)=0. When start<stop\text{start} < \text{stop}start<stop, this equals ∑j=startstop−1lengths(j)\sum_{j=\text{start}}^{\text{stop}-1} \text{lengths}(j)∑j=startstop−1​lengths(j).


12. HofmannMoser.compositionCoefficients

For an implicit constructor family C:N→Type uC : \mathbb{N} \to \text{Type } uC:N→Type u and explicit arguments:

  • last:N\text{last} : \mathbb{N}last:N (representing the index of the final argument among last+1\text{last} + 1last+1 arguments 0,1,…,last0, 1, \dots, \text{last}0,1,…,last),
  • lengths:N→N\text{lengths} : \mathbb{N} \to \mathbb{N}lengths:N→N (giving the context width of each argument),
  • Q:Annotation(C,contextWidth(lengths,0,last+1))Q : \text{Annotation}\big(C, \text{contextWidth}(\text{lengths}, 0, \text{last} + 1)\big)Q:Annotation(C,contextWidth(lengths,0,last+1)) (the combined input annotation of arity ∑k=0lastlengths(k)\sum_{k=0}^{\text{last}} \text{lengths}(k)∑k=0last​lengths(k)),
  • S:Annotation(C,last+1)S : \text{Annotation}(C, \text{last} + 1)S:Annotation(C,last+1) (the outer function call's input annotation of arity last+1\text{last} + 1last+1),
  • P:Π(i:N),  List(BasicFunction(C))→Annotation(C,lengths(i))P : \Pi (i : \mathbb{N}),\; \text{List}(\text{BasicFunction}(C)) \to \text{Annotation}(C, \text{lengths}(i))P:Π(i:N),List(BasicFunction(C))→Annotation(C,lengths(i)) (an indexed family of argument input annotations parameterized by a list of basic functions), and
  • R:N→List(BasicFunction(C))→Annotation(C,1)R : \mathbb{N} \to \text{List}(\text{BasicFunction}(C)) \to \text{Annotation}(C, 1)R:N→List(BasicFunction(C))→Annotation(C,1) (an indexed family of unary argument output annotations parameterized by a list of basic functions),

compositionCoefficients last lengths Q S P R is the conjunction of three universally quantified equations in Q\mathbb{Q}Q:

  1. Initial boundary (i=0i = 0i=0): For all lists first,rest:List(BasicFunction(C))\text{first}, \text{rest} : \text{List}(\text{BasicFunction}(C))first,rest:List(BasicFunction(C)), if ∣first∣=lengths(0)|\text{first}| = \text{lengths}(0)∣first∣=lengths(0) and ∣rest∣=contextWidth(lengths,1,last+1)=∑k=1lastlengths(k)|\text{rest}| = \text{contextWidth}(\text{lengths}, 1, \text{last} + 1) = \sum_{k=1}^{\text{last}} \text{lengths}(k)∣rest∣=contextWidth(lengths,1,last+1)=∑k=1last​lengths(k), then
annotationCoefficientList(Q,first+ ⁣+rest)=annotationCoefficientList(P(0,rest),first).\text{annotationCoefficientList}(Q, \text{first} \mathbin{+\!+} \text{rest}) = \text{annotationCoefficientList}(P(0, \text{rest}), \text{first}).annotationCoefficientList(Q,first++rest)=annotationCoefficientList(P(0,rest),first).
  1. Intermediate step transitions (0≤i<last0 \le i < \text{last}0≤i<last): For all i∈Ni \in \mathbb{N}i∈N with i<lasti < \text{last}i<last, all lists before,nextContext,after:List(BasicFunction(C))\text{before}, \text{nextContext}, \text{after} : \text{List}(\text{BasicFunction}(C))before,nextContext,after:List(BasicFunction(C)), and all single basic functions output:BasicFunction(C)\text{output} : \text{BasicFunction}(C)output:BasicFunction(C), if ∣before∣=i|\text{before}| = i∣before∣=i, ∣nextContext∣=lengths(i+1)|\text{nextContext}| = \text{lengths}(i + 1)∣nextContext∣=lengths(i+1), and ∣after∣=contextWidth(lengths,i+2,last+1)=∑k=i+2lastlengths(k)|\text{after}| = \text{contextWidth}(\text{lengths}, i + 2, \text{last} + 1) = \sum_{k=i+2}^{\text{last}} \text{lengths}(k)∣after∣=contextWidth(lengths,i+2,last+1)=∑k=i+2last​lengths(k), then
annotationCoefficientList(P(i+1,before+ ⁣+[output]+ ⁣+after), nextContext)=annotationCoefficientList(R(i,before+ ⁣+nextContext+ ⁣+after), [output]).\text{annotationCoefficientList}\big(P(i + 1, \text{before} \mathbin{+\!+} [\text{output}] \mathbin{+\!+} \text{after}),\, \text{nextContext}\big) = \text{annotationCoefficientList}\big(R(i, \text{before} \mathbin{+\!+} \text{nextContext} \mathbin{+\!+} \text{after}),\, [\text{output}]\big).annotationCoefficientList(P(i+1,before++[output]++after),nextContext)=annotationCoefficientList(R(i,before++nextContext++after),[output]).
  1. Final boundary (i=lasti = \text{last}i=last): For all lists before:List(BasicFunction(C))\text{before} : \text{List}(\text{BasicFunction}(C))before:List(BasicFunction(C)) and all output:BasicFunction(C)\text{output} : \text{BasicFunction}(C)output:BasicFunction(C), if ∣before∣=last|\text{before}| = \text{last}∣before∣=last, then
annotationCoefficientList(S,before+ ⁣+[output])=annotationCoefficientList(R(last,before),[output]).\text{annotationCoefficientList}(S, \text{before} \mathbin{+\!+} [\text{output}]) = \text{annotationCoefficientList}(R(\text{last}, \text{before}), [\text{output}]).annotationCoefficientList(S,before++[output])=annotationCoefficientList(R(last,before),[output]).

Degenerate and edge cases:

  • Because the outer annotation SSS has arity last+1\text{last} + 1last+1, only positive arities ≥1\ge 1≥1 can be represented.
  • When last=0\text{last} = 0last=0, the second conjunct (i<0i < 0i<0) is vacuously true, and in the first and third conjuncts ∣rest∣=contextWidth(lengths,1,1)=0|\text{rest}| = \text{contextWidth}(\text{lengths}, 1, 1) = 0∣rest∣=contextWidth(lengths,1,1)=0 and ∣before∣=0|\text{before}| = 0∣before∣=0, forcing rest=[]\text{rest} = []rest=[] and before=[]\text{before} = []before=[].
  • When i=last−1i = \text{last} - 1i=last−1 in the second conjunct, contextWidth(lengths,last+1,last+1)=0\text{contextWidth}(\text{lengths}, \text{last} + 1, \text{last} + 1) = 0contextWidth(lengths,last+1,last+1)=0, forcing after=[]\text{after} = []after=[].
  • Values of lengths(i)\text{lengths}(i)lengths(i), P(i,L)P(i, L)P(i,L), and R(i,L)R(i, L)R(i,L) for indices i>lasti > \text{last}i>last, or for lists LLL whose length does not equal i+contextWidth(lengths,i+1,last+1)i + \text{contextWidth}(\text{lengths}, i + 1, \text{last} + 1)i+contextWidth(lengths,i+1,last+1), are completely unconstrained.

13. HofmannMoser.replaceAt

For an implicit type α:Type u\alpha : \text{Type } uα:Type u, an explicit list xs:List α\text{xs} : \text{List } \alphaxs:List α, a natural number index i∈Ni \in \mathbb{N}i∈N, and a replacement list children:List α\text{children} : \text{List } \alphachildren:List α, replaceAt xs i children is defined as the list concatenation:

replaceAt(xs,i,children)=xs.take(i)+ ⁣+children+ ⁣+xs.drop(i+1).\text{replaceAt}(\text{xs}, i, \text{children}) = \text{xs}.\text{take}(i) \mathbin{+\!+} \text{children} \mathbin{+\!+} \text{xs}.\text{drop}(i + 1).replaceAt(xs,i,children)=xs.take(i)++children++xs.drop(i+1).

When i<∣xs∣i < |\text{xs}|i<∣xs∣, this replaces the single element at 0-based index iii of xs\text{xs}xs with the elements of children\text{children}children (removing the iii-th element if children=[]\text{children} = []children=[]). In the out-of-bounds case i≥∣xs∣i \ge |\text{xs}|i≥∣xs∣, xs.take(i)=xs\text{xs}.\text{take}(i) = \text{xs}xs.take(i)=xs and xs.drop(i+1)=[]\text{xs}.\text{drop}(i + 1) = []xs.drop(i+1)=[], so replaceAt(xs,i,children)=xs+ ⁣+children\text{replaceAt}(\text{xs}, i, \text{children}) = \text{xs} \mathbin{+\!+} \text{children}replaceAt(xs,i,children)=xs++children appends children\text{children}children to the end of xs\text{xs}xs without removing any element.


14. HofmannMoser.replaceAt_length

For an implicit type α:Type u\alpha : \text{Type } uα:Type u, explicit lists xs,children:List α\text{xs}, \text{children} : \text{List } \alphaxs,children:List α, an explicit index i∈Ni \in \mathbb{N}i∈N, and a hypothesis hi:i<∣xs∣h_i : i < |\text{xs}|hi​:i<∣xs∣, the theorem replaceAt_length asserts that

∣replaceAt(xs,i,children)∣=(∣xs∣−1)+∣children∣.|\text{replaceAt}(\text{xs}, i, \text{children})| = (|\text{xs}| - 1) + |\text{children}|.∣replaceAt(xs,i,children)∣=(∣xs∣−1)+∣children∣.

The hypothesis i<∣xs∣i < |\text{xs}|i<∣xs∣ guarantees ∣xs∣≥1|\text{xs}| \ge 1∣xs∣≥1, so truncating natural number subtraction ∣xs∣−1|\text{xs}| - 1∣xs∣−1 is exact.


15. HofmannMoser.additiveShiftAt

For an implicit constructor family C:N→Type uC : \mathbb{N} \to \text{Type } uC:N→Type u, implicit natural numbers n,k∈Nn, k \in \mathbb{N}n,k∈N, an explicit representation policy P:RepPolicy(C)P : \text{RepPolicy}(C)P:RepPolicy(C), an explicit coordinate position pos∈Fin n\text{pos} \in \text{Fin } npos∈Fin n, an explicit kkk-ary constructor symbol c∈C(k)c \in C(k)c∈C(k), and an explicit annotation Q:Annotation(C,n)Q : \text{Annotation}(C, n)Q:Annotation(C,n), additiveShiftAt P pos c Q produces an annotation of arity (n−1)+k(n - 1) + k(n−1)+k defined by applying List.flatMap to QQQ:

  • Here P:RepPolicy(C)P : \text{RepPolicy}(C)P:RepPolicy(C) consists of a choice function P.rep:BasicFunction(C)→TreeAutomaton(C)P.\text{rep} : \text{BasicFunction}(C) \to \text{TreeAutomaton}(C)P.rep:BasicFunction(C)→TreeAutomaton(C) together with a proof P.rep_basic:∀p,  (P.rep(p)).basic=p.valP.\text{rep\_basic} : \forall p,\; (P.\text{rep}(p)).\text{basic} = p.\text{val}P.rep_basic:∀p,(P.rep(p)).basic=p.val.
  • For each entry (p⃗,w)∈Q(\vec{p}, w) \in Q(p​,w)∈Q, let A=P.rep(p⃗(pos)):TreeAutomaton(C)A = P.\text{rep}(\vec{p}(\text{pos})) : \text{TreeAutomaton}(C)A=P.rep(p​(pos)):TreeAutomaton(C) be the representative tree automaton for the basic function at coordinate pos\text{pos}pos.
  • Filter the transition list A.rules(k,c)A.\text{rules}(k, c)A.rules(k,c) to those transition pairs tr=(q⃗,q0)∈(Fin k→Fin(A.stateCount))×Fin(A.stateCount)\text{tr} = (\vec{q}, q_0) \in (\text{Fin } k \to \text{Fin}(A.\text{stateCount})) \times \text{Fin}(A.\text{stateCount})tr=(q​,q0​)∈(Fin k→Fin(A.stateCount))×Fin(A.stateCount) satisfying q0=A.finalq_0 = A.\text{final}q0​=A.final.
  • For each such transition (q⃗,q0)(\vec{q}, q_0)(q​,q0​), let old=[p⃗(0),…,p⃗(n−1)]\text{old} = [\vec{p}(0), \dots, \vec{p}(n-1)]old=[p​(0),…,p​(n−1)] be the nnn-element list of basic functions from p⃗\vec{p}p​, and let
children=[BasicFunction.reroot(A,q⃗(0)), …, BasicFunction.reroot(A,q⃗(k−1))]\text{children} = \big[\text{BasicFunction.reroot}(A, \vec{q}(0)),\, \dots,\, \text{BasicFunction.reroot}(A, \vec{q}(k-1))\big]children=[BasicFunction.reroot(A,q​(0)),…,BasicFunction.reroot(A,q​(k−1))]

be the kkk-element list of basic functions where BasicFunction.reroot(A,q)\text{BasicFunction.reroot}(A, q)BasicFunction.reroot(A,q) is the basic function of the automaton identical to AAA except with final state qqq (computing v↦A.runCount(v,q)v \mapsto A.\text{runCount}(v, q)v↦A.runCount(v,q)).

  • Form the list new=replaceAt(old,pos.val,children)\text{new} = \text{replaceAt}(\text{old}, \text{pos}.\text{val}, \text{children})new=replaceAt(old,pos.val,children) of length (n−1)+k(n - 1) + k(n−1)+k, convert it back into a tuple i∈Fin((n−1)+k)↦new[i]i \in \text{Fin}((n - 1) + k) \mapsto \text{new}[i]i∈Fin((n−1)+k)↦new[i], and pair it with the original weight www.

Edge cases:

  • The existence of pos∈Fin n\text{pos} \in \text{Fin } npos∈Fin n implies n≥1n \ge 1n≥1.
  • When k=0k = 0k=0 (a constant constructor c∈C(0)c \in C(0)c∈C(0)), children=[]\text{children} = []children=[], so the pos\text{pos}pos-th coordinate is removed from p⃗\vec{p}p​ for each accepting transition in A.rules(0,c)A.\text{rules}(0, c)A.rules(0,c).
  • If A.rules(k,c)A.\text{rules}(k, c)A.rules(k,c) contains no transition with target state A.finalA.\text{final}A.final, the entry (p⃗,w)(\vec{p}, w)(p​,w) contributes zero entries to the output list.
  • Because A=P.rep(p⃗(pos))A = P.\text{rep}(\vec{p}(\text{pos}))A=P.rep(p​(pos)) is obtained from PPP, the resulting annotation list depends on the automaton chosen by the policy PPP.

16. HofmannMoser.replacePattern_length

For implicit arity-indexed type families C,D:N→Type uC, D : \mathbb{N} \to \text{Type } uC,D:N→Type u, an explicit list of terms patterns:List(Term(C,D))\text{patterns} : \text{List}(\text{Term}(C, D))patterns:List(Term(C,D)), an explicit position pos∈Fin(∣patterns∣)\text{pos} \in \text{Fin}(|\text{patterns}|)pos∈Fin(∣patterns∣), an implicit arity k∈Nk \in \mathbb{N}k∈N, and an explicit tuple of subterms args:Fin k→Term(C,D)\text{args} : \text{Fin } k \to \text{Term}(C, D)args:Fin k→Term(C,D), the theorem replacePattern_length asserts that replacing the pos\text{pos}pos-th element of patterns\text{patterns}patterns with the kkk-element list List.ofFn(args)=[args(0),…,args(k−1)]\text{List.ofFn}(\text{args}) = [\text{args}(0), \dots, \text{args}(k-1)]List.ofFn(args)=[args(0),…,args(k−1)] has length:

∣replaceAt(patterns,pos.val,List.ofFn(args))∣=(∣patterns∣−1)+k.\big|\text{replaceAt}(\text{patterns}, \text{pos}.\text{val}, \text{List.ofFn}(\text{args}))\big| = (|\text{patterns}| - 1) + k.​replaceAt(patterns,pos.val,List.ofFn(args))​=(∣patterns∣−1)+k.

17. HofmannMoser.PatternExpansion

For implicit type families C,D:N→Type uC, D : \mathbb{N} \to \text{Type } uC,D:N→Type u and an explicit representation policy P:RepPolicy(C)P : \text{RepPolicy}(C)P:RepPolicy(C), PatternExpansion P is an inductive predicate indexed by:

  1. a list of pattern terms patterns:List(Term(C,D))\text{patterns} : \text{List}(\text{Term}(C, D))patterns:List(Term(C,D)),
  2. an annotation Q:Annotation(C,∣patterns∣)Q : \text{Annotation}(C, |\text{patterns}|)Q:Annotation(C,∣patterns∣),
  3. a list of variable indices variables:List N\text{variables} : \text{List } \mathbb{N}variables:List N, and
  4. an annotation Q′:Annotation(C,∣variables∣)Q' : \text{Annotation}(C, |\text{variables}|)Q′:Annotation(C,∣variables∣),

defined by two constructors:

  • done: For any list of variable indices variables:List N\text{variables} : \text{List } \mathbb{N}variables:List N and any annotation Q:Annotation(C,∣variables∣)Q : \text{Annotation}(C, |\text{variables}|)Q:Annotation(C,∣variables∣),
PatternExpansion(P, variables.map(Term.var), (List.length_map(Term.var))−1▹Q, variables, Q)\text{PatternExpansion}\big(P,\, \text{variables}.\text{map}(\text{Term.var}),\, (\text{List.length\_map}(\text{Term.var}))^{-1} \triangleright Q,\, \text{variables},\, Q\big)PatternExpansion(P,variables.map(Term.var),(List.length_map(Term.var))−1▹Q,variables,Q)

holds, where variables.map(Term.var)=[Term.var(x0),…,Term.var(xm−1)]\text{variables}.\text{map}(\text{Term.var}) = [\text{Term.var}(x_0), \dots, \text{Term.var}(x_{m-1})]variables.map(Term.var)=[Term.var(x0​),…,Term.var(xm−1​)] and the annotation QQQ is cast along the equality ∣variables∣=∣variables.map(Term.var)∣|\text{variables}| = |\text{variables}.\text{map}(\text{Term.var})|∣variables∣=∣variables.map(Term.var)∣.

  • step: For any implicit arity k∈Nk \in \mathbb{N}k∈N, pattern list patterns:List(Term(C,D))\text{patterns} : \text{List}(\text{Term}(C, D))patterns:List(Term(C,D)), position pos∈Fin(∣patterns∣)\text{pos} \in \text{Fin}(|\text{patterns}|)pos∈Fin(∣patterns∣), constructor symbol c∈C(k)c \in C(k)c∈C(k), subterm tuple args:Fin k→Term(C,D)\text{args} : \text{Fin } k \to \text{Term}(C, D)args:Fin k→Term(C,D), equality proof hPattern:patterns[pos]=Term.func(inl c,args)h_{\text{Pattern}} : \text{patterns}[\text{pos}] = \text{Term.func}(\text{inl } c, \text{args})hPattern​:patterns[pos]=Term.func(inl c,args), input annotation Q:Annotation(C,∣patterns∣)Q : \text{Annotation}(C, |\text{patterns}|)Q:Annotation(C,∣patterns∣), output variable list variables:List N\text{variables} : \text{List } \mathbb{N}variables:List N, output annotation Q′:Annotation(C,∣variables∣)Q' : \text{Annotation}(C, |\text{variables}|)Q′:Annotation(C,∣variables∣), and recursive proof
hNext:PatternExpansion(P, replaceAt(patterns,pos.val,List.ofFn(args)), (replacePattern_length(patterns,pos,args))−1▹additiveShiftAt(P,pos,c,Q), variables, Q′),h_{\text{Next}} : \text{PatternExpansion}\Big(P,\, \text{replaceAt}(\text{patterns}, \text{pos}.\text{val}, \text{List.ofFn}(\text{args})),\, (\text{replacePattern\_length}(\text{patterns}, \text{pos}, \text{args}))^{-1} \triangleright \text{additiveShiftAt}(P, \text{pos}, c, Q),\, \text{variables},\, Q'\Big),hNext​:PatternExpansion(P,replaceAt(patterns,pos.val,List.ofFn(args)),(replacePattern_length(patterns,pos,args))−1▹additiveShiftAt(P,pos,c,Q),variables,Q′),

concludes PatternExpansion(P,patterns,Q,variables,Q′)\text{PatternExpansion}(P, \text{patterns}, Q, \text{variables}, Q')PatternExpansion(P,patterns,Q,variables,Q′).

Edge and degenerate cases:

  • PatternExpansion can only hold when every term in patterns\text{patterns}patterns is a constructor term (built solely from Term.var\text{Term.var}Term.var and Term.func(inl c,args)\text{Term.func}(\text{inl } c, \text{args})Term.func(inl c,args)); if any term in patterns\text{patterns}patterns contains a defined function symbol Term.func(inr f,args)\text{Term.func}(\text{inr } f, \text{args})Term.func(inr f,args), it can never be reduced to variables.map(Term.var)\text{variables}.\text{map}(\text{Term.var})variables.map(Term.var) and no derivation exists.
  • The list variables\text{variables}variables in done is not constrained to be duplicate-free (Nodup\text{Nodup}Nodup is not required); if the same variable xxx appears multiple times across patterns\text{patterns}patterns, xxx appears with the same multiplicity in variables\text{variables}variables.

18. HofmannMoser.argumentContexts

For an explicit indexed family of variable lists contexts:N→List N\text{contexts} : \mathbb{N} \to \text{List } \mathbb{N}contexts:N→List N and an explicit natural number arity∈N\text{arity} \in \mathbb{N}arity∈N, argumentContexts contexts arity is the flattened list of natural numbers obtained by concatenating contexts(0),contexts(1),…,contexts(arity−1)\text{contexts}(0), \text{contexts}(1), \dots, \text{contexts}(\text{arity} - 1)contexts(0),contexts(1),…,contexts(arity−1) in order via List.flatMap over List.range(arity)=[0,1,…,arity−1]\text{List.range}(\text{arity}) = [0, 1, \dots, \text{arity} - 1]List.range(arity)=[0,1,…,arity−1]:

argumentContexts(contexts,arity)=contexts(0)+ ⁣+contexts(1)+ ⁣+⋯+ ⁣+contexts(arity−1).\text{argumentContexts}(\text{contexts}, \text{arity}) = \text{contexts}(0) \mathbin{+\!+} \text{contexts}(1) \mathbin{+\!+} \dots \mathbin{+\!+} \text{contexts}(\text{arity} - 1).argumentContexts(contexts,arity)=contexts(0)++contexts(1)++⋯++contexts(arity−1).

When arity=0\text{arity} = 0arity=0, this returns the empty list [][][]. Values of contexts(i)\text{contexts}(i)contexts(i) for i≥arityi \ge \text{arity}i≥arity are ignored.


19. HofmannMoser.argumentContexts_length

For an explicit family contexts:N→List N\text{contexts} : \mathbb{N} \to \text{List } \mathbb{N}contexts:N→List N and an explicit natural number arity∈N\text{arity} \in \mathbb{N}arity∈N, the theorem argumentContexts_length asserts that the length of argumentContexts(contexts,arity)\text{argumentContexts}(\text{contexts}, \text{arity})argumentContexts(contexts,arity) equals the context width from 000 to arity\text{arity}arity of the individual list lengths:

∣argumentContexts(contexts,arity)∣=contextWidth(i↦∣contexts(i)∣, 0, arity)=∑k=0arity−1∣contexts(k)∣.|\text{argumentContexts}(\text{contexts}, \text{arity})| = \text{contextWidth}(i \mapsto |\text{contexts}(i)|,\, 0,\, \text{arity}) = \sum_{k=0}^{\text{arity}-1} |\text{contexts}(k)|.∣argumentContexts(contexts,arity)∣=contextWidth(i↦∣contexts(i)∣,0,arity)=k=0∑arity−1​∣contexts(k)∣.

20. HofmannMoser.listPremiseMode

For an implicit constructor family C:N→Type uC : \mathbb{N} \to \text{Type } uC:N→Type u, an explicit finite constructor witness S:FiniteConstructors(C)S : \text{FiniteConstructors}(C)S:FiniteConstructors(C), an explicit parent typing mode parent:TypingMode\text{parent} : \text{TypingMode}parent:TypingMode, and an explicit list of basic functions indices:List(BasicFunction(C))\text{indices} : \text{List}(\text{BasicFunction}(C))indices:List(BasicFunction(C)), listPremiseMode S parent indices is a noncomputable function (using classical decidability) returning a TypingMode\text{TypingMode}TypingMode:

listPremiseMode(S,parent,indices)={costFreeif parent=costFree,countedif parent=counted and ∀p∈indices,  p=BasicFunction.canonical(S),costFreeif parent=counted and ∃p∈indices,  p≠BasicFunction.canonical(S).\text{listPremiseMode}(S, \text{parent}, \text{indices}) = \begin{cases} \text{costFree} & \text{if } \text{parent} = \text{costFree}, \\ \text{counted} & \text{if } \text{parent} = \text{counted} \text{ and } \forall p \in \text{indices},\; p = \text{BasicFunction.canonical}(S), \\ \text{costFree} & \text{if } \text{parent} = \text{counted} \text{ and } \exists p \in \text{indices},\; p \ne \text{BasicFunction.canonical}(S). \end{cases}listPremiseMode(S,parent,indices)=⎩⎨⎧​costFreecountedcostFree​if parent=costFree,if parent=counted and ∀p∈indices,p=BasicFunction.canonical(S),if parent=counted and ∃p∈indices,p=BasicFunction.canonical(S).​

Here S:FiniteConstructors(C)S : \text{FiniteConstructors}(C)S:FiniteConstructors(C) is a structure providing an exhaustive list symbols:List(Σn,C(n))\text{symbols} : \text{List}(\Sigma n, C(n))symbols:List(Σn,C(n)) of all constructors and a proof ∃n,Nonempty(C(n))\exists n, \text{Nonempty}(C(n))∃n,Nonempty(C(n)), and BasicFunction.canonical(S)\text{BasicFunction.canonical}(S)BasicFunction.canonical(S) is the basic function induced by the 1-state tree automaton TreeAutomaton.canonical(S)\text{TreeAutomaton.canonical}(S)TreeAutomaton.canonical(S) (which has stateCount=1\text{stateCount} = 1stateCount=1, final=0\text{final} = 0final=0, and the single transition ((i↦0),0)((i \mapsto 0), 0)((i↦0),0) for every constructor, and hence maps every v∈Value(C)v \in \text{Value}(C)v∈Value(C) to 111). When indices=[]\text{indices} = []indices=[] and parent=counted\text{parent} = \text{counted}parent=counted, the universal condition ∀p∈[], p=BasicFunction.canonical(S)\forall p \in [],\, p = \text{BasicFunction.canonical}(S)∀p∈[],p=BasicFunction.canonical(S) holds vacuously, so the function returns counted\text{counted}counted.


21. HofmannMoser.Typing

For implicit arity-indexed type families C,D:N→Type uC, D : \mathbb{N} \to \text{Type } uC,D:N→Type u, an explicit finite constructor witness S:FiniteConstructors(C)S : \text{FiniteConstructors}(C)S:FiniteConstructors(C), an explicit representation policy P:RepPolicy(C)P : \text{RepPolicy}(C)P:RepPolicy(C), and an explicit signature bundle F:AnnotatedSignatures(C,D)F : \text{AnnotatedSignatures}(C, D)F:AnnotatedSignatures(C,D), Typing S P F is an inductive relation

Typing(S,P,F):TypingMode→Π(n:N),  (Fin n→N)→Annotation(C,n)→Term(C,D)→Annotation(C,1)→Prop\text{Typing}(S, P, F) : \text{TypingMode} \to \Pi (n : \mathbb{N}),\; (\text{Fin } n \to \mathbb{N}) \to \text{Annotation}(C, n) \to \text{Term}(C, D) \to \text{Annotation}(C, 1) \to \text{Prop}Typing(S,P,F):TypingMode→Π(n:N),(Fin n→N)→Annotation(C,n)→Term(C,D)→Annotation(C,1)→Prop

relating a typing mode mode\text{mode}mode, a context length n∈Nn \in \mathbb{N}n∈N, a context variable tuple xs:Fin n→N\text{xs} : \text{Fin } n \to \mathbb{N}xs:Fin n→N, an nnn-ary input annotation Q:Annotation(C,n)Q : \text{Annotation}(C, n)Q:Annotation(C,n), a term t:Term(C,D)t : \text{Term}(C, D)t:Term(C,D), and a unary output annotation Q′:Annotation(C,1)Q' : \text{Annotation}(C, 1)Q′:Annotation(C,1). It is generated by eight constructors:

  1. variable: For any mode:TypingMode\text{mode} : \text{TypingMode}mode:TypingMode, variable index x∈Nx \in \mathbb{N}x∈N, and unary annotation Q:Annotation(C,1)Q : \text{Annotation}(C, 1)Q:Annotation(C,1),
Typing(S,P,F,mode,1,(_∈Fin 1↦x),Q,Term.var(x),Q).\text{Typing}\big(S, P, F, \text{mode}, 1, (\_ \in \text{Fin } 1 \mapsto x), Q, \text{Term.var}(x), Q\big).Typing(S,P,F,mode,1,(_∈Fin 1↦x),Q,Term.var(x),Q).
  1. defined: For any mode:TypingMode\text{mode} : \text{TypingMode}mode:TypingMode, implicit arity n∈Nn \in \mathbb{N}n∈N, defined symbol f∈D(n)f \in D(n)f∈D(n), variable tuple xs:Fin n→N\text{xs} : \text{Fin } n \to \mathbb{N}xs:Fin n→N, input annotation Q:Annotation(C,n)Q : \text{Annotation}(C, n)Q:Annotation(C,n), and output annotation Q′:Annotation(C,1)Q' : \text{Annotation}(C, 1)Q′:Annotation(C,1), given:

    • hDistinct:Function.Injective(xs)h_{\text{Distinct}} : \text{Function.Injective}(\text{xs})hDistinct​:Function.Injective(xs) (all nnn variable indices xs(0),…,xs(n−1)\text{xs}(0), \dots, \text{xs}(n-1)xs(0),…,xs(n−1) are pairwise distinct), and
    • hannotated:(F.get(mode))(n,f,Q,Q′)h_{\text{annotated}} : (F.\text{get}(\text{mode}))(n, f, Q, Q')hannotated​:(F.get(mode))(n,f,Q,Q′),

    concludes

Typing(S,P,F,mode,n,xs,Q,Term.func(inr f,i↦Term.var(xs(i))),Q′).\text{Typing}\big(S, P, F, \text{mode}, n, \text{xs}, Q, \text{Term.func}(\text{inr } f, i \mapsto \text{Term.var}(\text{xs}(i))), Q'\big).Typing(S,P,F,mode,n,xs,Q,Term.func(inr f,i↦Term.var(xs(i))),Q′).
  1. constructor: For any mode:TypingMode\text{mode} : \text{TypingMode}mode:TypingMode, implicit arity n∈Nn \in \mathbb{N}n∈N, constructor symbol c∈C(n)c \in C(n)c∈C(n), variable tuple xs:Fin n→N\text{xs} : \text{Fin } n \to \mathbb{N}xs:Fin n→N, and output annotation Q:Annotation(C,1)Q : \text{Annotation}(C, 1)Q:Annotation(C,1), given:

    • hDistinct:Function.Injective(xs)h_{\text{Distinct}} : \text{Function.Injective}(\text{xs})hDistinct​:Function.Injective(xs),

    concludes

Typing(S,P,F,mode,n,xs, Nat.zero_add(n)▹additiveShift(P,m:=0,c,Q), Term.func(inl c,i↦Term.var(xs(i))), Q).\text{Typing}\big(S, P, F, \text{mode}, n, \text{xs},\, \text{Nat.zero\_add}(n) \triangleright \text{additiveShift}(P, m := 0, c, Q),\, \text{Term.func}(\text{inl } c, i \mapsto \text{Term.var}(\text{xs}(i))),\, Q\big).Typing(S,P,F,mode,n,xs,Nat.zero_add(n)▹additiveShift(P,m:=0,c,Q),Term.func(inl c,i↦Term.var(xs(i))),Q).

Here additiveShift(P,m:=0,c,Q):Annotation(C,0+n)\text{additiveShift}(P, m := 0, c, Q) : \text{Annotation}(C, 0 + n)additiveShift(P,m:=0,c,Q):Annotation(C,0+n) maps each entry (p⃗,w)∈Q(\vec{p}, w) \in Q(p​,w)∈Q (with A=P.rep(p⃗(0))A = P.\text{rep}(\vec{p}(0))A=P.rep(p​(0))) and each transition (q⃗,q0)∈A.rules(n,c)(\vec{q}, q_0) \in A.\text{rules}(n, c)(q​,q0​)∈A.rules(n,c) satisfying q0=A.finalq_0 = A.\text{final}q0​=A.final to the entry ((i↦BasicFunction.reroot(A,q⃗(i))),w)((i \mapsto \text{BasicFunction.reroot}(A, \vec{q}(i))), w)((i↦BasicFunction.reroot(A,q​(i))),w), which is then cast along 0+n=n0 + n = n0+n=n.

  1. weakenAnnotations: For any mode:TypingMode\text{mode} : \text{TypingMode}mode:TypingMode, implicit arity n∈Nn \in \mathbb{N}n∈N, variable tuple xs:Fin n→N\text{xs} : \text{Fin } n \to \mathbb{N}xs:Fin n→N, input annotations P0,Q:Annotation(C,n)P_0, Q : \text{Annotation}(C, n)P0​,Q:Annotation(C,n), output annotations P′,Q′:Annotation(C,1)P', Q' : \text{Annotation}(C, 1)P′,Q′:Annotation(C,1), and term t:Term(C,D)t : \text{Term}(C, D)t:Term(C,D), given:

    • hDistinct:Function.Injective(xs)h_{\text{Distinct}} : \text{Function.Injective}(\text{xs})hDistinct​:Function.Injective(xs),
    • h:Typing(S,P,F,mode,n,xs,P0,t,P′)h : \text{Typing}(S, P, F, \text{mode}, n, \text{xs}, P_0, t, P')h:Typing(S,P,F,mode,n,xs,P0​,t,P′),
    • hInput:annotationLe(P0,Q)h_{\text{Input}} : \text{annotationLe}(P_0, Q)hInput​:annotationLe(P0​,Q) (pointwise annotationCoefficient(P0,idx)≤annotationCoefficient(Q,idx)\text{annotationCoefficient}(P_0, \text{idx}) \le \text{annotationCoefficient}(Q, \text{idx})annotationCoefficient(P0​,idx)≤annotationCoefficient(Q,idx)), and
    • hOutput:annotationLe(Q′,P′)h_{\text{Output}} : \text{annotationLe}(Q', P')hOutput​:annotationLe(Q′,P′) (pointwise annotationCoefficient(Q′,idx)≤annotationCoefficient(P′,idx)\text{annotationCoefficient}(Q', \text{idx}) \le \text{annotationCoefficient}(P', \text{idx})annotationCoefficient(Q′,idx)≤annotationCoefficient(P′,idx)),

    concludes Typing(S,P,F,mode,n,xs,Q,t,Q′)\text{Typing}(S, P, F, \text{mode}, n, \text{xs}, Q, t, Q')Typing(S,P,F,mode,n,xs,Q,t,Q′).

  2. exchange: For any mode:TypingMode\text{mode} : \text{TypingMode}mode:TypingMode, implicit arity n∈Nn \in \mathbb{N}n∈N, variable tuple xs:Fin n→N\text{xs} : \text{Fin } n \to \mathbb{N}xs:Fin n→N, index map ρ:Fin n→Fin n\rho : \text{Fin } n \to \text{Fin } nρ:Fin n→Fin n, input annotation Q:Annotation(C,n)Q : \text{Annotation}(C, n)Q:Annotation(C,n), output annotation Q′:Annotation(C,1)Q' : \text{Annotation}(C, 1)Q′:Annotation(C,1), and term t:Term(C,D)t : \text{Term}(C, D)t:Term(C,D), given:

    • hInjective:Function.Injective(ρ)h_{\text{Injective}} : \text{Function.Injective}(\rho)hInjective​:Function.Injective(ρ),
    • hSurjective:Function.Surjective(ρ)h_{\text{Surjective}} : \text{Function.Surjective}(\rho)hSurjective​:Function.Surjective(ρ), and
    • h:Typing(S,P,F,mode,n,xs,Q,t,Q′)h : \text{Typing}(S, P, F, \text{mode}, n, \text{xs}, Q, t, Q')h:Typing(S,P,F,mode,n,xs,Q,t,Q′),

    concludes

Typing(S,P,F,mode,n,(i↦xs(ρ(i))),annotationReindex(ρ,Q),t,Q′).\text{Typing}\big(S, P, F, \text{mode}, n, (i \mapsto \text{xs}(\rho(i))), \text{annotationReindex}(\rho, Q), t, Q'\big).Typing(S,P,F,mode,n,(i↦xs(ρ(i))),annotationReindex(ρ,Q),t,Q′).

(Unlike the other structural rules, exchange does not explicitly require Function.Injective(xs)\text{Function.Injective}(\text{xs})Function.Injective(xs) as a hypothesis.)

  1. weakenContext: For any mode:TypingMode\text{mode} : \text{TypingMode}mode:TypingMode, implicit arity n∈Nn \in \mathbb{N}n∈N, extended variable tuple xs:Fin(n+1)→N\text{xs} : \text{Fin}(n + 1) \to \mathbb{N}xs:Fin(n+1)→N, input annotation Q:Annotation(C,n+1)Q : \text{Annotation}(C, n + 1)Q:Annotation(C,n+1), output annotation Q′:Annotation(C,1)Q' : \text{Annotation}(C, 1)Q′:Annotation(C,1), and term t:Term(C,D)t : \text{Term}(C, D)t:Term(C,D), given:

    • hDistinct:Function.Injective(xs)h_{\text{Distinct}} : \text{Function.Injective}(\text{xs})hDistinct​:Function.Injective(xs), and
    • h:Typing(S,P,F,mode,n,(i∈Fin n↦xs(Fin.castSucc i)), annotationProject(Q,canonicalTuple(S,1)), t, Q′)h : \text{Typing}\big(S, P, F, \text{mode}, n, (i \in \text{Fin } n \mapsto \text{xs}(\text{Fin.castSucc } i)),\, \text{annotationProject}(Q, \text{canonicalTuple}(S, 1)),\, t,\, Q'\big)h:Typing(S,P,F,mode,n,(i∈Fin n↦xs(Fin.castSucc i)),annotationProject(Q,canonicalTuple(S,1)),t,Q′), where annotationProject(Q,canonicalTuple(S,1))\text{annotationProject}(Q, \text{canonicalTuple}(S, 1))annotationProject(Q,canonicalTuple(S,1)) retains only those entries (p⃗,w)∈Q(\vec{p}, w) \in Q(p​,w)∈Q whose last coordinate p⃗(n)\vec{p}(n)p​(n) equals BasicFunction.canonical(S)\text{BasicFunction.canonical}(S)BasicFunction.canonical(S) and restricts p⃗\vec{p}p​ to its first nnn coordinates (i∈Fin n↦p⃗(i))(i \in \text{Fin } n \mapsto \vec{p}(i))(i∈Fin n↦p​(i)) with weight www,

    concludes Typing(S,P,F,mode,n+1,xs,Q,t,Q′)\text{Typing}(S, P, F, \text{mode}, n + 1, \text{xs}, Q, t, Q')Typing(S,P,F,mode,n+1,xs,Q,t,Q′). (There is no explicit side condition requiring xs(n)∉t.variables\text{xs}(n) \notin t.\text{variables}xs(n)∈/t.variables.)

  2. share: For any mode:TypingMode\text{mode} : \text{TypingMode}mode:TypingMode, implicit arity n∈Nn \in \mathbb{N}n∈N, context prefix xs:Fin n→N\text{xs} : \text{Fin } n \to \mathbb{N}xs:Fin n→N, variable indices x,y,z∈Nx, y, z \in \mathbb{N}x,y,z∈N, input annotation Q:Annotation(C,n+2)Q : \text{Annotation}(C, n + 2)Q:Annotation(C,n+2), output annotation Q′:Annotation(C,1)Q' : \text{Annotation}(C, 1)Q′:Annotation(C,1), and term t:Term(C,D)t : \text{Term}(C, D)t:Term(C,D), given:

    • hContext:Function.Injective(xs)h_{\text{Context}} : \text{Function.Injective}(\text{xs})hContext​:Function.Injective(xs),
    • hDistinct:x≠yh_{\text{Distinct}} : x \ne yhDistinct​:x=y,
    • hFresh:∀i∈Fin n,  xs(i)≠x∧xs(i)≠y∧xs(i)≠zh_{\text{Fresh}} : \forall i \in \text{Fin } n,\; \text{xs}(i) \ne x \land \text{xs}(i) \ne y \land \text{xs}(i) \ne zhFresh​:∀i∈Fin n,xs(i)=x∧xs(i)=y∧xs(i)=z,
    • hNew:z≠x∧z≠y∧z∉t.variablesh_{\text{New}} : z \ne x \land z \ne y \land z \notin t.\text{variables}hNew​:z=x∧z=y∧z∈/t.variables (where t.variablest.\text{variables}t.variables is the list of all variables occurring in ttt), and
    • h:Typing(S,P,F,mode,n+2,Fin.addCases(xs,i∈Fin 2↦if i.val=0 then x else y),Q,t,Q′)h : \text{Typing}\big(S, P, F, \text{mode}, n + 2, \text{Fin.addCases}(\text{xs}, i \in \text{Fin } 2 \mapsto \text{if } i.\text{val} = 0 \text{ then } x \text{ else } y), Q, t, Q'\big)h:Typing(S,P,F,mode,n+2,Fin.addCases(xs,i∈Fin 2↦if i.val=0 then x else y),Q,t,Q′),

    concludes

Typing(S,P,F,mode,n+1,Fin.addCases(xs,_∈Fin 1↦z), annotationShare(S,P,Q), t.rename(v↦if v=x∨v=y then z else v), Q′).\text{Typing}\Big(S, P, F, \text{mode}, n + 1, \text{Fin.addCases}(\text{xs}, \_ \in \text{Fin } 1 \mapsto z),\, \text{annotationShare}(S, P, Q),\, t.\text{rename}(v \mapsto \text{if } v = x \lor v = y \text{ then } z \text{ else } v),\, Q'\Big).Typing(S,P,F,mode,n+1,Fin.addCases(xs,_∈Fin 1↦z),annotationShare(S,P,Q),t.rename(v↦if v=x∨v=y then z else v),Q′).

Here annotationShare(S,P,Q):Annotation(C,n+1)\text{annotationShare}(S, P, Q) : \text{Annotation}(C, n + 1)annotationShare(S,P,Q):Annotation(C,n+1) replaces each entry (p⃗,w)∈Q(\vec{p}, w) \in Q(p​,w)∈Q with the (n+1)(n + 1)(n+1)-tuple that agrees with p⃗\vec{p}p​ on indices 0,…,n−10, \dots, n - 10,…,n−1 and assigns index nnn the product basic function BasicFunction.product(S,P,p⃗(n),p⃗(n+1))\text{BasicFunction.product}(S, P, \vec{p}(n), \vec{p}(n + 1))BasicFunction.product(S,P,p​(n),p​(n+1)) (induced by the padded product automaton of P.rep(p⃗(n))P.\text{rep}(\vec{p}(n))P.rep(p​(n)) and P.rep(p⃗(n+1))P.\text{rep}(\vec{p}(n + 1))P.rep(p​(n+1)) with state count A.stateCount⋅B.stateCount+1A.\text{stateCount} \cdot B.\text{stateCount} + 1A.stateCount⋅B.stateCount+1), and t.rename(… )t.\text{rename}(\dots)t.rename(…) replaces every variable occurrence of xxx or yyy in ttt with zzz.

  1. composition: For any mode:TypingMode\text{mode} : \text{TypingMode}mode:TypingMode, natural number last∈N\text{last} \in \mathbb{N}last∈N, symbol f∈C(last+1)⊕D(last+1)f \in C(\text{last} + 1) \oplus D(\text{last} + 1)f∈C(last+1)⊕D(last+1), context family contexts:N→List N\text{contexts} : \mathbb{N} \to \text{List } \mathbb{N}contexts:N→List N, term family terms:N→Term(C,D)\text{terms} : \mathbb{N} \to \text{Term}(C, D)terms:N→Term(C,D), fresh variable tuple fresh:Fin(last+1)→N\text{fresh} : \text{Fin}(\text{last} + 1) \to \mathbb{N}fresh:Fin(last+1)→N, combined input annotation Q:Annotation(C,∣argumentContexts(contexts,last+1)∣)Q : \text{Annotation}(C, |\text{argumentContexts}(\text{contexts}, \text{last} + 1)|)Q:Annotation(C,∣argumentContexts(contexts,last+1)∣), intermediate call annotation S′:Annotation(C,last+1)S' : \text{Annotation}(C, \text{last} + 1)S′:Annotation(C,last+1), output annotation Q′:Annotation(C,1)Q' : \text{Annotation}(C, 1)Q′:Annotation(C,1), and annotation families Parg:Π(i:N),  List(BasicFunction(C))→Annotation(C,∣contexts(i)∣)P_{\text{arg}} : \Pi (i : \mathbb{N}),\; \text{List}(\text{BasicFunction}(C)) \to \text{Annotation}(C, |\text{contexts}(i)|)Parg​:Π(i:N),List(BasicFunction(C))→Annotation(C,∣contexts(i)∣) and Rarg:N→List(BasicFunction(C))→Annotation(C,1)R_{\text{arg}} : \mathbb{N} \to \text{List}(\text{BasicFunction}(C)) \to \text{Annotation}(C, 1)Rarg​:N→List(BasicFunction(C))→Annotation(C,1), given:

    • hContexts:(argumentContexts(contexts,last+1)).Noduph_{\text{Contexts}} : (\text{argumentContexts}(\text{contexts}, \text{last} + 1)).\text{Nodup}hContexts​:(argumentContexts(contexts,last+1)).Nodup (the concatenation contexts(0)+ ⁣+⋯+ ⁣+contexts(last)\text{contexts}(0) \mathbin{+\!+} \dots \mathbin{+\!+} \text{contexts}(\text{last})contexts(0)++⋯++contexts(last) has no duplicate variables, so the individual contexts contexts(0),…,contexts(last)\text{contexts}(0), \dots, \text{contexts}(\text{last})contexts(0),…,contexts(last) are duplicate-free and pairwise disjoint),
    • hCoverage:∀i<last+1,  ∀x∈(terms(i)).variables,  x∈contexts(i)h_{\text{Coverage}} : \forall i < \text{last} + 1,\; \forall x \in (\text{terms}(i)).\text{variables},\; x \in \text{contexts}(i)hCoverage​:∀i<last+1,∀x∈(terms(i)).variables,x∈contexts(i),
    • hDistinct:Function.Injective(fresh)h_{\text{Distinct}} : \text{Function.Injective}(\text{fresh})hDistinct​:Function.Injective(fresh),
    • hFresh:∀i∈Fin(last+1),  fresh(i)∉argumentContexts(contexts,last+1)∧(∀j<last+1,  fresh(i)∉(terms(j)).variables)h_{\text{Fresh}} : \forall i \in \text{Fin}(\text{last} + 1),\; \text{fresh}(i) \notin \text{argumentContexts}(\text{contexts}, \text{last} + 1) \land (\forall j < \text{last} + 1,\; \text{fresh}(i) \notin (\text{terms}(j)).\text{variables})hFresh​:∀i∈Fin(last+1),fresh(i)∈/argumentContexts(contexts,last+1)∧(∀j<last+1,fresh(i)∈/(terms(j)).variables),
    • hCoefficients:compositionCoefficients(last, (i↦∣contexts(i)∣), (argumentContexts_length(contexts,last+1)▹Q), S′, Parg, Rarg)h_{\text{Coefficients}} : \text{compositionCoefficients}\big(\text{last},\, (i \mapsto |\text{contexts}(i)|),\, (\text{argumentContexts\_length}(\text{contexts}, \text{last} + 1) \triangleright Q),\, S',\, P_{\text{arg}},\, R_{\text{arg}}\big)hCoefficients​:compositionCoefficients(last,(i↦∣contexts(i)∣),(argumentContexts_length(contexts,last+1)▹Q),S′,Parg​,Rarg​),
    • hArguments:∀i<last+1,  ∀indices:List(BasicFunction(C)),  ∣indices∣=i+contextWidth(k↦∣contexts(k)∣,i+1,last+1)→Typing(S,P,F,listPremiseMode(S,mode,indices),∣contexts(i)∣,(contexts(i)).get,Parg(i,indices),terms(i),Rarg(i,indices))h_{\text{Arguments}} : \forall i < \text{last} + 1,\; \forall \text{indices} : \text{List}(\text{BasicFunction}(C)),\; |\text{indices}| = i + \text{contextWidth}(k \mapsto |\text{contexts}(k)|, i + 1, \text{last} + 1) \to \text{Typing}\big(S, P, F, \text{listPremiseMode}(S, \text{mode}, \text{indices}), |\text{contexts}(i)|, (\text{contexts}(i)).\text{get}, P_{\text{arg}}(i, \text{indices}), \text{terms}(i), R_{\text{arg}}(i, \text{indices})\big)hArguments​:∀i<last+1,∀indices:List(BasicFunction(C)),∣indices∣=i+contextWidth(k↦∣contexts(k)∣,i+1,last+1)→Typing(S,P,F,listPremiseMode(S,mode,indices),∣contexts(i)∣,(contexts(i)).get,Parg​(i,indices),terms(i),Rarg​(i,indices)), and
    • hFunction:Typing(S,P,F,mode,last+1,fresh,S′,Term.func(f,i↦Term.var(fresh(i))),Q′)h_{\text{Function}} : \text{Typing}\big(S, P, F, \text{mode}, \text{last} + 1, \text{fresh}, S', \text{Term.func}(f, i \mapsto \text{Term.var}(\text{fresh}(i))), Q'\big)hFunction​:Typing(S,P,F,mode,last+1,fresh,S′,Term.func(f,i↦Term.var(fresh(i))),Q′),

    concludes

Typing(S,P,F,mode,∣argumentContexts(contexts,last+1)∣,(argumentContexts(contexts,last+1)).get,Q,Term.func(f,i↦terms(i.val)),Q′).\text{Typing}\Big(S, P, F, \text{mode}, |\text{argumentContexts}(\text{contexts}, \text{last} + 1)|, (\text{argumentContexts}(\text{contexts}, \text{last} + 1)).\text{get}, Q, \text{Term.func}(f, i \mapsto \text{terms}(i.\text{val})), Q'\Big).Typing(S,P,F,mode,∣argumentContexts(contexts,last+1)∣,(argumentContexts(contexts,last+1)).get,Q,Term.func(f,i↦terms(i.val)),Q′).

Notice that composition only applies to function symbols fff of positive arity last+1≥1\text{last} + 1 \ge 1last+1≥1, and requires the argument contexts contexts(0),…,contexts(last)\text{contexts}(0), \dots, \text{contexts}(\text{last})contexts(0),…,contexts(last) to be pairwise disjoint before any subsequent applications of share.


22. HofmannMoser.onePotential

onePotential is the constant ⟨1,0≤1⟩\langle 1, 0 \le 1 \rangle⟨1,0≤1⟩ in the non-negative rational subtype {q∈Q∣0≤q}\{q \in \mathbb{Q} \mid 0 \le q\}{q∈Q∣0≤q} whose underlying rational value is 1∈Q1 \in \mathbb{Q}1∈Q.


23. HofmannMoser.Bounded

For implicit arity-indexed type families C,D:N→Type uC, D : \mathbb{N} \to \text{Type } uC,D:N→Type u, an explicit finite constructor witness S:FiniteConstructors(C)S : \text{FiniteConstructors}(C)S:FiniteConstructors(C), an explicit representation policy P:RepPolicy(C)P : \text{RepPolicy}(C)P:RepPolicy(C), an explicit signature bundle F:AnnotatedSignatures(C,D)F : \text{AnnotatedSignatures}(C, D)F:AnnotatedSignatures(C,D), an explicit rewrite system R:RewriteSystem(C,D)R : \text{RewriteSystem}(C, D)R:RewriteSystem(C,D) (a predicate Rule(C,D)→Prop\text{Rule}(C, D) \to \text{Prop}Rule(C,D)→Prop, where each rule:Rule(C,D)\text{rule} : \text{Rule}(C, D)rule:Rule(C,D) has fields arity:N\text{arity} : \mathbb{N}arity:N, symbol:D(arity)\text{symbol} : D(\text{arity})symbol:D(arity), patterns:Fin(arity)→Term(C,D)\text{patterns} : \text{Fin}(\text{arity}) \to \text{Term}(C, D)patterns:Fin(arity)→Term(C,D), and rhs:Term(C,D)\text{rhs} : \text{Term}(C, D)rhs:Term(C,D)), and an explicit typing mode mode:TypingMode\text{mode} : \text{TypingMode}mode:TypingMode, Bounded S P F R mode is the proposition asserting that:

∀rule:Rule(C,D),  R(rule)→∀Q:Annotation(C,rule.arity),  ∀Q′:Annotation(C,1),\forall \text{rule} : \text{Rule}(C, D),\; R(\text{rule}) \to \forall Q : \text{Annotation}(C, \text{rule}.\text{arity}),\; \forall Q' : \text{Annotation}(C, 1),∀rule:Rule(C,D),R(rule)→∀Q:Annotation(C,rule.arity),∀Q′:Annotation(C,1), (F.get(mode))(rule.arity,rule.symbol,Q,Q′)→(F.\text{get}(\text{mode}))(\text{rule}.\text{arity}, \text{rule}.\text{symbol}, Q, Q') \to(F.get(mode))(rule.arity,rule.symbol,Q,Q′)→

there exist a variable list variables:List N\text{variables} : \text{List } \mathbb{N}variables:List N and two annotations P0,shifted:Annotation(C,∣variables∣)P_0, \text{shifted} : \text{Annotation}(C, |\text{variables}|)P0​,shifted:Annotation(C,∣variables∣) satisfying all three of the following conditions:

  1. Pattern expansion:
PatternExpansion(P, List.ofFn(rule.patterns), (List.length_ofFn)−1▹Q, variables, shifted),\text{PatternExpansion}\big(P,\, \text{List.ofFn}(\text{rule}.\text{patterns}),\, (\text{List.length\_ofFn})^{-1} \triangleright Q,\, \text{variables},\, \text{shifted}\big),PatternExpansion(P,List.ofFn(rule.patterns),(List.length_ofFn)−1▹Q,variables,shifted),

where List.ofFn(rule.patterns)=[rule.patterns(0),…,rule.patterns(rule.arity−1)]\text{List.ofFn}(\text{rule}.\text{patterns}) = [\text{rule}.\text{patterns}(0), \dots, \text{rule}.\text{patterns}(\text{rule}.\text{arity} - 1)]List.ofFn(rule.patterns)=[rule.patterns(0),…,rule.patterns(rule.arity−1)]. 2. Mode-dependent potential step:

  • If mode=counted\text{mode} = \text{counted}mode=counted, then annotationEq(addConstant(S,P0,onePotential), shifted)\text{annotationEq}\big(\text{addConstant}(S, P_0, \text{onePotential}),\, \text{shifted}\big)annotationEq(addConstant(S,P0​,onePotential),shifted), where addConstant(S,P0,onePotential)=(canonicalTuple(S,∣variables∣),⟨1,0≤1⟩)::P0\text{addConstant}(S, P_0, \text{onePotential}) = (\text{canonicalTuple}(S, |\text{variables}|), \langle 1, 0 \le 1 \rangle) :: P_0addConstant(S,P0​,onePotential)=(canonicalTuple(S,∣variables∣),⟨1,0≤1⟩)::P0​ prepends the constant canonical tuple (i∈Fin(∣variables∣)↦BasicFunction.canonical(S))(i \in \text{Fin}(|\text{variables}|) \mapsto \text{BasicFunction.canonical}(S))(i∈Fin(∣variables∣)↦BasicFunction.canonical(S)) with weight 111 to P0P_0P0​ (so shifted\text{shifted}shifted has total coefficient equal to that of P0P_0P0​ plus 111 on the constant canonical tuple, and equal to that of P0P_0P0​ on all other tuples).
  • If mode=costFree\text{mode} = \text{costFree}mode=costFree, then annotationEq(P0,shifted)\text{annotationEq}(P_0, \text{shifted})annotationEq(P0​,shifted) (so P0P_0P0​ and shifted\text{shifted}shifted have identical total coefficients on all tuples).
  1. Right-hand side typing:
Typing(S,P,F,mode,∣variables∣,variables.get,P0,rule.rhs,Q′).\text{Typing}\big(S, P, F, \text{mode}, |\text{variables}|, \text{variables}.\text{get}, P_0, \text{rule}.\text{rhs}, Q'\big).Typing(S,P,F,mode,∣variables∣,variables.get,P0​,rule.rhs,Q′).

Degenerate and edge cases:

  • If RRR is empty (∀rule,¬R(rule)\forall \text{rule}, \neg R(\text{rule})∀rule,¬R(rule)) or if F.get(mode)F.\text{get}(\text{mode})F.get(mode) is the empty relation (∀n,f,Q,Q′,¬(F.get(mode))(n,f,Q,Q′)\forall n, f, Q, Q', \neg (F.\text{get}(\text{mode}))(n, f, Q, Q')∀n,f,Q,Q′,¬(F.get(mode))(n,f,Q,Q′)), then Bounded S P F R mode holds vacuously.
  • In counted\text{counted}counted mode, because all weights in P0P_0P0​ are non-negative, addConstant(S,P0,onePotential)\text{addConstant}(S, P_0, \text{onePotential})addConstant(S,P0​,onePotential) has coefficient at least 111 on canonicalTuple(S,∣variables∣)\text{canonicalTuple}(S, |\text{variables}|)canonicalTuple(S,∣variables∣); thus no (Q,Q′)(Q, Q')(Q,Q′) can satisfy F.counted(rule.arity,rule.symbol,Q,Q′)F.\text{counted}(\text{rule}.\text{arity}, \text{rule}.\text{symbol}, Q, Q')F.counted(rule.arity,rule.symbol,Q,Q′) for a rule in RRR if the pattern expansion of QQQ yields an annotation shifted\text{shifted}shifted whose coefficient on canonicalTuple(S,∣variables∣)\text{canonicalTuple}(S, |\text{variables}|)canonicalTuple(S,∣variables∣) is strictly less than 111 (such as Q=[]Q = []Q=[]).

24. HofmannMoser.BoundedSignatures

For implicit arity-indexed type families C,D:N→Type uC, D : \mathbb{N} \to \text{Type } uC,D:N→Type u, an explicit finite constructor witness S:FiniteConstructors(C)S : \text{FiniteConstructors}(C)S:FiniteConstructors(C), an explicit representation policy P:RepPolicy(C)P : \text{RepPolicy}(C)P:RepPolicy(C), an explicit signature bundle F:AnnotatedSignatures(C,D)F : \text{AnnotatedSignatures}(C, D)F:AnnotatedSignatures(C,D), and an explicit rewrite system R:RewriteSystem(C,D)R : \text{RewriteSystem}(C, D)R:RewriteSystem(C,D), BoundedSignatures S P F R is the conjunction:

BoundedSignatures(S,P,F,R)  ⟺  Bounded(S,P,F,R,counted)∧Bounded(S,P,F,R,costFree).\text{BoundedSignatures}(S, P, F, R) \iff \text{Bounded}(S, P, F, R, \text{counted}) \land \text{Bounded}(S, P, F, R, \text{costFree}).BoundedSignatures(S,P,F,R)⟺Bounded(S,P,F,R,counted)∧Bounded(S,P,F,R,costFree).

Like Bounded, this proposition holds vacuously if RRR contains no rules or if both F.countedF.\text{counted}F.counted and F.costFreeF.\text{costFree}F.costFree are empty relations.

Human review
  • Endorsed by Shuze Chen · Oct 28, 2026

    Confirmed by the moderator at approval.

  • Endorsed by kmehltretter82 · Oct 28, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me