Skip to main content

logicaffeine_proof/
sym_certify.rs

1//! Certified symmetry breaking — the centerpiece. Given a formula and a set of verified
2//! symmetry generators, add lex-leader symmetry-breaking predicates as **PR steps** (each
3//! self-checked, fail-closed), solve the augmented formula, and emit a single composed
4//! refutation that an independent checker accepts against the *original* formula alone.
5//!
6//! This closes the soundness gap of the old path (where the symmetry-broken formula was RUP-
7//! certified but the model-removing addition was only argued informally): here every SBP clause
8//! carries a propagation-redundancy witness derived from its symmetry, so the whole UNSAT
9//! result — symmetry steps included — is machine-checkable. The decisive wiring invariant is
10//! that `check_pr_refutation` runs against `formula` ALONE; the SBP clauses appear only as PR
11//! steps, never as free original clauses.
12
13use crate::cdcl::{Lit, SolveResult, Solver, Var};
14use crate::pr::{check_pr_refutation, is_pr};
15use crate::proof::{Perm, ProofStep, Witness};
16use crate::symmetry_detect::find_generators;
17
18/// The outcome of a certified-symmetry-breaking solve.
19#[derive(Clone, Debug)]
20pub struct CertifiedRefutation {
21    /// Whether the formula was refuted (proven UNSAT) AND the composed PR proof checks.
22    pub refuted: bool,
23    /// How many lex-leader SBP clauses were PR-certified and added.
24    pub sbp_clauses: usize,
25    /// The composed proof stream: PR symmetry steps followed by RUP learned clauses.
26    pub steps: Vec<ProofStep>,
27}
28
29/// The first-index lex-leader clause for `sigma`: over the smallest variable `v` that `sigma`
30/// moves, assert `v ⟹ sigma(v)` (the leading bit of `x ≤ₗₑₓ sigma(x)`). Returns `None` if
31/// `sigma` is the identity.
32fn lex_leader_lead_clause(num_vars: usize, sigma: &Perm) -> Option<Vec<Lit>> {
33    for v in 0..num_vars as Var {
34        let image = sigma.apply(Lit::pos(v));
35        if image != Lit::pos(v) {
36            return Some(vec![Lit::neg(v), image]);
37        }
38    }
39    None
40}
41
42/// Build the full lex-leader symmetry-breaking predicate for `sigma` over the moved-variable
43/// order, enforcing `x ≤ₗₑₓ σ(x)`. Returns the clauses (over base variables plus fresh auxiliary
44/// "tied-so-far" variables `e_i`, allocated starting at `aux_start`) and the number of aux
45/// variables used. This is the linear-size encoding that prunes the entire non-leader half of
46/// every σ-orbit — the real search-collapse predicate.
47pub fn lex_leader_clauses(
48    num_vars: usize,
49    aux_start: usize,
50    sigma: &Perm,
51) -> (Vec<Vec<Lit>>, usize) {
52    let support: Vec<Var> = (0..num_vars as Var)
53        .filter(|&v| sigma.apply(Lit::pos(v)) != Lit::pos(v))
54        .collect();
55    let mut clauses: Vec<Vec<Lit>> = Vec::new();
56    if support.is_empty() {
57        return (clauses, 0);
58    }
59    let a = |i: usize| Lit::pos(support[i]);
60    let b = |i: usize| sigma.apply(Lit::pos(support[i]));
61
62    // Position 0: a_0 ≤ b_0 unconditionally (the prefix before it is empty, hence tied).
63    clauses.push(vec![a(0).negated(), b(0)]);
64
65    // For i ≥ 1: define e_i ⟺ (tied through i-1) ∧ (a_{i-1} = b_{i-1}), then constrain
66    // e_i → (a_i ≤ b_i). `prev` is the tied-so-far literal (None at position 1 means "true").
67    let mut next_aux = aux_start;
68    let mut prev: Option<Lit> = None;
69    for i in 1..support.len() {
70        let e = Lit::pos(next_aux as Var);
71        next_aux += 1;
72        let (ap, bp) = (a(i - 1), b(i - 1));
73        match prev {
74            None => {
75                // e ⟺ (a_{i-1} = b_{i-1}).
76                clauses.push(vec![e.negated(), ap.negated(), bp]);
77                clauses.push(vec![e.negated(), ap, bp.negated()]);
78                clauses.push(vec![e, ap, bp]);
79                clauses.push(vec![e, ap.negated(), bp.negated()]);
80            }
81            Some(pe) => {
82                // e ⟺ pe ∧ (a_{i-1} = b_{i-1}).
83                clauses.push(vec![e.negated(), pe]);
84                clauses.push(vec![e.negated(), ap.negated(), bp]);
85                clauses.push(vec![e.negated(), ap, bp.negated()]);
86                clauses.push(vec![pe.negated(), e, ap, bp]);
87                clauses.push(vec![pe.negated(), e, ap.negated(), bp.negated()]);
88            }
89        }
90        clauses.push(vec![e.negated(), a(i).negated(), b(i)]);
91        prev = Some(e);
92    }
93    (clauses, next_aux - aux_start)
94}
95
96/// Solve `formula` with certified symmetry breaking under the given `generators` (each must be
97/// a genuine automorphism — they are re-checked implicitly by the per-clause PR self-check).
98///
99/// For each generator we propose its lead lex-leader clause, PR-self-check it against the
100/// database built so far (so a generator invalidated by earlier SBPs is simply skipped), add
101/// the survivors as PR steps, solve the augmented formula, and — if UNSAT — append the solver's
102/// learned clauses as RUP steps. The composed stream is verified against `formula` alone.
103pub fn certified_unsat(
104    num_vars: usize,
105    formula: &[Vec<Lit>],
106    generators: &[Perm],
107) -> CertifiedRefutation {
108    let mut db: Vec<Vec<Lit>> = formula.to_vec();
109    let mut steps: Vec<ProofStep> = Vec::new();
110
111    for sigma in generators {
112        let Some(clause) = lex_leader_lead_clause(num_vars, sigma) else {
113            continue;
114        };
115        let witness = Witness::Substitution(sigma.clone());
116        if is_pr(num_vars, &db, &clause, &witness) {
117            db.push(clause.clone());
118            steps.push(ProofStep::Pr { clause, witness });
119        }
120    }
121    let sbp_clauses = steps.len();
122
123    // Solve the augmented formula F ∧ SBP and collect its learned clauses as RUP steps.
124    let mut solver = Solver::new(num_vars);
125    for c in &db {
126        solver.add_clause(c.clone());
127    }
128    let refuted = match solver.solve() {
129        SolveResult::Sat(_) => false,
130        SolveResult::Unsat => {
131            for lc in solver.learned() {
132                steps.push(ProofStep::Rup(lc.lits.clone()));
133            }
134            // The decisive check: the whole stream is replayed against the ORIGINAL formula.
135            check_pr_refutation(num_vars, formula, &steps)
136        }
137    };
138
139    CertifiedRefutation {
140        refuted,
141        sbp_clauses,
142        steps,
143    }
144}
145
146/// Find a PR assignment-witness that certifies lex-leader clause `c` against `db`, drawing from
147/// a small principled candidate set (single literals of the clause, then the tied-prefix aux
148/// chain optionally combined with a clause literal). Every candidate is verified by [`is_pr`],
149/// so a returned witness is genuinely sound; `None` means none of the candidates worked.
150fn find_lex_witness(
151    nv: usize,
152    db: &[Vec<Lit>],
153    c: &[Lit],
154    base_nv: usize,
155    sigma: &Perm,
156) -> Option<Witness> {
157    // The substitution witness certifies the lead clause at ANY scale (its `db ∧ ¬C ⊢₁ σ(C)`
158    // check conflicts immediately), where an assignment witness would need F|α to be UP-refutable
159    // — which fails on large formulas. Try it first; it is rejected (fail-closed) once an earlier
160    // predicate has broken σ's automorphism of the database. σ is lifted to the auxiliary
161    // variables (as the identity) so the check is defined over the extended database.
162    let subst = Witness::Substitution(sigma.extended(nv));
163    if is_pr(nv, db, c, &subst) {
164        return Some(subst);
165    }
166    let accept = |lits: Vec<Lit>| {
167        let w = Witness::Assignment(lits);
168        is_pr(nv, db, c, &w).then_some(w)
169    };
170    // The witness only ever touches the clause's own variables and the auxiliary "tied" chain up
171    // to the clause's highest aux. Gather both polarities of those as the candidate pool.
172    let max_aux = c
173        .iter()
174        .map(|l| l.var())
175        .filter(|&v| (v as usize) >= base_nv)
176        .max();
177    let mut vars: Vec<Var> = c.iter().map(|l| l.var()).collect();
178    if let Some(ma) = max_aux {
179        vars.extend(base_nv as Var..=ma);
180    }
181    vars.sort_unstable();
182    vars.dedup();
183    let lits: Vec<Lit> = vars
184        .iter()
185        .flat_map(|&v| [Lit::pos(v), Lit::neg(v)])
186        .collect();
187
188    // Size 1.
189    for &l in &lits {
190        if let Some(w) = accept(vec![l]) {
191            return Some(w);
192        }
193    }
194    // The tied-prefix chain (the monotonicity clauses' witness), alone and with a clause literal.
195    if let Some(ma) = max_aux {
196        let prefix: Vec<Lit> = (base_nv as Var..ma).map(Lit::pos).collect();
197        if let Some(w) = accept(prefix.clone()) {
198            return Some(w);
199        }
200        for &l in c {
201            let mut cand = prefix.clone();
202            cand.push(l);
203            if let Some(w) = accept(cand) {
204                return Some(w);
205            }
206        }
207    }
208    // Size 2 over the candidate pool (no two literals of the same variable). Bounded on purpose:
209    // deeper witnesses do not exist for clauses whose certification would need F|α to be
210    // UP-refutable, so searching further only wastes time failing.
211    for i in 0..lits.len() {
212        for j in (i + 1)..lits.len() {
213            if lits[i].var() == lits[j].var() {
214                continue;
215            }
216            if let Some(w) = accept(vec![lits[i], lits[j]]) {
217                return Some(w);
218            }
219        }
220    }
221    None
222}
223
224/// Solve `formula` with FULL certified lex-leader symmetry breaking. For each generator, add the
225/// complete lex-leader chain (enforcing `x ≤ₗₑₓ σ(x)`) as PR steps — each clause certified by a
226/// principled witness — then solve and append the learned clauses as RUP steps. This prunes the
227/// non-leader half of every σ-orbit (real search collapse), with the whole refutation checked
228/// against `formula` alone. A generator whose chain cannot be fully certified is skipped
229/// (fail-closed); the result stays sound.
230/// Augment `formula` with the certified full lex-leader symmetry-breaking clauses for each
231/// generator, committing a generator's chain only when every clause of it certifies (else the
232/// generator is skipped — fail-closed). Returns the augmented clause set, the extended variable
233/// count (base + auxiliaries), and the PR proof steps that justify the added clauses. This is
234/// the symmetry-breaking front half shared by certified solving and by search-collapse
235/// measurement.
236pub fn symmetry_break_certified(
237    num_vars: usize,
238    formula: &[Vec<Lit>],
239    generators: &[Perm],
240) -> (Vec<Vec<Lit>>, usize, Vec<ProofStep>) {
241    let mut db: Vec<Vec<Lit>> = formula.to_vec();
242    let mut steps: Vec<ProofStep> = Vec::new();
243    let mut nv = num_vars;
244    for sigma in generators {
245        let (clauses, num_aux) = lex_leader_clauses(num_vars, nv, sigma);
246        if clauses.is_empty() {
247            continue;
248        }
249        let ext_nv = nv + num_aux;
250        // Commit each clause of the chain that certifies (a partial lex-leader is still sound —
251        // every committed clause is independently PR-checked); skip any that don't.
252        let mut committed = false;
253        for c in &clauses {
254            if let Some(w) = find_lex_witness(ext_nv, &db, c, num_vars, sigma) {
255                db.push(c.clone());
256                steps.push(ProofStep::Pr {
257                    clause: c.clone(),
258                    witness: w,
259                });
260                committed = true;
261            }
262        }
263        if committed {
264            nv = ext_nv;
265        }
266    }
267    (db, nv, steps)
268}
269
270pub fn certified_unsat_lex(
271    num_vars: usize,
272    formula: &[Vec<Lit>],
273    generators: &[Perm],
274) -> CertifiedRefutation {
275    let (db, nv, mut steps) = symmetry_break_certified(num_vars, formula, generators);
276    let sbp_clauses = steps.len();
277
278    let mut solver = Solver::new(nv);
279    for c in &db {
280        solver.add_clause(c.clone());
281    }
282    let refuted = match solver.solve() {
283        SolveResult::Sat(_) => false,
284        SolveResult::Unsat => {
285            for lc in solver.learned() {
286                steps.push(ProofStep::Rup(lc.lits.clone()));
287            }
288            check_pr_refutation(nv, formula, &steps)
289        }
290    };
291
292    CertifiedRefutation {
293        refuted,
294        sbp_clauses,
295        steps,
296    }
297}
298
299/// The permutation that swaps two pigeons of PHP(n) (exchanging their whole hole-rows) — a
300/// genuine automorphism of the pigeonhole formula.
301fn swap_pigeons(n: usize, holes: usize, i: usize, j: usize) -> Perm {
302    Perm::from_images(
303        (0..n * holes)
304            .map(|v| {
305                let (p, h) = (v / holes, v % holes);
306                let np = if p == i {
307                    j
308                } else if p == j {
309                    i
310                } else {
311                    p
312                };
313                Lit::pos((np * holes + h) as Var)
314            })
315            .collect(),
316    )
317}
318
319/// The Heule–Kiesl–Biere short PR refutation of PHP(n): a polynomial-size, fully certified proof
320/// — where the lex-leader provably cannot scale on UNSAT instances.
321///
322/// It frees holes one at a time. To free the last active hole `h` of PHP(m), it forces every
323/// non-last pigeon `i` out of it with the clause `¬x(i, h)`, certified by the **substitution
324/// witness "swap pigeon i with the last pigeon"** — a PHP automorphism whose SR check conflicts
325/// at once on the hole-`h` conflict clause (so it is sound at any scale). That confines the
326/// remaining pigeons to one fewer hole, reducing PHP(m) → PHP(m-1); after `O(n²)` such units RUP
327/// closes. The whole refutation is checked against the original PHP(n) alone.
328pub fn heule_php_refutation(n: usize) -> CertifiedRefutation {
329    let (cnf, _) = crate::families::php(n);
330    let holes = n.saturating_sub(1);
331    let nv = cnf.num_vars;
332    let mut db = cnf.clauses.clone();
333    let mut index = crate::symmetry_detect::AutomorphismIndex::with_clauses(nv, &cnf.clauses);
334    let mut steps: Vec<ProofStep> = Vec::new();
335
336    // Reduce PHP(m) to PHP(m-1) for m = n, n-1, …, 2, freeing hole (m-2) each round. The
337    // automorphism re-check rides the incrementally-grown index, so each step is O(support).
338    for m in (2..=n).rev() {
339        let hole = m - 2;
340        let last_pigeon = m - 1;
341        for i in 0..last_pigeon {
342            let clause = vec![Lit::neg((i * holes + hole) as Var)];
343            let witness = Witness::Substitution(swap_pigeons(n, holes, i, last_pigeon));
344            if crate::pr::is_pr_indexed(nv, &db, &mut index, &clause, &witness) {
345                db.push(clause.clone());
346                index.insert(clause.clone());
347                steps.push(ProofStep::Pr { clause, witness });
348            }
349        }
350    }
351    let sbp_clauses = steps.len();
352
353    let mut solver = Solver::new(nv);
354    for c in &db {
355        solver.add_clause(c.clone());
356    }
357    let refuted = match solver.solve() {
358        SolveResult::Sat(_) => false,
359        SolveResult::Unsat => {
360            for lc in solver.learned() {
361                steps.push(ProofStep::Rup(lc.lits.clone()));
362            }
363            crate::pr::check_pr_refutation_fast(nv, &cnf.clauses, &steps)
364        }
365    };
366
367    CertifiedRefutation {
368        refuted,
369        sbp_clauses,
370        steps,
371    }
372}
373
374/// The vertex-swap automorphism of `clique_coloring(n, k)`: exchange vertices `a` and `b` (every
375/// color of one ↔ the same color of the other), fixing all other vertices. A genuine symmetry of
376/// `Kₙ` (any two vertices are interchangeable), so it certifies the SR witnesses of a steered
377/// coloring refutation — variable layout `v*k + c`.
378fn swap_vertices(n: usize, k: usize, a: usize, b: usize) -> Perm {
379    let nv = n * k;
380    Perm::from_images(
381        (0..nv)
382            .map(|idx| {
383                let (v, c) = (idx / k, idx % k);
384                let nv2 = if v == a {
385                    b
386                } else if v == b {
387                    a
388                } else {
389                    v
390                };
391                Lit::pos((nv2 * k + c) as Var)
392            })
393            .collect(),
394    )
395}
396
397/// **Full-chain structural steering** of `clique_coloring(n, k)` (UNSAT for `k < n`): the Heule
398/// pigeonhole refutation transplanted onto the coloring encoding, wielding the *a-priori*
399/// vertex-swap symmetry rather than detecting it. `k + 1` mutually-adjacent vertices already form a
400/// PHP(k+1, k), so the proof forces those `k+1` vertices out of the colors one at a time — each
401/// clause `¬x(i, color)` certified by the substitution "swap vertex `i` with the last active
402/// vertex", whose SR check clashes at once on the corresponding at-most-one clause. The whole
403/// stream is verified against the original clique formula alone.
404pub fn heule_clique_refutation(n: usize, k: usize) -> CertifiedRefutation {
405    let (cnf, _) = crate::families::clique_coloring(n, k);
406    let nv = cnf.num_vars;
407    let mut db = cnf.clauses.clone();
408    let mut index = crate::symmetry_detect::AutomorphismIndex::with_clauses(nv, &cnf.clauses);
409    let mut steps: Vec<ProofStep> = Vec::new();
410    // k+1 vertices (capped at n) are a tight pigeonhole over the k colors.
411    let items = (k + 1).min(n);
412    let var = |v: usize, c: usize| (v * k + c) as Var;
413
414    for m in (2..=items).rev() {
415        let color = m - 2;
416        let last_vertex = m - 1;
417        for i in 0..last_vertex {
418            let clause = vec![Lit::neg(var(i, color))];
419            let witness = Witness::Substitution(swap_vertices(n, k, i, last_vertex));
420            if crate::pr::is_pr_indexed(nv, &db, &mut index, &clause, &witness) {
421                db.push(clause.clone());
422                index.insert(clause.clone());
423                steps.push(ProofStep::Pr { clause, witness });
424            }
425        }
426    }
427    let sbp_clauses = steps.len();
428
429    let mut solver = Solver::new(nv);
430    for c in &db {
431        solver.add_clause(c.clone());
432    }
433    let refuted = match solver.solve() {
434        SolveResult::Sat(_) => false,
435        SolveResult::Unsat => {
436            for lc in solver.learned() {
437                steps.push(ProofStep::Rup(lc.lits.clone()));
438            }
439            crate::pr::check_pr_refutation_fast(nv, &cnf.clauses, &steps)
440        }
441    };
442
443    CertifiedRefutation {
444        refuted,
445        sbp_clauses,
446        steps,
447    }
448}
449
450/// The Heule PHP(n) refutation **with its rank function attached** — each symmetry-breaking step
451/// is tagged by the round (`m` = active items remaining) it belongs to, a non-increasing measure
452/// whose descent bounds the proof size. The closing RUP steps take the bottom rank `1`. Feed the
453/// result to [`crate::complexity::RankedRefutation::certify`] to get a checkable `O(n²)` size bound
454/// alongside the correctness check.
455pub fn heule_php_ranked(n: usize) -> crate::complexity::RankedRefutation {
456    let (cnf, _) = crate::families::php(n);
457    let holes = n.saturating_sub(1);
458    let nv = cnf.num_vars;
459    let mut db = cnf.clauses.clone();
460    let mut index = crate::symmetry_detect::AutomorphismIndex::with_clauses(nv, &cnf.clauses);
461    let mut steps: Vec<ProofStep> = Vec::new();
462    let mut ranks: Vec<u64> = Vec::new();
463
464    for m in (2..=n).rev() {
465        let hole = m - 2;
466        let last_pigeon = m - 1;
467        for i in 0..last_pigeon {
468            let clause = vec![Lit::neg((i * holes + hole) as Var)];
469            let witness = Witness::Substitution(swap_pigeons(n, holes, i, last_pigeon));
470            if crate::pr::is_pr_indexed(nv, &db, &mut index, &clause, &witness) {
471                db.push(clause.clone());
472                index.insert(clause.clone());
473                steps.push(ProofStep::Pr { clause, witness });
474                ranks.push(m as u64); // rank = active items remaining this round (descends with m)
475            }
476        }
477    }
478
479    let mut solver = Solver::new(nv);
480    for c in &db {
481        solver.add_clause(c.clone());
482    }
483    let refuted = match solver.solve() {
484        SolveResult::Sat(_) => false,
485        SolveResult::Unsat => {
486            for lc in solver.learned() {
487                steps.push(ProofStep::Rup(lc.lits.clone()));
488                ranks.push(1); // the closing chain sits at the bottom level
489            }
490            crate::pr::check_pr_refutation_fast(nv, &cnf.clauses, &steps)
491        }
492    };
493
494    crate::complexity::RankedRefutation {
495        refuted,
496        steps,
497        ranks,
498    }
499}
500
501/// The steered clique-coloring refutation **with its rank function attached** — the analogue of
502/// [`heule_php_ranked`] over the coloring encoding, so a clique refutation also ships a checkable
503/// `O(n²)` size certificate (rank = active vertices remaining).
504pub fn heule_clique_ranked(n: usize, k: usize) -> crate::complexity::RankedRefutation {
505    let (cnf, _) = crate::families::clique_coloring(n, k);
506    let nv = cnf.num_vars;
507    let mut db = cnf.clauses.clone();
508    let mut index = crate::symmetry_detect::AutomorphismIndex::with_clauses(nv, &cnf.clauses);
509    let mut steps: Vec<ProofStep> = Vec::new();
510    let mut ranks: Vec<u64> = Vec::new();
511    let items = (k + 1).min(n);
512    let var = |v: usize, c: usize| (v * k + c) as Var;
513
514    for m in (2..=items).rev() {
515        let color = m - 2;
516        let last_vertex = m - 1;
517        for i in 0..last_vertex {
518            let clause = vec![Lit::neg(var(i, color))];
519            let witness = Witness::Substitution(swap_vertices(n, k, i, last_vertex));
520            if crate::pr::is_pr_indexed(nv, &db, &mut index, &clause, &witness) {
521                db.push(clause.clone());
522                index.insert(clause.clone());
523                steps.push(ProofStep::Pr { clause, witness });
524                ranks.push(m as u64);
525            }
526        }
527    }
528
529    let mut solver = Solver::new(nv);
530    for c in &db {
531        solver.add_clause(c.clone());
532    }
533    let refuted = match solver.solve() {
534        SolveResult::Sat(_) => false,
535        SolveResult::Unsat => {
536            for lc in solver.learned() {
537                steps.push(ProofStep::Rup(lc.lits.clone()));
538                ranks.push(1);
539            }
540            crate::pr::check_pr_refutation_fast(nv, &cnf.clauses, &steps)
541        }
542    };
543
544    crate::complexity::RankedRefutation {
545        refuted,
546        steps,
547        ranks,
548    }
549}
550
551/// A safety cap on the number of symmetry-breaking rounds — far above any real need (the group
552/// is finite and strictly shrinks each round), a guard against pathological inputs.
553const MAX_SBP_ROUNDS: usize = 100_000;
554
555/// Solve `formula` with FULL certified symmetry breaking, discovering the symmetries itself.
556///
557/// Each round: detect the residual symmetry group of the current database, certify ONE lead
558/// lex-leader predicate as a PR step (always sound — its generator is a fresh automorphism of
559/// the current database, so the SR check's conflict is immediate), and re-detect. Adding the
560/// predicate strictly shrinks the automorphism group, so the loop terminates with the whole group
561/// broken; then the augmented formula is solved and the learned clauses appended as RUP steps. The
562/// entire composed stream is verified against `formula` ALONE.
563///
564/// This breaks the *complete* group rather than one clause per generator, by re-detecting the
565/// stabilizer after each predicate — the natural "lift and shift" of detection + the SR checker.
566pub fn certified_unsat_auto(num_vars: usize, formula: &[Vec<Lit>]) -> CertifiedRefutation {
567    let mut db: Vec<Vec<Lit>> = formula.to_vec();
568    let mut steps: Vec<ProofStep> = Vec::new();
569
570    for _ in 0..MAX_SBP_ROUNDS {
571        let mut progressed = false;
572        for sigma in find_generators(num_vars, &db) {
573            let Some(clause) = lex_leader_lead_clause(num_vars, &sigma) else {
574                continue;
575            };
576            let witness = Witness::Substitution(sigma);
577            if is_pr(num_vars, &db, &clause, &witness) {
578                db.push(clause.clone());
579                steps.push(ProofStep::Pr { clause, witness });
580                progressed = true;
581                break;
582            }
583        }
584        if !progressed {
585            break;
586        }
587    }
588    let sbp_clauses = steps.len();
589
590    let mut solver = Solver::new(num_vars);
591    for c in &db {
592        solver.add_clause(c.clone());
593    }
594    let refuted = match solver.solve() {
595        SolveResult::Sat(_) => false,
596        SolveResult::Unsat => {
597            for lc in solver.learned() {
598                steps.push(ProofStep::Rup(lc.lits.clone()));
599            }
600            check_pr_refutation(num_vars, formula, &steps)
601        }
602    };
603
604    CertifiedRefutation {
605        refuted,
606        sbp_clauses,
607        steps,
608    }
609}
610
611#[cfg(test)]
612#[path = "../../logicaffeine_tests/unit/logicaffeine_proof/sym_certify/tests.rs"]
613mod tests;