Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Tree automata, basic resource functions, and resource potentials

Definition
HofmannMoser_Potential

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

amortized-analysiscomplexityterm-rewritingtree-automatatype-systems

Bottom-up nondeterministic tree automata, basic resource functions, and multivariate resource potentials (Sections 2–3, pp. 244–249).

A ground constructor value v∈Valv \in \mathsf{Val}v∈Val (Value C) is a constructor tree c(v1,…,vn)c(v_1, \dots, v_n)c(v1​,…,vn​) of size ∣v∣=1+∑i=1n∣vi∣|v| = 1 + \sum_{i=1}^n |v_i|∣v∣=1+∑i=1n​∣vi​∣ (Value.size), embedded injectively into first-order terms via Value.toTerm. A bottom-up nondeterministic tree automaton AAA (TreeAutomaton C) over a finite nonempty constructor signature (FiniteConstructors C) has state space Fin⁡(q)\operatorname{Fin}(q)Fin(q), a designated final state qfq_fqf​, and duplicate-free transition rules c(q1,…,qn)→qc(q_1, \dots, q_n) \to qc(q1​,…,qn​)→q. Its run-count function (A.runCount v q) counts bottom-up runs on vvv ending at qqq:

runCount⁡A(c(v1,…,vn),q)=∑((q1,…,qn),q)∈ΔA(c)∏i=1nrunCount⁡A(vi,qi),\operatorname{runCount}_A(c(v_1, \dots, v_n), q) = \sum_{((q_1, \dots, q_n), q) \in \Delta_A(c)} \prod_{i=1}^n \operatorname{runCount}_A(v_i, q_i),runCountA​(c(v1​,…,vn​),q)=((q1​,…,qn​),q)∈ΔA​(c)∑​i=1∏n​runCountA​(vi​,qi​),

and its basic resource function (Definition 2, p. 245) is pA(v)=runCount⁡A(v,qf)p_A(v) = \operatorname{runCount}_A(v, q_f)pA​(v)=runCountA​(v,qf​) (A.basic).

The type of basic resource functions is BF={f:Val→N∣∃A, pA=f}\mathsf{BF} = \{f : \mathsf{Val} \to \mathbb{N} \mid \exists A,\, p_A = f\}BF={f:Val→N∣∃A,pA​=f} (BasicFunction C), accompanied by a representative policy PPP (RepPolicy C) selecting one representative automaton P.rep(p)P.\mathrm{rep}(p)P.rep(p) for each p∈BFp \in \mathsf{BF}p∈BF (modeling the fixed enumeration A\mathfrak{A}A of Section 3, p. 246). Standard operations on BF\mathsf{BF}BF include the canonical one-state function ∅\emptyset∅ (BasicFunction.canonical), rerooting p(A,q)p_{(A, q)}p(A,q)​ (BasicFunction.reroot), and the Cartesian-product basic function (BasicFunction.product).

For an nnn-tuple p=(p1,…,pn)∈BFnp = (p_1, \dots, p_n) \in \mathsf{BF}^np=(p1​,…,pn​)∈BFn, the multivariate basic function (Definition 8, p. 247) is p(v1,…,vn)=∏i=1npi(vi)p(v_1, \dots, v_n) = \prod_{i=1}^n p_i(v_i)p(v1​,…,vn​)=∏i=1n​pi​(vi​) (multivariateBasic). A resource annotation QQQ of length nnn (Annotation C n) is a finite list of pairs (p,w)(p, w)(p,w) with p∈BFnp \in \mathsf{BF}^np∈BFn and w∈Q≥0w \in \mathbb{Q}_{\ge 0}w∈Q≥0​, inducing the potential (Definitions 5 and 10, pp. 246, 248)

Φ(v1,…,vn:Q)=∑(p,w)∈Qw⋅p(v1,…,vn).\Phi(v_1, \dots, v_n : Q) = \sum_{(p, w) \in Q} w \cdot p(v_1, \dots, v_n).Φ(v1​,…,vn​:Q)=(p,w)∈Q∑​w⋅p(v1​,…,vn​).

This module also defines the class RF\mathsf{RF}RF of unary resource functions (IsResourceFunction), constant addition Q+KQ + KQ+K (addConstant), coordinate projection πlB1,…,Bm(Q)\pi_l^{B_1, \dots, B_m}(Q)πlB1​,…,Bm​​(Q) (annotationProject), the additive constructor shift ◃c(Q)\triangleleft_c(Q)◃c​(Q) (additiveShift, Definition 11, p. 248), and the variable-sharing operator Υ(Q)\Upsilon(Q)Υ(Q) (annotationShare, Lemma 13, p. 249).

Formalization Note To ensure that TreeAutomaton.product always satisfies the nonemptiness invariant has_rule even when factor automata have disjoint rule supports, the product state space Fin⁡(qAqB+1)\operatorname{Fin}(q_A q_B + 1)Fin(qA​qB​+1) reserves its last index as an unreachable padding state equipped with a self-loop for each constructor.

Definition code
import Definitions.Def_HofmannMoser_Syntax

/-!
# Tree automata, basic resource functions, and resource potentials

Definitions for Sections 2–3 (Definitions 2, 5, 8, 10, and 11; Propositions 3 and 4;
Lemmas 7, 9, 12, and 13) of Martin Hofmann and Georg Moser, *Multivariate Amortised
Resource Analysis for Term Rewrite Systems*, TLCA 2015, pp. 244–249,
<https://doi.org/10.4230/LIPIcs.TLCA.2015.241>.

