Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Lemma 5.10, Corollary 5.11, Lemmas 5.15 & 5.16, and Examples 5.14 & 5.17: Concrete Erasure and Linear Algebra of Cost Inference

Proved
Grodin2026.lemmas_5_10_5_15_and_5_16_cost_inference

by kmehltretter82 · Nov 7, 2026 · Mathlib 0df444a (Lean v4.33.1)

amortized-analysiscost-analysismodal-type-theorysubstructural-type-systemstype-theory

Proves concrete ¬abs\neg\mathsf{abs}¬abs erasure for both synthetic modalities and phased computation types (Lemma 5.10, Corollary 5.11), proves that cost-free annotations (ValidSnocRecAnnotation 0) are closed under ⊕\oplus⊕ and k⊙−k \odot -k⊙− (Lemma 5.15) and cost-aware annotations (ValidSnocRecAnnotation stepCost) are closed under ⊕\oplus⊕ with cost-free annotations (Lemma 5.16), and verifies the three LP basis annotations Aca,Acf1,Acf2A_{\mathrm{ca}}, A_{\mathrm{cf1}}, A_{\mathrm{cf2}}Aca​,Acf1​,Acf2​ and their symbolic linear combination Aca⊕(p1⊙Acf1)⊕(p2⊙Acf2)A_{\mathrm{ca}} \oplus (p_1 \odot A_{\mathrm{cf1}}) \oplus (p_2 \odot A_{\mathrm{cf2}})Aca​⊕(p1​⊙Acf1​)⊕(p2​⊙Acf2​) for snoc′‾\underline{\mathsf{snoc'}}snoc′​ (Examples 5.14 & 5.17).

Preamble
import Definitions.Def_Grodin2026_Giralf
Formal statement
namespace Grodin2026

/-- **Lemma 5.10, Corollary 5.11, Example 5.14, Lemma 5.15, Lemma 5.16, and Example 5.17 (§5.3):**
1. **Synthetic and Phased $\neg\mathsf{abs}$ Erasure (Lemma 5.10 & Corollary 5.11):**
   - Under `¬ abs`, the synthetic abstract modality `OpenModal abs X` is contractible (`≃ PUnit`)
     and the synthetic concrete pushout `ClosedModal abs X` is equivalent to `X` (`≃ X`);
   - In the concrete ($\neg\mathsf{abs}$) world `.top`,
     $\mathsf{Abstraction}(\alpha : A_\top \multimap A_{\mathsf{abs}})_\top = A_\top$ (Lemma 5.10),
     $(\triangleright^p A)_\top = A_\top$ and $(\mathsf{spend}\langle c \rangle)_\top = \mathsf{charge}_{A_\top}\langle c \rangle$
     (Corollary 5.11(1)), and $(\mathsf{CList}^c_1(FX))_\top = (\mathsf{CList}^{(c_1, c_2)}_2(FX))_\top = F(\mathsf{List}\,X)$
     (Corollary 5.11(3)).
2. **Closure of Cost-Free Annotations under $\oplus$ and $k \odot -$ (Lemma 5.15):**
   If $A_1, A_2 : \mathsf{ListRecAnnotation}$ are valid cost-free annotations
   (`ValidSnocRecAnnotation 0`), then so are $A_1 \oplus A_2$ and $k \odot A_1$ for all $k : \mathbb{N}$.
3. **Closure of Cost-Aware Annotations under $\oplus$ with Cost-Free Annotations (Lemma 5.16):**
   If $A_1$ is a valid cost-aware annotation (`ValidSnocRecAnnotation stepCost A₁`) and $A_2$ is a
   valid cost-free annotation (`ValidSnocRecAnnotation 0 A₂`), then $A_1 \oplus A_2$ is a valid
   cost-aware annotation (`ValidSnocRecAnnotation stepCost (A₁ ⊕ A₂)`).
4. **Basis Inferences and Symbolic Combination for $\underline{\mathsf{snoc'}}$ (Examples 5.14 & 5.17):**
   - $A_{\mathrm{ca}}$ (`snocAnnCA`) is a valid cost-aware annotation (`stepCost = 1`) and
     $A_{\mathrm{cf1}}, A_{\mathrm{cf2}}$ (`snocAnnCF1`, `snocAnnCF2`) are valid cost-free annotations
     (`stepCost = 0`);
   - For all $p_1, p_2 : \mathbb{N}$, the symbolic linear combination
     $A_{\mathrm{ca}} \oplus (p_1 \odot A_{\mathrm{cf1}}) \oplus (p_2 \odot A_{\mathrm{cf2}})$
     (`snocSymbolicAnnotation p₁ p₂`) equals $\langle 1 + p_1 + p_2, p_2, 0, p_1, p_1, p_2 \rangle$
     and is a valid cost-aware annotation (`ValidSnocRecAnnotation 1`). -/
theorem lemmas_5_10_5_15_and_5_16_cost_inference :
    (∀ (abs : Prop) (X : Type),
      ¬ abs → Nonempty (OpenModal abs X ≃ PUnit) ∧ Nonempty (ClosedModal abs X ≃ X)) ∧
    (∀ (A_top A_abs : CostAlg) (alpha : CostHom A_top A_abs) (A : CompType)
       (X : Type) (p c c₁ c₂ : Nat),
      (AbstractionComp A_top A_abs alpha).top = A_top ∧
      (CreditComp p A).top = A.top ∧
      (spendComp c A).hom_top = chargeCostHom A.top c ∧
      (CList1Comp c X).top = FreeCostAlg (List X) ∧
      (CList2Comp c₁ c₂ X).top = FreeCostAlg (List X)) ∧
    (∀ (A₁ A₂ : ListRecAnnotation) (k : Nat),
      ValidSnocRecAnnotation 0 A₁ →
      ValidSnocRecAnnotation 0 A₂ →
      ValidSnocRecAnnotation 0 (ListRecAnnotation.add A₁ A₂) ∧
      ValidSnocRecAnnotation 0 (ListRecAnnotation.smul k A₁)) ∧
    (∀ (stepCost : Nat) (A₁ A₂ : ListRecAnnotation),
      ValidSnocRecAnnotation stepCost A₁ →
      ValidSnocRecAnnotation 0 A₂ →
      ValidSnocRecAnnotation stepCost (ListRecAnnotation.add A₁ A₂)) ∧
    (ValidSnocRecAnnotation 1 snocAnnCA ∧
     ValidSnocRecAnnotation 0 snocAnnCF1 ∧
     ValidSnocRecAnnotation 0 snocAnnCF2 ∧
     ∀ p₁ p₂ : Nat,
       snocSymbolicAnnotation p₁ p₂ = ⟨1 + p₁ + p₂, p₂, 0, p₁, p₁, p₂⟩ ∧
       ValidSnocRecAnnotation 1 (snocSymbolicAnnotation p₁ p₂)) := by
  sorry

end Grodin2026
Source
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 5.3, Lemma 5.10, Corollary 5.11, Example 5.14, Lemmas 5.15-5.16, Example 5.17, pp. 21-23.
Read-back

What the Lean code literally says, in plain math · Gemini 3.1 Pro (Independent Blind Auditor)

Read-back: The theorem lemmas_5_10_5_15_and_5_16_cost_inference asserts the conjunction of the following five statements:

  1. Synthetic Modal Erasure under ¬abs\neg\mathsf{abs}¬abs: For every proposition abs:Prop\mathsf{abs} : \mathrm{Prop}abs:Prop and every type X:TypeX : \mathrm{Type}X:Type, if ¬abs\neg\mathsf{abs}¬abs holds, then there exist type equivalences (Equiv):
◯absX=(abs→X)≃1and∙absX=Quot(ClosedRel abs X)≃X.\bigcirc_{\mathsf{abs}} X = (\mathsf{abs} \to X) \simeq \mathbf{1} \quad\text{and}\quad \bullet_{\mathsf{abs}} X = \mathrm{Quot}(\mathsf{ClosedRel}\,\mathsf{abs}\,X) \simeq X.◯abs​X=(abs→X)≃1and∙abs​X=Quot(ClosedRelabsX)≃X.
  1. Concrete-Phase (⊤\top⊤-World) Erasure of Cost Annotations: For all cost algebras A⊤,Aabs:CostAlgA_\top, A_{\mathsf{abs}} : \mathsf{CostAlg}A⊤​,Aabs​:CostAlg, every homomorphism α:A⊤⊸Aabs\alpha : A_\top \multimap A_{\mathsf{abs}}α:A⊤​⊸Aabs​, every computation type A∈CA \in \mathcal{C}A∈C, every type X:TypeX : \mathrm{Type}X:Type, and all p,c,c1,c2∈Np, c, c_1, c_2 \in \mathbb{N}p,c,c1​,c2​∈N:
    • (AbstractionComp(A⊤,Aabs,α))⊤=A⊤(\mathsf{AbstractionComp}(A_\top, A_{\mathsf{abs}}, \alpha))_\top = A_\top(AbstractionComp(A⊤​,Aabs​,α))⊤​=A⊤​;
    • (▹pA)⊤=A⊤(\triangleright^p A)_\top = A_\top(▹pA)⊤​=A⊤​;
    • (spend⟨c⟩A)⊤=chargeCostHom(A⊤,c)(\mathsf{spend}\langle c \rangle_A)_\top = \mathsf{chargeCostHom}(A_\top, c)(spend⟨c⟩A​)⊤​=chargeCostHom(A⊤​,c);
    • (CList1c(FX))⊤=F(List X)(\mathsf{CList}^c_1(FX))_\top = F(\mathsf{List}\,X)(CList1c​(FX))⊤​=F(ListX); and
    • (CList2(c1,c2)(FX))⊤=F(List X)(\mathsf{CList}^{(c_1, c_2)}_2(FX))_\top = F(\mathsf{List}\,X)(CList2(c1​,c2​)​(FX))⊤​=F(ListX).
  2. Closure of Cost-Free Annotations under Addition and Scalar Multiplication: For all list recursor annotations A1,A2∈ListRecAnnotationA_1, A_2 \in \mathsf{ListRecAnnotation}A1​,A2​∈ListRecAnnotation and every k∈Nk \in \mathbb{N}k∈N, if ValidSnocRecAnnotation(0,A1)\mathsf{ValidSnocRecAnnotation}(0, A_1)ValidSnocRecAnnotation(0,A1​) and ValidSnocRecAnnotation(0,A2)\mathsf{ValidSnocRecAnnotation}(0, A_2)ValidSnocRecAnnotation(0,A2​) hold (where ValidSnocRecAnnotation(stepCost,A)\mathsf{ValidSnocRecAnnotation}(\mathit{stepCost}, A)ValidSnocRecAnnotation(stepCost,A) means ∀n∈N,  n⋅stepCost+((n+1)⋅A.out_lin+(n+12)⋅A.out_quad)≤(n⋅A.in_lin+(n2)⋅A.in_quad)+A.ctx_q+A.debit\forall n \in \mathbb{N},\; n \cdot \mathit{stepCost} + ((n + 1) \cdot A.\mathit{out\_lin} + \binom{n + 1}{2} \cdot A.\mathit{out\_quad}) \le (n \cdot A.\mathit{in\_lin} + \binom{n}{2} \cdot A.\mathit{in\_quad}) + A.\mathit{ctx\_q} + A.\mathit{debit}∀n∈N,n⋅stepCost+((n+1)⋅A.out_lin+(2n+1​)⋅A.out_quad)≤(n⋅A.in_lin+(2n​)⋅A.in_quad)+A.ctx_q+A.debit), then both ValidSnocRecAnnotation(0,A1⊕A2)\mathsf{ValidSnocRecAnnotation}(0, A_1 \oplus A_2)ValidSnocRecAnnotation(0,A1​⊕A2​) and ValidSnocRecAnnotation(0,k⊙A1)\mathsf{ValidSnocRecAnnotation}(0, k \odot A_1)ValidSnocRecAnnotation(0,k⊙A1​) hold.
  3. Closure of Cost-Aware Annotations under Addition with Cost-Free Annotations: For every stepCost∈N\mathit{stepCost} \in \mathbb{N}stepCost∈N and all A1,A2∈ListRecAnnotationA_1, A_2 \in \mathsf{ListRecAnnotation}A1​,A2​∈ListRecAnnotation, if ValidSnocRecAnnotation(stepCost,A1)\mathsf{ValidSnocRecAnnotation}(\mathit{stepCost}, A_1)ValidSnocRecAnnotation(stepCost,A1​) and ValidSnocRecAnnotation(0,A2)\mathsf{ValidSnocRecAnnotation}(0, A_2)ValidSnocRecAnnotation(0,A2​) hold, then ValidSnocRecAnnotation(stepCost,A1⊕A2)\mathsf{ValidSnocRecAnnotation}(\mathit{stepCost}, A_1 \oplus A_2)ValidSnocRecAnnotation(stepCost,A1​⊕A2​) holds.
  4. Basis Annotations and Resource-Polymorphic Symbolic Combination for snoc':
    • ValidSnocRecAnnotation(1,snocAnnCA)\mathsf{ValidSnocRecAnnotation}(1, \mathsf{snocAnnCA})ValidSnocRecAnnotation(1,snocAnnCA) holds for snocAnnCA=(1,0,0,0,0,0)\mathsf{snocAnnCA} = (1, 0, 0, 0, 0, 0)snocAnnCA=(1,0,0,0,0,0);
    • ValidSnocRecAnnotation(0,snocAnnCF1)\mathsf{ValidSnocRecAnnotation}(0, \mathsf{snocAnnCF1})ValidSnocRecAnnotation(0,snocAnnCF1) holds for snocAnnCF1=(1,0,0,1,1,0)\mathsf{snocAnnCF1} = (1, 0, 0, 1, 1, 0)snocAnnCF1=(1,0,0,1,1,0);
    • ValidSnocRecAnnotation(0,snocAnnCF2)\mathsf{ValidSnocRecAnnotation}(0, \mathsf{snocAnnCF2})ValidSnocRecAnnotation(0,snocAnnCF2) holds for snocAnnCF2=(1,1,0,0,0,1)\mathsf{snocAnnCF2} = (1, 1, 0, 0, 0, 1)snocAnnCF2=(1,1,0,0,0,1); and
    • for all p1,p2∈Np_1, p_2 \in \mathbb{N}p1​,p2​∈N, the symbolic linear combination snocSymbolicAnnotation(p1,p2)=(snocAnnCA⊕(p1⊙snocAnnCF1))⊕(p2⊙snocAnnCF2)\mathsf{snocSymbolicAnnotation}(p_1, p_2) = (\mathsf{snocAnnCA} \oplus (p_1 \odot \mathsf{snocAnnCF1})) \oplus (p_2 \odot \mathsf{snocAnnCF2})snocSymbolicAnnotation(p1​,p2​)=(snocAnnCA⊕(p1​⊙snocAnnCF1))⊕(p2​⊙snocAnnCF2) equals (1+p1+p2,p2,0,p1,p1,p2)(1 + p_1 + p_2, p_2, 0, p_1, p_1, p_2)(1+p1​+p2​,p2​,0,p1​,p1​,p2​) and satisfies ValidSnocRecAnnotation(1,snocSymbolicAnnotation(p1,p2))\mathsf{ValidSnocRecAnnotation}(1, \mathsf{snocSymbolicAnnotation}(p_1, p_2))ValidSnocRecAnnotation(1,snocSymbolicAnnotation(p1​,p2​)).

Assessment: sound

Concerns: None

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