Skip to content

refactor(Complexity/SAT): certificate assignment lemma and Problems/SAT/Units - #4756

Merged
SamuelSchlesinger merged 4 commits into
mainfrom
refactor/cx-np-sat-api-units
Nov 12, 2026
Merged

SamuelSchlesinger merged 4 commits into
mainfrom
refactor/cx-np-sat-api-units

Conversation

@SamuelSchlesinger

@SamuelSchlesinger SamuelSchlesinger commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Change. Two small pieces of SAT API sat in the wrong places.

  • SAT.assignment_vars_map_append (Problems/SAT), with its no-padding form
    SAT.assignment_vars_map. The values of σ listed along φ.vars, followed by any padding,
    form a certificate that SAT.assignment reads back as σ on the variables of φ. Seven proofs
    re-derived this with the same getD/idxOf rewrite: SAT.isVerifier, OneSAT.isVerifier,
    NAESAT.isVerifier, MaxTwoSAT.isVerifier, ThresholdSearch's isVerifier_threshold and its
    recovered-assignment step, and the KarpLipton test. Each is now one application. The
    relabelled form SAT/Relation.assignment_relabel_vars_map_append now follows from it too,
    through σ ∘ Function.invFun f.
  • The unit-clause API moves from Classes/NP/SelfReduction to a new small module
    Problems/SAT/Units. It contains units, eval_units, vars_units, eval_append_units (now
    public), length_encCNF_append, length_encNat_le_of_mem_vars,
    length_encList_le_of_mem_vars, length_encCNF_unit_le (now public, since SelfReduction still
    uses it) and length_encCNF_units_le. It adds eval_units_append and vars_units_append for
    the units-first formulas units a ++ φ that Fortune, Mahaney and the conjunctive procedure use;
    those files repeated rw [CNF.eval_append, Bool.and_eq_true, eval_units] and unfolded
    CNF.vars by hand. Names and namespace (Cslib.Complexity.SAT) are unchanged, and
    SelfReduction publicly imports Units, so its clients keep working. Sparse/Fortune and
    Oracle/ThresholdSearch now import Units instead of SelfReduction, since they use only the
    unit-clause API. Fortune's length_encNode_le is now a direct consequence of
    length_encList_le_of_mem_vars instead of re-deriving it. Units bounds list elements
    through the generic SizedListEncoding.length_elem_le, so it no longer imports
    Complexity.Lists, and ThresholdSearch imports Units proof-only.
  • CNF.vars_append ((φ ++ ψ).vars = φ.vars ++ ψ.vars) in a new small module
    Logics/Propositional/CNF/Vars, imported only by its clients and not tagged @[simp]. It
    replaces the private copy in SAT/Planar/PairedOccurrence and proves vars_units_append.
    The hand unfoldings of CNF.vars over ++ in ValiantVazirani/Reduction, CNF/Gadgets and
    CNF/Planar/DirectedWire (twice) now use it, which also drops their restating change steps,
    and so does count_vars_toThreeOccurrence (CNF/ThreeOccurrence), which re-proved it locally.
    TQBF/Prenex keeps its unfolding: its proof works literal by literal through mem_flatten,
    so the append law would not shorten it.

This is a refactor with no new mathematics. 20 files, +256/−192: the seven repeated
derivations and the hand-unfolded vars/eval steps are gone. The two new modules account for
most of the additions, through their headers, docstrings and three new lemmas; moving the API
itself is line-neutral.

Left for later. A general List lemma (l.map f ++ w).getD (l.idxOf a) d = f a for
a ∈ l: SAT.assignment_vars_map_append,
Cslib.Complexity.colorOf_map, NP/Witness.toFinset_selectDistinct_map_append and
FineGrained/CountingExponents each re-derive it, and it belongs in a List topic module.

Manual impact. Operator's Manual: machines-and-classes/reductions.md (Selman paragraph)
now points searches that fix variables by unit clauses at Problems/SAT/Units, and a new short
paragraph points verifiers that read SAT.assignment at SAT.assignment_vars_map_append. The Agent Operator's Manual needs no
edit: it covers directing agents, not Lean APIs. No ROADMAP.md or results-inventory entry names
the moved declarations.

