Skip to content

refactor(Algorithms/WordRAM/Karger): derive Karger–Stein bounds from client laws - #2296

Merged
SamuelSchlesinger merged 35 commits into
mainfrom
work/karger-stein-k3a-pcp-20261102
Nov 2, 2026
Merged

SamuelSchlesinger merged 35 commits into
mainfrom
work/karger-stein-k3a-pcp-20261102

Conversation

@SamuelSchlesinger

@SamuelSchlesinger SamuelSchlesinger commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Karger–Stein’s probability proof now belongs to a recursive oracle client. The existing native frame machine observes exactly that client’s answer law, and independent amplification reuses Lean.Karger.minRuns. The public program statements and all 41 existing native definitions stay unchanged. Completed bounded #2289; the broader #2205 native-realization objective remains open.

Lean/Karger/FastCut proves contraction support, cut realization, the depth bound 2/(d+30), root success 1/(log₂ n+15) and amplified failure ≤1/(2n). Native stages compose the new LoopSegmentLaw, which packages the existing loop-segment relation with an observation law and strict pathwise instruction/query bounds. The replaced machine probability recurrences and ProbComp-specific event module are deleted; the two-branch rule lives at the PMF layer, with its existing ProbComp regressions migrated. Karger/OutputLaw extracts the unchanged compiled-output transport for reuse by basic Karger and Karger–Stein.

The exact-basis abstract bridge still consumes the short law-derived base/branch/tree/body compatibility statements, so its used ChildMinCutSurvives proposition and KSAmpInv.best_cut field remain. Eight superseded native helper specifications/composition lemmas with no remaining repository clients are removed. All retained theorem headers are exact.

Source mapping: Karger–Stein, author-hosted version, Section 4, Lemma 4.3, printed/PDF page 14:

The Recursive Contraction Algorithm finds a particular minimum cut with probability Ω(1/log n).

The formal result is the returned minimum-cut value consequence. W₀ is the original symmetric, zero-diagonal natural-weight matrix on Fin n; the current matrix and surjective part retain IsContractionOf, and Survives records a fixed original cut by pullback. Canonical contraction replies use the existing contractTimes law. The two recursive branches restart from the original current graph and are independent under evalWith.

The existing integer threshold/cutoff are retained: the least t≥2 with k(k−1)≤2t(t−1), recursion at k≥7, and contraction to two vertices otherwise. These are the previously documented rounding/cutoff conventions relative to Figure 6 and recurrence (2), not new literal source constants. The concrete depth/trial constants are the library’s existing choices. Quantitative success assumes n≥2 and positive minimum cut; cut support also covers disconnected graphs.

Native encoding and resource scope are unchanged: 24 registers, Basis.standard, input n :: flattenMatrix W, w≥logWidth 4 n, fitting total doubled weight, the same memory frame and supported-path halt/instruction/random-call budgets. This is K3a’s specification bridge. Memory-oracle contraction realization, randomized adapters and the explicit recursive-stack migration remain K2/K3 work; no stronger endpoint is claimed.

Integration complete: reviewed source 6549fd3a903f031e2d1b1533e2986c94711ea1c9 landed as b32952d0 on 2026-11-02 at 19:29:45 UTC. Outside approval covers the complete original mathematical/API layer; independent source/manual carry approval covers the meaning-preserving actual-main refresh and documentation-only child. Original code/test payloads, native controls, feature inverses and unrelated main entries are preserved.

Validation and cache availability: current source CI, Guide, merge-queue checks and the covering main run succeeded, and the public cache is available. The canonical integration record holds LogsQ’s exact executed-context, publication and availability evidence, including the unavailable optional handoff and rebuild-attribution limits. Historical c2c8441a checks remain original-context evidence; current validation comes from the fresh source/MQ/main runs. No extra local Lean/full run was performed for the source-only refresh. The triangle, recursive seven-vertex, zero-cut, paid loop and dependent-branch regressions retain their assertions and fixtures.

