mirror of
https://github.com/Z3Prover/z3
synced 2025-06-24 06:43:40 +00:00
use common idioms for factor-equivalence code
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
0a6759383a
commit
ce3fd22f3b
1 changed files with 11 additions and 13 deletions
|
@ -34,25 +34,19 @@ Revision History:
|
||||||
void factor_eqs(expr_ref_vector &v, expr_equiv_class &equiv) {
|
void factor_eqs(expr_ref_vector &v, expr_equiv_class &equiv) {
|
||||||
ast_manager &m = v.get_manager();
|
ast_manager &m = v.get_manager();
|
||||||
arith_util arith(m);
|
arith_util arith(m);
|
||||||
expr *e1, *e2;
|
expr *e1 = 0, *e2 = 0;
|
||||||
|
|
||||||
flatten_and(v);
|
flatten_and(v);
|
||||||
unsigned j = 0;
|
unsigned j = 0;
|
||||||
for (unsigned i = 0; i < v.size(); ++i) {
|
for (unsigned i = 0; i < v.size(); ++i) {
|
||||||
if (m.is_eq(v.get(i), e1, e2)) {
|
if (m.is_eq(v.get(i), e1, e2)) {
|
||||||
if (arith.is_zero(e1)) {
|
if (arith.is_zero(e1)) {
|
||||||
expr* t;
|
std::swap(e1, e2);
|
||||||
t = e1; e1 = e2; e2 = t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// y + -1*x == 0
|
// y + -1*x == 0
|
||||||
if (arith.is_zero(e2) && arith.is_add(e1) &&
|
expr* a0 = 0, *a1 = 0, *x = 0;
|
||||||
to_app(e1)->get_num_args() == 2) {
|
if (arith.is_zero(e2) && arith.is_add(e1, a0, a1)) {
|
||||||
expr *a0, *a1, *x;
|
|
||||||
|
|
||||||
a0 = to_app(e1)->get_arg(0);
|
|
||||||
a1 = to_app(e1)->get_arg(1);
|
|
||||||
|
|
||||||
if (arith.is_times_minus_one(a1, x)) {
|
if (arith.is_times_minus_one(a1, x)) {
|
||||||
e1 = a0;
|
e1 = a0;
|
||||||
e2 = x;
|
e2 = x;
|
||||||
|
@ -65,7 +59,9 @@ void factor_eqs(expr_ref_vector &v, expr_equiv_class &equiv) {
|
||||||
equiv.merge(e1, e2);
|
equiv.merge(e1, e2);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (j < i) {v[j] = v.get(i);}
|
if (j < i) {
|
||||||
|
v[j] = v.get(i);
|
||||||
|
}
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +83,9 @@ void equiv_to_expr(expr_equiv_class &equiv, expr_ref_vector &out) {
|
||||||
}
|
}
|
||||||
SASSERT(rep);
|
SASSERT(rep);
|
||||||
for (expr *elem : eq_class) {
|
for (expr *elem : eq_class) {
|
||||||
if (rep != elem) {out.push_back (m.mk_eq (rep, elem));}
|
if (rep != elem) {
|
||||||
|
out.push_back (m.mk_eq (rep, elem));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue