cadical 0.1.16

Rust bindings for the CaDiCaL SAT solver
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
#include "internal.hpp"

namespace CaDiCaL {

/*------------------------------------------------------------------------*/

// This implements an inprocessing version of blocked clause elimination and
// is assumed to be triggered just before bounded variable elimination.  It
// has a separate 'block' flag while variable elimination uses 'elim'.
// Thus it only tries to block clauses on a literal which was removed in an
// irredundant clause in negated form before and has not been tried to use
// as blocking literal since then.

/*------------------------------------------------------------------------*/

inline bool block_more_occs_size::operator() (unsigned a, unsigned b) {
  size_t s = internal->noccs (-internal->u2i (a));
  size_t t = internal->noccs (-internal->u2i (b));
  if (s > t)
    return true;
  if (s < t)
    return false;
  s = internal->noccs (internal->u2i (a));
  t = internal->noccs (internal->u2i (b));
  if (s > t)
    return true;
  if (s < t)
    return false;
  return a > b;
}

/*------------------------------------------------------------------------*/

// Determine whether 'c' is blocked on 'lit', by first marking all its
// literals and then checking all resolvents with negative clauses (with
// '-lit') are tautological.  We use a move-to-front scheme for both the
// occurrence list of negative clauses (with '-lit') and then for literals
// within each such clause.  The clause move-to-front scheme has the goal to
// find non-tautological clauses faster in the future, while the literal
// move-to-front scheme has the goal to faster find the matching literal,
// which makes the resolvent tautological (again in the future).

bool Internal::is_blocked_clause (Clause *c, int lit) {

  LOG (c, "trying to block on %d", lit);

  assert (c->size >= opts.blockminclslim);
  assert (c->size <= opts.blockmaxclslim);
  assert (active (lit));
  assert (!val (lit));
  assert (!c->garbage);
  assert (!c->redundant);
  assert (!level);

  mark (c); // First mark all literals in 'c'.

  Occs &os = occs (-lit);
  LOG ("resolving against at most %zd clauses with %d", os.size (), -lit);

  bool res = true; // Result is true if all resolvents tautological.

  // Can not use 'auto' here since we update 'os' during traversal.
  //
  const auto end_of_os = os.end ();
  auto i = os.begin ();

  Clause *prev_d = 0; // Previous non-tautological clause.

  for (; i != end_of_os; i++) {
    // Move the first clause with non-tautological resolvent to the front of
    // the occurrence list to improve finding it faster later.
    //
    Clause *d = *i;

    assert (!d->garbage);
    assert (!d->redundant);
    assert (d->size <= opts.blockmaxclslim);

    *i = prev_d; // Move previous non-tautological clause
    prev_d = d;  // backwards but remember clause at this position.

    LOG (d, "resolving on %d against", lit);
    stats.blockres++;

    int prev_other = 0; // Previous non-tautological literal.

    // No 'auto' since we update literals of 'd' during traversal.
    //
    const const_literal_iterator end_of_d = d->end ();
    literal_iterator l;

    for (l = d->begin (); l != end_of_d; l++) {
      // Same move-to-front mechanism for literals within a clause.  It
      // moves the first negatively marked literal to the front to find it
      // faster in the future.
      //
      const int other = *l;
      *l = prev_other;
      prev_other = other;
      if (other == -lit)
        continue;
      assert (other != lit);
      assert (active (other));
      assert (!val (other));
      if (marked (other) < 0) {
        LOG ("found tautological literal %d", other);
        d->literals[0] = other; // Move to front of 'd'.
        break;
      }
    }

    if (l == end_of_d) {
      LOG ("no tautological literal found");
      //
      // Since we did not find a tautological literal we restore the old
      // order of literals in the clause.
      //
      const const_literal_iterator begin_of_d = d->begin ();
      while (l-- != begin_of_d) {
        const int other = *l;
        *l = prev_other;
        prev_other = other;
      }
      res = false; // Now 'd' is a witness that 'c' is not blocked.
      os[0] = d;   // Move it to the front of the occurrence list.
      break;
    }
  }
  unmark (c); // ... all literals of the candidate clause.

  // If all resolvents are tautological and thus the clause is blocked we
  // restore the old order of clauses in the occurrence list of '-lit'.
  //
  if (res) {
    assert (i == end_of_os);
    const auto boc = os.begin ();
    while (i != boc) {
      Clause *d = *--i;
      *i = prev_d;
      prev_d = d;
    }
  }

  return res;
}

/*------------------------------------------------------------------------*/

void Internal::block_schedule (Blocker &blocker) {
  // Set skip flags for all literals in too large clauses.
  //
  for (const auto &c : clauses) {

    if (c->garbage)
      continue;
    if (c->redundant)
      continue;
    if (c->size <= opts.blockmaxclslim)
      continue;

    for (const auto &lit : *c)
      mark_skip (-lit);
  }

  // Connect all literal occurrences in irredundant clauses.
  //
  for (const auto &c : clauses) {

    if (c->garbage)
      continue;
    if (c->redundant)
      continue;

    for (const auto &lit : *c) {
      assert (active (lit));
      assert (!val (lit));
      occs (lit).push_back (c);
    }
  }

  // We establish the invariant that 'noccs' gives the number of actual
  // occurrences of 'lit' in non-garbage clauses,  while 'occs' might still
  // refer to garbage clauses, thus 'noccs (lit) <= occs (lit).size ()'.  It
  // is expensive to remove references to garbage clauses from 'occs' during
  // blocked clause elimination, but decrementing 'noccs' is cheap.

  for (auto lit : lits) {
    if (!active (lit))
      continue;
    assert (!val (lit));
    Occs &os = occs (lit);
    noccs (lit) = os.size ();
  }

  // Now we fill the schedule (priority queue) of candidate literals to be
  // tried as blocking literals.  It is probably slightly faster to do this
  // in one go after all occurrences have been determined, instead of
  // filling the priority queue during pushing occurrences.  Filling the
  // schedule can not be fused with the previous loop (easily) since we
  // first have to initialize 'noccs' for both 'lit' and '-lit'.

#ifndef QUIET
  int skipped = 0;
#endif

  for (auto idx : vars) {
    if (!active (idx))
      continue;
    if (frozen (idx)) {
#ifndef QUIET
      skipped += 2;
#endif
      continue;
    }
    assert (!val (idx));
    for (int sign = -1; sign <= 1; sign += 2) {
      const int lit = sign * idx;
      if (marked_skip (lit)) {
#ifndef QUIET
        skipped++;
#endif
        continue;
      }
      if (!marked_block (lit))
        continue;
      unmark_block (lit);
      LOG ("scheduling %d with %" PRId64 " positive and %" PRId64
           " negative occurrences",
           lit, noccs (lit), noccs (-lit));
      blocker.schedule.push_back (vlit (lit));
    }
  }

  PHASE ("block", stats.blockings,
         "scheduled %zd candidate literals %.2f%% (%d skipped %.2f%%)",
         blocker.schedule.size (),
         percent (blocker.schedule.size (), 2.0 * active ()), skipped,
         percent (skipped, 2.0 * active ()));
}

/*------------------------------------------------------------------------*/

// A literal is pure if it only occurs positive.  Then all clauses in which
// it occurs are blocked on it. This special case can be implemented faster
// than trying to block literals with at least one negative occurrence and
// is thus handled separately.  It also allows to avoid pushing blocked
// clauses onto the extension stack.

void Internal::block_pure_literal (Blocker &blocker, int lit) {
  if (frozen (lit))
    return;
  assert (active (lit));

  Occs &pos = occs (lit);
  Occs &nos = occs (-lit);

  assert (!noccs (-lit));
#ifndef NDEBUG
  for (const auto &c : nos)
    assert (c->garbage);
#endif
  stats.blockpurelits++;
  LOG ("found pure literal %d", lit);
#ifdef LOGGING
  int64_t pured = 0;
#endif
  for (const auto &c : pos) {
    if (c->garbage)
      continue;
    assert (!c->redundant);
    LOG (c, "pure literal %d in", lit);
    blocker.reschedule.push_back (c);
    if (proof) {
      proof->weaken_minus (c);
    }
    external->push_clause_on_extension_stack (c, lit);
    stats.blockpured++;
    mark_garbage (c);
#ifdef LOGGING
    pured++;
#endif
  }

  erase_vector (pos);
  erase_vector (nos);

  mark_pure (lit);
  stats.blockpured++;
  LOG ("blocking %" PRId64 " clauses on pure literal %d", pured, lit);
}

/*------------------------------------------------------------------------*/

// If there is only one negative clause with '-lit' it is faster to mark it
// instead of marking all the positive clauses with 'lit' one after the
// other and then resolving against the negative clause.

void Internal::block_literal_with_one_negative_occ (Blocker &blocker,
                                                    int lit) {
  assert (active (lit));
  assert (!frozen (lit));
  assert (noccs (lit) > 0);
  assert (noccs (-lit) == 1);

  Occs &nos = occs (-lit);
  assert (nos.size () >= 1);

  Clause *d = 0;
  for (const auto &c : nos) {
    if (c->garbage)
      continue;
    assert (!d);
    d = c;
#ifndef NDEBUG
    break;
#endif
  }
  assert (d);
  nos.resize (1);
  nos[0] = d;

  if (d && d->size > opts.blockmaxclslim) {
    LOG (d, "skipped common antecedent");
    return;
  }

  assert (!d->garbage);
  assert (!d->redundant);
  assert (d->size <= opts.blockmaxclslim);

  LOG (d, "common %d antecedent", lit);
  mark (d);
  int64_t blocked = 0;
#ifdef LOGGING
  int64_t skipped = 0;
#endif
  Occs &pos = occs (lit);

  // Again no 'auto' since 'pos' is update during traversal.
  //
  const auto eop = pos.end ();
  auto j = pos.begin (), i = j;

  for (; i != eop; i++) {
    Clause *c = *j++ = *i;

    if (c->garbage) {
      j--;
      continue;
    }
    if (c->size > opts.blockmaxclslim) {
#ifdef LOGGING
      skipped++;
#endif
      continue;
    }
    if (c->size < opts.blockminclslim) {
#ifdef LOGGING
      skipped++;
#endif
      continue;
    }

    LOG (c, "trying to block on %d", lit);

    // We use the same literal move-to-front strategy as in
    // 'is_blocked_clause'.  See there for more explanations.

    int prev_other = 0; // Previous non-tautological literal.

    // No 'auto' since literals of 'c' are updated during traversal.
    //
    const const_literal_iterator end_of_c = c->end ();
    literal_iterator l;

    for (l = c->begin (); l != end_of_c; l++) {
      const int other = *l;
      *l = prev_other;
      prev_other = other;
      if (other == lit)
        continue;
      assert (other != -lit);
      assert (active (other));
      assert (!val (other));
      if (marked (other) < 0) {
        LOG ("found tautological literal %d", other);
        c->literals[0] = other; // Move to front of 'c'.
        break;
      }
    }

    if (l == end_of_c) {
      LOG ("no tautological literal found");

      // Restore old literal order in the clause because.

      const const_literal_iterator begin_of_c = c->begin ();
      while (l-- != begin_of_c) {
        const int other = *l;
        *l = prev_other;
        prev_other = other;
      }

      continue; // ... with next candidate 'c' in 'pos'.
    }

    blocked++;
    LOG (c, "blocked");
    if (proof) {
      proof->weaken_minus (c);
    }
    external->push_clause_on_extension_stack (c, lit);
    blocker.reschedule.push_back (c);
    mark_garbage (c);
    j--;
  }
  if (j == pos.begin ())
    erase_vector (pos);
  else
    pos.resize (j - pos.begin ());

  stats.blocked += blocked;
  LOG ("blocked %" PRId64 " clauses on %d (skipped %" PRId64 ")", blocked,
       lit, skipped);

  unmark (d);
}

/*------------------------------------------------------------------------*/

// Determine the set of candidate clauses with 'lit', which are checked to
// be blocked by 'lit'.  Filter out too large and small clauses and which do
// not have any negated other literal in any of the clauses with '-lit'.

size_t Internal::block_candidates (Blocker &blocker, int lit) {

  assert (blocker.candidates.empty ());

  Occs &pos = occs (lit); // Positive occurrences of 'lit'.
  Occs &nos = occs (-lit);

  assert ((size_t) noccs (lit) <= pos.size ());
  assert ((size_t) noccs (-lit) == nos.size ()); // Already flushed.

  // Mark all literals in clauses with '-lit'.  Note that 'mark2' uses
  // separate bits for 'lit' and '-lit'.
  //
  for (const auto &c : nos)
    mark2 (c);

  const auto eop = pos.end ();
  auto j = pos.begin (), i = j;

  for (; i != eop; i++) {
    Clause *c = *j++ = *i;
    if (c->garbage) {
      j--;
      continue;
    }
    assert (!c->redundant);
    if (c->size > opts.blockmaxclslim)
      continue;
    if (c->size < opts.blockminclslim)
      continue;
    const const_literal_iterator eoc = c->end ();
    const_literal_iterator l;
    for (l = c->begin (); l != eoc; l++) {
      const int other = *l;
      if (other == lit)
        continue;
      assert (other != -lit);
      assert (active (other));
      assert (!val (other));
      if (marked2 (-other))
        break;
    }
    if (l != eoc)
      blocker.candidates.push_back (c);
  }
  if (j == pos.begin ())
    erase_vector (pos);
  else
    pos.resize (j - pos.begin ());

  assert (pos.size () == (size_t) noccs (lit)); // Now also flushed.

  for (const auto &c : nos)
    unmark (c);

  return blocker.candidates.size ();
}

/*------------------------------------------------------------------------*/

// Try to find a clause with '-lit' which does not have any literal in
// clauses with 'lit'.  If such a clause exists no candidate clause can be
// blocked on 'lit' since all candidates would produce a non-tautological
// resolvent with that clause.

Clause *Internal::block_impossible (Blocker &blocker, int lit) {
  assert (noccs (-lit) > 1);
  assert (blocker.candidates.size () > 1);

  for (const auto &c : blocker.candidates)
    mark2 (c);

  Occs &nos = occs (-lit);
  Clause *res = 0;

  for (const auto &c : nos) {
    assert (!c->garbage);
    assert (!c->redundant);
    assert (c->size <= opts.blockmaxclslim);
    const const_literal_iterator eoc = c->end ();
    const_literal_iterator l;
    for (l = c->begin (); l != eoc; l++) {
      const int other = *l;
      if (other == -lit)
        continue;
      assert (other != lit);
      assert (active (other));
      assert (!val (other));
      if (marked2 (-other))
        break;
    }
    if (l == eoc)
      res = c;
  }

  for (const auto &c : blocker.candidates)
    unmark (c);

  if (res) {
    LOG (res, "common non-tautological resolvent producing");
    blocker.candidates.clear ();
  }

  return res;
}

/*------------------------------------------------------------------------*/

// In the general case we have at least two negative occurrences.

void Internal::block_literal_with_at_least_two_negative_occs (
    Blocker &blocker, int lit) {
  assert (active (lit));
  assert (!frozen (lit));
  assert (noccs (lit) > 0);
  assert (noccs (-lit) > 1);

  Occs &nos = occs (-lit);
  assert ((size_t) noccs (-lit) <= nos.size ());

  int max_size = 0;

  // Flush all garbage clauses in occurrence list 'nos' of '-lit' and
  // determine the maximum size of negative clauses (with '-lit').
  //
  const auto eon = nos.end ();
  auto j = nos.begin (), i = j;
  for (; i != eon; i++) {
    Clause *c = *j++ = *i;
    if (c->garbage)
      j--;
    else if (c->size > max_size)
      max_size = c->size;
  }
  if (j == nos.begin ())
    erase_vector (nos);
  else
    nos.resize (j - nos.begin ());

  assert (nos.size () == (size_t) noccs (-lit));
  assert (nos.size () > 1);

  // If the maximum size of a negative clause (with '-lit') exceeds the
  // maximum clause size limit ignore this candidate literal.
  //
  if (max_size > opts.blockmaxclslim) {
    LOG ("maximum size %d of clauses with %d exceeds clause size limit %d",
         max_size, -lit, opts.blockmaxclslim);
    return;
  }

  LOG ("maximum size %d of clauses with %d", max_size, -lit);

  // We filter candidate clauses with positive occurrence of 'lit' in
  // 'blocker.candidates' and return if no candidate clause remains.
  // Candidates should be small enough and should have at least one literal
  // which occurs negated in one of the clauses with '-lit'.
  //
  size_t candidates = block_candidates (blocker, lit);
  if (!candidates) {
    LOG ("no candidate clauses found");
    return;
  }

  LOG ("found %zd candidate clauses", candidates);

  // We further search for a clause with '-lit' that has no literal
  // negated in any of the candidate clauses (except 'lit').  If such a
  // clause exists, we know that none of the candidates is blocked.
  //
  if (candidates > 1 && block_impossible (blocker, lit)) {
    LOG ("impossible to block any candidate clause on %d", lit);
    assert (blocker.candidates.empty ());
    return;
  }

  LOG ("trying to block %zd clauses out of %" PRId64 " with literal %d",
       candidates, noccs (lit), lit);

  int64_t blocked = 0;

  // Go over all remaining candidates and try to block them on 'lit'.
  //
  for (const auto &c : blocker.candidates) {
    assert (!c->garbage);
    assert (!c->redundant);
    if (!is_blocked_clause (c, lit))
      continue;
    blocked++;
    LOG (c, "blocked");
    if (proof) {
      proof->weaken_minus (c);
    }
    external->push_clause_on_extension_stack (c, lit);
    blocker.reschedule.push_back (c);
    mark_garbage (c);
  }

  LOG ("blocked %" PRId64
       " clauses on %d out of %zd candidates in %zd occurrences",
       blocked, lit, blocker.candidates.size (), occs (lit).size ());

  blocker.candidates.clear ();
  stats.blocked += blocked;
  if (blocked)
    flush_occs (lit);
}

/*------------------------------------------------------------------------*/

// Reschedule literals in a clause (except 'lit') which was blocked.

void Internal::block_reschedule_clause (Blocker &blocker, int lit,
                                        Clause *c) {
#ifdef NDEBUG
  (void) lit;
#endif
  assert (c->garbage);

  for (const auto &other : *c) {

    int64_t &n = noccs (other);
    assert (n > 0);
    n--;

    LOG ("updating %d with %" PRId64 " positive and %" PRId64
         " negative occurrences",
         other, noccs (other), noccs (-other));

    if (blocker.schedule.contains (vlit (-other)))
      blocker.schedule.update (vlit (-other));
    else if (active (other) && !frozen (other) && !marked_skip (-other)) {
      LOG ("rescheduling to block clauses on %d", -other);
      blocker.schedule.push_back (vlit (-other));
    }

    if (blocker.schedule.contains (vlit (other))) {
      assert (other != lit);
      blocker.schedule.update (vlit (other));
    }
  }
}

// Reschedule all literals in clauses blocked by 'lit' (except 'lit').

void Internal::block_reschedule (Blocker &blocker, int lit) {
  while (!blocker.reschedule.empty ()) {
    Clause *c = blocker.reschedule.back ();
    blocker.reschedule.pop_back ();
    block_reschedule_clause (blocker, lit, c);
  }
}

/*------------------------------------------------------------------------*/

void Internal::block_literal (Blocker &blocker, int lit) {
  assert (!marked_skip (lit));

  if (!active (lit))
    return; // Pure literal '-lit'.
  if (frozen (lit))
    return;

  assert (!val (lit));

  // If the maximum number of a negative clauses (with '-lit') exceeds the
  // occurrence limit ignore this candidate literal.
  //
  if (noccs (-lit) > opts.blockocclim)
    return;

  LOG ("blocking literal candidate %d "
       "with %" PRId64 " positive and %" PRId64 " negative occurrences",
       lit, noccs (lit), noccs (-lit));

  stats.blockcands++;

  assert (blocker.reschedule.empty ());
  assert (blocker.candidates.empty ());

  if (!noccs (-lit))
    block_pure_literal (blocker, lit);
  else if (!noccs (lit)) {
    // Rare situation, where the clause length limit was hit for 'lit' and
    // '-lit' is skipped and then it becomes pure.  Can be ignored.  We also
    // so it once happing for a 'elimboundmin=-1' and zero positive and one
    // negative occurrence.
  } else if (noccs (-lit) == 1)
    block_literal_with_one_negative_occ (blocker, lit);
  else
    block_literal_with_at_least_two_negative_occs (blocker, lit);

  // Done with blocked clause elimination on this literal and we do not
  // have to try blocked clause elimination on it again until irredundant
  // clauses with its negation are removed.
  //
  assert (!frozen (lit)); // just to be sure ...
  unmark_block (lit);
}

/*------------------------------------------------------------------------*/

bool Internal::block () {

  if (!opts.block)
    return false;
  if (unsat)
    return false;
  if (!stats.current.irredundant)
    return false;
  if (terminated_asynchronously ())
    return false;

  if (propagated < trail.size ()) {
    LOG ("need to propagate %zd units first", trail.size () - propagated);
    init_watches ();
    connect_watches ();
    if (!propagate ()) {
      LOG ("propagating units results in empty clause");
      learn_empty_clause ();
      assert (unsat);
    }
    clear_watches ();
    reset_watches ();
    if (unsat)
      return false;
  }

  START_SIMPLIFIER (block, BLOCK);

  stats.blockings++;

  LOG ("block-%" PRId64 "", stats.blockings);

  assert (!level);
  assert (!watching ());
  assert (!occurring ());

  mark_satisfied_clauses_as_garbage ();

  init_occs ();  // Occurrence lists for all literals.
  init_noccs (); // Number of occurrences to avoid flushing garbage clauses.

  Blocker blocker (this);
  block_schedule (blocker);

  int64_t blocked = stats.blocked;
  int64_t resolutions = stats.blockres;
  int64_t purelits = stats.blockpurelits;
  int64_t pured = stats.blockpured;

  while (!terminated_asynchronously () && !blocker.schedule.empty ()) {
    int lit = u2i (blocker.schedule.front ());
    blocker.schedule.pop_front ();
    block_literal (blocker, lit);
    block_reschedule (blocker, lit);
  }

  blocker.erase ();
  reset_noccs ();
  reset_occs ();

  resolutions = stats.blockres - resolutions;
  blocked = stats.blocked - blocked;

  PHASE ("block", stats.blockings,
         "blocked %" PRId64 " clauses in %" PRId64 " resolutions", blocked,
         resolutions);

  pured = stats.blockpured - pured;
  purelits = stats.blockpurelits - purelits;

  if (pured)
    mark_redundant_clauses_with_eliminated_variables_as_garbage ();

  if (purelits)
    PHASE ("block", stats.blockings,
           "found %" PRId64 " pure literals in %" PRId64 " clauses",
           purelits, pured);
  else
    PHASE ("block", stats.blockings, "no pure literals found");

  report ('b', !opts.reportall && !blocked);

  STOP_SIMPLIFIER (block, BLOCK);

  return blocked;
}

} // namespace CaDiCaL