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

Add more PDD utilities (div, pow) (#5180)

* Expose 'inv' on rationals to get reciprocal value

* Align parameter names with implementation

* Add cached operation that divides PDD by a constant

* Fix display for constant PDDs

* operator^ should probably call ^ instead of + (mk_xor instead of add)

* Add helper function 'pow' on PDDs
This commit is contained in:
Jakob Rath 2021-04-14 13:48:42 +02:00 committed by GitHub
parent 2f7069a8b7
commit 324d9ed461
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 146 additions and 20 deletions

View file

@ -63,7 +63,8 @@ namespace dd {
pdd_mul_op = 5,
pdd_reduce_op = 6,
pdd_subst_val_op = 7,
pdd_no_op = 8
pdd_div_const_op = 8,
pdd_no_op = 9
};
struct node {
@ -213,6 +214,9 @@ namespace dd {
PDD apply(PDD arg1, PDD arg2, pdd_op op);
PDD apply_rec(PDD arg1, PDD arg2, pdd_op op);
PDD minus_rec(PDD p);
PDD div_rec(PDD p, rational const& c, PDD c_pdd);
PDD pow(PDD p, unsigned j);
PDD pow_rec(PDD p, unsigned j);
PDD reduce_on_match(PDD a, PDD b);
bool lm_occurs(PDD p, PDD q) const;
@ -297,7 +301,7 @@ namespace dd {
struct mem_out {};
pdd_manager(unsigned nodes, semantics s = free_e, unsigned power_of_2 = 0);
pdd_manager(unsigned num_vars, semantics s = free_e, unsigned power_of_2 = 0);
~pdd_manager();
semantics get_semantics() const { return m_semantics; }
@ -317,6 +321,7 @@ namespace dd {
pdd sub(pdd const& a, pdd const& b);
pdd mul(pdd const& a, pdd const& b);
pdd mul(rational const& c, pdd const& b);
pdd div(pdd const& a, rational const& c);
pdd mk_or(pdd const& p, pdd const& q);
pdd mk_xor(pdd const& p, pdd const& q);
pdd mk_xor(pdd const& p, unsigned q);
@ -325,6 +330,7 @@ namespace dd {
pdd subst_val(pdd const& a, vector<std::pair<unsigned, rational>> const& s);
pdd subst_val(pdd const& a, unsigned v, rational const& val);
bool resolve(unsigned v, pdd const& p, pdd const& q, pdd& r);
pdd pow(pdd const& p, unsigned j);
bool is_linear(PDD p) { return degree(p) == 1; }
bool is_linear(pdd const& p);
@ -399,6 +405,8 @@ namespace dd {
pdd operator+(rational const& other) const { return m.add(other, *this); }
pdd operator~() const { return m.mk_not(*this); }
pdd rev_sub(rational const& r) const { return m.sub(m.mk_val(r), *this); }
pdd div(rational const& other) const { return m.div(*this, other); }
pdd pow(unsigned j) const { return m.pow(*this, j); }
pdd reduce(pdd const& other) const { return m.reduce(*this, other); }
bool different_leading_term(pdd const& other) const { return m.different_leading_term(*this, other); }
void factor(unsigned v, unsigned degree, pdd& lc, pdd& rest) const { m.factor(*this, v, degree, lc, rest); }
@ -433,8 +441,8 @@ namespace dd {
inline pdd operator+(int x, pdd const& b) { return b + rational(x); }
inline pdd operator+(pdd const& b, int x) { return b + rational(x); }
inline pdd operator^(unsigned x, pdd const& b) { return b + x; }
inline pdd operator^(bool x, pdd const& b) { return b + x; }
inline pdd operator^(unsigned x, pdd const& b) { return b ^ x; }
inline pdd operator^(bool x, pdd const& b) { return b ^ x; }
inline pdd operator-(rational const& r, pdd const& b) { return b.rev_sub(r); }
inline pdd operator-(int x, pdd const& b) { return rational(x) - b; }