carl  24.04
Computer ARithmetic Library
Conversion.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <carl-common/config.h>
4 #include "../poly/Conversion.h"
5 
6 namespace carl {
7 
8 template<typename ToPoly, typename FromPoly, typename = std::enable_if_t<needs_context_type<ToPoly>::value>>
9 inline VariableComparison<ToPoly> convert(const typename ToPoly::ContextType& context, const VariableComparison<FromPoly>& c) {
10  auto k = [&](){
11  if (std::holds_alternative<MultivariateRoot<FromPoly>>(c.value())) {
12  return std::get<MultivariateRoot<FromPoly>>(c.value()).k();
13  } else {
14  auto& ran = std::get<typename FromPoly::RootType>(c.value());
15  if (ran.is_numeric()) {
16  return (std::size_t)1;
17  } else {
18  // TODO circumvent this (i.e. store k inside the RAN, or store variable comparison always as MultivariateRoot combined with a concrete value)
19  auto roots = carl::real_roots(ran.polynomial());
20  auto it = std::find(roots.roots().begin(), roots.roots().end(), ran);
21  assert(it != roots.roots().end());
22  return (std::size_t)std::distance(roots.roots().begin(), it)+1;
23  }
24  }
25  }();
26  MultivariateRoot<ToPoly> mv(convert<ToPoly>(context, defining_polynomial(c)), k, c.var());
27  return VariableComparison<ToPoly>(c.var(), mv, c.relation(), c.negated());
28 }
29 template<typename ToPoly, typename FromPoly, typename = std::enable_if_t<!needs_context_type<ToPoly>::value>>
31  assert((std::holds_alternative<MultivariateRoot<FromPoly>>(c.value())));
32  const auto& m = std::get<MultivariateRoot<FromPoly>>(c.value());
33  MultivariateRoot<ToPoly> mv(convert<ToPoly>(m.poly()), m.k(), m.var());
34  return VariableComparison<ToPoly>(c.var(), mv, c.relation(), c.negated());
35 }
36 
37 }
carl is the main namespace for the library.
RealRootsResult< IntRepRealAlgebraicNumber< Number > > real_roots(const UnivariatePolynomial< Coeff > &polynomial, const Interval< Number > &interval=Interval< Number >::unbounded_interval())
Find all real roots of a univariate 'polynomial' with numeric coefficients within a given 'interval'.
Definition: RealRoots.h:25
BasicConstraint< ToPoly > convert(const typename ToPoly::ContextType &context, const BasicConstraint< FromPoly > &c)
Definition: Conversion.h:9
Poly defining_polynomial(const VariableComparison< Poly > &f)
Return a polynomial containing the lhs-variable that has a same root for the this lhs-variable as the...
Represent a sum type/variant of an (in)equality between a variable on the left-hand side and multivar...
const std::variant< MR, RAN > & value() const