14 using namespace presburger;
21 coefficients(coeffs), affine(aff) {
31 "dimensionality of affine functions does not match number of "
42 coefficients({constant}), affine({{}}) {}
46 "two quasi-polynomials with different numbers of symbols cannot "
49 sumCoeffs.append(x.coefficients);
50 std::vector<std::vector<SmallVector<Fraction>>> sumAff = affine;
51 sumAff.insert(sumAff.end(), x.affine.begin(), x.affine.end());
57 "two quasi-polynomials with different numbers of symbols cannot "
60 for (
Fraction &coeff : qp.coefficients)
67 "two quasi-polynomials with different numbers of "
68 "symbols cannot be multiplied!");
71 coeffs.reserve(coefficients.size() * x.coefficients.size());
72 for (
const Fraction &coeff : coefficients)
73 for (
const Fraction &xcoeff : x.coefficients)
74 coeffs.emplace_back(coeff * xcoeff);
76 std::vector<SmallVector<Fraction>>
product;
77 std::vector<std::vector<SmallVector<Fraction>>> aff;
78 aff.reserve(affine.size() * x.affine.size());
92 assert(x != 0 &&
"division by zero!");
94 for (
Fraction &coeff : qp.coefficients)
106 std::vector<SmallVector<Fraction>> newAffineTerm({});
107 std::vector<std::vector<SmallVector<Fraction>>> newAffine({});
111 for (
unsigned i = 0, e = coefficients.size(); i < e; i++) {
113 if (coefficients[i] ==
Fraction(0, 1))
115 bool product_is_zero =
119 return llvm::all_of(affine_ij,
120 [](
const Fraction &f) {
return f == 0; });
130 newCoeff = coefficients[i];
132 bool allCoeffsZero = llvm::all_of(
133 term.slice(0, numParam), [](
const Fraction &c) { return c == 0; });
135 newCoeff *= term[numParam];
137 newAffineTerm.emplace_back(term);
140 newCoeffs.emplace_back(newCoeff);
141 newAffine.emplace_back(newAffineTerm);
148 std::vector<std::vector<SmallVector<Fraction>>> newAffine({});
150 for (
unsigned i = 0, e = affine.size(); i < e; i++) {
151 bool alreadyPresent =
false;
152 for (
unsigned j = 0, f = newAffine.size();
j < f;
j++) {
153 if (affine[i] == newAffine[
j]) {
154 newCoeffs[
j] += coefficients[i];
155 alreadyPresent =
true;
160 newCoeffs.emplace_back(coefficients[i]);
161 newAffine.emplace_back(affine[i]);
169 for (
unsigned i = 0, e = coefficients.size(); i < e; ++i)
170 if (affine[i].empty())
171 constTerm += coefficients[i];
static int64_t product(ArrayRef< int64_t > vals)
PresburgerSpace is the space of all possible values of a tuple of integer valued variables/variables.
QuasiPolynomial operator/(const Fraction &x) const
QuasiPolynomial(unsigned numVars, ArrayRef< Fraction > coeffs={}, ArrayRef< std::vector< SmallVector< Fraction >>> aff={})
QuasiPolynomial operator-(const QuasiPolynomial &x) const
Fraction getConstantTerm()
QuasiPolynomial operator+(const QuasiPolynomial &x) const
QuasiPolynomial simplify()
QuasiPolynomial collectTerms()
QuasiPolynomial operator*(const QuasiPolynomial &x) const
unsigned getNumInputs() const
Include the generated interface declarations.
A class to represent fractions.
Eliminates variable at the specified position using Fourier-Motzkin variable elimination.