# Solver Notes

## Formula Notes

- The training split is a family of bit-vector sorting algorithm equivalence
  miters.  Names mention Bubble/Pancake/Insertion/Selection sorting, but the
  solver does not read filenames or comments.
- Formulas are topologically ordered Tseitin circuits.  The first `n * k`
  variables are input item bits.  Later blocks implement unsigned comparisons,
  mux-based compare-swap operations, XORs between the two network outputs, ORs
  per output word, and a final asserted miter OR.
- Parameters observed locally include `n` from 5 to 9 and bit width `k` from 3
  to 8.  Clause sizes are dominated by binary/ternary gate clauses plus small
  4/5-literal compare clauses and final OR clauses of size `n + 1` or `k + 1`.
- The final miter can be recovered without comments: the asserted final OR has
  `n` word-difference OR inputs; each word OR has `k` XOR inputs.  The first
  `n * k` variables are exactly the variables that never appear as the maximum
  variable of a defining clause.
- All baseline solved instances are UNSAT.  The current solver still proves
  UNSAT by CDCL/RUP rather than by a compact high-level sorting-network proof.

## Techniques Used

- DIMACS parser with no dependence on comments, paths, hashes, or filenames.
- Watched-literal Boolean constraint propagation and first-UIP CDCL, written
  from scratch in `solver.cpp`.  Binary clauses now use a dedicated implication
  watch path while retaining normal clause IDs for conflict analysis and proof
  logging.
- Initial activity and polarity are biased toward the positive miter cone,
  high-numbered tail variables, and the structurally recovered final XOR bits.
  This helps the search focus on output differences before drifting through
  arbitrary internal gates.
- A second structural activity boost is enabled for large formulas whose final
  XORs reference unusually early circuit variables; this catches the harder
  Bubble/Pancake-style miter layout without looking at filenames.
- Every learned clause is emitted as a VeriPB `rup` line.  Internal learned
  clause reduction marks weak learned clauses deleted and emits matching
  `del id ...` proof events, which improved proof-checking feasibility on
  large local traces.
- Proof logging uses a buffered writer, a reused proof-line buffer, and custom
  literal formatting to reduce overhead on multi-GB RUP traces.
- SAT answers, if ever found, are checked against the original clauses before
  printing a model.  UNSAT answers rely on the broker/VeriPB checker.

## Local Results

- `PancakeVsSelectionSort_5_6`: current solver about 6.1s after the binary
  implication watch change; VeriPB proof check about 20s with deletion events.
- `PancakeVsInsertSort_6_6`: solver about 61s; VeriPB proof check about 204s.
- `BubbleVsPancakeSort_6_6`: solver about 59s locally.
- `PancakeVsInsertSort_6_8`: current solver about 149s locally with exact
  miter-XOR activity boosting and binary implication watches.
- `BubbleVsPancakeSort_6_8`: solved locally in about 176s after adding the
  early-output-dependency activity boost.
- `PancakeVsSelectionSort_6_7`: solved locally in about 394s after the binary
  implication watch change; the proof is large and a local 900s VeriPB check
  did not finish, but the broker verifier has a 3000s limit.
- Broker submission `eval_20260509T045827Z_46125da2` for the inherited solver
  state solved 8/29 visible train results (`unsat`) and returned 21 `unknown`;
  it was sound but still below the 15/29 VBS baseline.
- Broker submission `eval_20260508T184924Z_a93096bc` solved 7/29 before the
  proof-logging and early-output-dependency changes.  It was sound but still
  below the 15/29 Kissat baseline.
- First broker submission solved 6/29 (`unsat`) and returned 23 `unknown`;
  this is sound but below the 15/29 Kissat baseline.
- Several larger instances still exceed a 180s local solver cutoff, including
  `PancakeVsSelectionSort_8_3`, `PancakeVsInsertSort_9_3`, and width-8 `n=6`
  cases.  The broker's 600s timeout may close some of these.

