11 namespace convert_poly {
12 template<
typename T,
typename S>
15 template<
typename A,
typename B,
typename C>
22 template<
typename A,
typename B,
typename C>
30 template<
typename A,
typename B,
typename C>
33 CARL_LOG_DEBUG(
"carl.converter",
"Converting Carl Multivariate Poly " << p <<
" with LPContext " << context);
43 if (denominator < 0) {
47 CARL_LOG_DEBUG(
"carl.converter",
"Coprime Factor/ Denominator: " << denominator);
48 lp_polynomial_t* res = lp_polynomial_new(context.lp_context());
49 for (
const auto& term : p) {
52 lp_monomial_construct(context.lp_context(), &t);
53 lp_monomial_set_coefficient(context.lp_context(), &t, (lp_integer_t*)mpz_class(term.coeff() * denominator).get_mpz_t());
54 if (term.monomial()) {
56 for (
const std::pair<carl::Variable, std::size_t>& var_pow : (*term.monomial()).exponents()) {
57 lp_monomial_push(&t, context.lp_variable(var_pow.first), var_pow.second);
60 lp_polynomial_add_monomial(res, &t);
61 lp_monomial_destruct(&t);
63 return LPPolynomial(res, context);
67 namespace conversion_private {
69 struct CollectTermData {
70 std::vector<carl::Term<T>> terms;
71 const LPContext& context;
72 CollectTermData(
const LPContext& c) : context(c) {}
76 void collectTermDataFunction(
const lp_polynomial_context_t* , lp_monomial_t* m,
void* d) {
77 CollectTermData<T>* data =
static_cast<CollectTermData<T>*
>(d);
79 for (
size_t i = 0; i < m->n; i++) {
80 auto carl_var = data->context.carl_variable(m->p[i].x);
81 assert(carl_var.has_value());
84 data->terms.emplace_back(term);
88 template<
typename A,
typename B,
typename C>
89 struct ConvertHelper<MultivariatePolynomial<
A, B, C>, LPPolynomial> {
90 static MultivariatePolynomial<A, B, C>
convert(
const LPPolynomial& p) {
91 conversion_private::CollectTermData<A> termdata(p.context());
93 lp_polynomial_traverse(p.get_internal(), conversion_private::collectTermDataFunction<A>, &termdata);
95 if (termdata.terms.empty()) {
96 return MultivariatePolynomial<A, B, C>();
98 return MultivariatePolynomial<A, B, C>(termdata.terms);
105 template<typename T, typename S, std::enable_if_t<is_polynomial_type<T>::value && is_polynomial_type<S>::value && !needs_context_type<T>::value,
int> = 0>
110 template<typename T, typename S, std::enable_if_t<is_polynomial_type<T>::value && is_polynomial_type<S>::value && needs_context_type<T>::value,
int> = 0>
111 inline T
convert(
const typename T::ContextType& c,
const S& r) {
#define CARL_LOG_DEBUG(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.
BasicConstraint< ToPoly > convert(const typename ToPoly::ContextType &context, const BasicConstraint< FromPoly > &c)
cln::cl_I get_denom(const cln::cl_RA &n)
Extract the denominator from a fraction.
The general-purpose multivariate polynomial class.
const Coeff & constant_part() const
Retrieve the constant term of this polynomial or zero, if there is no constant term.
Coeff coprime_factor() const
static ContextPolynomial< A, B, C > convert(const Context &context, const MultivariatePolynomial< A, B, C > &p)
static MultivariatePolynomial< A, B, C > convert(const ContextPolynomial< A, B, C > &p)
MultivariatePolynomial< Coeff, Ordering, Policies > as_multivariate() const
Represents a single term, that is a numeric coefficient and a monomial.