1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS |
8 |
|
* in the top-level source directory and their institutional affiliations. |
9 |
|
* All rights reserved. See the file COPYING in the top-level source |
10 |
|
* directory for licensing information. |
11 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* Arithmetic utility for polynomial normalization |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__THEORY__ARITH__POLY_NORM_H |
19 |
|
#define CVC5__THEORY__ARITH__POLY_NORM_H |
20 |
|
|
21 |
|
#include <unordered_map> |
22 |
|
|
23 |
|
#include "expr/node.h" |
24 |
|
#include "util/rational.h" |
25 |
|
|
26 |
|
namespace cvc5 { |
27 |
|
namespace theory { |
28 |
|
namespace arith { |
29 |
|
|
30 |
|
/** |
31 |
|
* A utility class for polynomial normalization. This is used by the proof |
32 |
|
* rule PfRule::ARITH_POLY_NORM. |
33 |
|
*/ |
34 |
818 |
class PolyNorm |
35 |
|
{ |
36 |
|
public: |
37 |
|
/** |
38 |
|
* Add the monomial x*c to this polynomial. |
39 |
|
* If x is null, then x*c is treated as c. |
40 |
|
*/ |
41 |
|
void addMonomial(TNode x, const Rational& c, bool isNeg = false); |
42 |
|
/** |
43 |
|
* Multiply this polynomial by the monomial x*c, where c is a CONST_RATIONAL. |
44 |
|
* If x is null, then x*c is treated as c. |
45 |
|
*/ |
46 |
|
void multiplyMonomial(TNode x, const Rational& c); |
47 |
|
/** Add polynomial p to this one. */ |
48 |
|
void add(const PolyNorm& p); |
49 |
|
/** Subtract polynomial p from this one. */ |
50 |
|
void subtract(const PolyNorm& p); |
51 |
|
/** Multiply this polynomial by p */ |
52 |
|
void multiply(const PolyNorm& p); |
53 |
|
/** Clear this polynomial */ |
54 |
|
void clear(); |
55 |
|
/** Return true if this polynomial is empty */ |
56 |
|
bool empty() const; |
57 |
|
/** Is this polynomial equal to polynomial p? */ |
58 |
|
bool isEqual(const PolyNorm& p) const; |
59 |
|
/** |
60 |
|
* Make polynomial from real term n. This method normalizes applications |
61 |
|
* of operators PLUS, MINUS, UMINUS, MULT, and NONLINEAR_MULT only. |
62 |
|
*/ |
63 |
|
static PolyNorm mkPolyNorm(TNode n); |
64 |
|
/** Do a and b normalize to the same polynomial? */ |
65 |
|
static bool isArithPolyNorm(TNode a, TNode b); |
66 |
|
|
67 |
|
private: |
68 |
|
/** |
69 |
|
* Given two terms that are variables in monomials, return the |
70 |
|
* variable for the monomial when they are multiplied. |
71 |
|
*/ |
72 |
|
static Node multMonoVar(TNode m1, TNode m2); |
73 |
|
/** Get the list of variables whose product is m */ |
74 |
|
static std::vector<TNode> getMonoVars(TNode m); |
75 |
|
/** The data, mapping monomial variables to coefficients */ |
76 |
|
std::unordered_map<Node, Rational> d_polyNorm; |
77 |
|
}; |
78 |
|
|
79 |
|
} // namespace arith |
80 |
|
} // namespace theory |
81 |
|
} // namespace cvc5 |
82 |
|
|
83 |
|
#endif /* CVC5__THEORY__ARITH__POLY_NORM_H */ |