# Solver Notes

## Formula Notes

The useful training split structure is not file-name dependent. The solver detects these shapes directly from clauses:

- Signed SGEN SAT instances have only binary clauses and 5-clauses. A binary clause `(a b)` is interpreted as an at-most-one edge between the signed items `~a` and `~b`. The connected components are size-5 signed blocks. The 5-clauses are the other two partitions. Each signed literal occurs in exactly one binary block and two 5-clauses, so the high-level problem is exact cover over rows that cover three columns.
- Pure ternary instances form signed-literal partitions into blocks of size 4 or 5. All triples over a block encode a cardinality lower bound over those signed literals. When the signed blocks include both polarities of every variable and the lower bounds sum to more than `n`, the formula is UNSAT by counting. This covers monotone `sNN`/`edges-024/025` cases and mixed signed `sgen3/sgen4-unsat` cases.
- Mixed signed ternary formulas, `edges-070/072` formulas with binary and ternary clauses, and `.mis.debugged` formulas are currently detected as unsupported and return `UNKNOWN`.

## Techniques Used

- Exact-cover SAT path:
  - Recover signed literals from binary at-most-one blocks.
  - Build rows from signed literals; each row covers one binary-block column and two 5-clause columns.
  - Try deterministic depth-first exact cover first, then bounded local repair and randomized restarts.
  - Convert chosen signed literals to a complete assignment and verify all CNF clauses before printing SAT.

- UNSAT proof path:
- For each signed ternary block of size 4, add the four triple clauses and divide by 3 to derive the block cardinality constraint.
  - For each block of size 5, derive all five size-4 sub-block constraints, add them, and divide by 4.
  - Add the derived constraints from the positive and negative partitions. Complementary literals normalize away in VeriPB, yielding an empty contradiction when the lower bounds exceed `n`.

## Local Results

Full pass over `/data/train` after the current implementation:

- `sat`: 23
- `unsat`: 48, all produced proofs verified with `veripb --cnf`
- `unknown`: 16
- no invalid models, invalid proofs, crashes, or local timeouts with a 110 second wrapper

Slow known case: `sgen6` exact-cover-shaped UNSAT instances are recognized as exact-cover candidates but no proof strategy is implemented, so they return `UNKNOWN` after the 50 second exact-cover budget.

## Remaining Things To Try

- Add a proof-producing infeasibility certificate for the signed exact-cover UNSAT cases (`sgen6`).
- Recover the `edges-070/072` binary-plus-ternary family as a matching or b-matching instance.
- Generate VeriPB proofs for Hall-style matching failures.
- Investigate `.mis.debugged` formulas; they appear to be expanded encodings with many units, binaries, and ternaries.

## Known Limitations

- The solver never reports UNSAT without writing a VeriPB proof and therefore leaves several detected-but-unproved high-level UNSAT cases as `UNKNOWN`.
- The SAT exact-cover budget is bounded to avoid spending the full broker timeout on unsupported UNSAT-shaped exact-cover instances.
- The fallback stochastic SAT search is only used for formulas containing 5-clauses when exact-cover detection fails; it is a conservative rescue path for stripped or weakened SAT encodings.

## Changelog

- Replaced the placeholder solver with a C++ structural solver.
- Added signed exact-cover recovery from binary clauses and 5-clauses.
- Added exact-cover search, local repair, randomized restarts, and complete CNF model checking.
- Added VeriPB cutting-planes proof generation for monotone pure ternary partition-count contradictions.
- Generalized ternary counting proofs from monotone clauses to signed-literal cardinality blocks.
- Updated `meta.json` with the solver strategy and techniques.
