mirror of
https://github.com/Z3Prover/z3
synced 2025-04-15 13:28:47 +00:00
optimize horner scheme
Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
parent
2584e777f9
commit
eb5b9557ed
|
@ -282,7 +282,7 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void push(vector<nex**>& front, nex** e) {
|
static void push_to_front(vector<nex**>& front, nex** e) {
|
||||||
TRACE("nla_cn", tout << **e << "\n";);
|
TRACE("nla_cn", tout << **e << "\n";);
|
||||||
front.push_back(e);
|
front.push_back(e);
|
||||||
}
|
}
|
||||||
|
@ -509,22 +509,22 @@ public:
|
||||||
|
|
||||||
TRACE("nla_cn_details", tout << "b = " << *b << "\n";);
|
TRACE("nla_cn_details", tout << "b = " << *b << "\n";);
|
||||||
e = mk_sum(mk_mul(mk_var(j), a), b); // e = j*a + b
|
e = mk_sum(mk_mul(mk_var(j), a), b); // e = j*a + b
|
||||||
if (a->get_degree() > 1) {
|
if (!to_sum(a)->is_linear()) {
|
||||||
nex **ptr_to_a = &(to_mul(to_sum(e)->children()[0]))->children()[1];
|
nex **ptr_to_a = &(to_mul(to_sum(e)->children()[0]))->children()[1];
|
||||||
push(front, ptr_to_a);
|
push_to_front(front, ptr_to_a);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b->is_sum() && b->get_degree() > 1) {
|
if (b->is_sum() && !to_sum(b)->is_linear()) {
|
||||||
nex **ptr_to_a = &(to_sum(e)->children()[1]);
|
nex **ptr_to_a = &(to_sum(e)->children()[1]);
|
||||||
push(front, ptr_to_a);
|
push_to_front(front, ptr_to_a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_front_with_split(nex* & e, lpvar j, vector<nex**> & front, nex* a, nex* b) {
|
void update_front_with_split(nex* & e, lpvar j, vector<nex**> & front, nex* a, nex* b) {
|
||||||
if (b == nullptr) {
|
if (b == nullptr) {
|
||||||
e = mk_mul(mk_var(j), a);
|
e = mk_mul(mk_var(j), a);
|
||||||
if (a->get_degree() > 1)
|
if (!to_sum(a)->is_linear())
|
||||||
push(front, &(to_mul(e)->children()[1]));
|
push_to_front(front, &(to_mul(e)->children()[1]));
|
||||||
} else {
|
} else {
|
||||||
update_front_with_split_with_non_empty_b(e, j, front, a, b);
|
update_front_with_split_with_non_empty_b(e, j, front, a, b);
|
||||||
}
|
}
|
||||||
|
|
|
@ -290,6 +290,17 @@ public:
|
||||||
ptr_vector<nex>* children_ptr() { return &m_children;}
|
ptr_vector<nex>* children_ptr() { return &m_children;}
|
||||||
unsigned size() const { return m_children.size(); }
|
unsigned size() const { return m_children.size(); }
|
||||||
|
|
||||||
|
|
||||||
|
bool is_linear() const {
|
||||||
|
TRACE("nex_details", tout << *this << "\n";);
|
||||||
|
for (auto e : children()) {
|
||||||
|
if (e->get_degree() > 1)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
TRACE("nex_details", tout << "linear\n";);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// we need a linear combination of at least two variables
|
// we need a linear combination of at least two variables
|
||||||
bool is_a_linear_term() const {
|
bool is_a_linear_term() const {
|
||||||
TRACE("nex_details", tout << *this << "\n";);
|
TRACE("nex_details", tout << *this << "\n";);
|
||||||
|
|
Loading…
Reference in a new issue