Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Composable counter-increment contracts for Algo2Lean calls

Definition
CLRS_Chapter4_Algo2LeanLib_CallCost

by Chutong · Oct 11, 2026 · Mathlib 0df444a (Lean v4.33.1)

algo2leanalgo2lean-clrs-chapter4-fd33cf9algorithmsclrsrunning-timetextbook

This bundle defines and supports additive named-clock increments across a call and their composition across consecutive calls. Increments relates the final counters to the initial counters plus a supplied natural-valued vector, so costs compose even when a caller begins with nonzero counters. The definitions distinguish counter monotonicity and exact additive increments from a truncated subtraction alone.

Formalization Note. This content is transcribed from Algo2Lean development snapshot fd33cf959b39f9e4a9fcfda4ef31d5a36b784d41, with explicit platform import and namespace adaptation. It is not attributed to public compiler v0.1.4. The submitted definition bundle must be checked without unfinished-proof assumptions.

Definition code
import Definitions.Def_CLRS_Chapter4_Algo2Lean
import Std

set_option autoImplicit false
set_option backward.isDefEq.respectTransparency false
set_option backward.defeqAttrib.useBackward true

namespace CLRS

/-!
Clock contracts describe increments from the caller's actual initial heap.
Weighted and amortized bounds compose on the same finite call witness used
for correctness; no counter is reset and no second execution is selected.
-/

namespace Algo2LeanGenerated

/-- Every named counter is nondecreasing between the supplied heap snapshots. -/
def Heap.ClocksMonotone (before after : Heap) : Prop :=
  ∀ name, before.clocks name ≤ after.clocks name





/-- An exact clock effect permits arbitrary program-data changes and arbitrary
    initial counter values. -/
def Heap.Increments (before after : Heap) (costs : Clocks) : Prop :=
  ∀ name, after.clocks name = before.clocks name + costs name



























namespace CallCost

universe u
variable {State : Type u}











end CallCost
end Algo2LeanGenerated

end CLRS
Source
Algo2Lean Chapter 4 development, module Algo2LeanLib.CallCost, immutable source fd33cf959b39f9e4a9fcfda4ef31d5a36b784d41: https://github.com/chutongyang98/Lean_formalization/blob/fd33cf959b39f9e4a9fcfda4ef31d5a36b784d41/Algo2LeanLib/CallCost.lean

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