19 #include <poly/upolynomial.h>
23 inline mpz_class to_integer(
const lp_integer_t* m) {
24 return *
reinterpret_cast<const mpz_class*
>(m);
27 inline mpq_class to_rational(
const lp_integer_t* m) {
28 return mpq_class(to_integer(m));
31 inline mpq_class to_rational(
const lp_rational_t* m) {
32 return *
reinterpret_cast<const mpq_class*
>(m);
35 inline mpq_class to_rational(
const lp_dyadic_rational_t* m) {
37 lp_integer_construct(&num);
38 lp_dyadic_rational_get_num(m, &num);
41 lp_integer_construct(&den);
42 lp_dyadic_rational_get_den(m, &den);
44 auto res = mpq_class(to_integer(&num), to_integer(&den));
46 lp_integer_destruct(&num);
47 lp_integer_destruct(&den);
52 inline mpq_class to_rational(
const lp_value_t* m){
54 case lp_value_type_t::LP_VALUE_INTEGER:
55 return to_rational(&m->value.z);
56 case lp_value_type_t::LP_VALUE_RATIONAL:
57 return to_rational(&m->value.q);
58 case lp_value_type_t::LP_VALUE_DYADIC_RATIONAL:
59 return to_rational(&m->value.dy_q);
61 CARL_LOG_ERROR(
"carl.converter",
"Cannot convert libpoly value: " << m <<
" to rational.");
70 lp_integer_t coeffs[lp_upolynomial_degree(p) + 1];
71 for (std::size_t i = 0; i < lp_upolynomial_degree(p) + 1; ++i) {
72 lp_integer_construct(&coeffs[i]);
74 lp_upolynomial_unpack(p, coeffs);
76 std::vector<mpq_class> carl_coeffs;
77 for (std::size_t i = 0; i < lp_upolynomial_degree(p) + 1; ++i) {
78 carl_coeffs.emplace_back(to_rational(&coeffs[i]));
79 lp_integer_destruct(&coeffs[i]);
82 CARL_LOG_TRACE(
"carl.converter",
"-> coefficients: " << carl_coeffs);
87 template<
typename Coeff, EnableIf<is_subset_of_rationals_type<Coeff>> = dummy>
94 lp_upolynomial_t* res = lp_upolynomial_construct(lp_Z, 0, mpz_class(
carl::get_num(p.
lcoeff())).get_mpz_t());
99 CARL_LOG_TRACE(
"carl.converter",
"Coprime Factor: " << coprimeFactor);
100 mpz_class denominator;
103 denominator = coprimeFactor > 0 ? mpz_class(
carl::get_num(coprimeFactor)) : mpz_class(-
carl::
get_num(coprimeFactor));
104 }
else if (coprimeFactor == 0) {
106 denominator = mpz_class(1);
108 denominator = mpz_class(coprimeFactor);
110 CARL_LOG_TRACE(
"carl.converter",
"Coprime factor/ denominator: " << denominator);
112 std::vector<mpz_class> coefficients;
113 std::vector<lp_integer_t> coefficients_ptr;
115 coefficients.emplace_back(c * denominator);
116 coefficients_ptr.emplace_back(*coefficients.back().get_mpz_t());
118 CARL_LOG_TRACE(
"carl.converter",
"coefficients: " << coefficients);
119 lp_upolynomial_t* res = lp_upolynomial_construct(lp_Z, p.
coefficients().size()-1,
reinterpret_cast<const lp_integer_t*
>(coefficients_ptr.data()));
132 lp_value_construct(&low, LP_VALUE_RATIONAL, &inter.
lower());
136 lp_value_construct(&low, LP_VALUE_RATIONAL, &inter.
lower());
141 low = *lp_value_minus_infinity();
149 lp_value_construct(&up, LP_VALUE_RATIONAL, &inter.
upper());
153 lp_value_construct(&up, LP_VALUE_RATIONAL, &inter.
upper());
158 up = *lp_value_plus_infinity();
163 lp_interval_t* res =
new lp_interval_t;
164 lp_interval_construct(res, &low, low_open, &up, up_open);
165 lp_value_destruct(&low);
166 lp_value_destruct(&up);
Implements utility functions concerning the (total) degree of monomials, terms and polynomials.
#define CARL_LOG_FUNC(channel, args)
#define CARL_LOG_ERROR(channel, msg)
#define CARL_LOG_TRACE(channel, msg)
carl is the main namespace for the library.
bool is_constant(const ContextPolynomial< Coeff, Ordering, Policies > &p)
cln::cl_I get_num(const cln::cl_RA &n)
Extract the numerator from a fraction.
typename UnderlyingNumberType< P >::type Coeff
cln::cl_I get_denom(const cln::cl_RA &n)
Extract the denominator from a fraction.
@ WEAK
the given bound is compared by a weak ordering relation
@ STRICT
the given bound is compared by a strict ordering relation
@ INFTY
the given bound is interpreted as minus or plus infinity depending on whether it is the left or the r...
A Variable represents an algebraic variable that can be used throughout carl.
The class which contains the interval arithmetic including trigonometric functions.
BoundType lower_bound_type() const
The getter for the lower bound type of the interval.
const Number & upper() const
The getter for the upper boundary of the interval.
const Number & lower() const
The getter for the lower boundary of the interval.
BoundType upper_bound_type() const
The getter for the upper bound type of the interval.
This class represents a univariate polynomial with coefficients of an arbitrary type.
Coefficient coprime_factor() const
Calculates a factor that would make the coefficients of this polynomial coprime integers.
const std::vector< Coefficient > & coefficients() const &
Retrieves the coefficients defining this polynomial.
const Coefficient & lcoeff() const
Returns the leading coefficient.