Skip to content

feat: batch implement reduction rules (phases 1-3)#1017

Merged
GiggleLiu merged 13 commits intomainfrom
jg/hard-rules
Apr 8, 2026
Merged

feat: batch implement reduction rules (phases 1-3)#1017
GiggleLiu merged 13 commits intomainfrom
jg/hard-rules

Conversation

@GiggleLiu
Copy link
Copy Markdown
Contributor

Summary

  • 10 reduction rules implemented across phases 1-3 of the rules-todo plan
  • 5 companion ILP rules added (MonochromaticTriangle, MinCoveringByCliques, IntegerKnapsack, FeasibleRegisterAssignment, Dir2CommodityIntFlow fix)
  • 2 proof-only edges for one-directional reductions (MVC→MinMaximalMatching, SubsetSum→IntegerKnapsack)
  • Paper entries added for all new rules

Witness-capable reductions (Phase 1)

Issue Reduction
#970 CircuitSAT → Satisfiability (Tseitin)
#825 Maximum2Satisfiability → MaxCut
#864 Satisfiability → Maximum2Satisfiability (GJS gadget)
#988 KSatisfiability(K3) → Decision<MinimumVertexCover>
#368 3SAT → DirectedTwoCommodityIntegralFlow

Phase 2 (investigate and fix)

Issue Reduction Result
#884 3SAT → MonochromaticTriangle + ILP Implemented
#905 3SAT → FeasibleRegisterAssignment + ILP Implemented (issue rewritten with correct Sethi Reduction 3)
#872 3SAT → RegisterSufficiency Blocked — extraction rule conflicts with arc orientation

Phase 3 (one-directional)

Issue Reduction Result
#893 MVC → MinMaximalMatching Proof-only edge (factor-2 gap)
#889 PartitionIntoCliques → MinCoveringByCliques Forward direction invalid; companion MinCoveringByCliques→ILP added
#521 SubsetSum → IntegerKnapsack + ILP Proof-only edge (multiplicity gap)

Issues updated

Test plan

  • make test passes
  • make clippy passes
  • make paper compiles
  • All new reduction tests pass (closed-loop, structure, extraction)
  • ILP companion rules verified with brute-force cross-checks

🤖 Generated with Claude Code

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR expands the reduction catalog by implementing multiple new polynomial-time reductions (including SAT-branch connectivity, 3SAT gadgets, and several ILP companion formulations), and updates the paper/test suite to cover the new edges—including explicitly “proof-only” embeddings that are intentionally not solver-executable.

Changes:

  • Add new reductions: CircuitSAT→SAT (Tseitin), SAT→MAX-2-SAT (GJS gadget), MAX-2-SAT→MaxCut, and several 3SAT-based constructions (e.g., →Decision MVC, →MonochromaticTriangle, →FeasibleRegisterAssignment, →DirectedTwoCommodityIntegralFlow).
  • Add ILP companion reductions for MonochromaticTriangle, MinimumCoveringByCliques, IntegerKnapsack, and FeasibleRegisterAssignment; adjust D2CIF→ILP conservation semantics to match the model definition.
  • Add proof-only edges (e.g., SubsetSum→IntegerKnapsack, MVC→MinimumMaximalMatching) and integrate them into example-db/paper + tests.

Reviewed changes