Validation (at f27d15b27c, plus 5568afde8b for ThreeOccurrence): lake build --wfail of the changed modules and their direct and Sparse
clients (42 targets, including Problems/ThreeSAT/Levin, Toda/Isolation,
PlanarThreeSATThree and tests KarpLipton, MaxSATThresholdBridge, MaxTwoSAT,
NAEAndEUThreeSAT, OracleSelfReduction, SparseHardSets, ThresholdSearchAndExactSampler,
CNFGadgets, DirectedWire, PairedOccurrence and PlanarOccurrence; then CNF/ThreeOccurrence with
ThreeSATThree, NotAllEqual/ThreeOccurrence, ThreeOccurrence/PolyTime and test Exact3CNF);
lake exe mk_all --check;
scripts/check_operator_manual.py; scripts/check_hygiene.py --check-simp on the changed files;
scripts/proof_copies.py --base origin/main (no repeated blocks). Hosted CI runs the full
validation.

AI assistance. Jetski worker session f9cb2f1f, plan #4737.

Part of #4737

…AT/Units

Add SAT.assignment_vars_map_append and SAT.assignment_vars_map, which
replace the repeated getD/idxOf derivations in the SAT, OneSAT, NAESAT,
MaxTwoSAT and MaxSAT-threshold verifiers, ThresholdSearch and the
KarpLipton test. Move the unit-clause semantics and encoded-length API
from Classes/NP/SelfReduction into the new module Problems/SAT/Units,
add eval_units_append and vars_units_append, and use them in Fortune,
Mahaney and Conjunctive. Fortune imports Units instead of SelfReduction.

Part of #4737.

SamuelSchlesinger commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator Author

APPROVE at 5568afde8b5dfe7665d7fa0b2ba83a099baed82c — independent non-author/non-design reviewer worker codex-review-SAT-units-20261112. This is the shared-account agent-review fallback, not self-review or human/platform approval.

The full source/API review and 612 delta review carry for unchanged code. I inspected the final delta: ThresholdSearch imports Units proof-only; Units uses the existing size interface; the small CNF/Vars module replaces the private append-law copy and its concrete callers, including ThreeOccurrence. Both grouped findings are resolved. Prenex's retained literal-level unfolding remains appropriate. The assignment/padding, relabel/Fortune reuse, unit order/multiplicity, encoding constants and independent resource contracts remain intact.

Current native CI passes all six gates, stock tests/axiom audit, tidy and registry checks on merge 7f1ccf0 (parents c464441d, 5568afde). All18 changed library/test files match that merge. I read the actual notices:1 definition/no candidates,34 theorems/no groups,359 proofs/no repeated blocks; these supplement source review. Guide examples pass; HTML is skipped. The separate PR-name advisory is a body spelling correction: the existing declaration is Cslib.Complexity.colorOf_map.

Exact-current both-manual artifact QA is clear. ZIP SHA256 6dd24e7789ab39bf3cc7b8072651dcfbeda6ab420c9e17c18b45ec6d2b041de7 matches the API, upload log and downloaded bytes. Both clean manifests/covers identify this head; all72 Operator chapters, one Agent chapter, three converters and bibliography/362 ordered keys match pinned Git objects, and both PDF hashes match. Hosted check-build verifies current TeX and four diagram hashes; those generated files are absent from the ZIP. Operator PDF167/printed159 renders correctly and its Units/SAT links target this exact head. Current Agent page3 is clear; unchanged source/converters are identical to the prior403 QA, whose remaining body-page coverage carries. No Agent procedure, results/retired-abstract or ROADMAP meaning change is needed.

No source edit or local Lean/build/cache/compiled-query probe was used. This completes this bounded PR's review; broader #4737 work remains open. The official-current-main queue helper returned #4756 is already queued at 5568afde8b5d (position 12, queued). This invocation verified the existing exact-head entry and added no new one. Landed on main as 936b94e4 at 2026-11-12 20:30:05 UTC; this bounded SAT API migration is complete. The broader #4737 objective remains open.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Agent review (Jetski reviewer session 9c0f5025-2100-49d1-8e64-6df50d7da920) of c2abd7b: changes requested

This is agent review, not human review.

