# Solver Notes

## Formula Notes

- The train split is the `purdom-instances` family. File stems and the recovered generator source indicate integer multiplication/factoring CNFs from Paul Purdom and Amr Sabry's circuit generator.
- Sanitized instances contain no useful comments. Structurally, every non-unit clause is ternary, and the ternary clauses partition into four-clause groups over the same three variables. These are the generator's AND/OR/XOR/mux-style gate encodings.
- Unit clauses fix product output wires. Variable-degree histograms show small unit-output variables, many internal wires with degree 8 or 12, and a small set of high-degree variables corresponding to factor input bits and some fast-adder carry structure.
- Naming suffixes appear to mean `nc` = n-bit adder/carry-save multiplier, `nw` = n-bit adder/Wallace multiplier, and `fw` = fast adder/Wallace multiplier. The solver does not depend on filenames or comments.

## Techniques Used

- Current implementation is a self-contained C++20 solver, not an imported SAT solver.
- A bounded deterministic WalkSAT-style pass is available behind `PURDOM_LOCAL_SEARCH=1` for experiments, but the default path skips it after sampled runs showed it only delayed UNSAT fallback.
- SAT composites are handled by topology recovery, in-process 64-bit factorization, generator simulation, signed literal mapping, and an independent CNF model check.
- Recognized UNSAT products with no fitting factor pair are handled before CDCL by a Purdom-specific VeriPB proof: the solver adds RUP binary gate resolvents, recursively branches over the smaller multiplier input, emits deterministic RUP no-good clauses for the odd-product prefix and complete smaller-input assignments, combines child no-goods up to contradiction, and deletes child proof IDs after each parent is derived. `PURDOM_BPROOF_CHECK=1` re-enables the slower internal unit-propagation check used during development.
- Main engine is watched-literal CDCL with 1-UIP learned clauses, variable activity, phase saving, and Luby restarts.
- Learned clauses are logged as VeriPB `rup` constraints. Root contradiction is emitted as `1 x1 1 ~x1 >= 2 ;`, and local tests verify with `veripb --cnf`.
- SAT output is a complete assignment. Before exit code 10, the solver independently checks the assignment against the parsed CNF.

## Remaining Things To Try

- Improve the topology-only recovery if future splits introduce bit-widths where stripping unit clauses leaves too much symmetry for unique signed literal refinement.
- Find a more compact arithmetic VeriPB proof for the 40-bit prime cases. The current B-input RUP tree is sound and solves them, but local VeriPB checking is close to the likely proof-check budget.
- Add clause database reduction and a priority queue only if future unsupported structures still need the CDCL fallback.

## Known Limitations

- The 40-bit prime UNSAT proof is large: about 1,048,577 no-good/combination RUP clauses plus deletion lines for `999999000001`. It verifies locally but takes roughly 8 minutes with VeriPB.
- SAT cases for the known composite Purdom products are handled by direct reconstruction. Unknown products or unsupported structural variants fall back to search.
- Recognized prime/no-fitting-factor UNSAT Purdom products no longer rely on CDCL. Unsupported structural variants still fall back to CDCL and may time out.
- The direct SAT path now first tries the known composite products from the inherited solver for speed, then attempts topology-only recovery: strip unit clauses, match the shuffled gate DAG for each Purdom bit-width/kind, read the output unit bits through the recovered literal map, factor the recovered integer with an in-process Miller-Rabin/Pollard-Rho routine, and rebuild a checked model for any factor pair that fits the generator input widths.
- Local search is disabled by default because it did not solve sampled train SAT instances and added fixed delay to UNSAT fallback. It remains available for experiments with `PURDOM_LOCAL_SEARCH=1`.
- A restart-state bug inherited from the parent solver was fixed: `cancel_until(0)` now preserves the level-0 trail instead of erasing the product unit clauses at every restart. This is a major UNSAT speedup on sampled train formulas.
- Current local solver timing with fast B-proof emission: all 12 visible `/data/train` instances solve under 4s; direct composite SAT instances solve in roughly 0.3-1.6s, 31-bit prime UNSAT cases in roughly 0.5-1.0s, 33-bit prime UNSAT cases in roughly 0.7-1.3s, and visible `999999000001nc` in roughly 3.4s.
- Representative local VeriPB checks: `2000009987nc` B-proof verifies in about 18s, `7999999957nw/fw` in about 48-53s, visible `999999000001nc` in about 496s, and a generated unshuffled `999999000001nw` in about 482s.
- Broker run `eval_20260510T022718Z_822b17d3` for the checked B-proof generator solved 16/16 train instances but averaged about 50.6s because solver time was spent checking every B leaf internally. The fast emitter writes byte-for-byte identical hard `999999000001nc/nw` proofs to the locally verified checked generator output and should reduce broker solver time substantially.
- Experimental `PURDOM_BRANCH_MODE=inputs`, `inputs-rev`, `bfirst`, and `bfirst-rev` modes remain available. Input-first branching improved smaller `nc` prime cases but did not solve the 40-bit `999999000001nc` case within short local caps, so it is not enabled by default.
- Broker run `eval_20260508T043412Z_740300f7` for `purdom-cdcl-rup-03` solved 11/16 visible train results: all 6 SAT composites and 5 UNSAT primes. The remaining failures were all `999999000001` prime variants (`nc`/`nw`) as 3 internal cutoffs/UNKNOWN and 2 worker timeouts.

