Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Ordinary multiplication: completion of the remaining matrix rows

Proved
CLRS.MatrixMultiplyAnalysis.rows_loop

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

algo2leanalgo2lean-clrs-chapter4-fd33cf9algorithmsclrslinear-algebrarunning-timetextbook

At the compiled function's named rows loop, let the natural dimension be nnn, the current integer row be s≥0s\ge0s≥0, and the natural number of remaining rows be mmm, with s+m=ns+m=ns+m=n. The observed matrix references, result reference, and locals must match these values. Assume the current heap extends an original heap storing AAA and BBB, the result outer array is fresh relative to that original heap, and it stores the partial product through row sss. Its completed rows have consecutive references beginning at a supplied base identifier, and its next unused row identifier is that base plus sss.

There is a finite completion returning the same outer array and storing the full ordinary matrix product, preserving the original heap, with

Δmultiply_add=mn2.\Delta\texttt{multiply\_add}=mn^2.Δmultiply_add=mn2.

The final row references are consecutive from the same base through all nnn rows, and the next unused row identifier is the base plus nnn. This is a local outer-loop contract; all representation and allocation invariants are explicit hypotheses rather than an assumption that the loop was reached from entry.

Platform namespace. The imported Chapter 4 source declarations live under CLRS in this upload to avoid collisions with independently published compiler versions. The immutable source reference retains the original declaration names.

Catalog organization (2026-10-11). This record was retired from the active Chapter 4 catalog to focus the presentation on three algorithms and four reusable recurrence results. Its mathematical statement and proof status are unchanged, and existing imports and links remain valid. The retained results are CLRS.Chapter4Publication.MatrixMultiply.correctness_and_running_time. Supporting lemmas needed by the retained results are included in their accepted proof files.

Preamble
import Definitions.Def_CLRS_Chapter4_Algo2Lean
import Definitions.Def_CLRS_Chapter4_Algo2LeanExamples_MatrixMultiply
import Definitions.Def_CLRS_Chapter4_Algo2LeanExamples_MatrixMultiplyGenerated
import Definitions.Def_CLRS_Chapter4_Algo2LeanExamples_MatrixMultiplyPoints
import Definitions.Def_CLRS_Chapter4_Algo2LeanLib_MatrixHeap
import Std

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

namespace CLRS
end CLRS
open CLRS
open MatrixMultiplyLibrary MatrixMultiplyLibrary.Algo2LeanGenerated
open Algo2LeanCore Algo2LeanGenerated
open Algo2LeanCore.MatrixHeap
namespace CLRS.MatrixMultiplyAnalysis
end CLRS.MatrixMultiplyAnalysis
open CLRS.MatrixMultiplyAnalysis

Formal statement
theorem CLRS.MatrixMultiplyAnalysis.rows_loop (count : Nat) (state : Configuration) (original : Heap)
    (a b result : CollectionRef) (av bv : Values) (n : Nat) (first : Int)
    (location : matrix_multiply.At.rows_loop state)
    (ra : matrix_multiply.Local.a state = some a)
    (rb : matrix_multiply.Local.b state = some b)
    (rn : matrix_multiply.Local.n state = some (n : Int))
    (rr : matrix_multiply.Local.result state = some result)
    (ri : matrix_multiply.Local.row state = some first)
    (bound : first + (count : Int) = n) (nonnegative : 0 ≤ first)
    (va : Stored original a av) (vb : Stored original b bv)
    (extension : Extends original state.heap) (fresh : original.nextCollection ≤ result)
    (current : Stored state.heap result (partialProduct av bv n first))
    (base : Nat) (allocated : state.heap.nextRef = base + first.toNat)
    (references : RowReferences state.heap result base first.toNat) :
    ∃ after, matrix_multiply.CallFrom state after result ∧ Extends original after ∧
      Stored after result (product av bv n) ∧
      after.clocks = (state.heap.tick "multiply_add" (count * (n * n))).clocks ∧
      after.nextRef = base + n ∧ RowReferences after result base n := by sorry
Source
Algo2Lean Chapter 4 development, declaration MatrixMultiplyAnalysis.rows_loop, immutable source fd33cf959b39f9e4a9fcfda4ef31d5a36b784d41: https://github.com/chutongyang98/Lean_formalization/blob/fd33cf959b39f9e4a9fcfda4ef31d5a36b784d41/examples/matrix_multiply.algo; https://github.com/chutongyang98/Lean_formalization/blob/fd33cf959b39f9e4a9fcfda4ef31d5a36b784d41/examples/analysis/matrix_multiply.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