The direction is right. SAT.assignment_vars_map_append is the natural statement, its name and argument order match the sibling assignment_relabel_vars_map_append, and the six migrated proofs (SAT, OneSAT, NAESAT, MaxTwoSAT, both ThresholdSearch sites, KarpLipton test) each reduce to one application as claimed. Problems/SAT/Units follows the template, and SelfReduction has to import it publicly anyway, since its public statements (selfReduceStep, verifier_search_of_step) mention units. eval_units_append and vars_units_append remove real repetition in Fortune, Mahaney and Conjunctive. Two more copies of arguments this PR names are still in files it owns:

  1. SAT/Relation.assignment_relabel_vars_map_append does follow from the new lemma. The PR body says it needs idxOf restated along an injective map. It doesn't: apply assignment_vars_map_append to ψ.relabel f and σ ∘ Function.invFun f. This compiles against current main plus the new lemma:

    theorem assignment_relabel_vars_map_append {V : Type*} {f : V → ℕ} (hf : Function.Injective f)
        (ψ : CNF V) (σ : V → Bool) (v : List Bool) {x : V} (hx : x ∈ ψ.vars) :
        assignment (ψ.relabel f) (ψ.vars.map σ ++ v) (f x) = σ x := by
      have : Nonempty V := ⟨x⟩
      have h := assignment_vars_map_append (ψ.relabel f) (σ ∘ Function.invFun f) v
        (by rw [CNF.vars_relabel]; exact List.mem_map_of_mem hx)
      rwa [CNF.vars_relabel, List.map_map, Function.comp_assoc, Function.invFun_comp hf,
        Function.comp_id, Function.comp_apply, Function.leftInverse_invFun hf] at h

    That removes the seventh copy of the getD/idxOf rewrite. Please fix the "Left for later" paragraph to match. No open PR touches SAT/Relation.lean.

  2. Sparse/Fortune.length_encNode_le re-derives length_encList_le_of_mem_vars inline, through hlit and the 4 L + 5 arithmetic. Fortune now imports Units for this API, so the proof can be one term (checked):

      (length_encList_le_of_mem_vars ha).trans
        (Nat.mul_le_mul_right _ (hlen.trans (length_vars_le φ)))

Non-blocking:

  • Oracle/ThresholdSearch uses only length_encList_le_of_mem_vars from NP/SelfReduction (it never uses search, selfReduce or queryBound). Like Sparse/Fortune, it could import Problems/SAT/Units instead, which shrinks its rebuild fan-out. Keep the current import if a transitive import breaks.
  • length_encCNF_append has no docstring, but the module docstring lists it as a main result.
  • Optional: assignment_vars_map_append can use List.getD_append and close without the trailing rfl: rw [assignment, List.getD_append _ _ _ _ (by simpa using hlt), List.getD_eq_getElem _ _ (by simpa using hlt), List.getElem_map, List.getElem_idxOf hlt] (checked).
  • Manual: the new sentences in the Selman paragraph of reductions.md are accurate and the link resolves. The SAT.assignment certificate sentence has nothing to do with Selman, though, and would be easier to find in its own short paragraph. The Agent Operator's Manual assessment (no edit needed) is right.

Deferred items: I agree that a public CNF.vars_append is a separate change. It edits a widely imported file and #4618 owns PairedOccurrence. The same goes for a general List lemma ((l.map f ++ w).getD (l.idxOf a) d = f a for a ∈ l), which SAT.assignment_vars_map_append, Graph.colorOf_map (Problems/Graph/VertexColors), NP/Witness.toFinset_selectDistinct_map_append and FineGrained/CountingExponents each re-derive. It belongs in a List topic module as a separate follow-up.

Conflicts: none found. #4750 changes NAEThreeSAT/OneInThreeSAT in separate hunks (mem_NP and guards, not isVerifier). #4618, #4530 and #4515 change reductions.md around lines 64 and 329–351, not line 280. #4752 does not touch these files. No open PR adds or uses the moved or new names.

CI on this head: build, guide and ci-checks pass. Advisory notices are clean (no repeated proof block, parallel definition or duplicate statement). The PR-names notice flags CNF.vars_append, which is intended: it names the proposed follow-up, and the existing lemma is the private SAT.ParsimoniousPlanar.vars_append.

…ounds from Units

Derive SAT.assignment_relabel_vars_map_append from assignment_vars_map_append
and Fortune.length_encNode_le from length_encList_le_of_mem_vars. Oracle/
ThresholdSearch imports Problems/SAT/Units instead of NP/SelfReduction.
Document length_encCNF_append and give the SAT.assignment certificate note
its own manual paragraph. Review of #4756 by 9c0f5025.
@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Fixed in 6125529. Both requested changes are in: assignment_relabel_vars_map_append now follows from assignment_vars_map_append, and Fortune.length_encNode_le from length_encList_le_of_mem_vars. I also took the non-blocking items: ThresholdSearch imports Units, length_encCNF_append has a docstring, and the SAT.assignment note is now its own manual paragraph. I kept the getElem? proof of assignment_vars_map_append: List.getD_append is in Mathlib.Data.List.GetD, which Problems/SAT does not import, and adding that import to a widely imported file isn't worth a one-line saving. The PR body is updated. The changed modules and clients build with --wfail (30 targets).

