3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-22 13:53:39 +00:00

work on horner form

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
Lev Nachmanson 2019-07-16 10:58:15 -07:00
parent 9cba261a9c
commit 0b86a282e4

View file

@ -67,6 +67,8 @@ class nla_expr {
nla_expr& back() { return m_es.back(); } nla_expr& back() { return m_es.back(); }
const nla_expr* begin() const { return m_es.begin(); } const nla_expr* begin() const { return m_es.begin(); }
const nla_expr* end() const { return m_es.end(); } const nla_expr* end() const { return m_es.end(); }
typename std::vector<nla_expr>::iterator begin() { return m_es.begin(); }
typename std::vector<nla_expr>::iterator end() { return m_es.end(); }
unsigned size() const { return m_es.size(); } unsigned size() const { return m_es.size(); }
void sort() { void sort() {
std::sort(m_order.begin(), m_order.end(), [this](unsigned i, unsigned j) { return m_es[i] < m_es[j]; }); std::sort(m_order.begin(), m_order.end(), [this](unsigned i, unsigned j) { return m_es[i] < m_es[j]; });
@ -127,13 +129,12 @@ public:
} }
void simplify() { void simplify() {
if (is_simple()) return;
bool has_sum = false;
if (is_sum()) { if (is_sum()) {
bool has_sum = false; for (auto & e : m_children) {
for (unsigned j = 0; j < m_children.es().size(); j++) {
auto& e = m_children.es()[j];
e.simplify(); e.simplify();
if (e.is_sum()) has_sum |= e.is_sum();
has_sum = true;
} }
if (has_sum) { if (has_sum) {
nla_expr n(expr_type::SUM); nla_expr n(expr_type::SUM);
@ -141,15 +142,12 @@ public:
n += e; n += e;
} }
*this = n; *this = n;
} }
} else if (is_mul()) { } else if (is_mul()) {
bool has_mul = false; bool has_mul = false;
for (unsigned j = 0; j < m_children.es().size(); j++) { for (auto & e : m_children) {
auto& e = m_children.es()[j];
e.simplify(); e.simplify();
if (e.is_mul()) has_mul |= e.is_mul();
has_mul = true;
} }
if (has_mul) { if (has_mul) {
nla_expr n(expr_type::MUL); nla_expr n(expr_type::MUL);
@ -209,7 +207,7 @@ public:
switch(m_type) { switch(m_type) {
case expr_type::SUM: case expr_type::SUM:
case expr_type::MUL: case expr_type::MUL:
return m_children.size() <= 1; return false;
default: default:
return true; return true;