Imports
import CLRSLean.Chapter_04.Section_04_1_Maximum_Subarray
import CLRSLean.Chapter_04.Section_04_2_Strassen_Algorithm
import CLRSLean.Chapter_04.Section_04_3_Substitution_Method
import CLRSLean.Chapter_04.Section_04_4_Recursion_Tree_Method
import CLRSLean.Chapter_04.Section_04_5_Master_Theorem
import CLRSLean.Chapter_04.Section_04_6_Master_Theorem_All_InputChapter 4. Divide-and-Conquer
Chapter 4 has several good Lean targets. The current first pass contains both an algorithmic specification for the maximum-subarray problem and the recurrence proof infrastructure used by later divide-and-conquer analyses. Sections 4.3 and 4.4 provide the proof-method infrastructure used by the Master-method file and by the executable maximum-subarray and Strassen runtime proofs.
-
Section 4.1 - The maximum-subarray problem:
provedfor functional correctness and the executable abstract control-step runtime. The file proves that the candidate enumerator contains exactly the nonempty contiguous subarrays, and thatmaxSubarrayreturns a candidate with maximum sum. It also proves thatmaxCrossingSubarrayreturns a maximum-sum candidate among all candidates crossing a split. Finally,subarray_append_left_or_right_or_crossingandsubarray_append_optimal_of_casesprovide the proof interface for the recursive combine step, andmaxSubarrayDivideStep_correctproves the executable combine step itself. The executable midpoint layer usesmaxPrefixLinear_result_correct,maxSuffixLinear_result_correct, andmaxCrossingSubarrayLinear_result_correctto avoid exhaustive search at recursive nodes.maxSubarrayDivideCosted_resulterases the attached cost,maxSubarrayDivideCosted_correctproves the returned candidate, the costed prefix/suffix/crossing executions prove their exact linear scan counts, andmaxSubarrayDivideCosted_cost_eqplusmaxSubarrayDivideCost_unfoldconnect the measured run to its actual mixed floor/ceiling recurrence. Finally,maxSubarrayDivideCost_isBigTheta_nlognproves the all-inputTheta(n log n)bound. The remaining refinement target is a lower-level list-allocation/integer-operation/RAM cost model. -
Section 4.2 - Strassen's algorithm for matrix multiplication:
provedfor 2 by 2 block algebra, the recursive algorithm, and runtime. The file provesCLRS.Chapter04.strassen2x2_correct: Strassen's seven products reconstruct ordinary 2 by 2 block matrix multiplication over an arbitrary ring. It then packages this into the recursive algorithmCLRS.Chapter04.strassenRecon depth-indexed power-of-two squaresCLRS.Chapter04.SqMat, with a scalar base case, and provesCLRS.Chapter04.strassenRec_correctthat it computes the true matrix product at every depth.CLRS.Chapter04.strassenRec_padOneshows that zero-padding an input into the next power-of-two block preserves the top-left product. FinallyCLRS.Chapter04.strassen_runtime_bigThetaproves the CLRS runtime: the recurrenceT(n) = 7 T(⌊n/2⌋) + n²isΘ(n^(log₂ 7)), discharged through the Chapter 4 Master-theorem case-1 wrapper. -
Section 4.3 - The substitution method:
provedfor one-step recurrence bounds. The file proves upper-bound, lower-bound, sandwich, linear, and geometric substitution templates. -
Section 4.4 - The recursion-tree method:
provedfor additive finite level expansions. The file proves exact unrolling into level-cost sums and envelope bounds for the resulting finite sums. -
Section 4.5 - The master method:
provedfor exact-power recurrences. The file proves the normalized recurrence expansion and three Master-style exact-power criteria for bounded, constant, and tail-dominated normalized forcing, plus a polylog case-2 extension (CLRS.Chapter04.master_case2_polylog_forcing): polynomial normalized forcingc·j^k ≤ forcing ≤ C·j^kgivesT(b^i) = Θ((i+1)^(k+1)·a^i), i.e. the standardf(n) = Θ(n^(log_b a)·log^k n)textbook case. -
Section 4.6 - Proof of the master theorem:
partial. The file proves floor/ceiling all-input recurrence interfaces, extracts exact-power recurrences from those models, and proves a compiler-clean transfer bridge from exact-powerO,Ω, andΘbounds to all natural inputs under monotone cost and explicit power-sandwich hypotheses. It also proves the adjacent-powerNat.loginterval and a directallInput_bigTheta_of_powerSteptheorem that discharges those sandwich hypotheses from monotone comparison scales with eventual one-step control. The discretecriticalPowerScaleandcriticalPowerLogScale(including the polylogcriticalPowerLogPolylogScale) andtailDominatedScalewrappers now turn exact-powerT(b^i) = Θ(a^i),T(b^i) = Θ((i+1)a^i), and tail-dominated bounds into all-input bounds, and Section 4.6 packages the floor/ceiling recurrence forms of exact-power Master cases 1, 2, and 3 for these discrete scales. It also proves the natural-exponent comparison layer fora = b^p, exposing case-1 results asΘ(n^p)and case-2 results asΘ((⌊log_b n⌋+1)n^p). A real-log bridgeCLRS.Chapter04.criticalPowerScale_isBigTheta_realLogScalenow connects the discrete scalea^(⌊log_b n⌋)to the textbook scalen^(log_b a)for alla ≥ 1andb > 1, and the named exact/floor/ceiling case-1 wrappers now expose CLRS-facingΘ(n^(log_b a))bounds directly. A second bridge proves the discrete case-2 scale isΘ(n^(log_b a) log n), and the named exact/floor/ ceiling case-2 wrappers expose that textbook scale directly. The case-3 regularity bridge connects the discrete tail-dominated scale to the textbook forcing function. The remaining chapter work is lower-level representation and RAM refinement, not recursive Strassen, maximum-subarray algorithm-level runtime, or a missing Master case.
namespace CLRSnamespace Chapter04end Chapter04end CLRS