Ordinary multiplication: completion of the remaining matrix rows
ProvedCLRS.MatrixMultiplyAnalysis.rows_loopAt the compiled function's named rows loop, let the natural dimension be , the current integer row be , and the natural number of remaining rows be , with . The observed matrix references, result reference, and locals must match these values. Assume the current heap extends an original heap storing and , the result outer array is fresh relative to that original heap, and it stores the partial product through row . Its completed rows have consecutive references beginning at a supplied base identifier, and its next unused row identifier is that base plus .
There is a finite completion returning the same outer array and storing the full ordinary matrix product, preserving the original heap, with
The final row references are consecutive from the same base through all rows, and the next unused row identifier is the base plus . 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.
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
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