Copilot reviewed 43 out of 43 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/suites/register_assignment_reductions.rs New integration tests for KSAT→FRA and FRA→ILP closed loops
tests/suites/reductions.rs Add integration tests for MinimumCoveringByCliques→ILP and MAX-2-SAT→MaxCut
tests/main.rs Register the new integration test suite module
src/unit_tests/rules/subsetsum_integerknapsack.rs Unit tests demonstrating forward embedding + backward gap
src/unit_tests/rules/satisfiability_maximum2satisfiability.rs Unit tests for SAT→MAX-2-SAT structure/closed-loop/gaps
src/unit_tests/rules/registry.rs Extend EdgeCapabilities tests for none()
src/unit_tests/rules/monochromatictriangle_ilp.rs Unit tests for MonochromaticTriangle→ILP constraints and feasibility
src/unit_tests/rules/minimumvertexcover_minimummaximalmatching.rs Unit tests validating proof-only MVC→MMM relationship/gap
src/unit_tests/rules/minimumcoveringbycliques_ilp.rs Unit tests for MinimumCoveringByCliques→ILP formulation and round-trip
src/unit_tests/rules/maximum2satisfiability_maxcut.rs Unit tests for MAX-2-SAT→MaxCut correctness and edge weights
src/unit_tests/rules/ksatisfiability_monochromatictriangle.rs Unit tests for 3SAT→MonochromaticTriangle gadget + extraction
src/unit_tests/rules/ksatisfiability_feasibleregisterassignment.rs Unit tests for 3SAT→FRA gadget structure/extraction/ILP loop
src/unit_tests/rules/ksatisfiability_directedtwocommodityintegralflow.rs Unit tests for 3SAT→D2CIF structure, encoding, and ILP loop
src/unit_tests/rules/ksatisfiability_decisionminimumvertexcover.rs Unit tests for 3SAT→Decision MVC wrapper reduction
src/unit_tests/rules/integerknapsack_ilp.rs Unit tests for IntegerKnapsack→ILP bounds/objective extraction
src/unit_tests/rules/graph.rs Registry/path existence tests for new reductions
src/unit_tests/rules/feasibleregisterassignment_ilp.rs Unit tests for FRA→ILP structure/round-trip/infeasibility
src/unit_tests/rules/directedtwocommodityintegralflow_ilp.rs Update tests for revised conservation constraints; add regression
src/unit_tests/rules/circuit_sat.rs Unit tests for CircuitSAT→SAT (Tseitin) correctness/counts
src/unit_tests/reduction_graph.rs Assert new proof-only edges and runtime witness edges are correctly flagged
src/unit_tests/models/misc/feasible_register_assignment.rs Add tests for num_same_register_pairs()
src/unit_tests/models/graph/directed_two_commodity_integral_flow.rs Regression test: disallow using other commodity’s source
src/unit_tests/example_db.rs Allow example-db consistency checks to tolerate proof-only edges
src/rules/subsetsum_integerknapsack.rs Register SubsetSum→IntegerKnapsack as proof-only edge + canonical example
src/rules/satisfiability_maximum2satisfiability.rs Implement SAT→MAX-2-SAT reduction (normalization + GJS gadget)
src/rules/registry.rs Add EdgeCapabilities::none() helper
src/rules/monochromatictriangle_ilp.rs Implement MonochromaticTriangle→ILP feasibility formulation
src/rules/mod.rs Wire up new rule modules and canonical examples
src/rules/minimumvertexcover_minimummaximalmatching.rs Register MVC→MMM as proof-only identity edge
src/rules/minimumcoveringbycliques_ilp.rs Implement MinimumCoveringByCliques→ILP with McCormick linearization
src/rules/maximum2satisfiability_maxcut.rs Implement MAX-2-SAT→MaxCut reduction via accumulated signed weights
src/rules/ksatisfiability_monochromatictriangle.rs Implement 3SAT→MonochromaticTriangle gadget + symmetry-aware extraction
src/rules/ksatisfiability_feasibleregisterassignment.rs Implement Sethi Reduction 3: 3SAT→FeasibleRegisterAssignment
src/rules/ksatisfiability_directedtwocommodityintegralflow.rs Implement padded occurrence-lobe 3SAT→D2CIF reduction + encoding helper
src/rules/ksatisfiability_decisionminimumvertexcover.rs Implement 3SAT→Decision wrapper
src/rules/integerknapsack_ilp.rs Implement IntegerKnapsack→ILP with explicit multiplicity upper bounds
src/rules/feasibleregisterassignment_ilp.rs Implement FRA→ILP formulation (ordering + live-range non-overlap)
src/rules/directedtwocommodityintegralflow_ilp.rs Fix D2CIF→ILP conservation to exclude only own source/sink per commodity
src/rules/circuit_sat.rs Implement CircuitSAT→SAT Tseitin encoding + normalization/constant folding
src/models/misc/feasible_register_assignment.rs Add num_same_register_pairs() helper used by ILP overhead/tests
src/models/graph/monochromatic_triangle.rs Add num_triangles() helper
src/models/graph/directed_two_commodity_integral_flow.rs Adjust model definition/evaluation for commodity-specific terminals
docs/paper/reductions.typ Document new rules (including proof-only notes) and update paper text/examples

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 6 to +12
use problemreductions::models::algebraic::{LinearConstraint, ObjectiveSense, ILP};
use problemreductions::models::graph::MinimumCoveringByCliques;
use problemreductions::prelude::*;
use problemreductions::rules::{Minimize, ReductionGraph};
use problemreductions::solvers::ILPSolver;
use problemreductions::topology::{Graph, SimpleGraph};
use problemreductions::types::Min;
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

