3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-28 03:15:50 +00:00

get univariate coefficients

This commit is contained in:
Jakob Rath 2022-03-11 18:03:39 +01:00
parent 74281fa830
commit 1de51da67e
3 changed files with 54 additions and 0 deletions

View file

@ -1141,6 +1141,32 @@ namespace dd {
}
}
/** Determine whether p contains at most one variable. */
bool pdd_manager::is_univariate(PDD p) {
unsigned const lvl = level(p);
while (!is_val(p)) {
if (!is_val(lo(p)))
return false;
if (level(p) != lvl)
return false;
p = hi(p);
}
return true;
}
/**
* Push coefficients of univariate polynomial in order of ascending degree.
* Example: a*x^2 + b*x + c ==> [ c, b, a ]
*/
void pdd_manager::get_univariate_coefficients(PDD p, vector<rational>& coeff) {
SASSERT(is_univariate(p));
while (!is_val(p)) {
coeff.push_back(val(lo(p)));
p = hi(p);
}
coeff.push_back(val(p));
}
/*
\brief determine if v occurs as a leaf variable.
*/

View file

@ -356,6 +356,9 @@ namespace dd {
bool is_monomial(PDD p);
bool is_univariate(PDD p);
void get_univariate_coefficients(PDD p, vector<rational>& coeff);
// create an spoly r if leading monomials of a and b overlap
bool try_spoly(pdd const& a, pdd const& b, pdd& r);
@ -413,6 +416,8 @@ namespace dd {
bool is_unary() const { return !is_val() && lo().is_zero() && hi().is_val(); }
bool is_binary() const { return m.is_binary(root); }
bool is_monomial() const { return m.is_monomial(root); }
bool is_univariate() const { return m.is_univariate(root); }
void get_univariate_coefficients(vector<rational>& coeff) const { m.get_univariate_coefficients(root, coeff); }
bool is_never_zero() const { return m.is_never_zero(root); }
bool var_is_leaf(unsigned v) const { return m.var_is_leaf(root, v); }