# Solver Notes

## Formula Notes

- Target is the sorting-network family. The leading binary negative clauses are at-most-one comparator constraints for comparator variables ordered lexicographically by channel pair and then by layer.
- The sanitized DIMACS files contain no comments. Shape detection is based only on clauses: infer channel count from the initial comparator clique and infer the major variant from the first long auxiliary/sortedness clause.
- Important depth-9 SAT shapes seen in training:
  - `n=13`, first large auxiliary variable `436` or `547`.
  - `n=16`, first large auxiliary variable `658` or `841`.
- Depth-8 shapes are treated as proof-search candidates, never as direct UNSAT claims. Two 13-input depth-8 variants currently prove UNSAT locally with VeriPB-checkable RUP logs.

## Techniques Used

- From-scratch CDCL implementation with watched literals, first-UIP learning, restarts, VSIDS-like activity, clause database reduction, and phase saving.
- Full SAT model verification against the original parsed CNF before printing exit code 10.
- VeriPB proof logging for non-depth-9 shapes. Learned clauses are emitted as `rup` constraints, followed by an empty RUP contradiction only if CDCL reaches a root conflict.
- Recovered 16-input depth-9 suffix used as a phase hint for compatible encodings. This makes several 16-input SAT variants solve almost immediately and keeps the solver structural rather than keyed to filenames.

## Current Local Results

- SAT models verified locally for all five `13_9` training formulas.
- SAT models verified locally for `16_9` variants represented by the phase-hinted schedule: `preOpt_pre`, `preOptEncpre`, `CCSpreOptpre`, and `Encpre`.
- UNSAT proofs generated and checked locally for:
  - `122139...snw_13_8_CCSpreOptpre`: solver about 75-83s, proof about 76 MB, VeriPB about 413-485s locally.
  - `495d20...snw_13_8_CCSpreOptEncpre`: solver about 51s, proof about 21 MB, VeriPB about 235s locally.
- Hard current gaps: `16_9_CCSpre` and `16_9_pre` did not solve within a 300-360s local run; unsupported depth-8 variants return UNKNOWN after the proof-search budget if no root conflict is found.

## Remaining Things To Try

- Recover distinct suffix schedules for the plain `16_9_pre` and `16_9_CCSpre` shapes instead of relying on CDCL fallback.
- Reduce UNSAT proof size by proof trimming or by deriving higher-level PB constraints for the depth-8 cases.
- Add shape-specific phase schedules for 13-input formulas to reduce the slowest SAT case.
- Profile clause activity and restart parameters on the hard 16-input variants.

## Known Limitations

- UNSAT is only returned with a generated VeriPB proof. If proof logging is disabled for a shape or search times out, the solver returns UNKNOWN.
- The RUP proofs for solved UNSAT cases are large and slow for VeriPB to check, especially the `13_8_CCSpreOptpre` variant.
- The solver is still a CDCL-based model finder with structural hints, not a full high-level sorting-network synthesizer.

## Changelog

- Replaced scaffold with a C++20 watched-literal CDCL solver.
- Added clause-shape detection from DIMACS content only.
- Added complete model verification before SAT output.
- Added recovered 16-input depth-9 phase hints.
- Added VeriPB RUP proof logging for proof-search shapes.
- Added local probe script under `tools/` for testing fixed comparator schedules.
