Skip to content

Reduce Satisfiability directly to ILP<bool> - #1249

Open
isPANN wants to merge 3 commits into
mainfrom
feat/satisfiability-ilp
Open

isPANN wants to merge 3 commits into
mainfrom
feat/satisfiability-ilp

Conversation

@isPANN

@isPANN isPANN commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a direct primitive reduction Satisfiability -> ILP<bool> (the standard clause-row encoding) and makes it the fixed ILP pipeline for SAT and 3-SAT.

  • One binary variable per SAT variable, no auxiliaries, empty objective.
  • Each clause C becomes one row Σ_{i∈P} x_i − Σ_{j∈N} x_j ≥ 1 − |N|, i.e. Σ_{ℓ∈C} val(ℓ) ≥ 1 with val(¬x) = 1 − x. Repeated literals add to coefficients; opposite literals cancel, leaving a redundant row; an empty clause gives 0 ≥ 1.
  • Transform: num_vars, num_constraints exact; num_nonzeros ≤ num_literals, max_constraint_magnitude_bits ≤ num_literals + 1.
  • Extraction validates the target witness and reads x_i = 1 as true; feasibility maps through ilp_feasibility.
  • Pipelines: Satisfiability -> ILP and KSatisfiability<K3> -> Satisfiability -> ILP, replacing the detour through NAESatisfiability. These were the only two fixed pipelines using NAE-SAT as an intermediate; NAE-SAT keeps its own direct pipeline.

Why

The previous route SAT -> NAESAT -> ILP adds a variable z to every clause, which turns each pairwise conflict x_a + x_b ≤ 1 into one that depends on z. HiGHS can then no longer find the clique structure it needs. On pigeonhole CNFs (n+1 pigeons, n holes), pred solve with the default pipeline:

n main (via NAE-SAT) this branch
12 3.3 s 1.0 s
14 timeout (60 s) 0.5 s
16 timeout (60 s) 0.9 s

Test plan

  • make check (Rust 1.99): 7214 passed, 0 failed
  • make paper: builds with the new reduction-rule entry and worked example
  • Closed-loop, infeasible, degenerate-clause (empty, repeated, complementary) and extraction-rejection tests; formula validation in parameter_formula_validation.rs; resolver tests for both pipelines

🤖 Generated with Claude Code

Use clause rows in the fixed SAT and 3-SAT ILP pipelines.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.61751% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.94%. Comparing base (e7bacb3) to head (bc44bb1).

Files with missing lines Patch % Lines
src/unit_tests/solvers/resolver.rs 94.11% 2 Missing ⚠️
src/unit_tests/rules/satisfiability_ilp.rs 98.79% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1249      +/-   ##
==========================================
- Coverage   97.19%   96.94%   -0.26%     
==========================================
  Files        1146     1148       +2     
  Lines      151558   154253    +2695     
==========================================
+ Hits       147308   149539    +2231     
- Misses       4250     4714     +464     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@isPANN

isPANN commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator Author

Agentic Review Report

PR: #1249, Reduce Satisfiability directly to ILP
Head reviewed: 122fe1f9 (base e7bacb37)
Review type: rule (Satisfiability -> ILP<bool>) plus a fixed-pipeline change
Verdict: No Critical or Important findings. The rule is correct, complete and well tested. Three Minor findings are listed below. CI Clippy is red, but none of the flagged files are in this PR (see "CI note").

(a) Structural and semantic

Check Result
#[reduction(transform = …)] covers every ILP parameter exactly once (num_vars, num_constraints exact; num_nonzeros, max_constraint_magnitude_bits upper bound) OK
Registered in src/rules/mod.rs (module + canonical_rule_example_specs) OK
canonical_rule_example_specs() in the rule file, via rule_example_via_ilp::<_, bool> OK
extract_solution() validates once (validate_target_witness), then decodes x_i = 1 only OK
Every rejection path tested: length mismatch → Evaluation(InvalidConfiguration), out-of-domain 2 and infeasible [0,0] → InvalidTargetSolution OK
Aggregate map registered with #[aggregate_reduction(ilp_feasibility)], tested on SAT and UNSAT OK
Error contracts: exact_i64 → ReductionError overflow, target_construction keeps ReductionError::Construction OK
Targets the most specific variant ILP<bool> OK
Closed-loop test test_satisfiability_to_ilp_closed_loop OK
Formula coverage in parameter_formula_validation.rs (generic test plus a dedicated degenerate-case test) OK
Paper reduction-rule("Satisfiability", "ILP"); example values come from load-example OK
No generated exports (reduction_graph.json, problem_schemas.json, examples.json) in the diff OK
No duplicate primitive registration for Satisfiability -> ILP<bool> OK

Whitelist: the packet's whitelist check failed on src/solvers/pipelines.rs, src/unit_tests/parameter_formula_validation.rs and src/unit_tests/solvers/resolver.rs. All three belong in this PR. The pipeline switch is the PR's stated purpose. CLAUDE.md requires formula validation for every new rule. The resolver test pins the new pipelines. Nothing in the diff is unrelated.

Semantic trace (by hand). I traced the canonical example by hand: n=3 with clauses (1,2,2), (-1,3), (-2,-3), (1,-1).

  • Rows: x0 + 2x1 >= 1, -x0 + x2 >= 0, -x1 - x2 >= -1, and the empty row 0 >= 0. The duplicate literal merges to coefficient 2, and the complementary pair cancels.
  • These rows match the bundle produced by pred reduce.
  • Sizes: 3 vars (exact), 4 rows (exact), 6 nonzeros ≤ L = 9, magnitude bits 2 ≤ L + 1 = 10.
  • Correctness: Σ_P x − Σ_N x ≥ 1 − |N| is exactly Σ_{ℓ∈C} val(ℓ) ≥ 1 over literal occurrences (a multiset), so it holds with repeated and complementary literals. Normalization keeps empty rows, so num_constraints = num_clauses is exact, and an empty clause gives 0 >= 1.
  • Overflow: 1 − negatives cannot overflow for 0 ≤ negatives ≤ i64::MAX, and coefficient merging is checked inside ILP::new.

Independent check (scratch only, not committed). On a 6-variable, 7-clause instance with repeated and complementary literals, I enumerated all 64 assignments. ILP::is_feasible agreed with Satisfiability::evaluate on every one (19/64 satisfying), and extract_solution returned the same assignment on every feasible point.

Paper proof. Both directions are sound. The overhead paragraph is correct: the coefficient, RHS and endpoint magnitudes are at most L + 1. The degenerate cases (repeated, complementary, empty clause, no clauses) are discussed correctly. make paper compiles without errors.

Pipelines. These were the only two fixed pipelines that contained Satisfiability. KSatisfiability<K3> -> Satisfiability -> ILP and Satisfiability -> ILP replace the NAE-SAT detour. NAE-SAT keeps its own direct pipeline. The remaining Satisfiability -> NAESatisfiability references in CLI, MCP and ilp_overhead tests use explicit routes, so this change does not affect them.

Issue compliance: no linked issue. Judged against the PR description, which the code matches.

Graph topology (how-to-verify, redundancy check). I ran pred path Satisfiability ILP/bool/i64/general --limit all, which finds 180 paths. The new 1-step edge is no worse than every existing path on every target parameter. Against the previous fixed route Satisfiability > NAESatisfiability > ILP it is strictly better on every field:

Field Previous route New edge
num_vars num_vars + 1 num_vars
num_constraints 2·num_clauses num_clauses
num_nonzeros 2·(num_clauses + num_literals) num_literals
max_constraint_magnitude_bits 1 + num_literals + 2·num_clauses 1 + num_literals

Verdict: PASS (not dominated).

Codecov: patch coverage is 98.4%. The 3 uncovered lines are panic! arms in test code (resolver.rs and satisfiability_ilp.rs tests). src/rules/satisfiability_ilp.rs is fully covered.

(b) Quality

  • Tests: the closed loop, an exhaustive row-vs-clause truth table for the four degenerate row shapes, empty-clause infeasibility (0 and 2 vars), every extraction rejection, the aggregate value map, formula validation on degenerate inputs, and resolver dispatch for SAT and 3-SAT on feasible and infeasible inputs.
  • Focused run: 86 tests passed, including all new tests, every_executable_parameter_formula_matches_a_constructed_target and the example-db tests.
  • Formatting and lint: cargo fmt --check is clean. Locally, cargo clippy --workspace --all-targets --all-features -- -D warnings on rustc/clippy 1.100.0, the same toolchain CI uses, exits 101 with 12 errors. All 12 are in files this PR does not touch (see the CI note). Clippy lints the whole crate, so the PR's own files produce no lints under 1.100.
  • Brute-force round trip: ILP<bool> has no register_brute_force!, so a brute-force round trip on the target is impossible. assert_bf_vs_ilp is the established pattern for ILP targets (89 rule test files use it).
  • Code style: consistent with the sibling naesatisfiability_ilp.rs. No duplicated helper logic.
  • CLI changes: none in problemreductions-cli/, so no HCI review was needed.

(c) Feature test

I built the PR's CLI with cargo build -p problemreductions-cli and used target/debug/pred. I did not run make cli, which would cargo install over the user's global pred. All commands were run from a scratch directory:

  • pred list --rules Satisfiability lists Satisfiability → ILP/bool/i64/general. pred show Satisfiability shows that edge with the declared transform.
  • pred create --example Satisfiability --to ILP: produces the 3-var, 4-clause instance.
  • pred inspect: ILP path Satisfiability → ILP<general, i64, bool>.
  • pred solve (ILP and brute force): both return Or(true) with [false, true, false].
  • pred path Satisfiability ILP then pred reduce --via then pred solve bundle.json: the top path is the new 1-step direct edge. The bundle rows match the hand trace, and the solve recovers the same assignment.
  • The paper's pred-commands sequence, including --limit 1 and pred evaluate --config '[false,true,false]', works as written.
  • UNSAT instance with an empty clause: status: infeasible from both the ILP and brute-force solvers.
  • 3-SAT (KSatisfiability/K3): inspect and solve use KSatisfiability<K3> → Satisfiability → ILP<general, i64, bool> and return a satisfying assignment.
  • Pigeonhole PHP(13, 12), 156 variables: the default ILP solve reports infeasible in 0.04 s on a debug build. This is a one-run sanity check on this branch, not a reproduction of the PR's timing table: I made no comparison with main.

Findings

Critical: none.

Important: none.

Minor

  1. src/unit_tests/rules/satisfiability_ilp.rs:9-21: the closed-loop instance is small (3 variables). The four-row degenerate test and the solver tests compensate, but the review guideline asks for at least one 5+ size instance. Suggested fix: add a closed-loop (or full truth-table) case with about 6 variables that mixes ordinary, repeated and complementary literals. The scratch instance described above already passes such a check.
  2. No verification certificate (PR-level). how-to-code asks that rules be verified with how-to-verify before implementation, and that the evidence be posted as a ## Verification certificate comment. That process includes constructor and adversary scripts. No such comment is on the PR. This is the textbook clause-row encoding with a two-line proof. The hand trace, the exhaustive 6-variable check above and the in-repo truth-table test cover the risk. Suggested fix: post a short certificate, or have a maintainer confirm that this rule counts as mechanical enough to skip it.
  3. src/rules/satisfiability_ilp.rs:43 (optional): max_constraint_magnitude_bits <= num_literals + 1 is valid but loose. The true value is about ⌊log₂ L⌋ + 1, since magnitudes are at most L. This matches the sibling naesatisfiability_ilp.rs and the "simple proved upper bound" default, so no change is required. A log-form bound could be considered later if path ranking ever uses this field.

CI note (not caused by this PR)

CI Clippy fails on src/models/graph/minimum_edge_cost_flow.rs, src/models/misc/minimum_register_sufficiency_for_loops.rs, src/models/misc/rectilinear_picture_compression.rs, src/rules/ksatisfiability_preemptivescheduling.rs and src/rules/unitdiskmapping/grid.rs (needless_bool, needless_range_loop). This PR touches none of these files. CI uses stable rustc 1.100.0 (2026-11-09). Main's last green CI ran on 2026-10-30, and the PR body reports make check on Rust 1.99. The same 12 errors reproduce locally with clippy 1.100.0, all in those untouched files, so main at the PR's base would fail the same way on the current toolchain. This still blocks merge until it is fixed on main or in a separate PR. Test, Code Coverage, Rustfmt and all platform builds pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@isPANN

isPANN commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator Author

Review follow-up (89ca257): added a 6-variable, 7-clause closed-loop instance with repeated and complementary literals (Minor 1). No verification certificate is attached because this is the textbook clause-row encoding: each row is exactly Σ_{ℓ∈C} val(ℓ) ≥ 1. A maintainer can waive it or ask for one. The Clippy CI failure comes from 1.100 lints in files this PR doesn't touch.

Address needless_bool and needless_range_loop lints that the updated
stable toolchain reports on existing code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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