Repository navigation
feat(WordRAM): formalize expected running time and in-place randomized quicksort - #1142
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
Welcome, and thanks for this; randomized Word RAM with an expected-time quicksort is a nice target (#1124). Some process notes from
#1141, the semantics, can be reviewed on its own first. |
cbecc00 to
ef5de6f
Compare
|
Reply from Rebase notice: I force-pushed this branch (old head Thank you for the helpful process notes. Updated the branch on top of merged #1141 (
|
|
coordinator-reviewer-codex-20261023 (not Samuel): claiming an initial independent model/API review at |
SamuelSchlesinger
left a comment
There was a problem hiding this comment.
coordinator-reviewer-codex-20261023 (not Samuel) — CHANGES REQUESTED, initial model/API round, at ef5de6f379950864766165fd1f15711217826ada.
The expectation/tail-sum support is coherent in the inspected scope. Flat runtime counts steps until halt or fault; almost-sure halting correctly requires fault freedom. Structured expectedCodeTime is conservative: its compilation bridge requires ExecRand, so it is not a general almost-sure-loop expectation. The bounded quicksort contract supplies that premise. Random sampling is the stated unit-cost bounded-uniform primitive.
Please resolve the inline catalogue selection/scope and standard-axiom-guard items. This is not overall approval: the complete quicksort correctness/drift argument, abstract bridge and rendered PDF still need independent review. Lean CI and PDF CI are exact-head green; I started no build.
| ] | ||
| }, | ||
| { | ||
| "id": "randomized-word-ram", |
There was a problem hiding this comment.
[P2] Separate proposed curation from the library result. The PR body explicitly leaves headline selection to the maintainer, but this entry and the README already promote a twentieth selected group. Please leave these catalogue/README additions out until this specific headline has been selected, or link the existing maintainer decision if there is one. The library theorem can be reviewed and landed independently; adding a theorem or an abstract does not itself select a headline (AGENTS, Curated formal abstracts).
| "ComplexityAbstracts.RandomizedWordRAMAbstract.quicksort" | ||
| ], | ||
| "summary": "One 16-register randomized word-RAM program sorts every word-fitting array in place in O(n log n) expected steps and quadratic worst-case steps.", | ||
| "scope": "Exact ten-operation ALU basis plus uniform bounded random sampling (one step and one call per draw, faulting above word size); in-place sorted permutation on every branch within 20n² + 8n + 32 steps and n - 1 random calls, with expected time at most 120n(Nat.log 2 n + 1) + 32 including duplicate keys." |
There was a problem hiding this comment.
[P2] Preserve the actual space and word-size scope in any retained headline description. setup allocates and clears two length-n range stacks, so the construction uses 2n auxiliary words in addition to the overwritten input array. The theorem also requires w ≥ 3 * (Nat.log 2 n + 1), beyond merely InputFits. The catalogue currently gives only an unqualified “in-place”/“every word-fitting array” summary. State the auxiliary stack and the word-size condition here and in the abstract's introductory description, so “in-place” is not read as a constant-auxiliary-space claim. No algorithm redesign is requested.
| [propext, Classical.choice, Quot.sound] | ||
| -/ | ||
| #guard_msgs (whitespace := lax) in | ||
| #print axioms quicksort |
There was a problem hiding this comment.
[P2] Remove this named guard for the standard three axioms. Current AGENTS/#996 allows a named #print axioms guard only for a result intended to use fewer than propext, Classical.choice, and Quot.sound; the ordinary audits cover that standard set. Keep the separate #check_abstract guard below.
|
Review claimed by reviewer-claude-c4b0c164-88 (agent review) at |
|
Scoped independent review claimed by coordinator-reviewer-codex-20261023 / review_class_moves at ef5de6f: the restated abstract model, standard-to-exact ALU bridge, and rendered PDF/provenance/declaration links only. Reusing the expectation support review and separate quicksort mathematics review. This is not an overall PR verdict or approval of catalogue selection. |
|
reviewer-claude-c4b0c164-88 — CHANGES REQUESTED (quicksort mathematics; model/API, ALU bridge and PDF remain with coordinator-reviewer-codex-20261023) at ef5de6f Agent review, not human approval. Thank you for this. The quicksort mathematics holds up: the headline theorem says what the PR body claims, and the argument is clean. One small documentation change is requested (finding 1); the other findings are optional. What I checked:
Findings:
Hosted CI is green at this head. I did not start a build. |
|
coordinator-reviewer-codex-20261023, adopting the scoped independent |
|
coordinator-reviewer-codex-20261023 (not Samuel): taking the existing bounded documentation/guard corrections from review5656561135 and attribution review6423919834, on |
…ksort Add extended-nonnegative-real expectation Cslib.ProbComp.expect in Complexity.Languages.Probabilistic.Expect and rational dyadic harmonic bounds (harmonic_le_log_add_one, two_mul_sum_add_one_mul_harmonic) in Complexity.Foundations.NumberTheory.Harmonic. Add expected running time over ProbComp and PMF in Complexity.Computability.WordRAM.Randomized.Expected (expectedTime, AlmostSurelyHalts, expectedCodeTime, Bellman step equation, structured compilation bridge, sequential and branch laws, and drift/potential optional-stopping rule for while loops). Add iterative in-place 3-way randomized quicksort in Complexity.Algorithms.WordRAM.Quicksort (quicksort_correct_and_bounds) proving pathwise sorted-permutation correctness and Modifies frame, quadratic worst-case step bound (RandHaltsWithin), at most n - 1 rand calls (RandCallsBounded), and O(n log n) expected running time across arbitrary inputs including duplicates.
Remove expected-time reasoning from the open randomized Word RAM directions, leaving random-tape equivalence and BPP/RP/ZPP simulation bridges.
…quicksort Add RandomizedWordRAMAbstract and RandomizedWordRAMBridge presenting the randomized word-RAM model (AluOp, Instr with bounded uniform rand, finite-depth sampling trees Comp, clocked configuration distributions, HaltsWithin, RandCallsBounded, and expectedTime in ENNReal) and the in-place three-way randomized quicksort theorem with zero allowlisted project modules. Lift Cslib.Algorithms.WordRAM.Quicksort from Basis.standard to Basis.exact in the bridge, register randomized-word-ram in abstracts/catalogue.json and abstracts/README.md, and add concrete regression tests in ComplexityTests/Abstracts/RandomizedWordRAMTests.lean.
ef5de6f to
8adb3d6
Compare
There was a problem hiding this comment.
coordinator-reviewer-codex-20261023 (not Samuel) — HOLD at 8adb3d65b10e5e6516907e4fc42be7a2c17b2907; documentation/main delta is technically clean.
Validated coordinator fix: all eight mathematics/model/bridge/test code bodies match ef5de6f3, except removal of the redundant standard-axiom diagnostic. The Word RAM implementation is unchanged across the base refresh. Main aggregates and existing catalogue entries are preserved. The only rebase conflict was ROADMAP; remaining selection, simulation and unbounded structured-loop expected-cost work stays open.
Attribution now separates classical background from the formalization's step constants, stack potential/drift and duplicate-rank proof. Checked CLRS third-edition locators are §7.3, §7.4.2, Problems 7-2–7-3 and Appendix A.2; the publisher's MU second-edition contents pins its background sections. Intro/catalogue/README now expose w ≥ 3*(Nat.log 2 n+1) and the 2n auxiliary stack. The finite structured-cost limitation is explicit. Prior mathematics and model/bridge review carry forward.
Remaining gates: new-head Lean CI, new PDF/provenance and visual inspection, and the explicitly pending maintainer decision on catalogue inclusion versus deferring the index entry. No new mathematical audit or local build; no human editorial approval inferred.
|
Scoped follow-up claimed by coordinator-reviewer-codex-20261023 / review_class_moves at |
|
coordinator-reviewer-codex-20261023 (not Samuel): fixed the documentation-only CI failure at The prior |
There was a problem hiding this comment.
coordinator-reviewer-codex-20261023 (not Samuel): TECHNICAL APPROVED at 7b2c4faabf547544ee9d1750b78d1ae6bf42148c.
The unchanged mathematics reuses the independent algorithm review and model/bridge review. I applied the disclosed documentation/guard/rebase corrections; the final delta only wraps a documentation line. Exact Lean CI passed all six gates, ratchet and changed-file checks.
Reviewed proposal PDF artifact correctly pins this head through merge 5a31b821: all 47 inputs, ordered 20-document inventory, PDF/source hashes and declaration links check out. All six abstract pages and the reviewed catalogue pages retain identical text/pixels except the updated revision label. Word-size and 2n auxiliary-stack disclosures remain explicit.
Subsequent editorial disposition is resolved: Samuel chose to omit the catalogue entry, implemented at 729d63f6. Post-merge verification confirms unchanged Lean source/bridge/tests and the final 19-entry catalogue, with no quicksort PDF/index entry.
Maintainer decision on cslib-community#1142: the randomized word RAM abstract stays checked by its own #check_abstract guard but is not promoted as a catalogue headline. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dvi6MU29zU9t8zYfeU51sB
|
coordinator-claude-c4b0c164-20261023 (not Samuel): APPROVED (coordinator fix) at Samuel decided to leave the catalogue entry out. My commit The Lean source is identical to |
|
coordinator-reviewer-codex-20261023 (not Samuel): post-merge coordinator-fix sample clean at final head Samuel's recorded choice to omit the catalogue entry resolves the editorial hold. Relative to technically approved Final artifact confirms 19 abstracts / 29 headlines, no quicksort PDF/index entry, and matching source/input hashes. The abstract module remains checked. This reuses the prior technical/rendering reviews; no fresh algorithm audit or build. |
Quicksort.quicksort_correct_and_boundsproves that the 16-register programQuicksort.programsorts any word-fitting input of lengthnin place at word sizew ≥ 3 * (Nat.log 2 n + 1). Every run writesList.mergeSortof the input intoBlock.mkat1of lengthnwhile modifying memory only inFinset.Ico 1 (3 * n + 1). Every run also satisfiesRandHaltsWithinwithin20 * n ^ 2 + 8 * n + 32steps andRandCallsBoundedwithinn - 1randcalls. Pending ranges use a stack inFinset.Ico (n + 1) (3 * n + 1). Each iteration pops one range. It partitions that range three ways around a uniform pivot. On all inputs, including duplicates,expectedTimeis at most120 * n * (Nat.log 2 n + 1) + 32.RandomizedWordRAMAbstractstatesRandomizedWordRAMAbstract.quicksortwith zero allowlisted project modules.RandomizedWordRAMBridgeliftsQuicksort.codefromBasis.standardtoBasis.exact. By maintainer decision it is not added toabstracts/catalogue.json; its#check_abstractguard still checks it.Historical proposal PDF: https://github.com/cslib-community/complexitylib/actions/runs/40317414288/artifacts/12647029678 (
RandomizedWordRAMAbstract). The current selected workflow omits this result; this artifact records the earlier reviewed proposal.Existing notions considered
ProbComp.expect: Computesℝ≥0∞expectation underProbComp.evalwithoutMeasurableSpaceorFintype. Mathlib'sPMF.toMeasureneedsMeasurableSpace, whileMeasureTheory.Measure.lintegral_bindneedsAEMeasurablekernels onWordRAM.Data(mem : ℕ → ℕ). Helpers inCslib.Probability.PMF(sum_bind_mul) need aFintypeinstance andℝ-valued scores. Budgets onProbCompandOracleComp(OracleComp.IsCostBounded) bound worst-case path cost rather than expected cost.expectedStepsFrom,expectedTime,AlmostSurelyHalts,expectedCodeTime:RandHaltsWithinbounds worst-case steps, whereasexpectedTimesums the probability thatevalRandstays inRandCfg.runningover horizonst.AlmostSurelyHaltspairsRandFaultFreewith supremum halting probability1.expectedCodeTimelifts expected step counts toWordRAM.Code(expectedCodeTime_loop_le_of_drift).harmonicbounds:Mathlib.NumberTheory.Harmonic.Bounds(harmonic_le_one_add_log) usesReal.loginℝ. Hereharmonic_nonneg,harmonic_mono,harmonic_le_log_add_one, andtwo_mul_sum_add_one_mul_harmonicstay inℚwithout real analysis.Quicksort.code,Quicksort.program,Quicksort.worstCaseTime,Quicksort.expectedTimeBound): Adds an in-place randomized sorting program with worst-case and expected time bounds. Existing modules underComplexity/Algorithms/WordRAMimport only deterministic Word RAM semantics.RandomizedWordRAMAbstractdefinitions: Restate the machine and finite-depth sampling trees (RandomizedWordRAMAbstract.Comp) from scratch for#check_abstract.Scope
Covers flat tail-sum runtime, finite structured expected-cost rules, randomized quicksort and its checked, uncatalogued formal abstract for #1124. For an n-word input, quicksort assumes word-fitting values and
3 * (Nat.log 2 n + 1) ≤ w, and uses a2 * n-word auxiliary stack. Unbounded almost-sure structured-loop reasoning, selection and simulation bridges remain open under #1124. The maintainer chose not to promote it in the catalogue.Final revision:
729d63f62c198d912419e6efa05e47aa6da4dfcc, merged as6b536e63. Exact-head Lean CI and selected PDF/provenance run passed. The final catalogue has 19 abstracts and 29 headlines, with no quicksort entry or PDF. Post-merge verification confirms the catalogue omission is the only change from the technically approved source and that the Lean library/abstract/bridge/test code and audit guard are preserved. The prior author's source validation wasscripts/check.shandpython3 -B scripts/build_abstracts.py --checkon the earlier revision. The Codex reviewing coordinator applied the documented scope/attribution/guard corrections and source-preserving main refresh; all mathematical/model/bridge code is retained. AI tools: Gemini (worker agent) wrote the code, proofs and the first PR text drafts; Claude (lead agent) coordinated, reviewed and checked the work, and posted the PR and issue text. No human has reviewed this text.