Lemmas 4.4, 4.6, 4.8, 4.10, 4.12, Corollaries 4.14 & 4.19, and Example 4.15: Credits, Debits, and Credit-Carrying Lists
ProvedGrodin2026.lemmas_4_4_to_4_12_credits_debits_and_clistamortized-analysiscost-analysismodal-type-theorysubstructural-type-systemstype-theory
Proves that credits are ghost data ( and , Lemma 4.4), the monoidal laws and (Lemma 4.6), the companion identity (Lemma 4.8), the equivalence connecting the physicist's and banker's views (Lemma 4.10), the credit-debit hom-set adjunction (Lemma 4.12), abstract-phase erasure for and (Corollaries 4.14 & 4.19), and the zero-abstract-cost homomorphism for pre-paid list reversal (Example 4.15).
Preamble
import Definitions.Def_Grodin2026_Banker
Formal statement
namespace Grodin2026
/-- **Lemma 4.4, Lemma 4.6, Lemma 4.8, Lemma 4.10, Lemma 4.12, Corollaries 4.14 & 4.19, and Example 4.15 (§4):**
1. **Credits Are Ghost Data (Lemma 4.4):** For all $c : \mathbb{N}$ and $A : \mathcal{C}$,
$\bullet(\triangleright^c A) = \bullet A$ and $\bigcirc(\triangleright^c A) = \bigcirc A$.
2. **Monoidal Laws of the Credit Operator (Lemma 4.6):** For all $A : \mathcal{C}$ and
$c_1, c_2 : \mathbb{N}$, $\triangleright^0 A = A$ and
$\triangleright^{c_1 + c_2} A = \triangleright^{c_1}(\triangleright^{c_2} A)$.
3. **Save–Spend Companion Identity (Lemma 4.8):** For all $c : \mathbb{N}$ and $A : \mathcal{C}$,
$\mathsf{spend}\langle c \rangle \circ \mathsf{save}\langle c \rangle = \mathsf{charge}_A\langle c \rangle$.
4. **Physicist–Banker Equivalence (Lemma 4.10):** For any value type $X$ and potential function
$\Phi : X \to \mathbb{N}$, $\mathsf{Potential}(\Phi : X \to \mathbb{N}) \simeq (x : X) \ltimes \triangleright^{\Phi(x)} \top$.
5. **Credit–Debit Adjunction $\triangleright^c \dashv \triangleleft^c$ (Lemma 4.12):** For all
$c : \mathbb{N}$ and $A, B : \mathcal{C}$, there is a canonical equivalence of hom-types
$\mathsf{LaxCompHom}(\triangleright^c A, B) \simeq \mathsf{CompHom}(A, \triangleleft^c B)$
mediated by the loan unit $\eta_c : A \multimap \triangleleft^c \triangleright^c A$ and loan
counit $\varepsilon_c : \triangleright^c \triangleleft^c B \mathrel{\multimap\!\!\!\!+} B$.
6. **Credit-Carrying Lists and Linear-Time Pre-Paid `reverse` (Corollaries 4.14 & 4.19, Example 4.15):**
- In the abstract phase ($\bigcirc$), both linear-credit lists $\mathsf{CList}^c_1(FX)$ and
quadratic-credit lists $\mathsf{CList}^{(c_1, c_2)}_2(FX)$ erase their credit annotations to
$\bigcirc(F(\mathsf{List}\,X))$;
- For every list $l$ and accumulator $acc$, `revAppendTop l acc = (l.length, l.reverseAux acc)`,
and `reverseCList1Top` and `reverseCList1Abs` assemble into a strict computation homomorphism
$\mathsf{reverse} : \mathsf{CList}^1_1(FX) \multimap F(\mathsf{List}\,X)$ with zero abstract cost. -/
theorem lemmas_4_4_to_4_12_credits_debits_and_clist :
(∀ (c : Nat) (A : CompType),
ClosedComp (CreditComp c A) = ClosedComp A ∧
OpenComp (CreditComp c A) = OpenComp A) ∧
(∀ (A : CompType),
CreditComp 0 A = A ∧
(∀ c₁ c₂ : Nat, CreditComp (c₁ + c₂) A = CreditComp c₁ (CreditComp c₂ A))) ∧
(∀ (c : Nat) (A : CompType),
(spendComp c A).comp (saveComp c A) = chargeCompHom A c) ∧
(∀ (X : Type) (Phi : X → Nat),
Nonempty (CompEquiv (PotentialType X Phi) (BankerPotentialComp X Phi))) ∧
(∀ (c : Nat) (A B : CompType),
Nonempty (LaxCompHom (CreditComp c A) B ≃ CompHom A (DebitComp c B))) ∧
(∀ (X : Type) (c c₁ c₂ : Nat),
OpenComp (CList1Comp c X) = OpenComp (FreeComp (List X)) ∧
OpenComp (CList2Comp c₁ c₂ X) = OpenComp (FreeComp (List X)) ∧
(∀ l acc : List X, revAppendTop l acc = (l.length, l.reverseAux acc)) ∧
∃ revHom : CompHom (CList1Comp 1 X) (FreeComp (List X)),
revHom.hom_top = reverseCList1Top ∧ revHom.hom_abs = reverseCList1Abs) := by
sorry
end Grodin2026Source
Harrison Grodin, Ethan Chu, Runming Li, Jan Hoffmann, and Robert Harper, 'Potential Functions as Types: A Synthetic Modal Formulation of Amortized Cost', arXiv:2607.08547v2, 2026. Section 4, Lemmas 4.4, 4.6, 4.8, 4.10, 4.12, Corollaries 4.14 & 4.19, Example 4.15, pp. 14-16.
Read-back
What the Lean code literally says, in plain math · Gemini 3.1 Pro (Independent Blind Auditor)
Read-back:
The theorem lemmas_4_4_to_4_12_credits_debits_and_clist asserts the conjunction of the following six statements:
- Modal Invariance of the Credit Operator (Credits as Ghost Data): For every and every phased computation type ,
- Monoidal Action Laws of the Credit Operator: For every phased computation type ,
- Save–Spend Composition Identity: For every and every phased computation type ,
- Equivalence of Physicist's Potential and Banker's Dependent Copower: For every type and every potential function , there exists a computation type equivalence (
CompEquiv) between and . - Credit–Debit Adjunction: For every and all phased computation types , there exists a bijection (
Equiv) between the type of lax computation homomorphisms and the type of strict computation homomorphisms . - Abstract Erasure of Credit-Carrying Lists and Pre-Paid Linear-Time
reverse: For every type and all :- and ;
- for all lists , ; and
- there exists a strict computation homomorphism with and (which incurs zero abstract cost).
Assessment: sound
Concerns: None