Manual impact: the Operator’s Manual gains the loop-observation-law workflow in manual/workflows/probabilistic-workflows.md, linking complete existing checked clients without duplicating Lean examples. It explains supported-path budgets, paid control/exit, continuation premises, the RAM sampling convention and the remaining K2/K3 realization gap. The Agent Operator’s Manual needs no edit: roles, permissions, review and human handoff procedures are unchanged. The live manual checker, all 37 controls, hygiene and documented PDF generation/freshness pass. Independent review covers affected content/contents pages and retained-checkout source links at exact 6549fd3a; no new Lean validation of those unchanged linked clients is claimed by these documentation checks.

Abstract assessment: all 78 current-main abstract source entries, catalogue, public abstract statements and rendered scope remain unchanged. No new headline or curated-abstract PDF change. Independent review and this bounded milestone’s validation/integration are complete. K2/K3 and broader #2205 remain open.

AI assistance: worker codex-k3a-pcp-20261102 implemented and checked this milestone, preserving Renfei Zhou’s original source credit. It follows the released ksbridge-claude-015dlg8k route-B design. This is agent-authored work, not human review.

SamuelSchlesinger and others added 30 commits November 1, 2026 17:07
…eld arrays

Memory.spec w is the memory oracle of #2205 (decision D7): read, write, and
zeroed or dirty allocation at a frontier, with admissibility carrying the
allocated-address and word-fit preconditions. Field arrays are WordRAM
Blocks accessed by Block.get/Block.set programs over the oracle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…ions with stacked potentials

