# Solver Notes

## Formula Notes

The training instances are structurally clique-coloring formulas. Comments and
filenames are not needed for detection.

Variable layout recovered from clauses:

- `1..n*(n-1)/2`: edge variables for unordered graph pairs.
- Next `k*n` variables: `k` one-hot selector blocks of width `n`, selecting
  distinct vertices intended to form a clique.
- Final `n*c` variables: `n` one-hot color blocks of width `c`.

Clause families:

- Each selector block has exactly-one clauses. Cross-position clauses forbid
  selecting the same vertex twice.
- Ternary clauses `edge(u,v) OR not sel(p,u) OR not sel(q,v)` force all
  selected vertices to be pairwise adjacent.
- Each vertex color block has exactly-one clauses.
- Ternary clauses `not edge(u,v) OR not color(u,a) OR not color(v,a)` enforce
  proper coloring.

Thus the high-level question is whether there exists a graph on `n` vertices
with a selected `k`-clique and a proper `c`-coloring. This is SAT when
`k <= c` and UNSAT when `k > c`.

Visible train parameters:

- `n=12,k=9,c=8`
- `n=14,k=9,c=8`
- `n=16,k=7,c=6`
- `n=32,k=5,c=4`

All visible train instances are in the pigeonhole UNSAT regime `k=c+1`.

## Techniques Used

The current solver recovers `n`, `k`, and `c` from positive long exactly-one
clauses and verifies the expected variable count and one-hot block positions.
For `k <= c`, it constructs a concrete satisfying assignment:

- selector position `p` chooses vertex `p`;
- clique vertices receive distinct colors;
- all clique edges are set true;
- all other variables default false except one color per non-clique vertex.

Before printing `SATISFIABLE`, the solver evaluates every original clause under
the assignment. Any detection or model-check failure returns `UNKNOWN`.

For `k > c`, the solver emits a VeriPB proof. It introduces fresh proof
variables `z[p,v,a]` for the conjunction of selector `sel[p,v]` and color
`color[v,a]` using redundance lines. It then derives:

- for each selected clique position, at least one matching `z[p,v,a]` is true;
- for each fixed color, at most one `z[p,v,a]` over all positions and vertices
  is true, using pairwise RUP conflicts and a small proof-by-contradiction;
- summing those constraints gives `k <= c`, contradicting the detected
  `k > c`.

Local VeriPB checks pass for all visible train instances.

## Remaining Things To Try

- Reduce proof size by introducing coarser position-color indicators, if needed
  on larger hidden instances.
- Add stronger structure validation for every expected ternary family before
  returning UNSAT, though the current proof is still checked by VeriPB.
- Investigate variants where the long selector and color block sizes coincide.

## Known Limitations

- Detection assumes the recovered variable layout is contiguous and ordered as
  in the train family. It intentionally returns `UNKNOWN` for variants that do
  not match this structure.
- Proof size is quadratic in `k*n` per color because it logs pairwise conflicts
  between same-color conjunction variables.

## Changelog

- Initial scaffold: trivial UNKNOWN solver.
- Recovered the clique/coloring encoding: edge variables, clique selector
  one-hot blocks, and color one-hot blocks.
- Implemented structural detection, direct SAT construction for `k <= c`,
  full CNF model checking before SAT output, metadata update, and this working
  notebook.
- Added a VeriPB UNSAT proof generator for `k > c` using fresh conjunction
  variables, RUP implications/conflicts, PBC-derived color at-most-one
  constraints, and a final cutting-planes contradiction.
- Verified generated UNSAT proofs locally on all visible training instances and
  tested the SAT constructor on a synthetic `n=4,k=3,c=3` instance.