ILPSolver is only re-exported when the ilp-solver feature is enabled (see problemreductions::solvers), but this file imports it unconditionally. This will break compilation of the test suite when ilp-solver is disabled. Gate the ILPSolver import (and any code that needs it) behind #[cfg(feature = "ilp-solver")], or move the import inside the already-cfgd module.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +7
use problemreductions::models::algebraic::ILP;
use problemreductions::models::formula::{CNFClause, KSatisfiability};
use problemreductions::models::misc::FeasibleRegisterAssignment;
use problemreductions::prelude::*;
use problemreductions::rules::{MinimizeSteps, ReductionGraph, ReductionPath};
use problemreductions::solvers::ILPSolver;
use problemreductions::types::{Or, ProblemSize};
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

This integration test suite uses ILPSolver and ILP reductions but is not gated behind #[cfg(feature = "ilp-solver")]. Since ILPSolver is only available with that feature, the crate’s tests will fail to compile in non-ILP builds. Consider gating the whole file (or at least both tests + the ILPSolver import) behind feature = "ilp-solver", similar to other suites.

Copilot uses AI. Check for mistakes.
Comment on lines 10 to 14
mod ksatisfiability_simultaneous_incongruences;
#[path = "suites/register_assignment_reductions.rs"]
mod register_assignment_reductions;
#[path = "suites/reductions.rs"]
mod reductions;
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

tests/suites/register_assignment_reductions.rs appears to require the ilp-solver feature, but this module is included unconditionally. If ilp-solver is disabled, the test build will fail due to missing ILPSolver/ILP reductions. Gate this mod register_assignment_reductions; behind #[cfg(feature = "ilp-solver")] (or gate the module contents).

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

❌ Patch coverage is 97.58701% with 52 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.12%. Comparing base (fb9c608) to head (6bb08ae).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/rules/circuit_sat.rs 90.82% 21 Missing ⚠️
src/rules/satisfiability_maximum2satisfiability.rs 83.33% 16 Missing ⚠️
src/rules/subsetsum_integerknapsack.rs 85.18% 8 Missing ⚠️
src/rules/ksatisfiability_monochromatictriangle.rs 97.02% 3 Missing ⚠️
...satisfiability_directedtwocommodityintegralflow.rs 99.06% 2 Missing ⚠️
...rules/minimumvertexcover_minimummaximalmatching.rs 96.55% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1017      +/-   ##
==========================================
- Coverage   98.12%   98.12%   -0.01%     
==========================================
  Files         923      949      +26     
  Lines       95916    98044    +2128     
==========================================
+ Hits        94120    96201    +2081     
- Misses       1796     1843      +47     

☔ View full report in Codecov by Sentry.
📢 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.

GiggleLiu and others added 2 commits April 8, 2026 09:40
Add reduction-rule entries for KSatisfiability → FeasibleRegisterAssignment
(Sethi Reduction 3) and FeasibleRegisterAssignment → ILP.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Address Copilot review comments: ILPSolver and related imports in
integration tests were unconditional but only used in feature-gated
blocks. Gate them with #[cfg(feature = "ilp-solver")].

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@GiggleLiu GiggleLiu merged commit a784239 into main Apr 8, 2026
5 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