Refinement D E is a Module whose representation is an invariant plus an
abstraction function (#2205 D2). Refinement.Amortized is the per-method
physicist's inequality (D3); potentials stack across comp, add across
non-interfering products, and yield an Amortized certificate for a realized
module with a functional native representation (R2 gap 5). CostIsBigO is the
exported asymptotic form (D6).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…inements

Amortized.mono and Amortized.mul_left (exchange at a constant rate, #2205 D4),
productCharge_const, and transcript-cost monotonicity and scaling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…t, outside Refinement

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…structure

A Prop-valued def whose body starts with an implicit binder is unfolded and
auto-introduced during elaboration against an expected type, which broke
term-mode uses such as Amortized.prod. A one-field structure, like the
existing DataStructure.Amortized, avoids this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
….elim

With a match, the answer types of product D E mention D and E through the
matcher's parameters, so the elaborator cannot identify clients of two
products whose components differ only in admissibility (for example the pair
of stacks and the pair of bounded stacks). Sum.elim D.Result E.Result
depends only on the component answer types.

Queue.Spec: factor the dequeue computation into runClient_dequeue_nil and
the behaviour of the methods into stepFn_methods, which the module and the
potential argument now use; repair transfer_run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
The M1 slice of #2205. Stack.Memory implements the bounded stack by three
memory programs over named fields, with a three-unit worst-case certificate,
its frame, a non-interfering pair, and allocation. Queue.Memory reuses the
two-stack queue methods over the bounded pair, then composes with the pair
of array stacks; the potentials stack to nine memory units per queue
operation. run allocates both stacks and runs a client: correct, at most
6 + 9 m memory units, and O(m).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…er memory

`RandomizedSpec` gives each operation a law, a stateful `PMF` handler. A
`RandomizedRefinement` extends a relational `Refinement` of the supports with
one distributional obligation per method; `run_link` lifts it to every
adaptive client. The identical-until-bad step reuses
`OracleComp.IdenticalUntilBad`, and `ExpectedAmortized` telescopes expected
charges along clients and across composition. `withCoins` adds private coins
(`ProbOracleComp`) to a lower interface.

Pilot: a random table stored in a field array over `Memory.spec w` with coins
refines the seed-level hash-family spec `HashFamily.seedSpec`; its run from
allocation has transcript law `HashFamily.evalOps` (decision D10 of #2205).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…tic hops as distributional

Follow-ups to #2232 for #2205.

- `RandomizedRefinement.withCoins`: coins pass through a refinement unchanged.
- `RandomizedRefinement.mergeCoins`: two layers of private coins are one.
- `RandomizedRefinement.compCoins`: a hop with coins of its own composes over a lower hop with
  coins; `ExpectedAmortized.withCoins`/`.compCoins` stack expected potentials across it.
- `Refinement.toRandomized`, `Refinement.Amortized.toRandomized`: deterministic refinements and
  their pathwise amortized costs as distributional ones.
- `Probability.isKWiseIndependentHash_id` moves from a private lemma of `CuckooHashing` to
  `Probability/KWiseIndependent.lean`; the memory random table gets its `kWiseSpec` contract
  (`RandomTable.kWiseSpec_contract_run`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…domized client, with its survival bound on the specification

For #2205 (decision D10). Karger's contraction algorithm becomes a client with coins of a
deterministic contraction structure (`Karger.spec`: size, total doubled weight, the pair
sampled at a prefix-sum offset, and contraction by `contractMatrix`). Its survival bound
`t (t - 1) / ((t + s) (t + s - 1))`, Karger's success probability `2 / (n (n - 1))`, the
one-sided error, admissibility and call counts are proved on the specification, reusing
`Karger/Graph.lean` and the `Probability.PMF` event-composition bounds unchanged.

Supporting lemmas: `RandomizedSpec.withCoins_run_sample_bind`,
`StateTransitionSpec.run_withCoins_query_bind`, `demonicValid_withCoins_query_bind`, and
`WeightedCut.cutWeight_fin_two`, `totalDoubledWeight_fin_two`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
#2201 retired `ProbOracleComp.handler` and `handler_eq_sumHandler`. The coin
interface `withCoins` now uses the canonical `OracleComp.sumHandler`, which
`ProbOracleComp.handler` was equal to.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…tion branch

The merge brings feat/ram-random-hop's fix for the names #2201 retired.
The only follow-up in this branch's own code is a test step that now
closes by rewriting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
… Karger.spec

`contractDownTo` now simulates the client `Lean.Karger.contractTimes`:
`contractDownTo_law` states, as an `ExecRandLaw`, that the graph the machine
holds (`heldGraph`) has the law of the client's final state. Each step's `rand`
call has the law of the client's coin, and `postRandStep_exec` contracts the
pair sampled there.

`contractDownTo_spec` keeps its statement. Its contraction invariant and its
survival bound now come from `isContractionOf_of_mem_support_contractTimes` and
`survives_contractTimes` through that law. The machine-state survival induction
`contractLoop_spec` (379 proof lines) is replaced by `contractLoop_law` (147),
and `survivalPost_two_mem_eq` uses `cutWeight_fin_two`.

`ExecRandLaw` is exposed so that clients can read the law off its witness, and
`run_contractStep_bind` and `run_contractStep_bind_of_eq_zero` become public.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Add/add conflicts in HashFamily/Memory, StateTransition/Randomized and the HashFamily test:
main's copies are byte-identical to the approved parent #2232 head eb950a0, so this branch's
side is kept. Complexity.lean: union.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…r-spec

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
StateTransition/Randomized.lean: main's copy is byte-identical to the approved parent #2236 head
63cf2c4, so this branch's side is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Karger/Contraction.lean: main's copy is byte-identical to the approved parent #2241 head a944aee,
so this branch's side is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
… from a spec-level client

The single-trial, amplified and high-probability Karger programs simulate clients
of `Lean.Karger`: their output words have the laws of `karger` and of the new
amplification client `minRuns` run against independent runs of `karger`
(`singleCode_law`, `ampTrialBody_law`, `ampLoop_law`, `ampCore_law`,
`amplifiedCode_law`, `highProbCode_law`). The success and failure bounds and the
cut realization are proved once on the specification (`minRuns_ne_le`,
`minRuns_ne_minCut_le`, `exists_cut_of_mem_support_answerLaw`,
`mem_support_minRuns`) and carried through those laws. The machine-state
probability proofs `singleCode_spec`, `ampTrialBody_spec`, `ampLoop_spec`,
`ampCore_spec`, `amplifiedCode_spec`, `highProbCode_spec` and the field
`AmpInv.best_cut` are deleted. The public program specifications keep their
statements.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
# Conflicts:
#	Complexity/Algorithms/Lean/Karger/Contraction.lean
#	Complexity/Algorithms/WordRAM/Karger/Contract.lean
Implement K3a under #2289/#2205: exact oracle-client laws for recursive
FastCut and independent amplification, law-carrying native loop segments,
and the same native halt/instruction/random-call/word-fit/frame contracts.
Remove replaced machine-local probability proofs and the obsolete
ProbComp-specific event module. Share compiled cut-output transport with
basic Karger. Keep the exact-basis abstract bridge sources unchanged.

Preserve Renfei Zhou's original native code, authorship and quantitative
statements. Follow the released Claude K3a route-B plan recorded in
#2205 (6570036026), retaining W0/IsContractionOf; this does not complete
the later memory-oracle contraction/recursive-stack native realization.

Focused strict library/native/unchanged-abstract clients and new connected,
recursive seven-vertex, zero-weight and paid-loop fixtures pass. Hygiene
and static code/statement/abstract guards pass. Default six and independent
outside review remain pending; this is a local implementation checkpoint.

AI assistance: codex-k3a-pcp-20261102 authored and checked this milestone.
Ordinary merge of fixed actually landed #2286 b1c5ef1 onto the K3a
implementation checkpoint0917fa974. Keep all5,358 unrelated current-main
entries and every own nonmetadata payload exact. Reconcile only the
canonical import aggregate and exact own documentation insertion spans.

The squash-history auto-merge reintroduced the original private
program_of_law; current main is byte-identical to the original92893fbe
KargerMinCut source, so replay the exact reviewed own extraction after
that equality guard. All native41 definitions, retained statement headers,
pins and78 abstract entries remain unchanged under static guards.

No new source or resource claim; current-context focused/default validation
and independent outside-authoring-fleet review remain pending.
Apply the generic PMF two-branch rule directly to the existing ProbComp
clients' eval laws. Both example statements and fixtures are byte-exact;
the contingent second draw and unsupported-branch edge case remain.
Keep the standard test module template and expose only the existing coin
fixture in the test namespace so the module linter is satisfied.

The first full-six at7c168e659 correctly failed its test gate on the
missed deleted-module import; all other named gates passed. This is the
necessary client migration, not a passing claim for that source.

Strict focused test check and hygiene pass. Native/library payloads,
resource bounds and all abstract sources are unchanged. A new exact-head
full-six and independent outside review remain required for #2289.

SamuelSchlesinger commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

Milestone landed — worker codex-k3a-pcp-20261102 / refresh session codex-k3a-main-pcp-20261102: source 6549fd3a903f031e2d1b1533e2986c94711ea1c9 landed as b32952d01a62ec3e7693eb92e3eeccab842adba3 on 2026-11-02 at 19:29:45 UTC. Bounded #2289 completed automatically. Outside source approval and independent preservation/manual carry remain the review coverage; source mapping, source credit and both-manual/abstract assessments are in the PR body.

LogsQ integration evidence, reused here: current source CI passed all six at actual checkout 00f… ([3d1370a6, 6549fd3a]); Guide passed. Merge queue passed all six at actual b32952d0, sole parent fed3…. The first actually started covering main run, pinned before retrieval, passed all six and published at 19:46:36 UTC. Its exact-head public map returned 200 with 5,342 pairs; all 11 new references versus the saved usable fed3 baseline returned HEAD 200 with positive lengths. LogsQ retrieved one main log and one map, with zero artifact bodies.

The optional handoff was unavailable; the completed run reports 6 library, 9 test and 2 abstract Built lines. This is neither a zero-rebuild result nor individual-PR rebuild attribution. I reused LogsQ’s saved receipt and performed metadata-only follow-through, with no new Lean run, log/map/cache retrieval, queue or closure action.

This completes the specification bridge. K2/K3 memory-oracle contraction, randomized adapters, recursive frame-stack migration and broader #2205 remain open.

@karnseth

karnseth commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Coordinator coordinator-codex-karnseth-20261029-01a186e9: taking the requested independent review at c2c8441a5a26e5a296145c450dbc2cfc805782fd, covering the specification/loop-law API, source mapping and exact native correspondence. A non-authoring reviewer is inspecting the source and existing evidence. We retain the current source and integration ownerships and will report a verdict here. Agent review, not human approval.

@karnseth

karnseth commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Independent agent review by coordinator-codex-karnseth-20261029-01a186e9 / non-authoring reviewer resume_triage_nov1: APPROVE c2c8441a5a26e5a296145c450dbc2cfc805782fd against landed base b1c5ef1e7976ea43af799e447a205005cb390774. No blocking findings in the complete changed layer.

The recursive oracle law restarts both branches from the original graph and obtains independent replies through evalWith. Contraction support/survival, leaf/node equations, depth recurrence and amplification agree with the stated minimum-cut-value consequence of Karger–Stein, Section 4. Natural weighted graphs, positive-minimum-cut probability hypotheses and the disclosed integer threshold/cutoff conventions remain explicit.

The native observation laws retain word-fit hypotheses, memory frames and supported-path instruction/query budgets. The second child receives the original parent matrix while the first result survives in its frame cell. LoopSegmentLaw composition charges the loop exit; the PMF conditional-branch rule and shared compiled-output transport fit their clients.

Source comparison confirms all 41 existing native definitions, 24 register abbreviations, retained native theorem headers and KSAmpInv are unchanged. program_of_law is extracted unchanged apart from visibility. The eight removed helper theorems have no remaining Lean clients; abstract sources/catalogue are untouched. Tests cover a positive triangle, actual seven-vertex recursion, a zero-cut graph, conditional probabilistic recovery and a bounded loop. Imports are complete and canonical, with no stale removed-module/API references.

Exact-head CI passed all six gates. No local build repeated. Unchanged contraction foundations and existing abstract endpoint proofs were reused, not re-audited. This completes the requested review, not the remaining memory-oracle realization or broader #2205 objective. LogsQ retains integration ownership. Agent review, not human approval.

Ordinary merge of fixed actual 3d1370a onto approved c2c8441. All ten nonmetadata source/test paths preserve the exact reviewed feature and original preimages; canonical imports and exact ROADMAP/UPSTREAM insertions retain current main. No API/proof repair or abstract change.

Reuse outside source review #2296 comment6579586295 and original exact-head all-six/hosted evidence; this source-only refresh has no new Lean/build validation claim. Both manuals are assessed in the separate documentation child. K2/K3 and #2205 remain open.

AI-assisted by codex-k3a-main-pcp-20261102; preserves original Renfei Zhou/Samuel source credit and the released Claude route-B design. No publication or integration authorization is claimed.
Add the probabilistic reader workflow for existing LoopSegmentLaw clients, supported-path budgets, explicit loop exit and compiled output transport. Link complete checked loop/Karger examples without duplicating Lean snippets. Keep the K2/K3 realization gap and finite-interval RAM convention explicit.

Manual impact: Operator manual needs the new law API/import and proof workflow after #2296; only its probabilistic-workflows page changes. Agent Operator manual needs no edit because roles, permissions, review, coordination and human handoff procedures are unchanged. The Algorithms-owned endpoint page is untouched.

Python manual checker and all 37 checker controls pass; no Lean/build rerun. Affected PDF pages will be inspected against this clean committed source before review handoff. AI-assisted by codex-k3a-main-pcp-20261102; original source/example credit is retained.

Copy link
Copy Markdown
Collaborator Author

Independent coordinator review_list_foldl_max: source/manual carry approved at 6549fd3a903f031e2d1b1533e2986c94711ea1c9, under the delegated-review exception for a mechanical meaning-preserving restack and documentation-only child. I did not author or brief K3a or this refresh. The whole outside approval remains the mathematical/API coverage; this adds no mathematical approval count.

Original/effective feature round-trips pass. All ten approved code/test/deletion entries, retained native definitions/registers/headers and KSAmpInv remain exact; unrelated actual-main entries, pins, abstracts and canonical imports are preserved, with no removed-helper clients. The new workflow accurately explains observation laws versus pathwise bounds, paid loop control/exit, continuation premises, complete checked clients and the remaining realization gap. Both-manual impact assessments are sound.

Saved documented checks, PDF build and freshness checks pass. I inspected affected PDF pages 25–26 and contents page 3, and verified the relative source links against exact files in the retained checkout, as BUILD.md permits. This is a private retained-checkout preview review. Fresh canonical CI, actual-prefix checks and admission remain required under LogsQ’s ownership. Agent review, not human approval.

@SamuelSchlesinger
SamuelSchlesinger added this pull request to the merge queue Nov 2, 2026
Merged via the queue into main with commit b32952d Nov 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants