Tree automata, basic resource functions, and resource potentials
DefinitionHofmannMoser_PotentialBottom-up nondeterministic tree automata, basic resource functions, and multivariate resource potentials (Sections 2–3, pp. 244–249).
A ground constructor value (Value C) is a constructor tree of size (Value.size), embedded injectively into first-order terms via Value.toTerm. A bottom-up nondeterministic tree automaton (TreeAutomaton C) over a finite nonempty constructor signature (FiniteConstructors C) has state space , a designated final state , and duplicate-free transition rules . Its run-count function (A.runCount v q) counts bottom-up runs on ending at :
and its basic resource function (Definition 2, p. 245) is (A.basic).
The type of basic resource functions is (BasicFunction C), accompanied by a representative policy (RepPolicy C) selecting one representative automaton for each (modeling the fixed enumeration of Section 3, p. 246). Standard operations on include the canonical one-state function (BasicFunction.canonical), rerooting (BasicFunction.reroot), and the Cartesian-product basic function (BasicFunction.product).
For an -tuple , the multivariate basic function (Definition 8, p. 247) is (multivariateBasic). A resource annotation of length (Annotation C n) is a finite list of pairs with and , inducing the potential (Definitions 5 and 10, pp. 246, 248)
This module also defines the class of unary resource functions (IsResourceFunction), constant addition (addConstant), coordinate projection (annotationProject), the additive constructor shift (additiveShift, Definition 11, p. 248), and the variable-sharing operator (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 reserves its last index as an unreachable padding state equipped with a self-loop for each constructor.
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
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 at universe level , is the inductive type of ground constructor trees generated by a single constructor : for any implicit arity , any constructor symbol , and any -tuple of child values (where ), . When , is empty, so is the unique empty tuple and is a leaf; if is empty, has no base cases and is uninhabited. Unlike , contains no variable nodes and no defined-function symbols.
HofmannMoser.FiniteConstructors
Given an arity-indexed family of constructor types , is a structure with three fields:
- , a finite ordered list of dependent pairs with and (not required to be duplicate-free);
- , a proof that every constructor symbol of every arity appears in ;
- , a proof that there exists at least one arity for which is inhabited. Note that does not require to be inhabited, so can hold even when is empty.
HofmannMoser.Value.size
Given an implicit constructor family and a value , is defined by structural recursion on (with and ) as
where the sum is the list sum of . When , the list is empty and the sum is , so a leaf node has size and for every .
HofmannMoser.Value.toTerm
Given implicit arity-indexed constructor and defined-function symbol families and a value , embeds into the inductive term type (generated by variables for and function applications for and ) by structural recursion:
HofmannMoser.Value.toTerm_isValue
For any implicit arity-indexed families and any value , the embedded term satisfies the inductive predicate (which holds if and only if a term in is built exclusively from left-injected constructor applications whose arguments recursively satisfy ).
HofmannMoser.Value.exists_of_isValue
For any implicit arity-indexed families , any implicit term , and a proof , there exists a value such that in .
HofmannMoser.Value.toTerm_injective
For any implicit arity-indexed families , the map is injective: for all , if , then .
HofmannMoser.TreeAutomaton
Given an arity-indexed constructor family , is a structure with six fields:
- , the number of states ;
- , a single designated final state (since is inhabited by , every satisfies );
- , assigning to each arity and constructor a finite list of transition rules consisting of an -tuple of child states and a target state ;
- , a proof that each rule list has no duplicate elements;
- , a proof that only finitely many constructor symbols across all arities have a nonempty rule list;
- , a proof that at least one constructor symbol of some arity has a nonempty rule list (which implies is uninhabited if is empty for all ).
HofmannMoser.TreeAutomaton.canonical
Given an implicit constructor family and a finite-constructor witness , is the tree automaton defined by , , and (a singleton list containing the unique transition on state ) for every and , with witnessed by and witnessed by .
HofmannMoser.TreeAutomaton.reroot
Given an implicit constructor family , a tree automaton , and a state , is the automaton identical to in all fields except that its designated final state is replaced by .
HofmannMoser.TreeAutomaton.runCount
Given an implicit constructor family , a tree automaton , a value , and a state , is defined recursively on (with and ) by
where is filtered by boolean equality , each matching rule is mapped to the left-folded product (starting from ) of the list , and the resulting list is summed. When , the product over is , so counts the transitions in with output state (either or , since is duplicate-free and is a singleton). If no rules in have target state , the sum is .
HofmannMoser.TreeAutomaton.basic
Given an implicit constructor family , a tree automaton , and a value , is defined as , the run count of on at the final state .
HofmannMoser.dedupFinite
Given an implicit type and a list , is a noncomputable definition (using classical choice to decide list membership without a DecidableEq assumption on ) returning a subtype element where is a list constructed by structural recursion on (mapping to , and mapping with recursive result to if and if ), proves that contains no duplicates, and proves that has the exact same elements as .
HofmannMoser.productState
Given implicit natural numbers and indices and , is the bounded natural number with value .
HofmannMoser.productState_injective
For any implicit and any and , if in , then and .
HofmannMoser.productState_ne_padding
For any implicit and any and , , where is the maximum index with numerical value .
HofmannMoser.TreeAutomaton.productRules
Given an implicit constructor family , two tree automata , an arity , and a constructor symbol , let and . Then is the list of transition rules in obtained by concatenating:
- For each and each (via
flatMapandmap), the paired transition rule
- A trailing singleton list consisting of the self-loop rule on the padding state .
Because the padding rule is unconditionally appended, is nonempty for every and , even when or is empty.
HofmannMoser.TreeAutomaton.product
Given an implicit constructor family , a finite-constructor witness , and two tree automata , is the noncomputably defined product automaton with:
- ;
- ;
- , the classical deduplication of ;
- provided by ;
- witnessed by and (since every constructor has at least the padding rule in );
- witnessed by choosing from and using the presence of the padding rule in .
HofmannMoser.TreeAutomaton.product_rule_mem_iff
For any implicit constructor family , any , any , any , any , and any transition rule ,
HofmannMoser.IsBasicFunction
Given an explicit constructor family and a function , holds if and only if there exists a tree automaton such that (meaning for all ).
HofmannMoser.BasicFunction
Given an explicit constructor family , is an abbreviation for the subtype .
HofmannMoser.RepPolicy
Given an explicit constructor family , is a structure packaging a representation choice for basic functions, with two fields:
- , assigning a tree automaton to each basic function;
- , a proof that the chosen automaton computes the underlying function .
HofmannMoser.classicalRepPolicy
Given an explicit constructor family , is the noncomputable representation policy that maps each to (an arbitrary tree automaton witnessing ), with .
HofmannMoser.BasicFunction.ofAutomaton
Given an implicit constructor family and a tree automaton , is the subtype element packaging with as its existential witness.
HofmannMoser.BasicFunction.canonical
Given an implicit constructor family and a finite-constructor witness , is , the basic function induced by the 1-state canonical automaton (which evaluates to on every ).
HofmannMoser.BasicFunction.reroot
Given an implicit constructor family , a tree automaton , and a state , is , the basic function induced by rerooting at state .
HofmannMoser.BasicFunction.product
Given an implicit constructor family , a finite-constructor witness , a representation policy , and two basic functions , is the noncomputable basic function
HofmannMoser.Annotation
Given an explicit constructor family and an arity , is an abbreviation for
a finite ordered list of pairs consisting of an -tuple of basic functions and a non-negative rational coefficient . Because is a plain list, it may be empty, may contain entries with , and may contain duplicate -tuples across multiple entries.
HofmannMoser.canonicalTuple
Given an implicit constructor family , a finite-constructor witness , and an arity , is the constant -tuple .
HofmannMoser.addConstant
Given an implicit constructor family , an implicit arity , a finite-constructor witness , an annotation , and a non-negative rational number , is the list formed by prepending to .
HofmannMoser.annotationProject
Given an implicit constructor family , implicit natural numbers , an annotation , and an -tuple , is the noncomputably defined list (using classical decidability for equality of tuples in ) obtained by applying List.filterMap to : each entry whose last coordinates equal is mapped to , and all other entries are dropped. When , the suffix condition holds vacuously for every entry in .
HofmannMoser.multivariateBasic
Given an implicit constructor family , an implicit arity , an -tuple of basic functions , and an -tuple of values , is the product
computed as the left-folded product (starting at ) of the list . When , this product is .
HofmannMoser.potential
Given an implicit constructor family , an implicit arity , an annotation , and an -tuple of values , is the rational sum
When , . Duplicate tuples in are summed with multiplicity, and since every coefficient and , always holds.
HofmannMoser.IsResourceFunction
Given an explicit constructor family and a function , holds if and only if there exists a unary annotation such that for every value ,
where is the 1-tuple with sole entry .
HofmannMoser.shiftTuples
Given an implicit constructor family , implicit natural numbers , a representation policy , a constructor symbol , and an -tuple of basic functions , let be the representative automaton assigned by to the last coordinate . Then is obtained by filtering to those transition rules with , and mapping each matching transition to the -tuple of basic functions (defined via Fin.addCases) that equals on the first indices and equals on the last indices . Because is obtained via , the resulting list of tuples depends on the automaton representative chosen by .
HofmannMoser.additiveShift
Given an implicit constructor family , implicit natural numbers , a representation policy , a constructor symbol , and an annotation , is the annotation obtained by List.flatMap over each entry , replacing it with the list of pairs . Any entry for which is empty produces no entries in the result.
HofmannMoser.annotationShare
Given an implicit constructor family , an implicit natural number , a finite-constructor witness , a representation policy , and an -ary annotation , is the noncomputably defined annotation obtained by mapping each entry to , where (defined via Fin.addCases) equals on the first coordinates and equals
on the final coordinate .
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.