Skip to content

Commit b1b39e8

Browse files
authored
Merge pull request #7618 from tautschnig/features/less-than-prop
Enable constant propagation in less-than encoding
2 parents 6f82023 + e265a42 commit b1b39e8

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

regression/solver-hardness/solver-hardness-simple/test.desc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ main.c
55
^SIGNAL=0$
66
^VERIFICATION FAILED$
77
\"SAT_hardness\":\{(\"ClauseSet\":\[.*\]|\"Clauses\":\d+|\"Variables\":\d+|\"Literals\":\d+),(\"ClauseSet\":\[.*\]|\"Clauses\":\d+|\"Variables\":\d+|\"Literals\":\d+),(\"ClauseSet\":\[.*\]|\"Clauses\":\d+|\"Variables\":\d+|\"Literals\":\d+),(\"ClauseSet\":\[.*\]|\"Clauses\":\d+|\"Variables\":\d+|\"Literals\":\d+)\}
8-
\"GOTO_ID\":32,\"SAT_hardness\":\{\"ClauseSet\":\[.*,571\],\"Clauses\":571
98
--
109
^warning: ignoring

src/solvers/flattening/bv_utils.cpp

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,22 +1201,31 @@ literalt bv_utilst::lt_or_le(
12011201
size_t start;
12021202
size_t i;
12031203

1204-
compareBelow = prop.new_variables(bv0.size());
1205-
result = prop.new_variable();
1206-
12071204
if(rep == representationt::SIGNED)
12081205
{
1206+
if(top0.is_false() && top1.is_true())
1207+
return const_literal(false);
1208+
else if(top0.is_true() && top1.is_false())
1209+
return const_literal(true);
1210+
12091211
INVARIANT(
12101212
bv0.size() >= 2, "signed bitvectors should have at least two bits");
1211-
start = compareBelow.size() - 2;
1213+
compareBelow = prop.new_variables(bv0.size() - 1);
1214+
start = compareBelow.size() - 1;
12121215

1213-
literalt firstComp=compareBelow[start];
1216+
literalt &firstComp = compareBelow[start];
1217+
if(top0.is_false())
1218+
firstComp = !top1;
1219+
else if(top0.is_true())
1220+
firstComp = top1;
1221+
else if(top1.is_false())
1222+
firstComp = !top0;
1223+
else if(top1.is_true())
1224+
firstComp = top0;
12141225

1215-
// When comparing signs we are comparing the top bit
1216-
#ifdef INCLUDE_REDUNDANT_CLAUSES
1217-
prop.l_set_to_true(compareBelow[start + 1])
1218-
#endif
1226+
result = prop.new_variable();
12191227

1228+
// When comparing signs we are comparing the top bit
12201229
// Four cases...
12211230
prop.lcnf(top0, top1, firstComp); // + + compare needed
12221231
prop.lcnf(top0, !top1, !result); // + - result false and no compare needed
@@ -1231,8 +1240,10 @@ literalt bv_utilst::lt_or_le(
12311240
else
12321241
{
12331242
// Unsigned is much easier
1243+
compareBelow = prop.new_variables(bv0.size() - 1);
1244+
compareBelow.push_back(const_literal(true));
12341245
start = compareBelow.size() - 1;
1235-
prop.l_set_to_true(compareBelow[start]);
1246+
result = prop.new_variable();
12361247
}
12371248

12381249
// Determine the output
@@ -1241,6 +1252,16 @@ literalt bv_utilst::lt_or_le(
12411252
i = start;
12421253
do
12431254
{
1255+
if(compareBelow[i].is_false())
1256+
continue;
1257+
else if(compareBelow[i].is_true())
1258+
{
1259+
if(bv0[i].is_false() && bv1[i].is_true())
1260+
return const_literal(true);
1261+
else if(bv0[i].is_true() && bv1[i].is_false())
1262+
return const_literal(false);
1263+
}
1264+
12441265
prop.lcnf(!compareBelow[i], bv0[i], !bv1[i], result);
12451266
prop.lcnf(!compareBelow[i], !bv0[i], bv1[i], !result);
12461267
}

0 commit comments

Comments
 (0)