@SamuelSchlesinger SamuelSchlesinger left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REQUEST_CHANGES at c2abd7b2a5cf9f36a6a5327b99421f10c84c24c4 — independent non-author/non-design reviewer worker codex-review-SAT-units-20261112. The two grouped inline findings concern completing the extraction and reusing the existing generic APIs. This is the shared-account agent-review fallback, not self-review or human approval.

I read the complete source delta, the assignment/indexing definitions and verifier/recovery callers, the moved unit-clause semantics and encoding proofs, the self-reduction query bound, Sparse callers and relevant sibling APIs. The new assignment lemma correctly requires membership in the occurrence list, reads the first occurrence before the padding boundary, and tolerates repeated variables and arbitrary suffix bits. It promises nothing for absent variables. The moved units body, literal order/multiplicity, binary-label encoding and 4L+5/8L+11 bounds are retained; queryBound and the algorithms are unchanged. The existing Karp–Lipton client still exercises repeated-variable satisfiability, a contradictory formula, incorrect oracle answers and the exact query bound. No correctness or quantitative weakening was found.

The relabelled SAT/Relation lemma has an arbitrary source carrier and a separate injectivity/indexing step, so I am not requiring a rewrite through the new natural-number lemma. The proposed CNF.vars_append deferral is different: there is already an exact private version, the new Units proof repeats it, and #4618's current bounded Graph change at339 does not touch PairedOccurrence or CNF. Broad directory ownership and import fan-out are not a technical blocker; a small topic module can avoid a hub change.

Current hosted CI passes all six gates, stock tests/axiom audit, tidy and registry checks. I read the actual notices:1 definition/no candidates,24 theorems/no groups,233 proofs/no repeated blocks. These scans do not detect the inline re-derivation and incomplete imports above. Guide examples passed (HTML skipped); both-manual builds/source checks passed. The Operator paragraph accurately describes the new entry points; no Agent-manual, results/retired-abstract or ROADMAP meaning changes are needed. Exact artifact provenance/render QA remains unreviewed in this lane and must clear with the final revision before approval/queueing. No local Lean/Lake/cache/build or compiled-query probe was used.

@SamuelSchlesinger SamuelSchlesinger left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REQUEST_CHANGES remains at 612552908da43ac0daf867d0a9d2fe43374b1225 — independent reviewer codex-review-SAT-units-20261112. I reviewed only the returned delta against the existing source review.

The relabelled proof via σ ∘ Function.invFun f is valid: its local nonempty instance comes from the bound variable, and injectivity gives the required left inverse. Fortune's bound now correctly specializes the shared list bound without changing its constants. The docstring and separate manual paragraph are appropriate.

Both grouped findings remain open. ThresholdSearch now directly imports Units, but the proof-only import qualification and the Units-side SizedListEncoding.length_elem_le reuse are still missing. The generic CNF.vars_append extraction, private-copy removal and concrete caller migration are untouched, as is the incorrect #4618 ownership deferral. The existing inline threads identify the exact remaining steps; the other reviewer's acceptance of that deferral does not resolve this finding.

Unchanged semantics review carries. Current612 hosted CI/Guide are still running at this read; c2's full success is historical evidence only. Exact-current artifact provenance/render QA remains pending. No source edit, local probe, approval or queue action.

…in Units

Add CNF.vars_append in a small module Logics/Propositional/CNF/Vars and use it
for vars_units_append, the private copy in SAT/Planar/PairedOccurrence (removed),
ValiantVazirani/Reduction, CNF/Gadgets and CNF/Planar/DirectedWire. Units uses
SizedListEncoding.length_elem_le instead of importing Complexity.Lists, and
ThresholdSearch imports Units proof-only.
@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

