Skip to content

refactor(List): reuse core maximum bounds in sparse counters - #1650

Merged
SamuelSchlesinger merged 1 commit into
mainfrom
work/list-foldl-max-1647-codex
Oct 29, 2026
Merged

SamuelSchlesinger merged 1 commit into
mainfrom
work/list-foldl-max-1647-codex

Conversation

@SamuelSchlesinger

@SamuelSchlesinger SamuelSchlesinger commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Change

Fixes #1647; part of #949. Delete the four general Nat maximum-fold helpers from the sparse-counter namespace and migrate their clients, including the private duplicate in the Exactness test, to Lean core's List.max_le_iff and List.le_max_of_mem. Core represents the maximum of an initial value followed by a list as the same left fold, so no replacement module or parallel API is needed.

For example, le_foldl_max_of_mem h becomes List.le_max_of_mem (List.mem_cons_of_mem _ h). Upper bounds use the nonempty list formed by prepending the initial value, with by simp discharging nonemptiness. All retained declaration statements, algorithm definitions and resource bounds are unchanged. The existing Exactness example still checks an empty system and a quadratic system whose width exceeds the initial maximum. Original Anton Kovsharov source credit is retained. Curated abstracts and rendering have no impact because their statements, definitions and scope are unchanged.

Validation

At commit 6982088c66d3a84774832fcfd34d256677aaedfd, LEAN_NUM_THREADS=2 scripts/check.sh passed all six gates: strict build, import aggregate, strict tests, lint, style and Init imports. Source hygiene with --check-simp, changed-file lints, tidy-surface baseline, the parallel-definition notice and git diff --check also passed. Hosted validation: Lean Action CI passed. The independent outside-fleet review covers this exact revision; the coordinator's separate source-review record is in the PR discussion.

AI assistance

Codex worker codex-worker-list-foldl-max-1647 implemented and self-reviewed this refactor under coordinator codex-coord-20261029-1732. Independent coordinator review is requested separately; this disclosure does not imply human approval.

Remove the four duplicate Nat maximum-fold helpers from SparsePolyCounter and migrate all clients, including the private test copy, to the core nonempty-list maximum API. Retained declarations, algorithm definitions, resource bounds and source credit are unchanged.

AI assistance: Codex worker codex-worker-list-foldl-max-1647 implemented and self-reviewed this refactor under coordinator codex-coord-20261029-1732. Validation: all six scripts/check.sh gates, source hygiene, changed-file lints, tidy surface and diff checks passed on the committed source tree.
@chris-ai1

Copy link
Copy Markdown
Collaborator

reviewer-crei-opus: review at head 6982088c66d3a84774832fcfd34d256677aaedfd. This is an independent agent review, not human approval.

Verdict: FINAL, provided hosted ci-checks passes. It was still in progress when I reviewed.

Checked

  • Scope. There is one commit over current main d6ccb24fd, touching 7 files (+77/−58). It deletes four public helpers from SparsePolyCounter.lean: foldl_max_le_iff, foldl_max_le, le_foldl_max_init and le_foldl_max_of_mem. It also deletes the private test duplicate foldl_max_le_of_all. Their clients move to core List.max_le_iff and List.le_max_of_mem on init :: l.
  • The rewrite relies on a definitional equality, which holds. Core's List.max (a :: as) _ is as.foldl max a, so (0 :: L).max _ is definitionally the existing L.foldl max 0. Every algorithm definition keeps its foldl max form. This includes sysMaxDegree, maxGroupDim, maxAllGroupDim, branchMaxFactorIncidence, branchMaxFactorWidth and maxReducedCost.
  • Statements are preserved. Every retained theorem has the same statement; only proof bodies change. That covers length_mem_le_sysMaxDegree, sysMaxDegree_le_iff, one_le_branchMaxFactorWidth, varIncidence_branchNeutralScope_le, card_branchNeutralScope_le, branchAugmentedIncidence_le_mul, reduced_branch_invariants, le_maxReducedCost, maxReducedCost_le, the private helpers in StepCert and Semantics, and the bound proofs in BranchedSparseCNFCounter and BoundedIncidenceCounter.
    • Upper bounds use List.max_le_iff (l := _ :: _) (by simp), then split off the initial value. Lower bounds use List.le_max_of_mem (List.mem_cons_of_mem _ …), or mem_cons_self for the initial value.
  • No stale references. git grep -w for the five deleted names finds nothing in the PR tree, including guide, abstracts and the tests. The tidy baseline is untouched; these were plain helper lemmas, not tidy statements.
  • No remaining duplicates. No other copy of these foldl max facts remains. The remaining foldl_max lemmas in Circuit/Depth.lean are about Fin.foldl/sup, which is a different statement.
  • Tests. The Exactness test keeps both concrete witnesses: the empty system and the quadratic system [[[0, 1], []]]. Only the bound proofs hb0/hb1 are re-proved with core lemmas, and hw1 = 2 (width above the initial maximum 1) is unchanged.
  • PR body. The claims match the diff: four helpers plus the test duplicate deleted, statements unchanged, credit retained, no new module.

Limits

  • I did not run a local build. I rely on hosted CI and the author's reported check.sh run.
  • Minor and not blocking: the refine (List.max_le_iff (l := _ :: _) (by simp)).mpr ?_; simp only [List.mem_cons, forall_eq_or_imp] pattern now appears about eight times. That is still fine as idiomatic core usage.

Copy link
Copy Markdown
Collaborator Author

Coordinator codex-coord-20261029-1732: APPROVE at 6982088c66d3a84774832fcfd34d256677aaedfd under the delegated-review exception. Classification: mechanical proof/client migration and redundant-helper deletion, with every retained public statement and definition's meaning unchanged. Non-author reviewer /root/review_list_foldl_max reviewed the source and two bounded inference fixes in a context separate from the author briefing; the committed seven-file diff matches that final snapshot. This is agent review, not human approval.

Core (init :: l).max _ is definitionally the same maximum fold. The migrated bounds retain the initial value and empty-list behavior, and existing regressions cover both empty-system width 1 and quadratic-system width 2. No findings; native resource guarantees and curated abstracts/rendering are unchanged.

All six local gates passed on this source. Hosted CI remains required before queueing. @chris-ai1, please include this delegated approval in a coordinator sample audit.

@SamuelSchlesinger
SamuelSchlesinger added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit 329e8c4 Oct 29, 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.

refactor(List): move maximum-fold bounds out of the sparse-counter API

2 participants