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

work on Grobner

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
Lev Nachmanson 2019-10-09 10:33:47 -07:00
parent 7d13bcb18e
commit 2c1d68e163
3 changed files with 47 additions and 42 deletions

View file

@ -581,28 +581,16 @@ grobner::equation * grobner::copy_equation(equation const * eq) {
return r; return r;
} }
/** bool grobner::simplify_for_loop(equation const * source, equation * target, bool & result, unsigned& j ) {
\brief Simplify the target equation using the source as a rewrite rule. bool simplified = false;
Return 0 if target was not simplified.
Return target if target was simplified but source->m_scope_lvl <= target->m_scope_lvl.
Return new_equation if source->m_scope_lvl > target->m_scope_lvl, moreover target is freezed, and new_equation contains the result.
*/
grobner::equation * grobner::simplify(equation const * source, equation * target) {
TRACE("grobner", tout << "simplifying: "; display_equation(tout, *target); tout << "using: "; display_equation(tout, *source););
if (source->get_num_monomials() == 0)
return nullptr;
m_stats.m_simplify++;
bool result = false;
bool simplified;
do {
simplified = false;
unsigned i = 0; unsigned i = 0;
unsigned j = 0; j = 0;
unsigned sz = target->m_monomials.size(); unsigned sz = target->m_monomials.size();
monomial const * LT = source->get_monomial(0); monomial const * LT = source->get_monomial(0);
ptr_vector<monomial> & new_monomials = m_tmp_monomials; ptr_vector<monomial> & new_monomials = m_tmp_monomials;
new_monomials.reset(); new_monomials.reset();
ptr_vector<expr> & rest = m_tmp_vars1; ptr_vector<expr> & rest = m_tmp_vars1;
for (; i < sz; i++) { for (; i < sz; i++) {
monomial * curr = target->m_monomials[i]; monomial * curr = target->m_monomials[i];
rest.reset(); rest.reset();
@ -629,13 +617,33 @@ grobner::equation * grobner::simplify(equation const * source, equation * target
j++; j++;
} }
} }
if (simplified) { return simplified;
}
/**
\brief Simplify the target equation using the source as a rewrite rule.
Return 0 if target was not simplified.
Return target if target was simplified but source->m_scope_lvl <= target->m_scope_lvl.
Return new_equation if source->m_scope_lvl > target->m_scope_lvl, moreover target is freezed, and new_equation contains the result.
*/
grobner::equation * grobner::simplify(equation const * source, equation * target) {
TRACE("grobner", tout << "simplifying: "; display_equation(tout, *target); tout << "using: "; display_equation(tout, *source););
if (source->get_num_monomials() == 0)
return nullptr;
m_stats.m_simplify++;
bool result = false;
do {
unsigned j;
if( simplify_for_loop(source, target, result, j)) {
target->m_monomials.shrink(j); target->m_monomials.shrink(j);
target->m_monomials.append(new_monomials.size(), new_monomials.c_ptr()); target->m_monomials.append(m_tmp_monomials.size(), m_tmp_monomials.c_ptr());
simplify(target); simplify(target);
} else {
break;
} }
} }
while (simplified && !m_manager.canceled()); while (!m_manager.canceled());
TRACE("grobner", tout << "result: "; display_equation(tout, *target);); TRACE("grobner", tout << "result: "; display_equation(tout, *target););
return result ? target : nullptr; return result ? target : nullptr;
} }

View file

@ -166,6 +166,7 @@ protected:
equation * copy_equation(equation const * eq); equation * copy_equation(equation const * eq);
equation * simplify(equation const * source, equation * target); equation * simplify(equation const * source, equation * target);
bool simplify_for_loop(equation const * source, equation * target, bool&, unsigned &);
equation * simplify_using_processed(equation * eq); equation * simplify_using_processed(equation * eq);

View file

@ -344,8 +344,4 @@ public:
} }
} }
}; // end of var_eqs }; // end of var_eqs
// template <typename T>
// std::ostream& operator<<(var_eqs<T> const& ve, std::ostream& out) { return ve.display(out); }
} }