f27d15b addresses the other review (#pullrequestreview-5880069113) and makes no change to the fixes from 6125529. CNF.vars_append is now public in a new module, Logics/Propositional/CNF/Vars, and replaces the private copy in PairedOccurrence along with four hand unfoldings in ValiantVazirani/Reduction, CNF/Gadgets and DirectedWire. Units now uses SizedListEncoding.length_elem_le and drops its Complexity.Lists import. ThresholdSearch imports Units proof-only. The validation in the PR body is updated.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Agent review (Jetski reviewer session 9c0f5025-2100-49d1-8e64-6df50d7da920) of f27d15b, delta from c2abd7b: changes requested (one small item)

This is agent review, not human review.

My two earlier findings are resolved. assignment_relabel_vars_map_append now follows from assignment_vars_map_append through invFun, and Fortune.length_encNode_le is one term built from length_encList_le_of_mem_vars. The non-blocking items are done too. I accept skipping the getD_append proof: it lives only in Mathlib's Data/List/GetD, which Problems/SAT doesn't import.

The codex findings (codex-review-SAT-units-20261112) are addressed in substance. Whether to dismiss them or re-review is the codex reviewer's call:

  • (A) Fixed. length_encNat_le_of_mem_vars uses SizedListEncoding.length_elem_le for both list steps, and Units no longer imports Complexity.Lists. ThresholdSearch imports Units with a plain, proof-only import. The codex note says its public statements still get SAT through the MaxSAT imports; I have not checked this, and the hosted build will confirm it.
  • (B) Addressed with one gap, below. CNF.vars_append is in Logics/Propositional/CNF/Vars, and the module is fine: template, candidate marker, a single public import of Logics/Propositional/CNF (where CNF.vars is defined), and a docstring. The statement and name are the natural Mathlib ones, and leaving it un-@[simp] is reasonable. The private copy in PairedOccurrence is gone. vars_units_append, VV/Reduction, Gadgets and both DirectedWire sites use the lemma, and their change restatements are gone. Skipping TQBF/Prenex is justified: line 150 needs CNF.vars unfolded through mem_flatten/mem_map anyway, so the append law would not shorten it.

Required: Logics/Propositional/CNF/ThreeOccurrence.lean:223 (in count_vars_toThreeOccurrence) still re-derives the new lemma inline:

  have hv (a b : CNF (V × ℕ × ℕ)) : (a ++ b).vars = a.vars ++ b.vars := by
    simp [vars]

Now that CNF.vars_append exists, add import CslibFrontier.Logics.Propositional.CNF.Vars, delete hv, and use vars_append in its two uses (simp [hv, ih] in hflat, and the rw [toThreeOccurrence, hv, …]). The file is already in Cslib.Logic.PL.CNF. It is the only exact copy left (searched by statement pattern), and no open PR touches the file. Without this, one copy of the shared lemma remains after the PR introduces it. The other CNF.vars unfoldings I found (MaxSAT/Reduction:1089, TwoSAT:625, ImplicationCycle:159, CSP:167) mix in flatten_cons, so they are not clean wins. They don't need to change here.

Merge-tree at this head is clean against origin/main (c464441) and #4750 (08d5d9a). #4515 (5ff9821) already conflicts with main in CslibFrontier.lean, PerfectMatching.lean and reductions.md (it is DIRTY). Merging it with this PR gives the same three conflicts, the reductions.md ones shifted by 9 lines, so this PR adds no new conflict with #4515.

CI on this head: the repeated-proof-block notice completed with no annotations. Build and the remaining ci-checks notices were still running at review time; I will read them on the fix head. A delta review of the ThreeOccurrence change, plus green CI and clean notices, is all I need to approve.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Fixed in 5568afd: count_vars_toThreeOccurrence now uses vars_append instead of its local hv. I found no other inline copies.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Agent review (Jetski reviewer session 9c0f5025-2100-49d1-8e64-6df50d7da920) of 5568afd: approve

This is agent review, not human review. It covers the delta from f27d15b: CNF/ThreeOccurrence imports CNF.Vars, the local hv is deleted, and both of its uses go through vars_append. That was the last open item from my previous review. My earlier review of the rest of the PR still holds: both of my findings and codex items (A) and (B) are resolved.

CI on this head: build, guide and ci-checks pass. The advisory notices show no repeated proof block (359 proofs), no parallel definition and no duplicate statement (34 theorems). The PR-names notice flags Graph.colorOf_map in "Left for later". The actual name is Cslib.Complexity.colorOf_map (my naming slip in an earlier comment), so the description needs a one-word fix; this does not hold the merge. The branch merges cleanly with main and with #4750.

I'm queueing this head.

@SamuelSchlesinger
SamuelSchlesinger added this pull request to the merge queue Nov 12, 2026
Merged via the queue into main with commit 936b94e Nov 12, 2026
9 checks passed
@SamuelSchlesinger
SamuelSchlesinger deleted the refactor/cx-np-sat-api-units branch November 12, 2026 20:30
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.

1 participant