Resource typing rules and bounded term rewrite systems
DefinitionHofmannMoser_TypingResource-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- input annotations and length- output annotations to each -ary defined symbol . The structure AnnotatedSignatures C D bundles separate signature relations for charged (TypingMode.counted, ) and uncharged (TypingMode.costFree, ) derivations, and AnnotatedSignatureExtensional expresses invariance under coefficient-wise annotation equality (annotationEq, defined via annotationCoefficient).
The inductive judgment (Typing S P F mode n xs Q t Q', Figure 2, p. 251) formalizes all eight typing rules of the paper:
variable: typing a single variable .defined: typing a flat defined call from .constructor: typing a flat constructor application with input annotation and output annotation .weakenAnnotations: relaxing input and output annotations along pointwise coefficient inequality and (annotationLe).exchange: simultaneously permuting context variables and annotation coordinates along a bijection (annotationReindex).weakenContext: dropping a trailing context variable by projecting the annotation at the canonical basic function (annotationProject).share: contracting two distinct variables into a fresh variable via (annotationShare).composition: typing an application of positive arity across concatenated argument contexts (argumentContexts), governed by the coupling equationscompositionCoefficientsand the mode selectorlistPremiseMode(which uses counted mode for the all-canonical index 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 in and every signature annotation for expands to pattern variables and an annotation typing with in counted mode and in cost-free mode.
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
Read-back
What the Lean code literally says, in plain math · gemini-2.5-pro
1. HofmannMoser.AnnotatedSignature
For a universe level and two arity-indexed type families (representing -ary constructor symbols and -ary defined function symbols for each ), AnnotatedSignature C D is an abbreviation for the dependent relation type
Here, for any , is the list type , where:
- is the inductive type of finite ground constructor trees built via for , , and ;
- is the subtype of functions on ground constructor values computed by the accepting run count of some finite bottom-up tree automaton ; and
- is the subtype of non-negative rational weights.
An element is an arbitrary predicate relating an arity , a defined symbol , an -ary input annotation , and a unary output annotation . No functionality, non-emptiness, or invariance under list reordering is imposed by the type itself (in particular, a symbol may be related to zero, one, or multiple annotation pairs , including when or when or is the empty list ).
2. HofmannMoser.TypingMode
TypingMode is a two-element inductive enumeration type equipped with a derived decidable equality instance (), consisting of the two nullary constructors:
- , and
- .
3. HofmannMoser.AnnotatedSignatures
For a universe level and arity-indexed type families , AnnotatedSignatures C D is a two-field structure bundling two annotated signature relations:
- , and
- ,
where each field has type . The structure imposes no coupling or compatibility condition between and .
4. HofmannMoser.AnnotatedSignatures.get
For implicit arity-indexed type families , an explicit signature bundle , and an explicit mode , AnnotatedSignatures.get F mode projects the corresponding component of :
5. HofmannMoser.annotationReindex
For an implicit constructor family , an implicit arity , an explicit finite index map , and an explicit annotation list , annotationReindex ρ Q is the annotation of arity obtained by mapping over the list and precomposing each entry's tuple of basic functions with :
The definition does not require to be injective or surjective. If collapses distinct tuples into the same composite tuple , both entries remain as separate elements in the resulting list without merging their weights. When or , the list is unchanged.
6. HofmannMoser.annotationCoefficient
For an implicit constructor family , an implicit arity , an explicit annotation list , and an explicit target tuple , annotationCoefficient Q index is a noncomputable rational number in defined (using classical decidability of equality on ) as the sum of the underlying rational weights of all entries in whose first component equals :
Because is a subtype of with a proof component in , equality is extensional equality of the underlying functions at each coordinate . If does not occur in (in particular, if ), the result is . If occurs multiple times in , all matching weights are added together. Although every weight satisfies , the return type is plain rather than the non-negative subtype.
7. HofmannMoser.annotationEq
For an implicit constructor family , an implicit arity , and two explicit annotations , annotationEq P Q is the proposition asserting that and assign the same total rational coefficient to every -tuple of basic functions:
This equivalence identifies annotations that differ by list permutation, presence of zero-weight entries , or splitting of a tuple's weight across duplicate entries.
8. HofmannMoser.annotationLe
For an implicit constructor family , an implicit arity , and two explicit annotations , annotationLe P Q is the proposition asserting pointwise inequality of total rational coefficients across all -tuples of basic functions:
9. HofmannMoser.AnnotatedSignatureExtensional
For implicit arity-indexed type families and an explicit annotated signature , AnnotatedSignatureExtensional F is the proposition asserting that respects coefficient-wise annotation equivalence () in both its input and output annotation arguments:
10. HofmannMoser.annotationCoefficientList
For an implicit constructor family , an implicit arity , an explicit annotation , and an explicit list of basic functions , annotationCoefficientList Q indices is a noncomputable rational number in defined by:
In the degenerate case where the length does not match the arity parameter of , the function returns the fallback value .
11. HofmannMoser.contextWidth
For an explicit sequence of natural numbers and explicit bounds , contextWidth lengths start stop is the natural number computed by summing for running over :
Here is truncating natural number subtraction: whenever , , the range list is empty, and . When , this equals .
12. HofmannMoser.compositionCoefficients
For an implicit constructor family and explicit arguments:
- (representing the index of the final argument among arguments ),
- (giving the context width of each argument),
- (the combined input annotation of arity ),
- (the outer function call's input annotation of arity ),
- (an indexed family of argument input annotations parameterized by a list of basic functions), and
- (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 :
- Initial boundary (): For all lists , if and , then
- Intermediate step transitions (): For all with , all lists , and all single basic functions , if , , and , then
- Final boundary (): For all lists and all , if , then
Degenerate and edge cases:
- Because the outer annotation has arity , only positive arities can be represented.
- When , the second conjunct () is vacuously true, and in the first and third conjuncts and , forcing and .
- When in the second conjunct, , forcing .
- Values of , , and for indices , or for lists whose length does not equal , are completely unconstrained.
13. HofmannMoser.replaceAt
For an implicit type , an explicit list , a natural number index , and a replacement list , replaceAt xs i children is defined as the list concatenation:
When , this replaces the single element at 0-based index of with the elements of (removing the -th element if ). In the out-of-bounds case , and , so appends to the end of without removing any element.
14. HofmannMoser.replaceAt_length
For an implicit type , explicit lists , an explicit index , and a hypothesis , the theorem replaceAt_length asserts that
The hypothesis guarantees , so truncating natural number subtraction is exact.
15. HofmannMoser.additiveShiftAt
For an implicit constructor family , implicit natural numbers , an explicit representation policy , an explicit coordinate position , an explicit -ary constructor symbol , and an explicit annotation , additiveShiftAt P pos c Q produces an annotation of arity defined by applying List.flatMap to :
- Here consists of a choice function together with a proof .
- For each entry , let be the representative tree automaton for the basic function at coordinate .
- Filter the transition list to those transition pairs satisfying .
- For each such transition , let be the -element list of basic functions from , and let
be the -element list of basic functions where is the basic function of the automaton identical to except with final state (computing ).
- Form the list of length , convert it back into a tuple , and pair it with the original weight .
Edge cases:
- The existence of implies .
- When (a constant constructor ), , so the -th coordinate is removed from for each accepting transition in .
- If contains no transition with target state , the entry contributes zero entries to the output list.
- Because is obtained from , the resulting annotation list depends on the automaton chosen by the policy .
16. HofmannMoser.replacePattern_length
For implicit arity-indexed type families , an explicit list of terms , an explicit position , an implicit arity , and an explicit tuple of subterms , the theorem replacePattern_length asserts that replacing the -th element of with the -element list has length:
17. HofmannMoser.PatternExpansion
For implicit type families and an explicit representation policy , PatternExpansion P is an inductive predicate indexed by:
- a list of pattern terms ,
- an annotation ,
- a list of variable indices , and
- an annotation ,
defined by two constructors:
done: For any list of variable indices and any annotation ,
holds, where and the annotation is cast along the equality .
step: For any implicit arity , pattern list , position , constructor symbol , subterm tuple , equality proof , input annotation , output variable list , output annotation , and recursive proof
concludes .
Edge and degenerate cases:
PatternExpansioncan only hold when every term in is a constructor term (built solely from and ); if any term in contains a defined function symbol , it can never be reduced to and no derivation exists.- The list in
doneis not constrained to be duplicate-free ( is not required); if the same variable appears multiple times across , appears with the same multiplicity in .
18. HofmannMoser.argumentContexts
For an explicit indexed family of variable lists and an explicit natural number , argumentContexts contexts arity is the flattened list of natural numbers obtained by concatenating in order via List.flatMap over :
When , this returns the empty list . Values of for are ignored.
19. HofmannMoser.argumentContexts_length
For an explicit family and an explicit natural number , the theorem argumentContexts_length asserts that the length of equals the context width from to of the individual list lengths:
20. HofmannMoser.listPremiseMode
For an implicit constructor family , an explicit finite constructor witness , an explicit parent typing mode , and an explicit list of basic functions , listPremiseMode S parent indices is a noncomputable function (using classical decidability) returning a :
Here is a structure providing an exhaustive list of all constructors and a proof , and is the basic function induced by the 1-state tree automaton (which has , , and the single transition for every constructor, and hence maps every to ). When and , the universal condition holds vacuously, so the function returns .
21. HofmannMoser.Typing
For implicit arity-indexed type families , an explicit finite constructor witness , an explicit representation policy , and an explicit signature bundle , Typing S P F is an inductive relation
relating a typing mode , a context length , a context variable tuple , an -ary input annotation , a term , and a unary output annotation . It is generated by eight constructors:
variable: For any , variable index , and unary annotation ,
-
defined: For any , implicit arity , defined symbol , variable tuple , input annotation , and output annotation , given:- (all variable indices are pairwise distinct), and
- ,
concludes
-
constructor: For any , implicit arity , constructor symbol , variable tuple , and output annotation , given:- ,
concludes
Here maps each entry (with ) and each transition satisfying to the entry , which is then cast along .
-
weakenAnnotations: For any , implicit arity , variable tuple , input annotations , output annotations , and term , given:- ,
- ,
- (pointwise ), and
- (pointwise ),
concludes .
-
exchange: For any , implicit arity , variable tuple , index map , input annotation , output annotation , and term , given:- ,
- , and
- ,
concludes
(Unlike the other structural rules, exchange does not explicitly require as a hypothesis.)
-
weakenContext: For any , implicit arity , extended variable tuple , input annotation , output annotation , and term , given:- , and
- , where retains only those entries whose last coordinate equals and restricts to its first coordinates with weight ,
concludes . (There is no explicit side condition requiring .)
-
share: For any , implicit arity , context prefix , variable indices , input annotation , output annotation , and term , given:- ,
- ,
- ,
- (where is the list of all variables occurring in ), and
- ,
concludes
Here replaces each entry with the -tuple that agrees with on indices and assigns index the product basic function (induced by the padded product automaton of and with state count ), and replaces every variable occurrence of or in with .
-
composition: For any , natural number , symbol , context family , term family , fresh variable tuple , combined input annotation , intermediate call annotation , output annotation , and annotation families and , given:- (the concatenation has no duplicate variables, so the individual contexts are duplicate-free and pairwise disjoint),
- ,
- ,
- ,
- ,
- , and
- ,
concludes
Notice that composition only applies to function symbols of positive arity , and requires the argument contexts to be pairwise disjoint before any subsequent applications of share.
22. HofmannMoser.onePotential
onePotential is the constant in the non-negative rational subtype whose underlying rational value is .
23. HofmannMoser.Bounded
For implicit arity-indexed type families , an explicit finite constructor witness , an explicit representation policy , an explicit signature bundle , an explicit rewrite system (a predicate , where each has fields , , , and ), and an explicit typing mode , Bounded S P F R mode is the proposition asserting that:
there exist a variable list and two annotations satisfying all three of the following conditions:
- Pattern expansion:
where . 2. Mode-dependent potential step:
- If , then , where prepends the constant canonical tuple with weight to (so has total coefficient equal to that of plus on the constant canonical tuple, and equal to that of on all other tuples).
- If , then (so and have identical total coefficients on all tuples).
- Right-hand side typing:
Degenerate and edge cases:
- If is empty () or if is the empty relation (), then
Bounded S P F R modeholds vacuously. - In mode, because all weights in are non-negative, has coefficient at least on ; thus no can satisfy for a rule in if the pattern expansion of yields an annotation whose coefficient on is strictly less than (such as ).
24. HofmannMoser.BoundedSignatures
For implicit arity-indexed type families , an explicit finite constructor witness , an explicit representation policy , an explicit signature bundle , and an explicit rewrite system , BoundedSignatures S P F R is the conjunction:
Like Bounded, this proposition holds vacuously if contains no rules or if both and are empty relations.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.