mirror of
https://github.com/Z3Prover/z3
synced 2025-07-27 22:47:55 +00:00
integrating NB suggestions
Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
parent
617e1387f4
commit
7642f74142
2 changed files with 32 additions and 117 deletions
|
@ -125,127 +125,42 @@ void nex_creator::simplify_children_of_mul(vector<nex_pow> & children, rational&
|
||||||
|
|
||||||
TRACE("grobner_d", print_vector(children, tout););
|
TRACE("grobner_d", print_vector(children, tout););
|
||||||
}
|
}
|
||||||
bool nex_creator:: gt_on_powers_mul_same_degree(const vector<nex_pow>& a, const nex_mul& b) const {
|
|
||||||
bool inside_a_p = false; // inside_a_p is true means we still compare the old position of it_a
|
template <typename T>
|
||||||
bool inside_b_p = false; // inside_b_p is true means we still compare the old position of it_b
|
bool nex_creator::gt_on_powers_mul_same_degree(const T& a, const nex_mul& b) const {
|
||||||
auto it_a = a.begin();
|
bool ret = false;
|
||||||
auto it_b = b.begin();
|
unsigned a_pow = a.begin()->pow();
|
||||||
auto a_end = a.end();
|
unsigned b_pow = b.begin()->pow();
|
||||||
auto b_end = b.end();
|
for (auto it_a = a.begin(), it_b = b.begin(); it_a != a.end() && it_b != b.end(); ) {
|
||||||
unsigned a_pow, b_pow;
|
|
||||||
lbool ret = l_undef;
|
|
||||||
while (true) {
|
|
||||||
if (!inside_a_p) { a_pow = it_a->pow(); }
|
|
||||||
if (!inside_b_p) { b_pow = it_b->pow(); }
|
|
||||||
if (gt(it_a->e(), it_b->e())){
|
if (gt(it_a->e(), it_b->e())){
|
||||||
ret = l_true;
|
ret = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (gt(it_b->e(), it_a->e())) {
|
if (gt(it_b->e(), it_a->e())){
|
||||||
ret = l_false;
|
ret = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (a_pow == b_pow) {
|
if (a_pow > b_pow) { // b should be advanced
|
||||||
inside_a_p = inside_b_p = false;
|
|
||||||
it_a++; it_b++;
|
|
||||||
if (it_a == a_end) {
|
|
||||||
ret = l_false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (it_b == b_end) { // it_a is not at the end
|
|
||||||
ret = l_false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// no iterator reached the end
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (a_pow > b_pow) {
|
|
||||||
it_a++;
|
|
||||||
if (it_a == a_end) {
|
|
||||||
ret = l_true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
inside_a_p = false;
|
|
||||||
inside_b_p = true;
|
|
||||||
b_pow -= a_pow;
|
b_pow -= a_pow;
|
||||||
} else {
|
++it_b;
|
||||||
SASSERT(a_pow < b_pow);
|
if (it_b != b.end()) b_pow = it_b->pow();
|
||||||
a_pow -= b_pow;
|
ret = true;
|
||||||
it_b++;
|
}
|
||||||
if (it_b == b_end) {
|
else if (a_pow < b_pow) { // a should be advanced
|
||||||
ret = l_false;
|
b_pow -= a_pow;
|
||||||
break;
|
++it_a;
|
||||||
}
|
if (it_a != a.end()) a_pow = it_a->pow();
|
||||||
inside_a_p = true;
|
ret = false;
|
||||||
inside_b_p = false;
|
}
|
||||||
|
else {
|
||||||
|
++it_a;
|
||||||
|
++it_b;
|
||||||
|
if (it_a != a.end()) a_pow = it_a->pow();
|
||||||
|
if (it_b != b.end()) b_pow = it_b->pow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TRACE("nex_less", tout << "a = "; print_vector(a, tout) << (ret != l_false?" < ":" >= ") << b << "\n";);
|
TRACE("nex_less", tout << "a = "; print_vector(a, tout) << (ret?" > ":" <= ") << b << "\n";);
|
||||||
return ret != l_false;
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
bool nex_creator::gt_on_mul_mul_same_degree(const nex_mul& a, const nex_mul& b) const {
|
|
||||||
bool inside_a_p = false; // inside_a_p is true means we still compare the old position of it_a
|
|
||||||
bool inside_b_p = false; // inside_b_p is true means we still compare the old position of it_b
|
|
||||||
auto it_a = a.begin();
|
|
||||||
auto it_b = b.begin();
|
|
||||||
auto a_end = a.end();
|
|
||||||
auto b_end = b.end();
|
|
||||||
unsigned a_pow, b_pow;
|
|
||||||
lbool ret = l_undef;
|
|
||||||
while (true) {
|
|
||||||
if (!inside_a_p) { a_pow = it_a->pow(); }
|
|
||||||
if (!inside_b_p) { b_pow = it_b->pow(); }
|
|
||||||
if (gt(it_a->e(), it_b->e())){
|
|
||||||
ret = l_true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (gt(it_b->e(), it_a->e())) {
|
|
||||||
ret = l_false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (a_pow == b_pow) {
|
|
||||||
inside_a_p = inside_b_p = false;
|
|
||||||
it_a++; it_b++;
|
|
||||||
if (it_a == a_end) {
|
|
||||||
if (it_b != b_end) {
|
|
||||||
ret = l_false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
SASSERT(it_a == a_end && it_b == b_end);
|
|
||||||
ret = to_lbool(a.coeff() > b.coeff());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (it_b == b_end) { // it_a is not at the end
|
|
||||||
ret = l_false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// no iterator reached the end
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (a_pow > b_pow) {
|
|
||||||
it_a++;
|
|
||||||
if (it_a == a_end) {
|
|
||||||
ret = l_true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
inside_a_p = false;
|
|
||||||
inside_b_p = true;
|
|
||||||
b_pow -= a_pow;
|
|
||||||
} else {
|
|
||||||
SASSERT(a_pow < b_pow);
|
|
||||||
a_pow -= b_pow;
|
|
||||||
it_b++;
|
|
||||||
if (it_b == b_end) {
|
|
||||||
ret = l_false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
inside_a_p = true;
|
|
||||||
inside_b_p = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TRACE("grobner_d", tout << "a = " << a << (ret != l_false?" < ":" >= ") << b << "\n";);
|
|
||||||
return ret != l_false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nex_creator::children_are_simplified(const vector<nex_pow>& children) const {
|
bool nex_creator::children_are_simplified(const vector<nex_pow>& children) const {
|
||||||
|
@ -269,7 +184,7 @@ bool nex_creator::gt_on_mul_mul(const nex_mul& a, const nex_mul& b) const {
|
||||||
SASSERT(is_simplified(&a) && is_simplified(&b));
|
SASSERT(is_simplified(&a) && is_simplified(&b));
|
||||||
unsigned a_deg = a.get_degree();
|
unsigned a_deg = a.get_degree();
|
||||||
unsigned b_deg = b.get_degree();
|
unsigned b_deg = b.get_degree();
|
||||||
return a_deg == b_deg ? gt_on_mul_mul_same_degree(a, b) : a_deg > b_deg;
|
return a_deg == b_deg ? gt_on_powers_mul_same_degree(a, b) : a_deg > b_deg;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nex_creator::gt_on_var_nex(const nex_var* a, const nex* b) const {
|
bool nex_creator::gt_on_var_nex(const nex_var* a, const nex* b) const {
|
||||||
|
|
|
@ -244,11 +244,11 @@ public:
|
||||||
bool children_are_simplified(const vector<nex_pow>& children) const;
|
bool children_are_simplified(const vector<nex_pow>& children) const;
|
||||||
bool gt(const nex* a, const nex* b) const;
|
bool gt(const nex* a, const nex* b) const;
|
||||||
bool gt_nex_powers(const vector<nex_pow>&, const nex* b) const;
|
bool gt_nex_powers(const vector<nex_pow>&, const nex* b) const;
|
||||||
bool gt_on_powers_mul(const vector<nex_pow>&, const nex_mul& b) const;
|
bool gt_on_powers_mul(const vector<nex_pow>&, const nex_mul& b) const;
|
||||||
bool gt_on_powers_mul_same_degree(const vector<nex_pow>&, const nex_mul& b) const;
|
template <typename T>
|
||||||
|
bool gt_on_powers_mul_same_degree(const T&, const nex_mul& b) const;
|
||||||
bool gt_for_sort_join_sum(const nex* a, const nex* b) const;
|
bool gt_for_sort_join_sum(const nex* a, const nex* b) const;
|
||||||
bool gt_on_mul_mul(const nex_mul& a, const nex_mul& b) const;
|
bool gt_on_mul_mul(const nex_mul& a, const nex_mul& b) const;
|
||||||
bool gt_on_mul_mul_same_degree(const nex_mul& a, const nex_mul& b) const;
|
|
||||||
bool gt_on_var_nex(const nex_var* a, const nex* b) const;
|
bool gt_on_var_nex(const nex_var* a, const nex* b) const;
|
||||||
bool gt_on_mul_nex(const nex_mul* a, const nex* b) const;
|
bool gt_on_mul_nex(const nex_mul* a, const nex* b) const;
|
||||||
bool gt_on_sum_sum(const nex_sum* a, const nex_sum* b) const;
|
bool gt_on_sum_sum(const nex_sum* a, const nex_sum* b) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue