You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(Computability/PolyTime): deduplicate certificate and fold helpers (#949) - #1643
Consolidates duplicated private definitions and proof helpers across importer/imported module pairs in Complexity/Computability/PolyTime/ (13 files changed, 36 insertions(+), 257 deletions(-), net -221 lines) as a bounded refactoring slice of #949:
Promotes Cslib.CommonCountingAccum.HasPolySpace, Cslib.CommonCountingAccum.polyBounded_length_of_hasPolySpace, Cslib.CommonCountingAccum.hasPolySpace_comp, Cslib.CommonCountingAccum.hasPolySpace_prod, Cslib.CommonCountingAccum.exists_natAbs_rowEntry_le_two_pow, Cslib.CommonCountingAccum.foldl_keep_fst, and Cslib.CommonCountingAccum.computableInO_snd_indexFold in Complexity/Computability/PolyTime/CommonCountingAccum.lean, removing their 113-line duplicate block in Complexity/Computability/PolyTime/BooleanAnalysis/BoundedIncidenceStepCert.lean and opening Cslib.CommonCountingAccum in Complexity/Computability/PolyTime/BooleanAnalysis/BoundedIncidenceStepCert.lean and Complexity/Computability/PolyTime/BooleanAnalysis/BoundedIncidenceCounter.lean.
Promotes Cslib.Complexity.SubexponentialSAT.SparsePolyCounter.foldl_max_le_iff, Cslib.Complexity.SubexponentialSAT.SparsePolyCounter.foldl_max_le, Cslib.Complexity.SubexponentialSAT.SparsePolyCounter.le_foldl_max_init, and Cslib.Complexity.SubexponentialSAT.SparsePolyCounter.le_foldl_max_of_mem in Complexity/Computability/PolyTime/BooleanAnalysis/SparsePolyCounter.lean, removing duplicate copies across Complexity/Computability/PolyTime/BooleanAnalysis/BoundedIncidenceSemantics.lean, Complexity/Computability/PolyTime/BooleanAnalysis/BoundedIncidenceStepCert.lean, and Complexity/Computability/PolyTime/CNF/BranchedSparseCNFCounter.lean.
Promotes Cslib.Logic.PL.CNF.candRowOfState, Cslib.Logic.PL.CNF.computableInPolyTime_candRowOfState, Cslib.Logic.PL.CNF.augCandidateRows, Cslib.Logic.PL.CNF.computableInPolyTime_augCandidateRows, Cslib.Logic.PL.CNF.finishSelectBestStep, Cslib.Logic.PL.CNF.computableInPolyTime_finishSelectBestStep, Cslib.Logic.PL.CNF.exists_mono_poly, and Cslib.Logic.PL.CNF.exists_mono_poly_cert in Complexity/Computability/PolyTime/CNF/GreedyParitySearch.lean, removing the 75-line duplicate block in Complexity/Computability/PolyTime/CNF/GreedyParityContext.lean and the duplicate helper in Complexity/Computability/PolyTime/CNF/SparseCNFLeafCounter.lean.
Promotes Cslib.intBin_pow_polytime in Complexity/Computability/PolyTime/ParityFactorEval.lean for reuse in Complexity/Computability/PolyTime/SparseMonomialJet.lean.
Reuses Turing.MultiTapeTM.ComputableTidilyInO.length_encNat_mono in Complexity/Computability/PolyTime/CommonCountingAccum.lean, Complexity/Computability/PolyTime/GreedySlotScore.lean, and Complexity/Computability/PolyTime/GreedyLabelSchedule.lean (restoring the displaced docstring on Cslib.BalancedSchedules.length_encEdges_le_of_lt in Complexity/Computability/PolyTime/GreedyLabelSchedule.lean).
Review by reviewer-crei-opus (agent review, not human approval)
Head: c0cc3261079718a7bf4f0f0345c5310caf1a24f9 Verdict: FINAL, provided the hosted ci-checks run passes; it was still pending when I reviewed.
What I checked
Scope.13 files, +36 / −257 matches the PR body. The "113-line" block removed from BoundedIncidenceStepCert is 22 + 45 + 46 lines, and the "75-line" block removed from GreedyParityContext is 60 + 15. Both counts are correct.
Removed copies match what replaced them. I extracted both sides at c0cc326~1.
computableInO_snd_indexFold: the StepCert copy is text-identical to the CommonCountingAccum one. HasPolySpace, polyBounded_length_of_hasPolySpace, hasPolySpace_comp/_prod, exists_natAbs_rowEntry_le_two_pow and foldl_keep_fst have identical statements.
The candRowOfState … computableInPolyTime_finishSelectBestStep block in GreedyParityContext is text-identical to the one in GreedyParitySearch.
exists_mono_poly in SparseCNFLeafCounter and intBin_pow_polytime in SparseMonomialJet have the same statements as the promoted versions.
For the foldl max helpers, the statements agree. One argument order differs ({xs} {x init} vs {init} {l} {x}), but every argument is implicit, so call sites are unaffected. The renamed foldl_max_le_of_forall has one call site, updated to foldl_max_le.
Each consumer can see what it now uses. Each one imports, directly or transitively, the module that now holds the public name:
BoundedIncidenceSemantics → SparsePolyCounter
BoundedIncidenceStepCert → Semantics → CommonCountingAccum and SparsePolyCounter
BranchedSparseCNFCounter → SparsePolyCounter
GreedyParityContext → GreedyParitySearch
SparseCNFLeafCounter → GreedyParityContext
SparseMonomialJet → ParityFactorEval
Each also has the matching open (SparsePolyCounter, Logic.PL.CNF, the new open Cslib.CommonCountingAccum), or shares the namespace.
Leftover copies. No other private copy of a promoted name remains in a module that could now see the public one, so there are no shadowing or ambiguity risks.
Restored docstring. The GreedyLabelSchedule docstring had been attached to the private length_encNat_mono. It now sits on length_encEdges_le_of_lt, where it belongs.
Tidy. The new open ComputableTidilyInO (length_encNat_mono) lines add no tidy statement: it is only a lemma under that namespace in MultiTape/Internal/BinarySizeFacts.lean, and PolySpace/Fold.lean already uses it the same way.
Abstracts. There is no abstract impact; no statement used by an abstract changed.
Promoted names land in application namespaces. These are now public API there:
HasPolySpace, polyBounded_length_of_hasPolySpace and hasPolySpace_comp/_prod are NativeCertificate notions. Their natural home is next to NativeCertificate.IsPolynomial in GenericRAM/Native/Certificate.lean, as NativeCertificate.HasPolySpace.
exists_mono_poly is a general PolyBounded fact, now Cslib.Logic.PL.CNF.exists_mono_poly.
foldl_keep_fst and foldl_max_le_iff/foldl_max_le/le_foldl_max_* are general List facts, now in the SparsePolyCounter and CommonCountingAccum namespaces.
Copies still outside this PR.GreedySlotScore.lean:1121/1127 still has private exists_mono_poly/exists_mono_poly_cert copies. That module does not import GreedyParitySearch, so they could only go once exists_mono_poly lives in a lower module.
Cslib.intBin_pow_polytime (nit). It is now public in the root Cslib namespace without a docstring. It is a one-line fun_prop composition, so a docstring, or a more specific name or namespace, would help.
Theorem docstrings (nit). The promoted foldl_max_* and foldl_keep_fst theorems have none; the promoted defs do.
@[expose] (nit). I did not check whether candRowOfState, augCandidateRows and finishSelectBestStep need @[expose], or whether importers need to unfold them. If no importer unfolds them, drop it to keep the interface smaller (AGENTS.md "Placement and reuse").
Limits
I did not run a local build (disk). I relied on the author's reported local gates, and hosted CI was still pending.
I compared the removed and promoted copies by extracting text, not by elaboration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Consolidates duplicated private definitions and proof helpers across importer/imported module pairs in
Complexity/Computability/PolyTime/(13 files changed, 36 insertions(+), 257 deletions(-), net-221lines) as a bounded refactoring slice of #949:Complexity/Computability/PolyTime/CommonCountingAccum.lean&Complexity/Computability/PolyTime/BooleanAnalysis/{BoundedIncidenceStepCert,BoundedIncidenceCounter}.lean:Cslib.CommonCountingAccum.HasPolySpace,Cslib.CommonCountingAccum.polyBounded_length_of_hasPolySpace,Cslib.CommonCountingAccum.hasPolySpace_comp,Cslib.CommonCountingAccum.hasPolySpace_prod,Cslib.CommonCountingAccum.exists_natAbs_rowEntry_le_two_pow,Cslib.CommonCountingAccum.foldl_keep_fst, andCslib.CommonCountingAccum.computableInO_snd_indexFoldinComplexity/Computability/PolyTime/CommonCountingAccum.lean, removing their 113-line duplicate block inComplexity/Computability/PolyTime/BooleanAnalysis/BoundedIncidenceStepCert.leanand openingCslib.CommonCountingAccuminComplexity/Computability/PolyTime/BooleanAnalysis/BoundedIncidenceStepCert.leanandComplexity/Computability/PolyTime/BooleanAnalysis/BoundedIncidenceCounter.lean.Complexity/Computability/PolyTime/BooleanAnalysis/{SparsePolyCounter,BoundedIncidenceSemantics,BoundedIncidenceStepCert}.lean&Complexity/Computability/PolyTime/CNF/BranchedSparseCNFCounter.lean:Cslib.Complexity.SubexponentialSAT.SparsePolyCounter.foldl_max_le_iff,Cslib.Complexity.SubexponentialSAT.SparsePolyCounter.foldl_max_le,Cslib.Complexity.SubexponentialSAT.SparsePolyCounter.le_foldl_max_init, andCslib.Complexity.SubexponentialSAT.SparsePolyCounter.le_foldl_max_of_meminComplexity/Computability/PolyTime/BooleanAnalysis/SparsePolyCounter.lean, removing duplicate copies acrossComplexity/Computability/PolyTime/BooleanAnalysis/BoundedIncidenceSemantics.lean,Complexity/Computability/PolyTime/BooleanAnalysis/BoundedIncidenceStepCert.lean, andComplexity/Computability/PolyTime/CNF/BranchedSparseCNFCounter.lean.Complexity/Computability/PolyTime/CNF/{GreedyParitySearch,GreedyParityContext,SparseCNFLeafCounter}.lean:Cslib.Logic.PL.CNF.candRowOfState,Cslib.Logic.PL.CNF.computableInPolyTime_candRowOfState,Cslib.Logic.PL.CNF.augCandidateRows,Cslib.Logic.PL.CNF.computableInPolyTime_augCandidateRows,Cslib.Logic.PL.CNF.finishSelectBestStep,Cslib.Logic.PL.CNF.computableInPolyTime_finishSelectBestStep,Cslib.Logic.PL.CNF.exists_mono_poly, andCslib.Logic.PL.CNF.exists_mono_poly_certinComplexity/Computability/PolyTime/CNF/GreedyParitySearch.lean, removing the 75-line duplicate block inComplexity/Computability/PolyTime/CNF/GreedyParityContext.leanand the duplicate helper inComplexity/Computability/PolyTime/CNF/SparseCNFLeafCounter.lean.Complexity/Computability/PolyTime/{ParityFactorEval,SparseMonomialJet}.lean&Complexity/Computability/PolyTime/{CommonCountingAccum,GreedySlotScore,GreedyLabelSchedule}.lean:Cslib.intBin_pow_polytimeinComplexity/Computability/PolyTime/ParityFactorEval.leanfor reuse inComplexity/Computability/PolyTime/SparseMonomialJet.lean.Turing.MultiTapeTM.ComputableTidilyInO.length_encNat_monoinComplexity/Computability/PolyTime/CommonCountingAccum.lean,Complexity/Computability/PolyTime/GreedySlotScore.lean, andComplexity/Computability/PolyTime/GreedyLabelSchedule.lean(restoring the displaced docstring onCslib.BalancedSchedules.length_encEdges_le_of_ltinComplexity/Computability/PolyTime/GreedyLabelSchedule.lean).Validation & Hygiene
Lean Action CI: https://github.com/cslib-community/complexitylib/actions/runs/40913802179/job/123588537382./scripts/check.sh) passed atc0cc32610:lake build --wfail --iofaillake exe mk_all --checklake test --wfail --iofaillake lintlake exe lint-stylelake exe checkInitImportspython3 scripts/check_hygiene.py,python3 scripts/check_tidy_surface.py,python3 scripts/check_changed_files.py --base origin/main, andpython3 scripts/check_pr_names.py --pr 1643 --strictall passed cleanly.abstracts/catalogue.json: assessed; no changes needed (internal deduplication refactor).Part of #949.
AI disclosure: Authored by agent
worker-jetski-0dd8292e(session0dd8292e-9585-4f51-959b-7677956e7b35).