mirror of
https://github.com/Z3Prover/z3
synced 2025-06-27 00:18:45 +00:00
parity debugging
This commit is contained in:
parent
1434c1117c
commit
68b74ca6a7
3 changed files with 38 additions and 12 deletions
|
@ -810,10 +810,17 @@ namespace polysat {
|
||||||
unsigned offset = coeff.trailing_zeros();
|
unsigned offset = coeff.trailing_zeros();
|
||||||
verbose_stream() << "COEFF " << coeff << "\n";
|
verbose_stream() << "COEFF " << coeff << "\n";
|
||||||
#endif
|
#endif
|
||||||
|
#if 0
|
||||||
unsigned j = 0;
|
unsigned j = 0;
|
||||||
while (j < N && is_forced_true(s.parity(p, j)))
|
while (j < N && is_forced_true(s.parity(p, j + 1)))
|
||||||
++j;
|
++j;
|
||||||
return j;
|
return j;
|
||||||
|
#else
|
||||||
|
for (unsigned j = N; j > 0; --j)
|
||||||
|
if (is_forced_true(s.parity(p, j)))
|
||||||
|
return j;
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned saturation::max_parity(pdd const& p) {
|
unsigned saturation::max_parity(pdd const& p) {
|
||||||
|
@ -826,8 +833,8 @@ namespace polysat {
|
||||||
// TBD: factor p
|
// TBD: factor p
|
||||||
|
|
||||||
for (unsigned j = 0; j < N; ++j)
|
for (unsigned j = 0; j < N; ++j)
|
||||||
if (is_forced_false(s.parity(p, j)))
|
if (is_forced_true(s.parity_at_most(p, j)))
|
||||||
return j + 1;
|
return j;
|
||||||
return N;
|
return N;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -852,10 +859,10 @@ namespace polysat {
|
||||||
auto propagate1 = [&](signed_constraint premise, signed_constraint conseq) {
|
auto propagate1 = [&](signed_constraint premise, signed_constraint conseq) {
|
||||||
if (is_forced_false(premise))
|
if (is_forced_false(premise))
|
||||||
return false;
|
return false;
|
||||||
|
IF_VERBOSE(1, verbose_stream() << "propagate " << axb_l_y << " " << premise << " => " << conseq << "\n");
|
||||||
m_lemma.reset();
|
m_lemma.reset();
|
||||||
m_lemma.insert_eval(~s.eq(y));
|
m_lemma.insert_eval(~s.eq(y));
|
||||||
m_lemma.insert_eval(~premise);
|
m_lemma.insert_eval(~premise);
|
||||||
IF_VERBOSE(1, verbose_stream() << "propagate " << axb_l_y << " " << premise << " => " << conseq << "\n");
|
|
||||||
return propagate(x, core, axb_l_y, conseq);
|
return propagate(x, core, axb_l_y, conseq);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -864,11 +871,11 @@ namespace polysat {
|
||||||
return false;
|
return false;
|
||||||
if (is_forced_false(premise2))
|
if (is_forced_false(premise2))
|
||||||
return false;
|
return false;
|
||||||
|
IF_VERBOSE(1, verbose_stream() << "propagate " << axb_l_y << " " << premise1 << " " << premise2 << " => " << conseq << "\n");
|
||||||
m_lemma.reset();
|
m_lemma.reset();
|
||||||
m_lemma.insert_eval(~s.eq(y));
|
m_lemma.insert_eval(~s.eq(y));
|
||||||
m_lemma.insert_eval(~premise1);
|
m_lemma.insert_eval(~premise1);
|
||||||
m_lemma.insert_eval(~premise2);
|
m_lemma.insert_eval(~premise2);
|
||||||
IF_VERBOSE(1, verbose_stream() << "propagate " << axb_l_y << " " << premise1 << " " << premise2 << " => " << conseq << "\n");
|
|
||||||
return propagate(x, core, axb_l_y, conseq);
|
return propagate(x, core, axb_l_y, conseq);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -889,8 +896,8 @@ namespace polysat {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto at_most = [&](pdd const& p, unsigned k) {
|
auto at_most = [&](pdd const& p, unsigned k) {
|
||||||
VERIFY(k != N);
|
VERIFY(k < N);
|
||||||
return ~s.parity(p, k + 1);
|
return s.parity_at_most(p, k);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto at_least = [&](pdd const& p, unsigned k) {
|
auto at_least = [&](pdd const& p, unsigned k) {
|
||||||
|
|
|
@ -1059,6 +1059,7 @@ namespace polysat {
|
||||||
|
|
||||||
void solver::assign_eval(sat::literal lit) {
|
void solver::assign_eval(sat::literal lit) {
|
||||||
signed_constraint const c = lit2cnstr(lit);
|
signed_constraint const c = lit2cnstr(lit);
|
||||||
|
LOG_V(10, "Evaluate: " << lit_pp(*this ,lit));
|
||||||
SASSERT(c.is_currently_true(*this));
|
SASSERT(c.is_currently_true(*this));
|
||||||
unsigned level = 0;
|
unsigned level = 0;
|
||||||
// NOTE: constraint may be evaluated even if some variables are still unassigned (e.g., 0*x doesn't depend on x).
|
// NOTE: constraint may be evaluated even if some variables are still unassigned (e.g., 0*x doesn't depend on x).
|
||||||
|
|
|
@ -418,16 +418,34 @@ namespace polysat {
|
||||||
signed_constraint eq(pdd const& p, unsigned q) { return eq(p - q); }
|
signed_constraint eq(pdd const& p, unsigned q) { return eq(p - q); }
|
||||||
signed_constraint odd(pdd const& p) { return ~even(p); }
|
signed_constraint odd(pdd const& p) { return ~even(p); }
|
||||||
signed_constraint even(pdd const& p) { return parity(p, 1); }
|
signed_constraint even(pdd const& p) { return parity(p, 1); }
|
||||||
/** parity(p) >= k (<=> p * 2^(K-k) == 0) */
|
/** parity(p) >= k */
|
||||||
signed_constraint parity(pdd const& p, unsigned k) {
|
signed_constraint parity(pdd const& p, unsigned k) { // TODO: rename to parity_at_least?
|
||||||
unsigned N = p.manager().power_of_2();
|
unsigned N = p.manager().power_of_2();
|
||||||
|
// parity(p) >= k
|
||||||
|
// <=> p * 2^(N - k) == 0
|
||||||
if (k >= N)
|
if (k >= N)
|
||||||
return eq(p);
|
return eq(p);
|
||||||
else if (k == 0)
|
else if (k == 0) {
|
||||||
return odd(p);
|
// parity(p) >= 0 is a tautology
|
||||||
|
verbose_stream() << "REDUNDANT parity constraint: parity(" << p << ", " << k << ")\n";
|
||||||
|
return eq(p.manager().zero());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return eq(p * rational::power_of_two(N - k));
|
return eq(p * rational::power_of_two(N - k));
|
||||||
}
|
}
|
||||||
|
/** parity(p) <= k */
|
||||||
|
signed_constraint parity_at_most(pdd const& p, unsigned k) {
|
||||||
|
unsigned N = p.manager().power_of_2();
|
||||||
|
// parity(p) <= k
|
||||||
|
// <=> ~(parity(p) >= k+1)
|
||||||
|
if (k >= N) {
|
||||||
|
// parity(p) <= N is a tautology
|
||||||
|
verbose_stream() << "REDUNDANT parity constraint: parity(" << p << ", " << k << ")\n";
|
||||||
|
return eq(p.manager().zero());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return ~parity(p, k + 1);
|
||||||
|
}
|
||||||
signed_constraint diseq(pdd const& p, rational const& q) { return diseq(p - q); }
|
signed_constraint diseq(pdd const& p, rational const& q) { return diseq(p - q); }
|
||||||
signed_constraint diseq(pdd const& p, unsigned q) { return diseq(p - q); }
|
signed_constraint diseq(pdd const& p, unsigned q) { return diseq(p - q); }
|
||||||
signed_constraint ule(pdd const& p, pdd const& q) { return m_constraints.ule(p, q); }
|
signed_constraint ule(pdd const& p, pdd const& q) { return m_constraints.ule(p, q); }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue