11 #include "llvm/ADT/SmallVector.h"
14 namespace polynomial {
16 template <
typename PolyT,
typename MonomialT>
20 std::sort(monomialsCopy.begin(), monomialsCopy.end());
24 if (std::adjacent_find(monomialsCopy.begin(), monomialsCopy.end(),
25 [](
const MonomialT &lhs,
const MonomialT &rhs) {
26 return lhs.getExponent() == rhs.getExponent();
27 }) != monomialsCopy.end()) {
31 return PolyT(monomialsCopy);
34 FailureOr<IntPolynomial>
36 return fromMonomialsImpl<IntPolynomial, IntMonomial>(monomials);
39 FailureOr<FloatPolynomial>
41 return fromMonomialsImpl<FloatPolynomial, FloatMonomial>(monomials);
44 template <
typename PolyT,
typename MonomialT,
typename CoeffT>
47 auto size = coeffs.size();
48 monomials.reserve(size);
49 for (
size_t i = 0; i < size; i++) {
50 monomials.emplace_back(coeffs[i], i);
52 auto result = PolyT::fromMonomials(monomials);
55 assert(succeeded(result));
56 return result.value();
60 return fromCoefficientsImpl<IntPolynomial, IntMonomial, int64_t>(coeffs);
64 return fromCoefficientsImpl<FloatPolynomial, FloatMonomial, double>(coeffs);
A single-variable polynomial with double coefficients.
static FailureOr< FloatPolynomial > fromMonomials(ArrayRef< FloatMonomial > monomials)
static FloatPolynomial fromCoefficients(ArrayRef< double > coeffs)
Returns a polynomial with coefficients given by coeffs.
A single-variable polynomial with integer coefficients.
static IntPolynomial fromCoefficients(ArrayRef< int64_t > coeffs)
Returns a polynomial with coefficients given by coeffs.
static FailureOr< IntPolynomial > fromMonomials(ArrayRef< IntMonomial > monomials)
FailureOr< PolyT > fromMonomialsImpl(ArrayRef< MonomialT > monomials)
PolyT fromCoefficientsImpl(ArrayRef< CoeffT > coeffs)
Include the generated interface declarations.