ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
strengthen.c
Go to the documentation of this file.
1#include "strengthen.h"
2#include "collect.h"
3#include "inline.h"
4#include "promote.h"
5
7
8static clause *large_on_the_fly_strengthen (kissat *solver, clause *c,
9 unsigned lit) {
10 KISSAT_assert (solver->antecedent_size > 3);
11 LOGCLS (c,
12 "large on-the-fly strengthening "
13 "by removing %s from",
14 LOGLIT (lit));
15 unsigned *lits = c->lits;
16 KISSAT_assert (lits[0] == lit || lits[1] == lit);
17 INC (on_the_fly_strengthened);
18#ifndef KISSAT_NDEBUG
19 clause *old_next = kissat_next_clause (c);
20#endif
21 if (lits[0] == lit)
22 SWAP (unsigned, lits[0], lits[1]);
23 KISSAT_assert (lits[1] == lit);
24 const reference ref = kissat_reference_clause (solver, c);
25 kissat_unwatch_blocking (solver, lit, ref);
26 SHRINK_CLAUSE_IN_PROOF (c, lit, lits[0]);
27 CHECK_SHRINK_CLAUSE (c, lit, lits[0]);
28 {
29 const unsigned old_size = c->size;
30 unsigned new_size = 1;
31 const bool irredundant = !c->redundant;
32 for (unsigned i = 2; i < old_size; i++) {
33 const unsigned other = lits[i];
34 KISSAT_assert (VALUE (other) < 0);
35 if (!LEVEL (other))
36 continue;
37 lits[new_size++] = other;
38 if (irredundant)
39 kissat_mark_added_literal (solver, other);
40 }
41 KISSAT_assert (new_size > 2);
42 c->size = new_size;
43 c->searched = 2;
44 if (c->redundant && c->glue >= new_size)
45 kissat_promote_clause (solver, c, new_size - 1);
46 if (!c->shrunken) {
47 c->shrunken = true;
48 lits[old_size - 1] = INVALID_LIT;
49 }
50 }
51 LOGCLS (c, "unsorted on-the-fly strengthened");
52 {
53 KISSAT_assert (VALUE (lits[1]) < 0);
54 unsigned highest_pos = 1;
55 unsigned highest_level = LEVEL (lits[1]);
56 const unsigned size = c->size;
57 for (unsigned i = 2; i < size; i++) {
58 const unsigned other = lits[i];
59 KISSAT_assert (VALUE (other) < 0);
60 const unsigned level = LEVEL (other);
61 if (level <= highest_level)
62 continue;
63 highest_pos = i;
64 highest_level = level;
65 }
66 if (highest_pos != 1)
67 SWAP (unsigned, lits[1], lits[highest_pos]);
68 LOGCLS (c, "sorted on-the-fly strengthened");
69 kissat_watch_blocking (solver, lits[1], lits[0], ref);
70 }
71 {
72 watches *watches = &WATCHES (lits[0]);
73#ifndef KISSAT_NDEBUG
74 const watch *const end_of_watches = END_WATCHES (*watches);
75#endif
77 KISSAT_assert (solver->watching);
78 for (;;) {
79 KISSAT_assert (p != end_of_watches);
80 const watch head = *p++;
81 if (head.type.binary)
82 continue;
83 KISSAT_assert (p != end_of_watches);
84 const watch tail = *p++;
85 if (tail.large.ref == ref)
86 break;
87 }
88 p[-2].blocking.lit = lits[1];
89 LOGREF (ref, "updating watching %s now blocking %s in",
90 LOGLIT (lits[0]), LOGLIT (lits[1]));
91 }
92#ifndef KISSAT_NDEBUG
93 clause *new_next = kissat_next_clause (c);
94 KISSAT_assert (old_next == new_next);
95#endif
96 LOGCLS (c, "conflicting");
97 return c;
98}
99
100static clause *binary_on_the_fly_strengthen (kissat *solver, clause *c,
101 unsigned lit) {
102 KISSAT_assert (solver->antecedent_size == 3);
103 LOGCLS (c,
104 "binary on-the-fly strengthening "
105 "by removing %s from",
106 LOGLIT (lit));
107 unsigned first = INVALID_LIT, second = INVALID_LIT;
108#ifndef KISSAT_NDEBUG
109 bool found = false;
110#endif
111 for (all_literals_in_clause (other, c)) {
112 if (other == lit) {
113#ifndef KISSAT_NDEBUG
114 KISSAT_assert (!found);
115 found = true;
116#endif
117 continue;
118 }
119 KISSAT_assert (VALUE (other) < 0);
120 if (!LEVEL (other))
121 continue;
122 if (first == INVALID_LIT)
123 first = other;
124 else {
125 KISSAT_assert (second == INVALID_LIT);
126 second = other;
127#ifndef KISSAT_NDEBUG
128 break;
129#endif
130 }
131 }
132 KISSAT_assert (found);
133 KISSAT_assert (second != INVALID_LIT);
134 LOGBINARY (first, second, "on-the-fly strengthened");
135 kissat_new_binary_clause (solver, first, second);
136 const reference ref = kissat_reference_clause (solver, c);
137 kissat_unwatch_blocking (solver, c->lits[0], ref);
138 kissat_unwatch_blocking (solver, c->lits[1], ref);
140 clause *conflict = kissat_binary_conflict (solver, first, second);
141 return conflict;
142}
143
145 unsigned lit) {
147 KISSAT_assert (solver->antecedent_size > 2);
148 if (!c->redundant)
149 kissat_mark_removed_literal (solver, lit);
150 clause *res;
151 if (solver->antecedent_size == 3)
152 res = binary_on_the_fly_strengthen (solver, c, lit);
153 else
154 res = large_on_the_fly_strengthen (solver, c, lit);
155 return res;
156}
157
159 LOGCLS (c, "on-the-fly subsuming");
160 LOGCLS (d, "on-the-fly subsumed");
161 KISSAT_assert (c != d);
163 KISSAT_assert (c->size > 1);
164 KISSAT_assert (c->size <= d->size);
166 INC (on_the_fly_subsumed);
167 if (d->redundant) {
168 if (c->redundant && c->glue > d->glue)
170 return;
171 }
172 if (!c->redundant)
173 return;
174 if (c->size > 2) {
175 c->redundant = false;
176 LOGCLS (c, "turned");
178 }
179 statistics *statistics = &solver->statistics_;
180 if (c->size > 2) {
181 KISSAT_assert (statistics->clauses_irredundant < UINT64_MAX);
182 statistics->clauses_irredundant++;
183 } else {
184 KISSAT_assert (statistics->clauses_binary < UINT64_MAX);
185 statistics->clauses_binary++;
186 }
187 KISSAT_assert (statistics->clauses_redundant > 0);
188 statistics->clauses_redundant--;
189}
190
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define LEVEL(LIT)
Definition assign.h:34
#define INVALID_LIT
#define INC(NAME)
#define CHECK_SHRINK_CLAUSE(...)
Definition check.h:158
void kissat_mark_clause_as_garbage(kissat *solver, clause *c)
Definition clause.c:164
void kissat_new_binary_clause(kissat *solver, unsigned first, unsigned second)
Definition clause.c:122
void kissat_update_last_irredundant(kissat *solver, clause *irredundant)
Definition collect.c:200
pcover irredundant()
Cube * p
Definition exorList.c:222
#define all_literals_in_clause(LIT, C)
Definition clause.h:47
#define KISSAT_assert(ignore)
Definition global.h:13
#define solver
Definition kitten.c:211
#define LOGREF(...)
Definition logging.h:433
#define LOGBINARY(...)
Definition logging.h:442
#define LOGCLS(...)
Definition logging.h:415
#define LOGLIT(...)
Definition logging.hpp:99
unsigned long long size
Definition giaNewBdd.h:39
unsigned short ref
Definition giaNewBdd.h:38
ABC_NAMESPACE_IMPL_START void kissat_promote_clause(kissat *solver, clause *c, unsigned new_glue)
Definition promote.c:7
#define SHRINK_CLAUSE_IN_PROOF(...)
Definition proof.h:145
ABC_NAMESPACE_HEADER_START typedef unsigned reference
Definition reference.h:9
int lit
Definition satVec.h:130
void kissat_on_the_fly_subsume(kissat *solver, clause *c, clause *d)
Definition strengthen.c:158
clause * kissat_on_the_fly_strengthen(kissat *solver, clause *c, unsigned lit)
Definition strengthen.c:144
unsigned glue
Definition clause.h:23
unsigned lits[3]
Definition clause.h:39
bool redundant
Definition clause.h:28
unsigned searched
Definition clause.h:36
unsigned size
Definition clause.h:37
bool shrunken
Definition clause.h:29
bool garbage
Definition clause.h:25
Definition watch.h:41
large_watch large
Definition watch.h:45
watch_type type
Definition watch.h:42
#define SWAP(TYPE, A, B)
Definition utilities.h:151
#define VALUE(LIT)
Definition value.h:10
#define BEGIN_WATCHES(WS)
Definition watch.h:115
#define END_WATCHES(WS)
Definition watch.h:118
vector watches
Definition watch.h:49
#define WATCHES(LIT)
Definition watch.h:137