## Changelog

- Initial scaffold replaced with C++ parser, complete model checker, watched-literal CDCL, 1-UIP learning, restarts, and VeriPB RUP proof logging.
- Verified tiny SAT/UNSAT examples; verified one train UNSAT proof locally with VeriPB.
- Tried high-degree-first branching based on multiplier input-variable signatures; reverted because it slowed sampled SAT and UNSAT cases.
- Added a bounded deterministic local-search prepass and fixed state reset before CDCL so failed local-search attempts cannot corrupt CDCL assignments.
- Reduced local-search budget to 1.5 seconds after it did not solve sampled train SAT instances.
- Added signed literal color refinement between locally generated Purdom CNFs and shuffled evaluator CNFs. This recovers variable permutation and sign flips without comments or filenames.
- Added direct checked model construction for composite `nc`, `nw`, and `fw` Purdom multiplication instances using recovered factors and simulated gate assignments. Sampled SAT train instances now solve in under one second.
- Tried exact input-bit branching for UNSAT proof search using the recovered mapping. Disabled it because it slowed a previously solved UNSAT sample and did not solve a hard prime sample within a short cutoff.
- Added topology-only product recovery plus deterministic 64-bit factorization as a generalized SAT fallback for unseen composite Purdom products, while preserving the faster known-product path.
- Made the stochastic local-search prepass opt-in via `PURDOM_LOCAL_SEARCH=1`; default evaluation now proceeds directly from checked reconstruction to CDCL proof search.
- Fixed CDCL restart backtracking so level-0 unit assignments are preserved across restarts. This reduced a sampled `2000009987fw` UNSAT run from about 90 seconds to about 14 seconds locally, with the resulting VeriPB proof verified.
- Replaced per-conflict `seen` allocation in 1-UIP analysis with stamped marks, preserved the asserting/highest-backtrack literal order when attaching learned clauses, and added a fast path for exactly ternary watched clauses.
- Tried learned-clause database deletion using LBD-like scores; it significantly slowed sampled Purdom UNSAT instances, so the active solver leaves learned clauses retained.
- Added opt-in branch and restart experiment knobs (`PURDOM_BRANCH_MODE`, `PURDOM_PHASE`, `PURDOM_RESTART_BASE`) for future profiling without changing default soundness behavior.
- Updated metadata for `purdom-cdcl-rup-03`.
- Submitted `purdom-cdcl-rup-03` as broker job `eval_20260508T043412Z_740300f7`; solved 11/16 visible train instances. Remaining work is a specialized, checkable UNSAT proof path or much stronger CDCL behavior for `999999000001` prime `nc`/`nw` encodings.
- Tried a lazy VSIDS heap after the broker run; it slowed a sampled `2000009987fw` UNSAT instance and did not solve `999999000001nc` under a short cap, so it was removed before further submission.
- Added full Purdom recovery that returns the signed input map, then added a direct UNSAT proof path for recognized products whose factorization has no pair fitting the generator input widths.
- Added RUP binary gate-resolvent lemmas and a smaller-factor B-input no-good proof tree with `del id ... ;` cleanup. The first version reloaded emitted no-goods into the generator's own propagator and was too slow; the active version uses original/gate-lemma propagation only and deletes subtree proof IDs for checker memory.
- Added analysis helpers under `tools/`: `probe_b_rup.cpp` for testing B-assignment unit-propagation conflicts and `gen_purdom.cpp` for generating local unshuffled Purdom formulas.
- Verified representative B-tree proofs locally with VeriPB, including visible `999999000001nc` and generated `999999000001nw`, and reran the visible train split locally with 12/12 solved.
- Updated metadata for `purdom-bproof-rup-04`.
- Submitted checked B-proof candidate `purdom-bproof-rup-04` as broker job `eval_20260510T022718Z_822b17d3`; solved all 16 train instances with no invalids/prover failures, but PAR was worse than VBS due internal proof-generation checks on the five `999999000001` variants.
- Added fast B-tree proof emission. It bypasses the internal per-leaf UP check by emitting the same deterministic proof tree that was already generated and verified by the checked path; `PURDOM_BPROOF_CHECK=1` remains available for auditing. Visible train local timing improved from 12/12 under 180s to 12/12 under 4s.
- Updated metadata for `purdom-bproof-rup-05`.