Each bottom-up nondeterministic tree automaton `A` defines a basic resource function
`A.basic : Value C → Nat` counting accepting runs on ground constructor values (Definition 2).
Because language-equivalent nondeterministic automata need not have equal accepting-run counts,
and distinct state spaces with equal run-count functions can produce different child transition
decompositions when shifted, resource annotations are indexed by basic functions
`BasicFunction C` (`{f : Value C → Nat // IsBasicFunction C f}`) together with a fixed
representative policy `RepPolicy C` selecting one representative automaton `P.rep p` for each
basic function `p` (representing the paper's fixed enumeration `𝔄`). Annotations are stored
as finite lists of weighted basic-function tuples whose duplicate keys contribute additively
to the coefficient family.
-/

namespace HofmannMoser

universe u

/-- A ground constructor term, with the arity tracked by the constructor's index. -/
inductive Value (C : Nat → Type u) where
  | node {n : Nat} (c : C n) (children : Fin n → Value C) : Value C

/-- A finite nonempty constructor signature, as required in §2 of the paper. The list is
only an enumeration; duplicates do not introduce additional constructors. -/
structure FiniteConstructors (C : Nat → Type u) where
  symbols : List (Sigma C)
  contains : ∀ n (c : C n), Sigma.mk n c ∈ symbols
  nonempty : ∃ n, Nonempty (C n)

namespace Value

/-- The size `|v|` of a ground constructor value is the number of constructor symbols
occurring in `v` (§2, p. 244). -/
def size {C : Nat → Type u} : Value C → Nat
  | .node _ children => 1 + (List.ofFn fun i ↦ (children i).size).sum

/-- Embed a constructor-only ground tree into the paper's full first-order term syntax. -/
def toTerm {C D : Nat → Type u} : Value C → Term C D
  | .node c children => .func (.inl c) fun i ↦ (children i).toTerm

/-- The embedding of a constructor-only ground tree is a value in the term syntax. -/
theorem toTerm_isValue {C D : Nat → Type u} (v : Value C) : IsValue (v.toTerm (D := D)) := by
  cases v with
  | node c children =>
    apply IsValue.constructor
    intro i
    exact toTerm_isValue (children i)

/-- Every constructor-only ground term has a representation by a `Value` tree. -/
theorem exists_of_isValue {C D : Nat → Type u} {t : Term C D} (ht : IsValue t) :
    ∃ v : Value C, v.toTerm (D := D) = t := by
  induction ht with
  | constructor c args _ ih =>
    let values := fun i ↦ Classical.choose (ih i)
    refine ⟨.node c values, ?_⟩
    simp only [toTerm]
    congr 1
    funext i
    exact Classical.choose_spec (ih i)

/-- The embedding `Value.toTerm` is injective. -/
theorem toTerm_injective {C D : Nat → Type u} :
    Function.Injective (Value.toTerm (C := C) (D := D)) := by
  intro v₁
  induction v₁ with
  | node c₁ children₁ ih =>
    intro v₂ h
    cases v₂ with
    | node c₂ children₂ =>
      simp only [toTerm] at h
      injection h with hlen hsum hargs
      subst hlen
      injection hsum with hc
      subst hc
      have hchildren : (fun i ↦ (children₁ i).toTerm (D := D)) =
          (fun i ↦ (children₂ i).toTerm (D := D)) := eq_of_heq hargs
      congr 1
      funext i
      exact ih i (congrFun hchildren i)

end Value

/-- A finite bottom-up nondeterministic tree automaton with one designated final state.
The rules for each constructor form a set, so repeated transitions cannot count twice.
`finite_rules` asserts finiteness even if the ambient constructor family is infinite. -/
structure TreeAutomaton (C : Nat → Type u) where
  stateCount : Nat
  final : Fin stateCount
  rules : (n : Nat) → C n → List ((Fin n → Fin stateCount) × Fin stateCount)
  no_duplicate_rules : ∀ n c, (rules n c).Nodup
  finite_rules : ∃ support : List (Sigma C),
    ∀ n (c : C n), (rules n c).length > 0 → Sigma.mk n c ∈ support
  has_rule : ∃ (n : Nat) (c : C n), (rules n c).length > 0

namespace TreeAutomaton

variable {C : Nat → Type u}

/-- The canonical one-state automaton `∅` has one transition for each constructor.
Every constructor value has exactly one accepting run in it (Definition 2, p. 245). -/
def canonical (S : FiniteConstructors C) : TreeAutomaton C where
  stateCount := 1
  final := 0
  rules := fun _ _ ↦ [(fun _ ↦ 0, 0)]
  no_duplicate_rules := by intro n c; simp
  finite_rules := by
    refine ⟨S.symbols, ?_⟩
    intro n c _
    exact S.contains n c
  has_rule := by
    obtain ⟨n, ⟨c⟩⟩ := S.nonempty
    exact ⟨n, c, by simp⟩

/-- The automaton `(A, q)` obtained from `A` by replacing its designated final state with `q`
(§2, p. 245). -/
def reroot (A : TreeAutomaton C) (q : Fin A.stateCount) : TreeAutomaton C :=
  { A with final := q }

/-- Definition 2 and Proposition 3: the number of runs of `A` on `v` ending in state `q`.
The nullary product is one. Different runs leading to the same state are all counted. -/
def runCount (A : TreeAutomaton C) : Value C → Fin A.stateCount → Nat
  | .node c children, q =>
    (((A.rules _ c).filter (fun tr ↦ tr.2 == q)).map fun tr ↦
      (List.ofFn fun i ↦ A.runCount (children i) (tr.1 i)).foldl (· * ·) 1).sum

/-- Definition 2: the basic function `p_A`, counting accepting runs of `A` on `v`. -/
def basic (A : TreeAutomaton C) (v : Value C) : Nat := A.runCount v A.final

end TreeAutomaton

/-- Remove duplicate elements from a finite list while preserving membership. -/
noncomputable def dedupFinite {α : Type u} (xs : List α) :
    {ys : List α // ys.Nodup ∧ ∀ x, x ∈ ys ↔ x ∈ xs} := by
  classical
  induction xs with
  | nil => exact ⟨[], by simp⟩
  | cons x xs ih =>
    obtain ⟨ys, hy, heq⟩ := ih
    by_cases hx : x ∈ ys
    · refine ⟨ys, hy, ?_⟩
      intro a
      simp only [List.mem_cons, ← heq]
      exact ⟨fun ha => Or.inr ha, fun h => h.elim (fun h => h ▸ hx) id⟩
    · refine ⟨x :: ys, List.nodup_cons.mpr ⟨hx, hy⟩, ?_⟩
      intro a
      simp only [List.mem_cons, heq]

/-- Encode a pair of states `(i, j)` into `Fin (a * b + 1)`, reserving the last state
`Fin.last (a * b)` as a padding state. -/
def productState {a b : Nat} (i : Fin a) (j : Fin b) : Fin (a * b + 1) :=
  ⟨i.val * b + j.val, by
    have h : i.val * b + j.val < (i.val + 1) * b := by
      simp only [Nat.add_mul, Nat.one_mul]
      exact Nat.add_lt_add_left j.isLt _
    have h' : (i.val + 1) * b ≤ a * b := Nat.mul_le_mul_right b (Nat.succ_le_of_lt i.isLt)
    exact Nat.lt_trans (Nat.lt_of_lt_of_le h h') (Nat.lt_succ_self _)⟩

/-- Pair encoding is injective; the last finite state is reserved for padding. -/
theorem productState_injective {a b : Nat} (i i' : Fin a) (j j' : Fin b)
    (h : productState i j = productState i' j') : i = i' ∧ j = j' := by
  have hb : 0 < b := Nat.lt_of_le_of_lt (Nat.zero_le _) j.isLt
  have quot (x : Fin a) (y : Fin b) : (x.val * b + y.val) / b = x.val := by
    rw [Nat.mul_comm, Nat.add_comm, Nat.add_mul_div_left _ _ hb, Nat.div_eq_of_lt y.isLt]
    simp
  have rem (x : Fin a) (y : Fin b) : (x.val * b + y.val) % b = y.val := by
    rw [Nat.mul_comm, Nat.add_comm, Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt y.isLt]
  have heq : i.val * b + j.val = i'.val * b + j'.val := congrArg Fin.val h
  constructor
  · apply Fin.ext
    have hd := congrArg (fun n : Nat ↦ n / b) heq
    simpa only [quot] using hd
  · apply Fin.ext
    have hm := congrArg (fun n : Nat ↦ n % b) heq
    simpa only [rem] using hm

/-- Encoded pairs cannot equal the fresh padding state. -/
theorem productState_ne_padding {a b : Nat} (i : Fin a) (j : Fin b) :
    productState i j ≠ Fin.last (a * b) := by
  have h : i.val * b + j.val < a * b := by
    have h₁ : i.val * b + j.val < (i.val + 1) * b := by
      simp only [Nat.add_mul, Nat.one_mul]
      exact Nat.add_lt_add_left j.isLt _
    exact Nat.lt_of_lt_of_le h₁ (Nat.mul_le_mul_right b (Nat.succ_le_of_lt i.isLt))
  intro heq
  have hv : i.val * b + j.val = a * b := congrArg Fin.val heq
  omega

namespace TreeAutomaton

variable {C : Nat → Type u}

/-- Raw transitions of the Cartesian-product automaton, together with one self-loop on
the padding state `Fin.last (A.stateCount * B.stateCount)` for each constructor. -/
def productRules (A B : TreeAutomaton C) (n : Nat) (c : C n) :
    List ((Fin n → Fin (A.stateCount * B.stateCount + 1)) ×
      Fin (A.stateCount * B.stateCount + 1)) :=
  ((A.rules n c).flatMap fun ar ↦ (B.rules n c).map fun br ↦
    (fun i ↦ productState (ar.1 i) (br.1 i), productState ar.2 br.2)) ++
    [(fun _ ↦ Fin.last _, Fin.last _)]

/-- Cartesian-product automaton construction used in Lemmas 7 and 9. Pair states encode
the product `Fin A.stateCount × Fin B.stateCount`, and the final state is
`productState A.final B.final`. A separate unreachable padding state has a transition for
each constructor so that `has_rule` holds even when `A` and `B` have disjoint rule supports. -/
noncomputable def product (S : FiniteConstructors C) (A B : TreeAutomaton C) :
    TreeAutomaton C where
  stateCount := A.stateCount * B.stateCount + 1
  final := productState A.final B.final
  rules := fun n c ↦ (dedupFinite (productRules A B n c)).1
  no_duplicate_rules := fun n c ↦ (dedupFinite (productRules A B n c)).2.1
  finite_rules := by
    refine ⟨S.symbols, ?_⟩
    intro n c _
    exact S.contains n c
  has_rule := by
    obtain ⟨n, ⟨c⟩⟩ := S.nonempty
    refine ⟨n, c, ?_⟩
    apply List.length_pos_iff.mpr
    let pad : (Fin n → Fin (A.stateCount * B.stateCount + 1)) ×
        Fin (A.stateCount * B.stateCount + 1) := (fun _ ↦ Fin.last _, Fin.last _)
    have hpad : pad ∈ (dedupFinite (productRules A B n c)).1 :=
      ((dedupFinite (productRules A B n c)).2.2 pad).2 (by simp [productRules, pad])
    exact List.ne_nil_of_mem hpad

/-- Product transitions are precisely the paired transitions together with the padding
transition. -/
theorem product_rule_mem_iff (S : FiniteConstructors C) (A B : TreeAutomaton C)
    (n : Nat) (c : C n) (tr : (Fin n → Fin (A.stateCount * B.stateCount + 1)) ×
      Fin (A.stateCount * B.stateCount + 1)) :
    tr ∈ (product S A B).rules n c ↔ tr ∈ productRules A B n c :=
  (dedupFinite (productRules A B n c)).2.2 tr

end TreeAutomaton

/-- Definition 2: a function `Value C → Nat` is a basic resource function (`f ∈ BF`) if it
is the accepting-run count `A.basic` of some tree automaton `A` over `C`. -/
def IsBasicFunction (C : Nat → Type u) (f : Value C → Nat) : Prop :=
  ∃ A : TreeAutomaton C, A.basic = f

/-- The type `BF` of basic resource functions over `C` (Definition 2, p. 245). Two elements
of `BasicFunction C` are equal if and only if they assign the same run count to every value. -/
abbrev BasicFunction (C : Nat → Type u) := {f : Value C → Nat // IsBasicFunction C f}

/-- A fixed choice of one representative automaton per basic function, modeling the paper's
chosen enumeration `𝔄` (§3, p. 246). -/
structure RepPolicy (C : Nat → Type u) where
  rep : BasicFunction C → TreeAutomaton C
  rep_basic : ∀ p, (rep p).basic = p.val

/-- Classical representative policy choosing one witness automaton for each basic function. -/
noncomputable def classicalRepPolicy (C : Nat → Type u) : RepPolicy C where
  rep p := Classical.choose p.property
  rep_basic p := Classical.choose_spec p.property

namespace BasicFunction

variable {C : Nat → Type u}

/-- Project a tree automaton `A` to the basic resource function `p_A` it computes. -/
def ofAutomaton (A : TreeAutomaton C) : BasicFunction C :=
  ⟨A.basic, ⟨A, rfl⟩⟩

/-- The canonical basic resource function `p_∅` (Definition 2, p. 245). -/
def canonical (S : FiniteConstructors C) : BasicFunction C :=
  ofAutomaton (TreeAutomaton.canonical S)

/-- The basic resource function `p_{(A, q)}` of `A` rerooted at state `q` (§3, p. 245). -/
def reroot (A : TreeAutomaton C) (q : Fin A.stateCount) : BasicFunction C :=
  ofAutomaton (A.reroot q)

/-- Product of two basic functions via the Cartesian-product automaton of their chosen
representatives (Lemmas 7 and 9, pp. 247–248). -/
noncomputable def product (S : FiniteConstructors C) (P : RepPolicy C)
    (p₁ p₂ : BasicFunction C) : BasicFunction C :=
  ofAutomaton (TreeAutomaton.product S (P.rep p₁) (P.rep p₂))

end BasicFunction

/-- A resource annotation of length `n` (§3, p. 248): a finite list of weighted tuples of
basic resource functions. Duplicate tuples contribute additively to the represented
finitely supported coefficient family. Coefficients are nonnegative rationals. -/
abbrev Annotation (C : Nat → Type u) (n : Nat) :=
  List ((Fin n → BasicFunction C) × {q : Rat // 0 ≤ q})

/-- The all-canonical tuple `∅⃗ = (∅, …, ∅)` of length `n` (§3, p. 248). -/
def canonicalTuple {C : Nat → Type u} (S : FiniteConstructors C) (n : Nat) :
    Fin n → BasicFunction C := fun _ ↦ BasicFunction.canonical S

/-- Constant addition `Q + K` (§3, p. 249): add `K` to the coefficient of the canonical
tuple `∅⃗`, retaining all existing entries. -/
def addConstant {C : Nat → Type u} {n : Nat} (S : FiniteConstructors C)
    (Q : Annotation C n) (K : {q : Rat // 0 ≤ q}) : Annotation C n :=
  (canonicalTuple S n, K) :: Q

/-- Projection `π_l^{B₁,…,B_m}(Q)` of a length `l + m` annotation at a fixed suffix tuple
of basic functions (§3, p. 249). -/
noncomputable def annotationProject {C : Nat → Type u} {l m : Nat}
    (Q : Annotation C (l + m)) (suffix : Fin m → BasicFunction C) : Annotation C l := by
  classical
  exact Q.filterMap fun entry ↦
    if (fun i ↦ entry.1 (Fin.natAdd l i)) = suffix then
      some (fun i ↦ entry.1 (Fin.castAdd m i), entry.2)
    else none

/-- Definition 8: the multivariate basic function `p_{(A₁,…,A_n)}(v₁,…,v_n) =
p_{A₁}(v₁) ⋯ p_{A_n}(v_n)` evaluated on a sequence of values. -/
def multivariateBasic {C : Nat → Type u} {n : Nat}
    (ps : Fin n → BasicFunction C) (values : Fin n → Value C) : Nat :=
  (List.ofFn fun i ↦ (ps i).val (values i)).foldl (· * ·) 1

/-- Definitions 5 and 10: the potential `Φ(v₁, …, v_n : Q)` of a sequence of constructor
values with respect to an annotation `Q`. -/
def potential {C : Nat → Type u} {n : Nat}
    (Q : Annotation C n) (values : Fin n → Value C) : Rat :=
  (Q.map fun entry ↦ entry.2.1 * (multivariateBasic entry.1 values : Rat)).sum

/-- Definition 5: a function `r : Value C → Rat` is a resource function (`r ∈ RF`) if it is
a nonnegative rational linear combination of basic functions, i.e., the potential of a
length-1 annotation. -/
def IsResourceFunction (C : Nat → Type u) (r : Value C → Rat) : Prop :=
  ∃ Q : Annotation C 1, ∀ v, r v = potential Q (fun _ ↦ v)

/-- Child basic-function tuples generated by expanding the last coordinate of `tuple` at
constructor `c` using the transitions of its fixed representative `P.rep (tuple (Fin.last m))`
and rerooting at each child state. -/
def shiftTuples {C : Nat → Type u} {m n : Nat} (P : RepPolicy C) (c : C n)
    (tuple : Fin (m + 1) → BasicFunction C) : List (Fin (m + n) → BasicFunction C) :=
  let A := P.rep (tuple (Fin.last m))
  (((A.rules n c).filter fun tr ↦ tr.2 == A.final)).map fun tr ↦
    Fin.addCases (fun i ↦ tuple (Fin.castSucc i)) (fun i ↦ BasicFunction.reroot A (tr.1 i))

/-- Definition 11: the additive shift `◁_c(Q)` of a length `m + 1` annotation at an `n`-ary
constructor `c`. For each entry, the last basic function `p` is expanded along the transitions
into the final state of its fixed representative `P.rep p`, replacing `p` with the rerooted
child basic functions. -/
def additiveShift {C : Nat → Type u} {m n : Nat}
    (P : RepPolicy C) (c : C n) (Q : Annotation C (m + 1)) : Annotation C (m + n) :=
  Q.flatMap fun entry ↦ (shiftTuples P c entry.1).map fun outTuple ↦ (outTuple, entry.2)

/-- Lemma 13: the sharing operator `Υ(Q)` replacing the last two basic functions of each
tuple in a length `m + 2` annotation by their product basic function. -/
noncomputable def annotationShare {C : Nat → Type u} {m : Nat}
    (S : FiniteConstructors C) (P : RepPolicy C) (Q : Annotation C (m + 2)) :
    Annotation C (m + 1) :=
  Q.map fun entry ↦
    (Fin.addCases (fun i ↦ entry.1 (Fin.castAdd 2 i))
      (fun _ ↦ BasicFunction.product S P
        (entry.1 (Fin.natAdd m (0 : Fin 2)))
        (entry.1 (Fin.natAdd m (1 : Fin 2)))), entry.2)

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, Sections 2--3, pp. 244--249, Definitions 2, 5, 8, 10, 11
Read-back

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

HofmannMoser.Value

Given an arity-indexed family of constructor types C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u at universe level uuu, Value(C):Type u\mathsf{Value}(C) : \mathsf{Type}\ uValue(C):Type u is the inductive type of ground constructor trees generated by a single constructor node\mathsf{node}node: for any implicit arity n∈Nn \in \mathbb{N}n∈N, any constructor symbol c∈C(n)c \in C(n)c∈C(n), and any nnn-tuple of child values children:Fin n→Value(C)\mathit{children} : \mathsf{Fin}\ n \to \mathsf{Value}(C)children:Fin n→Value(C) (where Fin n={0,…,n−1}\mathsf{Fin}\ n = \{0, \dots, n-1\}Fin n={0,…,n−1}), node(c,children)∈Value(C)\mathsf{node}(c, \mathit{children}) \in \mathsf{Value}(C)node(c,children)∈Value(C). When n=0n = 0n=0, Fin 0\mathsf{Fin}\ 0Fin 0 is empty, so children\mathit{children}children is the unique empty tuple and node(c,children)\mathsf{node}(c, \mathit{children})node(c,children) is a leaf; if C(0)C(0)C(0) is empty, Value(C)\mathsf{Value}(C)Value(C) has no base cases and is uninhabited. Unlike Term(C,D)\mathsf{Term}(C, D)Term(C,D), Value(C)\mathsf{Value}(C)Value(C) contains no variable nodes and no defined-function symbols.

HofmannMoser.FiniteConstructors

Given an arity-indexed family of constructor types C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, FiniteConstructors(C):Type u\mathsf{FiniteConstructors}(C) : \mathsf{Type}\ uFiniteConstructors(C):Type u is a structure with three fields:

  • symbols:List(∑n∈NC(n))\mathsf{symbols} : \mathsf{List}\left(\sum_{n \in \mathbb{N}} C(n)\right)symbols:List(∑n∈N​C(n)), a finite ordered list of dependent pairs (n,c)(n, c)(n,c) with n∈Nn \in \mathbb{N}n∈N and c∈C(n)c \in C(n)c∈C(n) (not required to be duplicate-free);
  • contains:∀n∈N, ∀c∈C(n), (n,c)∈symbols\mathsf{contains} : \forall n \in \mathbb{N},\ \forall c \in C(n),\ (n, c) \in \mathsf{symbols}contains:∀n∈N, ∀c∈C(n), (n,c)∈symbols, a proof that every constructor symbol of every arity appears in symbols\mathsf{symbols}symbols;
  • nonempty:∃n∈N, Nonempty(C(n))\mathsf{nonempty} : \exists n \in \mathbb{N},\ \mathsf{Nonempty}(C(n))nonempty:∃n∈N, Nonempty(C(n)), a proof that there exists at least one arity n∈Nn \in \mathbb{N}n∈N for which C(n)C(n)C(n) is inhabited. Note that nonempty\mathsf{nonempty}nonempty does not require C(0)C(0)C(0) to be inhabited, so FiniteConstructors(C)\mathsf{FiniteConstructors}(C)FiniteConstructors(C) can hold even when Value(C)\mathsf{Value}(C)Value(C) is empty.

HofmannMoser.Value.size

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u and a value v∈Value(C)v \in \mathsf{Value}(C)v∈Value(C), Value.size(v)∈N\mathsf{Value.size}(v) \in \mathbb{N}Value.size(v)∈N is defined by structural recursion on v=node(c,children)v = \mathsf{node}(c, \mathit{children})v=node(c,children) (with c∈C(n)c \in C(n)c∈C(n) and children:Fin n→Value(C)\mathit{children} : \mathsf{Fin}\ n \to \mathsf{Value}(C)children:Fin n→Value(C)) as

size(node(c,children))=1+∑i=0n−1size(children(i)),\mathsf{size}(\mathsf{node}(c, \mathit{children})) = 1 + \sum_{i=0}^{n-1} \mathsf{size}(\mathit{children}(i)),size(node(c,children))=1+i=0∑n−1​size(children(i)),

where the sum is the list sum of [size(children(0)),…,size(children(n−1))][\mathsf{size}(\mathit{children}(0)), \dots, \mathsf{size}(\mathit{children}(n-1))][size(children(0)),…,size(children(n−1))]. When n=0n = 0n=0, the list is empty and the sum is 000, so a leaf node has size 111 and size(v)≥1\mathsf{size}(v) \ge 1size(v)≥1 for every v∈Value(C)v \in \mathsf{Value}(C)v∈Value(C).

HofmannMoser.Value.toTerm

Given implicit arity-indexed constructor and defined-function symbol families C,D:N→Type uC, D : \mathbb{N} \to \mathsf{Type}\ uC,D:N→Type u and a value v∈Value(C)v \in \mathsf{Value}(C)v∈Value(C), Value.toTerm(v)∈Term(C,D)\mathsf{Value.toTerm}(v) \in \mathsf{Term}(C, D)Value.toTerm(v)∈Term(C,D) embeds vvv into the inductive term type Term(C,D)\mathsf{Term}(C, D)Term(C,D) (generated by variables var(x)\mathsf{var}(x)var(x) for x∈Nx \in \mathbb{N}x∈N and function applications func(f,args)\mathsf{func}(f, \mathit{args})func(f,args) for f∈C(n)⊕D(n)f \in C(n) \oplus D(n)f∈C(n)⊕D(n) and args:Fin n→Term(C,D)\mathit{args} : \mathsf{Fin}\ n \to \mathsf{Term}(C, D)args:Fin n→Term(C,D)) by structural recursion:

toTerm(node(c,children))=func(inl(c),i↦toTerm(children(i))).\mathsf{toTerm}(\mathsf{node}(c, \mathit{children})) = \mathsf{func}(\mathsf{inl}(c), i \mapsto \mathsf{toTerm}(\mathit{children}(i))).toTerm(node(c,children))=func(inl(c),i↦toTerm(children(i))).

HofmannMoser.Value.toTerm_isValue

For any implicit arity-indexed families C,D:N→Type uC, D : \mathbb{N} \to \mathsf{Type}\ uC,D:N→Type u and any value v∈Value(C)v \in \mathsf{Value}(C)v∈Value(C), the embedded term Value.toTerm(v)∈Term(C,D)\mathsf{Value.toTerm}(v) \in \mathsf{Term}(C, D)Value.toTerm(v)∈Term(C,D) satisfies the inductive predicate IsValue(Value.toTerm(v))\mathsf{IsValue}(\mathsf{Value.toTerm}(v))IsValue(Value.toTerm(v)) (which holds if and only if a term in Term(C,D)\mathsf{Term}(C, D)Term(C,D) is built exclusively from left-injected constructor applications func(inl(c),args)\mathsf{func}(\mathsf{inl}(c), \mathit{args})func(inl(c),args) whose arguments recursively satisfy IsValue\mathsf{IsValue}IsValue).

HofmannMoser.Value.exists_of_isValue

For any implicit arity-indexed families C,D:N→Type uC, D : \mathbb{N} \to \mathsf{Type}\ uC,D:N→Type u, any implicit term t∈Term(C,D)t \in \mathsf{Term}(C, D)t∈Term(C,D), and a proof ht:IsValue(t)\mathit{ht} : \mathsf{IsValue}(t)ht:IsValue(t), there exists a value v∈Value(C)v \in \mathsf{Value}(C)v∈Value(C) such that Value.toTerm(v)=t\mathsf{Value.toTerm}(v) = tValue.toTerm(v)=t in Term(C,D)\mathsf{Term}(C, D)Term(C,D).

HofmannMoser.Value.toTerm_injective

For any implicit arity-indexed families C,D:N→Type uC, D : \mathbb{N} \to \mathsf{Type}\ uC,D:N→Type u, the map Value.toTerm:Value(C)→Term(C,D)\mathsf{Value.toTerm} : \mathsf{Value}(C) \to \mathsf{Term}(C, D)Value.toTerm:Value(C)→Term(C,D) is injective: for all v1,v2∈Value(C)v_1, v_2 \in \mathsf{Value}(C)v1​,v2​∈Value(C), if Value.toTerm(v1)=Value.toTerm(v2)\mathsf{Value.toTerm}(v_1) = \mathsf{Value.toTerm}(v_2)Value.toTerm(v1​)=Value.toTerm(v2​), then v1=v2v_1 = v_2v1​=v2​.

HofmannMoser.TreeAutomaton

Given an arity-indexed constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, TreeAutomaton(C):Type u\mathsf{TreeAutomaton}(C) : \mathsf{Type}\ uTreeAutomaton(C):Type u is a structure with six fields:

  • stateCount∈N\mathsf{stateCount} \in \mathbb{N}stateCount∈N, the number of states NNN;
  • final∈Fin(stateCount)\mathsf{final} \in \mathsf{Fin}(\mathsf{stateCount})final∈Fin(stateCount), a single designated final state (since Fin N\mathsf{Fin}\ NFin N is inhabited by final\mathsf{final}final, every TreeAutomaton(C)\mathsf{TreeAutomaton}(C)TreeAutomaton(C) satisfies stateCount≥1\mathsf{stateCount} \ge 1stateCount≥1);
  • rules:∏n∈N(C(n)→List((Fin n→Fin(stateCount))×Fin(stateCount)))\mathsf{rules} : \prod_{n \in \mathbb{N}} \left(C(n) \to \mathsf{List}\big((\mathsf{Fin}\ n \to \mathsf{Fin}(\mathsf{stateCount})) \times \mathsf{Fin}(\mathsf{stateCount})\big)\right)rules:∏n∈N​(C(n)→List((Fin n→Fin(stateCount))×Fin(stateCount))), assigning to each arity n∈Nn \in \mathbb{N}n∈N and constructor c∈C(n)c \in C(n)c∈C(n) a finite list of transition rules (tr1,tr2)(\mathit{tr}_1, \mathit{tr}_2)(tr1​,tr2​) consisting of an nnn-tuple of child states tr1:Fin n→Fin(stateCount)\mathit{tr}_1 : \mathsf{Fin}\ n \to \mathsf{Fin}(\mathsf{stateCount})tr1​:Fin n→Fin(stateCount) and a target state tr2∈Fin(stateCount)\mathit{tr}_2 \in \mathsf{Fin}(\mathsf{stateCount})tr2​∈Fin(stateCount);
  • no_duplicate_rules:∀n∈N, ∀c∈C(n), (rules(n,c)).Nodup\mathsf{no\_duplicate\_rules} : \forall n \in \mathbb{N},\ \forall c \in C(n),\ (\mathsf{rules}(n, c)).\mathsf{Nodup}no_duplicate_rules:∀n∈N, ∀c∈C(n), (rules(n,c)).Nodup, a proof that each rule list rules(n,c)\mathsf{rules}(n, c)rules(n,c) has no duplicate elements;
  • finite_rules:∃support:List(∑n∈NC(n)), ∀n∈N, ∀c∈C(n), ∣rules(n,c)∣>0  ⟹  (n,c)∈support\mathsf{finite\_rules} : \exists \mathit{support} : \mathsf{List}\left(\sum_{n \in \mathbb{N}} C(n)\right),\ \forall n \in \mathbb{N},\ \forall c \in C(n),\ |\mathsf{rules}(n, c)| > 0 \implies (n, c) \in \mathit{support}finite_rules:∃support:List(∑n∈N​C(n)), ∀n∈N, ∀c∈C(n), ∣rules(n,c)∣>0⟹(n,c)∈support, a proof that only finitely many constructor symbols across all arities have a nonempty rule list;
  • has_rule:∃n∈N, ∃c∈C(n), ∣rules(n,c)∣>0\mathsf{has\_rule} : \exists n \in \mathbb{N},\ \exists c \in C(n),\ |\mathsf{rules}(n, c)| > 0has_rule:∃n∈N, ∃c∈C(n), ∣rules(n,c)∣>0, a proof that at least one constructor symbol of some arity has a nonempty rule list (which implies TreeAutomaton(C)\mathsf{TreeAutomaton}(C)TreeAutomaton(C) is uninhabited if C(n)C(n)C(n) is empty for all n∈Nn \in \mathbb{N}n∈N).

HofmannMoser.TreeAutomaton.canonical

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u and a finite-constructor witness S:FiniteConstructors(C)S : \mathsf{FiniteConstructors}(C)S:FiniteConstructors(C), TreeAutomaton.canonical(S)∈TreeAutomaton(C)\mathsf{TreeAutomaton.canonical}(S) \in \mathsf{TreeAutomaton}(C)TreeAutomaton.canonical(S)∈TreeAutomaton(C) is the tree automaton defined by stateCount=1\mathsf{stateCount} = 1stateCount=1, final=0∈Fin 1\mathsf{final} = 0 \in \mathsf{Fin}\ 1final=0∈Fin 1, and rules(n,c)=[((i↦0),0)]\mathsf{rules}(n, c) = [((i \mapsto 0), 0)]rules(n,c)=[((i↦0),0)] (a singleton list containing the unique transition on state 000) for every n∈Nn \in \mathbb{N}n∈N and c∈C(n)c \in C(n)c∈C(n), with finite_rules\mathsf{finite\_rules}finite_rules witnessed by S.symbolsS.\mathsf{symbols}S.symbols and has_rule\mathsf{has\_rule}has_rule witnessed by S.nonemptyS.\mathsf{nonempty}S.nonempty.

HofmannMoser.TreeAutomaton.reroot

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, a tree automaton A∈TreeAutomaton(C)A \in \mathsf{TreeAutomaton}(C)A∈TreeAutomaton(C), and a state q∈Fin(A.stateCount)q \in \mathsf{Fin}(A.\mathsf{stateCount})q∈Fin(A.stateCount), TreeAutomaton.reroot(A,q)∈TreeAutomaton(C)\mathsf{TreeAutomaton.reroot}(A, q) \in \mathsf{TreeAutomaton}(C)TreeAutomaton.reroot(A,q)∈TreeAutomaton(C) is the automaton identical to AAA in all fields except that its designated final state final\mathsf{final}final is replaced by qqq.

HofmannMoser.TreeAutomaton.runCount

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, a tree automaton A∈TreeAutomaton(C)A \in \mathsf{TreeAutomaton}(C)A∈TreeAutomaton(C), a value v∈Value(C)v \in \mathsf{Value}(C)v∈Value(C), and a state q∈Fin(A.stateCount)q \in \mathsf{Fin}(A.\mathsf{stateCount})q∈Fin(A.stateCount), TreeAutomaton.runCount(A,v,q)∈N\mathsf{TreeAutomaton.runCount}(A, v, q) \in \mathbb{N}TreeAutomaton.runCount(A,v,q)∈N is defined recursively on v=node(c,children)v = \mathsf{node}(c, \mathit{children})v=node(c,children) (with c∈C(n)c \in C(n)c∈C(n) and children:Fin n→Value(C)\mathit{children} : \mathsf{Fin}\ n \to \mathsf{Value}(C)children:Fin n→Value(C)) by

runCount(A,node(c,children),q)=∑(tr1,tr2)∈A.rules(n,c)tr2=q∏i=0n−1runCount(A,children(i),tr1(i)),\mathsf{runCount}(A, \mathsf{node}(c, \mathit{children}), q) = \sum_{\substack{(\mathit{tr}_1, \mathit{tr}_2) \in A.\mathsf{rules}(n, c) \\ \mathit{tr}_2 = q}} \prod_{i=0}^{n-1} \mathsf{runCount}(A, \mathit{children}(i), \mathit{tr}_1(i)),runCount(A,node(c,children),q)=(tr1​,tr2​)∈A.rules(n,c)tr2​=q​∑​i=0∏n−1​runCount(A,children(i),tr1​(i)),

where A.rules(n,c)A.\mathsf{rules}(n, c)A.rules(n,c) is filtered by boolean equality tr2==q\mathit{tr}_2 == qtr2​==q, each matching rule is mapped to the left-folded product (starting from 111) of the list [runCount(A,children(0),tr1(0)),…,runCount(A,children(n−1),tr1(n−1))][\mathsf{runCount}(A, \mathit{children}(0), \mathit{tr}_1(0)), \dots, \mathsf{runCount}(A, \mathit{children}(n-1), \mathit{tr}_1(n-1))][runCount(A,children(0),tr1​(0)),…,runCount(A,children(n−1),tr1​(n−1))], and the resulting list is summed. When n=0n = 0n=0, the product over i∈Fin 0i \in \mathsf{Fin}\ 0i∈Fin 0 is 111, so runCount(A,node(c,children),q)\mathsf{runCount}(A, \mathsf{node}(c, \mathit{children}), q)runCount(A,node(c,children),q) counts the transitions in A.rules(0,c)A.\mathsf{rules}(0, c)A.rules(0,c) with output state qqq (either 000 or 111, since A.rules(0,c)A.\mathsf{rules}(0, c)A.rules(0,c) is duplicate-free and Fin 0→Fin(A.stateCount)\mathsf{Fin}\ 0 \to \mathsf{Fin}(A.\mathsf{stateCount})Fin 0→Fin(A.stateCount) is a singleton). If no rules in A.rules(n,c)A.\mathsf{rules}(n, c)A.rules(n,c) have target state qqq, the sum is 000.

HofmannMoser.TreeAutomaton.basic

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, a tree automaton A∈TreeAutomaton(C)A \in \mathsf{TreeAutomaton}(C)A∈TreeAutomaton(C), and a value v∈Value(C)v \in \mathsf{Value}(C)v∈Value(C), TreeAutomaton.basic(A,v)∈N\mathsf{TreeAutomaton.basic}(A, v) \in \mathbb{N}TreeAutomaton.basic(A,v)∈N is defined as TreeAutomaton.runCount(A,v,A.final)\mathsf{TreeAutomaton.runCount}(A, v, A.\mathsf{final})TreeAutomaton.runCount(A,v,A.final), the run count of AAA on vvv at the final state A.finalA.\mathsf{final}A.final.

HofmannMoser.dedupFinite

Given an implicit type α:Type u\alpha : \mathsf{Type}\ uα:Type u and a list xs:List α\mathit{xs} : \mathsf{List}\ \alphaxs:List α, dedupFinite(xs)\mathsf{dedupFinite}(\mathit{xs})dedupFinite(xs) is a noncomputable definition (using classical choice to decide list membership without a DecidableEq assumption on α\alphaα) returning a subtype element ⟨ys,(hnodup,hmem)⟩\langle \mathit{ys}, (\mathit{h}_{\mathsf{nodup}}, \mathit{h}_{\mathsf{mem}}) \rangle⟨ys,(hnodup​,hmem​)⟩ where ys:List α\mathit{ys} : \mathsf{List}\ \alphays:List α is a list constructed by structural recursion on xs\mathit{xs}xs (mapping [][][] to [][][], and mapping x::xs′x :: \mathit{xs}'x::xs′ with recursive result ys′\mathit{ys}'ys′ to ys′\mathit{ys}'ys′ if x∈ys′x \in \mathit{ys}'x∈ys′ and x::ys′x :: \mathit{ys}'x::ys′ if x∉ys′x \notin \mathit{ys}'x∈/ys′), hnodup:ys.Nodup\mathit{h}_{\mathsf{nodup}} : \mathit{ys}.\mathsf{Nodup}hnodup​:ys.Nodup proves that ys\mathit{ys}ys contains no duplicates, and hmem:∀x∈α, x∈ys  ⟺  x∈xs\mathit{h}_{\mathsf{mem}} : \forall x \in \alpha,\ x \in \mathit{ys} \iff x \in \mathit{xs}hmem​:∀x∈α, x∈ys⟺x∈xs proves that ys\mathit{ys}ys has the exact same elements as xs\mathit{xs}xs.

HofmannMoser.productState

Given implicit natural numbers a,b∈Na, b \in \mathbb{N}a,b∈N and indices i∈Fin ai \in \mathsf{Fin}\ ai∈Fin a and j∈Fin bj \in \mathsf{Fin}\ bj∈Fin b, productState(i,j)∈Fin(a⋅b+1)\mathsf{productState}(i, j) \in \mathsf{Fin}(a \cdot b + 1)productState(i,j)∈Fin(a⋅b+1) is the bounded natural number with value i.val⋅b+j.val<a⋅b<a⋅b+1i.\mathsf{val} \cdot b + j.\mathsf{val} < a \cdot b < a \cdot b + 1i.val⋅b+j.val<a⋅b<a⋅b+1.

HofmannMoser.productState_injective

For any implicit a,b∈Na, b \in \mathbb{N}a,b∈N and any i,i′∈Fin ai, i' \in \mathsf{Fin}\ ai,i′∈Fin a and j,j′∈Fin bj, j' \in \mathsf{Fin}\ bj,j′∈Fin b, if productState(i,j)=productState(i′,j′)\mathsf{productState}(i, j) = \mathsf{productState}(i', j')productState(i,j)=productState(i′,j′) in Fin(a⋅b+1)\mathsf{Fin}(a \cdot b + 1)Fin(a⋅b+1), then i=i′i = i'i=i′ and j=j′j = j'j=j′.

HofmannMoser.productState_ne_padding

For any implicit a,b∈Na, b \in \mathbb{N}a,b∈N and any i∈Fin ai \in \mathsf{Fin}\ ai∈Fin a and j∈Fin bj \in \mathsf{Fin}\ bj∈Fin b, productState(i,j)≠Fin.last(a⋅b)\mathsf{productState}(i, j) \ne \mathsf{Fin.last}(a \cdot b)productState(i,j)=Fin.last(a⋅b), where Fin.last(a⋅b)∈Fin(a⋅b+1)\mathsf{Fin.last}(a \cdot b) \in \mathsf{Fin}(a \cdot b + 1)Fin.last(a⋅b)∈Fin(a⋅b+1) is the maximum index with numerical value a⋅ba \cdot ba⋅b.

HofmannMoser.TreeAutomaton.productRules

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, two tree automata A,B∈TreeAutomaton(C)A, B \in \mathsf{TreeAutomaton}(C)A,B∈TreeAutomaton(C), an arity n∈Nn \in \mathbb{N}n∈N, and a constructor symbol c∈C(n)c \in C(n)c∈C(n), let N×=A.stateCount⋅B.stateCount+1N_{\times} = A.\mathsf{stateCount} \cdot B.\mathsf{stateCount} + 1N×​=A.stateCount⋅B.stateCount+1 and qpad=Fin.last(A.stateCount⋅B.stateCount)∈Fin N×q_{\mathsf{pad}} = \mathsf{Fin.last}(A.\mathsf{stateCount} \cdot B.\mathsf{stateCount}) \in \mathsf{Fin}\ N_{\times}qpad​=Fin.last(A.stateCount⋅B.stateCount)∈Fin N×​. Then TreeAutomaton.productRules(A,B,n,c)\mathsf{TreeAutomaton.productRules}(A, B, n, c)TreeAutomaton.productRules(A,B,n,c) is the list of transition rules in (Fin n→Fin N×)×Fin N×(\mathsf{Fin}\ n \to \mathsf{Fin}\ N_{\times}) \times \mathsf{Fin}\ N_{\times}(Fin n→Fin N×​)×Fin N×​ obtained by concatenating:

  1. For each (ar1,ar2)∈A.rules(n,c)(\mathit{ar}_1, \mathit{ar}_2) \in A.\mathsf{rules}(n, c)(ar1​,ar2​)∈A.rules(n,c) and each (br1,br2)∈B.rules(n,c)(\mathit{br}_1, \mathit{br}_2) \in B.\mathsf{rules}(n, c)(br1​,br2​)∈B.rules(n,c) (via flatMap and map), the paired transition rule
(i↦productState(ar1(i),br1(i)), productState(ar2,br2));\big(i \mapsto \mathsf{productState}(\mathit{ar}_1(i), \mathit{br}_1(i)),\ \mathsf{productState}(\mathit{ar}_2, \mathit{br}_2)\big);(i↦productState(ar1​(i),br1​(i)), productState(ar2​,br2​));
  1. A trailing singleton list [((i↦qpad),qpad)][((i \mapsto q_{\mathsf{pad}}), q_{\mathsf{pad}})][((i↦qpad​),qpad​)] consisting of the self-loop rule on the padding state qpadq_{\mathsf{pad}}qpad​.

Because the padding rule is unconditionally appended, productRules(A,B,n,c)\mathsf{productRules}(A, B, n, c)productRules(A,B,n,c) is nonempty for every n∈Nn \in \mathbb{N}n∈N and c∈C(n)c \in C(n)c∈C(n), even when A.rules(n,c)A.\mathsf{rules}(n, c)A.rules(n,c) or B.rules(n,c)B.\mathsf{rules}(n, c)B.rules(n,c) is empty.

HofmannMoser.TreeAutomaton.product

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, a finite-constructor witness S:FiniteConstructors(C)S : \mathsf{FiniteConstructors}(C)S:FiniteConstructors(C), and two tree automata A,B∈TreeAutomaton(C)A, B \in \mathsf{TreeAutomaton}(C)A,B∈TreeAutomaton(C), TreeAutomaton.product(S,A,B)∈TreeAutomaton(C)\mathsf{TreeAutomaton.product}(S, A, B) \in \mathsf{TreeAutomaton}(C)TreeAutomaton.product(S,A,B)∈TreeAutomaton(C) is the noncomputably defined product automaton with:

  • stateCount=A.stateCount⋅B.stateCount+1\mathsf{stateCount} = A.\mathsf{stateCount} \cdot B.\mathsf{stateCount} + 1stateCount=A.stateCount⋅B.stateCount+1;
  • final=productState(A.final,B.final)\mathsf{final} = \mathsf{productState}(A.\mathsf{final}, B.\mathsf{final})final=productState(A.final,B.final);
  • rules(n,c)=(dedupFinite(productRules(A,B,n,c))).1\mathsf{rules}(n, c) = (\mathsf{dedupFinite}(\mathsf{productRules}(A, B, n, c))).1rules(n,c)=(dedupFinite(productRules(A,B,n,c))).1, the classical deduplication of productRules(A,B,n,c)\mathsf{productRules}(A, B, n, c)productRules(A,B,n,c);
  • no_duplicate_rules\mathsf{no\_duplicate\_rules}no_duplicate_rules provided by dedupFinite\mathsf{dedupFinite}dedupFinite;
  • finite_rules\mathsf{finite\_rules}finite_rules witnessed by S.symbolsS.\mathsf{symbols}S.symbols and S.containsS.\mathsf{contains}S.contains (since every constructor c∈C(n)c \in C(n)c∈C(n) has at least the padding rule in rules(n,c)\mathsf{rules}(n, c)rules(n,c));
  • has_rule\mathsf{has\_rule}has_rule witnessed by choosing (n,c)(n, c)(n,c) from S.nonemptyS.\mathsf{nonempty}S.nonempty and using the presence of the padding rule ((i↦Fin.last),Fin.last)((i \mapsto \mathsf{Fin.last}), \mathsf{Fin.last})((i↦Fin.last),Fin.last) in rules(n,c)\mathsf{rules}(n, c)rules(n,c).

HofmannMoser.TreeAutomaton.product_rule_mem_iff

For any implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, any S:FiniteConstructors(C)S : \mathsf{FiniteConstructors}(C)S:FiniteConstructors(C), any A,B∈TreeAutomaton(C)A, B \in \mathsf{TreeAutomaton}(C)A,B∈TreeAutomaton(C), any n∈Nn \in \mathbb{N}n∈N, any c∈C(n)c \in C(n)c∈C(n), and any transition rule tr∈(Fin n→Fin(A.stateCount⋅B.stateCount+1))×Fin(A.stateCount⋅B.stateCount+1)\mathit{tr} \in (\mathsf{Fin}\ n \to \mathsf{Fin}(A.\mathsf{stateCount} \cdot B.\mathsf{stateCount} + 1)) \times \mathsf{Fin}(A.\mathsf{stateCount} \cdot B.\mathsf{stateCount} + 1)tr∈(Fin n→Fin(A.stateCount⋅B.stateCount+1))×Fin(A.stateCount⋅B.stateCount+1),

tr∈(TreeAutomaton.product(S,A,B)).rules(n,c)  ⟺  tr∈TreeAutomaton.productRules(A,B,n,c).\mathit{tr} \in (\mathsf{TreeAutomaton.product}(S, A, B)).\mathsf{rules}(n, c) \iff \mathit{tr} \in \mathsf{TreeAutomaton.productRules}(A, B, n, c).tr∈(TreeAutomaton.product(S,A,B)).rules(n,c)⟺tr∈TreeAutomaton.productRules(A,B,n,c).

HofmannMoser.IsBasicFunction

Given an explicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u and a function f:Value(C)→Nf : \mathsf{Value}(C) \to \mathbb{N}f:Value(C)→N, IsBasicFunction(C,f):Prop\mathsf{IsBasicFunction}(C, f) : \mathsf{Prop}IsBasicFunction(C,f):Prop holds if and only if there exists a tree automaton A∈TreeAutomaton(C)A \in \mathsf{TreeAutomaton}(C)A∈TreeAutomaton(C) such that A.basic=fA.\mathsf{basic} = fA.basic=f (meaning runCount(A,v,A.final)=f(v)\mathsf{runCount}(A, v, A.\mathsf{final}) = f(v)runCount(A,v,A.final)=f(v) for all v∈Value(C)v \in \mathsf{Value}(C)v∈Value(C)).

HofmannMoser.BasicFunction

Given an explicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, BasicFunction(C):Type u\mathsf{BasicFunction}(C) : \mathsf{Type}\ uBasicFunction(C):Type u is an abbreviation for the subtype {f:Value(C)→N∣IsBasicFunction(C,f)}\{f : \mathsf{Value}(C) \to \mathbb{N} \mid \mathsf{IsBasicFunction}(C, f)\}{f:Value(C)→N∣IsBasicFunction(C,f)}.

HofmannMoser.RepPolicy

Given an explicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, RepPolicy(C):Type u\mathsf{RepPolicy}(C) : \mathsf{Type}\ uRepPolicy(C):Type u is a structure packaging a representation choice for basic functions, with two fields:

  • rep:BasicFunction(C)→TreeAutomaton(C)\mathsf{rep} : \mathsf{BasicFunction}(C) \to \mathsf{TreeAutomaton}(C)rep:BasicFunction(C)→TreeAutomaton(C), assigning a tree automaton to each basic function;
  • rep_basic:∀p∈BasicFunction(C), (rep(p)).basic=p.val\mathsf{rep\_basic} : \forall p \in \mathsf{BasicFunction}(C),\ (\mathsf{rep}(p)).\mathsf{basic} = p.\mathsf{val}rep_basic:∀p∈BasicFunction(C), (rep(p)).basic=p.val, a proof that the chosen automaton rep(p)\mathsf{rep}(p)rep(p) computes the underlying function p.valp.\mathsf{val}p.val.

HofmannMoser.classicalRepPolicy

Given an explicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, classicalRepPolicy(C)∈RepPolicy(C)\mathsf{classicalRepPolicy}(C) \in \mathsf{RepPolicy}(C)classicalRepPolicy(C)∈RepPolicy(C) is the noncomputable representation policy that maps each p∈BasicFunction(C)p \in \mathsf{BasicFunction}(C)p∈BasicFunction(C) to Classical.choose(p.property)\mathsf{Classical.choose}(p.\mathsf{property})Classical.choose(p.property) (an arbitrary tree automaton witnessing ∃A∈TreeAutomaton(C), A.basic=p.val\exists A \in \mathsf{TreeAutomaton}(C),\ A.\mathsf{basic} = p.\mathsf{val}∃A∈TreeAutomaton(C), A.basic=p.val), with rep_basic(p)=Classical.choose_spec(p.property)\mathsf{rep\_basic}(p) = \mathsf{Classical.choose\_spec}(p.\mathsf{property})rep_basic(p)=Classical.choose_spec(p.property).

HofmannMoser.BasicFunction.ofAutomaton

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u and a tree automaton A∈TreeAutomaton(C)A \in \mathsf{TreeAutomaton}(C)A∈TreeAutomaton(C), BasicFunction.ofAutomaton(A)∈BasicFunction(C)\mathsf{BasicFunction.ofAutomaton}(A) \in \mathsf{BasicFunction}(C)BasicFunction.ofAutomaton(A)∈BasicFunction(C) is the subtype element ⟨A.basic,⟨A,rfl⟩⟩\langle A.\mathsf{basic}, \langle A, \mathsf{rfl} \rangle \rangle⟨A.basic,⟨A,rfl⟩⟩ packaging A.basicA.\mathsf{basic}A.basic with AAA as its existential witness.

HofmannMoser.BasicFunction.canonical

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u and a finite-constructor witness S:FiniteConstructors(C)S : \mathsf{FiniteConstructors}(C)S:FiniteConstructors(C), BasicFunction.canonical(S)∈BasicFunction(C)\mathsf{BasicFunction.canonical}(S) \in \mathsf{BasicFunction}(C)BasicFunction.canonical(S)∈BasicFunction(C) is BasicFunction.ofAutomaton(TreeAutomaton.canonical(S))\mathsf{BasicFunction.ofAutomaton}(\mathsf{TreeAutomaton.canonical}(S))BasicFunction.ofAutomaton(TreeAutomaton.canonical(S)), the basic function induced by the 1-state canonical automaton (which evaluates to 111 on every v∈Value(C)v \in \mathsf{Value}(C)v∈Value(C)).

HofmannMoser.BasicFunction.reroot

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, a tree automaton A∈TreeAutomaton(C)A \in \mathsf{TreeAutomaton}(C)A∈TreeAutomaton(C), and a state q∈Fin(A.stateCount)q \in \mathsf{Fin}(A.\mathsf{stateCount})q∈Fin(A.stateCount), BasicFunction.reroot(A,q)∈BasicFunction(C)\mathsf{BasicFunction.reroot}(A, q) \in \mathsf{BasicFunction}(C)BasicFunction.reroot(A,q)∈BasicFunction(C) is BasicFunction.ofAutomaton(A.reroot(q))\mathsf{BasicFunction.ofAutomaton}(A.\mathsf{reroot}(q))BasicFunction.ofAutomaton(A.reroot(q)), the basic function v↦runCount(A,v,q)v \mapsto \mathsf{runCount}(A, v, q)v↦runCount(A,v,q) induced by rerooting AAA at state qqq.

HofmannMoser.BasicFunction.product

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, a finite-constructor witness S:FiniteConstructors(C)S : \mathsf{FiniteConstructors}(C)S:FiniteConstructors(C), a representation policy P:RepPolicy(C)P : \mathsf{RepPolicy}(C)P:RepPolicy(C), and two basic functions p1,p2∈BasicFunction(C)p_1, p_2 \in \mathsf{BasicFunction}(C)p1​,p2​∈BasicFunction(C), BasicFunction.product(S,P,p1,p2)∈BasicFunction(C)\mathsf{BasicFunction.product}(S, P, p_1, p_2) \in \mathsf{BasicFunction}(C)BasicFunction.product(S,P,p1​,p2​)∈BasicFunction(C) is the noncomputable basic function

BasicFunction.ofAutomaton(TreeAutomaton.product(S,P.rep(p1),P.rep(p2))).\mathsf{BasicFunction.ofAutomaton}\big(\mathsf{TreeAutomaton.product}(S, P.\mathsf{rep}(p_1), P.\mathsf{rep}(p_2))\big).BasicFunction.ofAutomaton(TreeAutomaton.product(S,P.rep(p1​),P.rep(p2​))).

HofmannMoser.Annotation

Given an explicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u and an arity n∈Nn \in \mathbb{N}n∈N, Annotation(C,n):Type u\mathsf{Annotation}(C, n) : \mathsf{Type}\ uAnnotation(C,n):Type u is an abbreviation for

List((Fin n→BasicFunction(C))×{q∈Q∣0≤q}),\mathsf{List}\Big((\mathsf{Fin}\ n \to \mathsf{BasicFunction}(C)) \times \{q \in \mathbb{Q} \mid 0 \le q\}\Big),List((Fin n→BasicFunction(C))×{q∈Q∣0≤q}),

a finite ordered list of pairs (ps,q)(\mathit{ps}, q)(ps,q) consisting of an nnn-tuple of basic functions ps\mathit{ps}ps and a non-negative rational coefficient qqq. Because Annotation(C,n)\mathsf{Annotation}(C, n)Annotation(C,n) is a plain list, it may be empty, may contain entries with q=0q = 0q=0, and may contain duplicate nnn-tuples ps\mathit{ps}ps across multiple entries.

HofmannMoser.canonicalTuple

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, a finite-constructor witness S:FiniteConstructors(C)S : \mathsf{FiniteConstructors}(C)S:FiniteConstructors(C), and an arity n∈Nn \in \mathbb{N}n∈N, canonicalTuple(S,n):Fin n→BasicFunction(C)\mathsf{canonicalTuple}(S, n) : \mathsf{Fin}\ n \to \mathsf{BasicFunction}(C)canonicalTuple(S,n):Fin n→BasicFunction(C) is the constant nnn-tuple i↦BasicFunction.canonical(S)i \mapsto \mathsf{BasicFunction.canonical}(S)i↦BasicFunction.canonical(S).

HofmannMoser.addConstant

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, an implicit arity n∈Nn \in \mathbb{N}n∈N, a finite-constructor witness S:FiniteConstructors(C)S : \mathsf{FiniteConstructors}(C)S:FiniteConstructors(C), an annotation Q∈Annotation(C,n)Q \in \mathsf{Annotation}(C, n)Q∈Annotation(C,n), and a non-negative rational number K∈{q∈Q∣0≤q}K \in \{q \in \mathbb{Q} \mid 0 \le q\}K∈{q∈Q∣0≤q}, addConstant(S,Q,K)∈Annotation(C,n)\mathsf{addConstant}(S, Q, K) \in \mathsf{Annotation}(C, n)addConstant(S,Q,K)∈Annotation(C,n) is the list (canonicalTuple(S,n),K)::Q(\mathsf{canonicalTuple}(S, n), K) :: Q(canonicalTuple(S,n),K)::Q formed by prepending (canonicalTuple(S,n),K)(\mathsf{canonicalTuple}(S, n), K)(canonicalTuple(S,n),K) to QQQ.

HofmannMoser.annotationProject

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, implicit natural numbers l,m∈Nl, m \in \mathbb{N}l,m∈N, an annotation Q∈Annotation(C,l+m)Q \in \mathsf{Annotation}(C, l + m)Q∈Annotation(C,l+m), and an mmm-tuple suffix:Fin m→BasicFunction(C)\mathit{suffix} : \mathsf{Fin}\ m \to \mathsf{BasicFunction}(C)suffix:Fin m→BasicFunction(C), annotationProject(Q,suffix)∈Annotation(C,l)\mathsf{annotationProject}(Q, \mathit{suffix}) \in \mathsf{Annotation}(C, l)annotationProject(Q,suffix)∈Annotation(C,l) is the noncomputably defined list (using classical decidability for equality of tuples in Fin m→BasicFunction(C)\mathsf{Fin}\ m \to \mathsf{BasicFunction}(C)Fin m→BasicFunction(C)) obtained by applying List.filterMap to QQQ: each entry (ps,q)∈Q(\mathit{ps}, q) \in Q(ps,q)∈Q whose last mmm coordinates i↦ps(Fin.natAdd(l,i))i \mapsto \mathit{ps}(\mathsf{Fin.natAdd}(l, i))i↦ps(Fin.natAdd(l,i)) equal suffix\mathit{suffix}suffix is mapped to (i↦ps(Fin.castAdd(m,i)), q)\big(i \mapsto \mathit{ps}(\mathsf{Fin.castAdd}(m, i)),\ q\big)(i↦ps(Fin.castAdd(m,i)), q), and all other entries are dropped. When m=0m = 0m=0, the suffix condition holds vacuously for every entry in QQQ.

HofmannMoser.multivariateBasic

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, an implicit arity n∈Nn \in \mathbb{N}n∈N, an nnn-tuple of basic functions ps:Fin n→BasicFunction(C)\mathit{ps} : \mathsf{Fin}\ n \to \mathsf{BasicFunction}(C)ps:Fin n→BasicFunction(C), and an nnn-tuple of values values:Fin n→Value(C)\mathit{values} : \mathsf{Fin}\ n \to \mathsf{Value}(C)values:Fin n→Value(C), multivariateBasic(ps,values)∈N\mathsf{multivariateBasic}(\mathit{ps}, \mathit{values}) \in \mathbb{N}multivariateBasic(ps,values)∈N is the product

multivariateBasic(ps,values)=∏i=0n−1(ps(i)).val(values(i)),\mathsf{multivariateBasic}(\mathit{ps}, \mathit{values}) = \prod_{i=0}^{n-1} (\mathit{ps}(i)).\mathsf{val}(\mathit{values}(i)),multivariateBasic(ps,values)=i=0∏n−1​(ps(i)).val(values(i)),

computed as the left-folded product (starting at 111) of the list [(ps(0)).val(values(0)),…,(ps(n−1)).val(values(n−1))][(\mathit{ps}(0)).\mathsf{val}(\mathit{values}(0)), \dots, (\mathit{ps}(n-1)).\mathsf{val}(\mathit{values}(n-1))][(ps(0)).val(values(0)),…,(ps(n−1)).val(values(n−1))]. When n=0n = 0n=0, this product is 111.

HofmannMoser.potential

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, an implicit arity n∈Nn \in \mathbb{N}n∈N, an annotation Q∈Annotation(C,n)Q \in \mathsf{Annotation}(C, n)Q∈Annotation(C,n), and an nnn-tuple of values values:Fin n→Value(C)\mathit{values} : \mathsf{Fin}\ n \to \mathsf{Value}(C)values:Fin n→Value(C), potential(Q,values)∈Q\mathsf{potential}(Q, \mathit{values}) \in \mathbb{Q}potential(Q,values)∈Q is the rational sum

potential(Q,values)=∑(ps,q)∈Qq.val⋅(multivariateBasic(ps,values):Q)=∑(ps,q)∈Qq.val⋅∏i=0n−1(ps(i)).val(values(i)).\mathsf{potential}(Q, \mathit{values}) = \sum_{(\mathit{ps}, q) \in Q} q.\mathsf{val} \cdot \big(\mathsf{multivariateBasic}(\mathit{ps}, \mathit{values}) : \mathbb{Q}\big) = \sum_{(\mathit{ps}, q) \in Q} q.\mathsf{val} \cdot \prod_{i=0}^{n-1} (\mathit{ps}(i)).\mathsf{val}(\mathit{values}(i)).potential(Q,values)=(ps,q)∈Q∑​q.val⋅(multivariateBasic(ps,values):Q)=(ps,q)∈Q∑​q.val⋅i=0∏n−1​(ps(i)).val(values(i)).

When Q=[]Q = []Q=[], potential([],values)=0\mathsf{potential}([], \mathit{values}) = 0potential([],values)=0. Duplicate tuples in QQQ are summed with multiplicity, and since every coefficient q.val≥0q.\mathsf{val} \ge 0q.val≥0 and multivariateBasic(ps,values)∈N\mathsf{multivariateBasic}(\mathit{ps}, \mathit{values}) \in \mathbb{N}multivariateBasic(ps,values)∈N, potential(Q,values)≥0\mathsf{potential}(Q, \mathit{values}) \ge 0potential(Q,values)≥0 always holds.

HofmannMoser.IsResourceFunction

Given an explicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u and a function r:Value(C)→Qr : \mathsf{Value}(C) \to \mathbb{Q}r:Value(C)→Q, IsResourceFunction(C,r):Prop\mathsf{IsResourceFunction}(C, r) : \mathsf{Prop}IsResourceFunction(C,r):Prop holds if and only if there exists a unary annotation Q∈Annotation(C,1)Q \in \mathsf{Annotation}(C, 1)Q∈Annotation(C,1) such that for every value v∈Value(C)v \in \mathsf{Value}(C)v∈Value(C),

r(v)=potential(Q,(i↦v)),r(v) = \mathsf{potential}(Q, (i \mapsto v)),r(v)=potential(Q,(i↦v)),

where (i↦v):Fin 1→Value(C)(i \mapsto v) : \mathsf{Fin}\ 1 \to \mathsf{Value}(C)(i↦v):Fin 1→Value(C) is the 1-tuple with sole entry vvv.

HofmannMoser.shiftTuples

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, implicit natural numbers m,n∈Nm, n \in \mathbb{N}m,n∈N, a representation policy P:RepPolicy(C)P : \mathsf{RepPolicy}(C)P:RepPolicy(C), a constructor symbol c∈C(n)c \in C(n)c∈C(n), and an (m+1)(m+1)(m+1)-tuple of basic functions tuple:Fin(m+1)→BasicFunction(C)\mathit{tuple} : \mathsf{Fin}(m + 1) \to \mathsf{BasicFunction}(C)tuple:Fin(m+1)→BasicFunction(C), let A=P.rep(tuple(Fin.last m))∈TreeAutomaton(C)A = P.\mathsf{rep}(\mathit{tuple}(\mathsf{Fin.last}\ m)) \in \mathsf{TreeAutomaton}(C)A=P.rep(tuple(Fin.last m))∈TreeAutomaton(C) be the representative automaton assigned by PPP to the last coordinate tuple(m)\mathit{tuple}(m)tuple(m). Then shiftTuples(P,c,tuple):List(Fin(m+n)→BasicFunction(C))\mathsf{shiftTuples}(P, c, \mathit{tuple}) : \mathsf{List}(\mathsf{Fin}(m + n) \to \mathsf{BasicFunction}(C))shiftTuples(P,c,tuple):List(Fin(m+n)→BasicFunction(C)) is obtained by filtering A.rules(n,c)A.\mathsf{rules}(n, c)A.rules(n,c) to those transition rules tr=(tr1,tr2)\mathit{tr} = (\mathit{tr}_1, \mathit{tr}_2)tr=(tr1​,tr2​) with tr2==A.final\mathit{tr}_2 == A.\mathsf{final}tr2​==A.final, and mapping each matching transition tr\mathit{tr}tr to the (m+n)(m+n)(m+n)-tuple of basic functions (defined via Fin.addCases) that equals tuple(Fin.castSucc i)\mathit{tuple}(\mathsf{Fin.castSucc}\ i)tuple(Fin.castSucc i) on the first mmm indices i∈Fin mi \in \mathsf{Fin}\ mi∈Fin m and equals BasicFunction.reroot(A,tr1(j))\mathsf{BasicFunction.reroot}(A, \mathit{tr}_1(j))BasicFunction.reroot(A,tr1​(j)) on the last nnn indices j∈Fin nj \in \mathsf{Fin}\ nj∈Fin n. Because AAA is obtained via P.repP.\mathsf{rep}P.rep, the resulting list of tuples depends on the automaton representative chosen by PPP.

HofmannMoser.additiveShift

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, implicit natural numbers m,n∈Nm, n \in \mathbb{N}m,n∈N, a representation policy P:RepPolicy(C)P : \mathsf{RepPolicy}(C)P:RepPolicy(C), a constructor symbol c∈C(n)c \in C(n)c∈C(n), and an annotation Q∈Annotation(C,m+1)Q \in \mathsf{Annotation}(C, m + 1)Q∈Annotation(C,m+1), additiveShift(P,c,Q)∈Annotation(C,m+n)\mathsf{additiveShift}(P, c, Q) \in \mathsf{Annotation}(C, m + n)additiveShift(P,c,Q)∈Annotation(C,m+n) is the annotation obtained by List.flatMap over each entry (tuple,q)∈Q(\mathit{tuple}, q) \in Q(tuple,q)∈Q, replacing it with the list of pairs [(outTuple,q)∣outTuple∈shiftTuples(P,c,tuple)][(\mathit{outTuple}, q) \mid \mathit{outTuple} \in \mathsf{shiftTuples}(P, c, \mathit{tuple})][(outTuple,q)∣outTuple∈shiftTuples(P,c,tuple)]. Any entry (tuple,q)∈Q(\mathit{tuple}, q) \in Q(tuple,q)∈Q for which shiftTuples(P,c,tuple)\mathsf{shiftTuples}(P, c, \mathit{tuple})shiftTuples(P,c,tuple) is empty produces no entries in the result.

HofmannMoser.annotationShare

Given an implicit constructor family C:N→Type uC : \mathbb{N} \to \mathsf{Type}\ uC:N→Type u, an implicit natural number m∈Nm \in \mathbb{N}m∈N, a finite-constructor witness S:FiniteConstructors(C)S : \mathsf{FiniteConstructors}(C)S:FiniteConstructors(C), a representation policy P:RepPolicy(C)P : \mathsf{RepPolicy}(C)P:RepPolicy(C), and an (m+2)(m+2)(m+2)-ary annotation Q∈Annotation(C,m+2)Q \in \mathsf{Annotation}(C, m + 2)Q∈Annotation(C,m+2), annotationShare(S,P,Q)∈Annotation(C,m+1)\mathsf{annotationShare}(S, P, Q) \in \mathsf{Annotation}(C, m + 1)annotationShare(S,P,Q)∈Annotation(C,m+1) is the noncomputably defined annotation obtained by mapping each entry (tuple,q)∈Q(\mathit{tuple}, q) \in Q(tuple,q)∈Q to (outTuple,q)(\mathit{outTuple}, q)(outTuple,q), where outTuple:Fin(m+1)→BasicFunction(C)\mathit{outTuple} : \mathsf{Fin}(m + 1) \to \mathsf{BasicFunction}(C)outTuple:Fin(m+1)→BasicFunction(C) (defined via Fin.addCases) equals tuple(Fin.castAdd(2,i))\mathit{tuple}(\mathsf{Fin.castAdd}(2, i))tuple(Fin.castAdd(2,i)) on the first mmm coordinates i∈Fin mi \in \mathsf{Fin}\ mi∈Fin m and equals

BasicFunction.product(S,P,tuple(Fin.natAdd(m,0)),tuple(Fin.natAdd(m,1)))\mathsf{BasicFunction.product}\big(S, P, \mathit{tuple}(\mathsf{Fin.natAdd}(m, 0)), \mathit{tuple}(\mathsf{Fin.natAdd}(m, 1))\big)BasicFunction.product(S,P,tuple(Fin.natAdd(m,0)),tuple(Fin.natAdd(m,1)))

on the final coordinate mmm.

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