## Remaining Things To Try

- Replace CDCL proof search with a compact high-level proof of sorting network
  equivalence.  The likely route is a threshold/rank invariant: for every
  threshold, compare-swap maps predicates by AND/OR, so both networks produce
  the same sorted predicate vector.
- Learn or prove local compare-swap sortedness constraints and add them before
  the global miter proof.  Direct RUP of sortedness clauses failed in early
  experiments, so they need subproofs or a PB proof strategy.
- Improve CDCL with LBD-aware restarts, better clause minimization, and more
  precise miter/XOR assumption scheduling.  A failed-literal pass over output
  XOR bits was tested and was slower on `PancakeVsSelectionSort_5_6`.
- Local mux permutation lemmas are RUP-verifiable, but adding all such lemmas
  slowed the current CDCL search on small local tests.  They may still be useful
  inside a threshold/rank proof generator.
- Consider VeriPB `red`/dominance rules for symmetry or zero-one-principle
  reductions if the proof format can be used safely.

## Known Limitations

- This is still a CDCL proof generator, not the final specialized
  high-level solver envisioned by the mission.  It may not beat Kissat on
  solved count.
- Proofs are large.  Deletion events help on larger traces but increase line
  count and can slow small proof checks.
- Exact miter-XOR detection is active only as a branching/activity heuristic.
  The structural mux-lemma code remains in the source for future experiments
  but is not active in the current search path.
- Dedicated binary propagation improves solver speed but does not change the
  underlying CDCL proof size enough for the larger `7_x`, `8_x`, and `9_x`
  misses; several still return UNKNOWN near the 600s cutoff.

## Changelog

- Replaced the placeholder with a C++20 watched-literal CDCL solver.
- Added VeriPB RUP proof emission and local proof verification.
- Fixed root-level backtracking so unit assignments are preserved.
- Added conservative SAT model verification before returning SAT.
- Added learned clause database reduction and mirrored VeriPB deletion events.
- Changed proof generation to stream directly to `<out.pbp>` and free deleted
  learned clause literals, reducing long-run memory pressure substantially.
- Added `tools/profile_family.py` for repeatable family statistics.
- Updated metadata and this notebook before broker submission.
- Enabled structural recovery of final miter XOR bits and boosted them in the
  initial CDCL activity heuristic; this improved local small-instance runtime
  and kept proofs VeriPB-checkable.
- Tested failed-literal proving over final XOR bits, learned-clause
  minimization, Luby restarts, XOR-output-bit boosting, and bulk mux permutation
  lemmas; these variants regressed local wall time or timed out and are not
  active in the submitted path.
- Optimized proof-line emission with buffered binary output and custom PB
  literal formatting, reducing local `PancakeVsInsertSort_6_8` wall time from
  about 198s to about 188s without changing the conflict trace.
- Added a guarded early-output-dependency activity boost for large formulas
  whose final XOR cone reaches very early variables; this solved the local
  `BubbleVsPancakeSort_6_8` instance that the previous submission missed.
- Submitted the inherited state as `eval_20260509T045827Z_46125da2`; it solved
  8/29 visible train results and remained below the 15/29 baseline.
- Added a dedicated binary-clause implication watch path.  This preserves
  clause IDs for reasons/proofs, speeds local `PancakeVsInsertSort_6_8` from
  roughly 190s to 149s, and newly solves local
  `PancakeVsSelectionSort_6_7` within the solver timeout.
- Reused the proof-line string buffer and increased the proof stream buffer to
  reduce allocation and I/O overhead during multi-GB RUP trace generation.
- Tested and rejected several variants in this run: lower-size early-output
  boosting, stronger output-dependency boosting, word-OR miter branching,
  failed-literal seeding with a tiny budget, learned-clause minimization
  (rejected by VeriPB), root simplification, lazy activity heap branching,
  mux permutation lemmas, and more frequent database reduction.
