11 #if BOOST_VERSION >= 105900
12 #ifdef USE_CLN_NUMBERS
13 namespace boost {
namespace spirit {
namespace traits {
14 template<>
inline bool scale(
int exp, cln::cl_RA& r, cln::cl_RA acc) {
21 #if BOOST_VERSION < 107000
22 template<>
inline bool is_equal_to_one(
const cln::cl_RA& value) {
28 namespace boost {
namespace spirit {
namespace traits {
29 template<>
inline bool scale(
int exp, mpq_class& r, mpq_class acc) {
36 #if BOOST_VERSION < 107000
37 template<>
inline bool is_equal_to_one(
const mpq_class& value) {
41 template<>
inline mpq_class negate(
bool neg,
const mpq_class& n) {
42 return neg ? mpq_class(-n) : n;
46 #ifdef USE_CLN_NUMBERS
47 namespace boost {
namespace spirit {
namespace traits {
48 template<>
inline void scale(
int exp, cln::cl_RA& r) {
54 #if BOOST_VERSION < 107000
55 template<>
inline bool is_equal_to_one(
const cln::cl_RA& value) {
61 namespace boost {
namespace spirit {
namespace traits {
62 template<>
inline void scale(
int exp, mpq_class& r) {
68 #if BOOST_VERSION < 107000
69 template<>
inline bool is_equal_to_one(
const mpq_class& value) {
73 template<>
inline mpq_class negate(
bool neg,
const mpq_class& n) {
74 return neg ? mpq_class(-n) : n;
82 template<
typename Pol>
83 struct ExpressionParser:
public qi::grammar<Iterator, ExpressionType<Pol>(), Skipper> {
89 template<
typename T,
typename U>
91 return Pol(lhs) +
Pol(rhs);
99 return (lhs) +
Pol(rhs);
103 return (lhs) +
Pol(rhs);
107 typename std::enable_if<!std::is_same<Formula<Pol>, T>::value,
expr_type>::type
109 return (lhs) + (rhs);
113 typename std::enable_if<!std::is_same<Formula<Pol>, T>::value,
expr_type>::type
115 return (rhs) +
Pol(lhs);
119 return (lhs) + (rhs);
124 throw std::runtime_error(
"No addition for formula");
128 typename std::enable_if<!std::is_same<Formula<Pol>, T>::value,
expr_type>::type
130 throw std::runtime_error(
"No addition for formula");
136 template<
typename T,
typename U>
138 return Pol(lhs) -
Pol(rhs);
142 return (lhs) - (rhs);
146 return (lhs) -
Pol(rhs);
150 return (lhs) -
Pol(rhs);
154 typename std::enable_if<!std::is_same<Formula<Pol>, T>::value,
expr_type>::type
156 return (lhs) - (rhs);
160 typename std::enable_if<!std::is_same<Formula<Pol>, T>::value,
expr_type>::type
162 return (rhs) -
Pol(lhs);
166 return (lhs) - (rhs);
171 throw std::runtime_error(
"No subtraction for formula");
175 typename std::enable_if<!std::is_same<Formula<Pol>, T>::value,
expr_type>::type
177 throw std::runtime_error(
"No subtraction for formula");
183 template<
typename T,
typename U>
184 typename std::enable_if<!std::is_same<Formula<Pol>, T>::value,
expr_type>::type
190 typename std::enable_if<!std::is_same<Formula<Pol>, T>::value,
expr_type>::type
196 return (lhs) *
Pol(rhs);
200 return (lhs) *
Pol(rhs);
204 return (rhs) *
Pol(lhs);
208 return (rhs) *
Pol(lhs);
213 throw std::runtime_error(
"No multiplication for formula");
217 typename std::enable_if<!std::is_same<Formula<Pol>, T>::value,
expr_type>::type
219 throw std::runtime_error(
"No multiplication for formula");
230 typename std::enable_if<!std::is_base_of<Formula<Pol>, T>::value,
expr_type>::type
236 return lhs /
Pol(rhs);
240 return lhs /
Pol(rhs);
248 typename std::enable_if<!std::is_same<Formula<Pol>, T>::value,
expr_type>::type
254 typename std::enable_if<!std::is_same<Formula<Pol>, T>::value,
expr_type>::type
260 template<
typename T,
typename U>
261 typename std::enable_if<!std::is_same<Formula<Pol>, T>::value,
expr_type>::type
268 throw std::runtime_error(
"No division for formula");
272 typename std::enable_if<!std::is_same<Formula<Pol>, T>::value,
expr_type>::type
274 throw std::runtime_error(
"No division for formula");
306 throw std::runtime_error(
"No power for fomula");
318 throw std::runtime_error(
"No negate for fomula");
325 std::cout <<
"Rational function " <<
expr << std::endl;
329 std::cout <<
"Polynomial " <<
expr << std::endl;
333 std::cout <<
"Term " <<
expr << std::endl;
337 std::cout <<
"Monomial " <<
expr << std::endl;
341 std::cout <<
"Coefficient " <<
expr << std::endl;
345 std::cout <<
"Variable " <<
expr << std::endl;
349 std::cout <<
"Formula " <<
expr << std::endl;
365 varname = qi::lexeme[ (qi::alpha | qi::char_(
"_")) >> *(qi::alnum | qi::char_(
"_"))];
373 atom = (
boolean[qi::_val = qi::_1] |
monomial[qi::_val = qi::_1] |
coeff[qi::_val = qi::_1]);
403 if ((vptr =
varmap.find(s)) !=
nullptr) {
427 for (
const auto& op: ops) {
428 switch (boost::fusion::at_c<0>(op)) {
430 res = boost::apply_visitor(
perform_addition(), res, boost::fusion::at_c<1>(op) );
452 for (
const auto& op: ops) {
465 for (
const auto& op: ops) {
466 switch (boost::fusion::at_c<0>(op)) {
468 res = boost::apply_visitor(
perform_addition(), res, boost::fusion::at_c<1>(op) );
480 res = boost::apply_visitor(
perform_division(), res, boost::fusion::at_c<1>(op) );
490 for (
const auto& op: ops) {
491 switch (boost::fusion::at_c<0>(op)) {
493 res = boost::apply_visitor(
perform_power(boost::fusion::at_c<1>(op)), res );
510 throw std::runtime_error(
"Unknown unary operator");
528 qi::real_parser<CoeffType,RationalPolicies<CoeffType>>
coeff;
MultivariatePolynomial< Rational > Pol
Monomial::Arg createMonomial(T &&... t)
std::size_t exponent
Type of an exponent.
cln::cl_RA reciprocal(const cln::cl_RA &a)
Interval< Number > exp(const Interval< Number > &i)
Variable fresh_real_variable() noexcept
Interval< Number > pow(const Interval< Number > &i, Integer exp)
boost::spirit::qi::space_type Skipper
std::string::const_iterator Iterator
boost::variant< typename Pol::CoeffType, carl::Variable, carl::Monomial::Arg, carl::Term< typename Pol::CoeffType >, Pol, RationalFunction< Pol >, carl::Formula< Pol > > ExpressionType
A Variable represents an algebraic variable that can be used throughout carl.
static const Variable NO_VARIABLE
Instance of an invalid variable.
std::string get_name(Variable v, bool variableName=true) const
Get a human-readable name for the given variable.
Variable find_variable_with_name(const std::string &name) const noexcept
Searches in the friendly names list for a variable with the given name.
std::shared_ptr< const Monomial > Arg
Represents a single term, that is a numeric coefficient and a monomial.
static VariablePool & getInstance()
Returns the single instance of this class by reference.
Represent an SMT formula, which can be an atom for some background theory or a boolean combination of...
qi::symbols< char, Operation > operationShift
qi::symbols< char, carl::FormulaType > operationImp
qi::rule< Iterator, expr_type(), Skipper > expr_power
qi::rule< Iterator, Operation(), Skipper > operationScaleLA
expr_type booleanUnaryExpr(const std::vector< carl::FormulaType > &ops, const expr_type &first)
qi::symbols< char, Variable > varmap
expr_type signExpr(const std::vector< Operation > &ops, const expr_type &first)
qi::rule< Iterator, expr_type(), Skipper > atom
qi::rule< Iterator, expr_type(), Skipper > monomial
Variable newVariable(const std::string &s)
void addVariable(Variable::Arg v)
ExpressionType< Pol > expr_type
qi::real_parser< CoeffType, RationalPolicies< CoeffType > > coeff
expr_type makeBool(bool value)
qi::symbols< char, Operation > operationSign
expr_type arithmeticExpr(const expr_type &first, const std::vector< boost::fusion::vector2< Operation, expr_type >> &ops)
qi::rule< Iterator, expr_type(), Skipper > boolean
expr_type booleanBinaryExpr(const expr_type &first, const std::vector< boost::fusion::vector2< carl::FormulaType, expr_type >> &ops)
qi::symbols< char, carl::FormulaType > operationNot
qi::rule< Iterator, expr_type(), Skipper > expr
qi::rule< Iterator, expr_type(), Skipper > expr_sum
qi::rule< Iterator, expr_type(), Skipper > main
expr_type powExpr(const expr_type &first, const std::vector< boost::fusion::vector2< Operation, exponent >> &ops)
qi::symbols< char, carl::FormulaType > operationIff
qi::symbols< char, Operation > operationPow
qi::uint_parser< exponent, 10, 1,-1 > exponentVal
qi::rule< Iterator, expr_type(), Skipper > expr_product
qi::rule< Iterator, std::string(), Skipper > varname
qi::symbols< char, carl::FormulaType > operationAnd
qi::rule< Iterator, Variable(), Skipper > variable
qi::symbols< char, Operation > operationScale
qi::rule< Iterator, expr_type(), Skipper > expr_sign
expr_type operator()(const RatFun< Pol > &lhs, const Monomial::Arg &rhs) const
std::enable_if<!std::is_same< Formula< Pol >, T >::value, expr_type >::type operator()(const T &lhs, const RatFun< Pol > &rhs) const
expr_type operator()(const RatFun< Pol > &lhs, const RatFun< Pol > &rhs) const
expr_type operator()(const T &lhs, const U &rhs) const
std::enable_if<!std::is_same< Formula< Pol >, T >::value, expr_type >::type operator()(const T &lhs, const Formula< Pol > &rhs) const
expr_type operator()(const CoeffType &lhs, const CoeffType &rhs) const
expr_type operator()(const RatFun< Pol > &lhs, const Term< CoeffType > &rhs) const
expr_type operator()(const Formula< Pol > &lhs, const T &rhs) const
std::enable_if<!std::is_same< Formula< Pol >, T >::value, expr_type >::type operator()(const RatFun< Pol > &lhs, const T &rhs) const
std::enable_if<!std::is_same< Formula< Pol >, T >::value, expr_type >::type operator()(const T &lhs, const Formula< Pol > &rhs) const
expr_type operator()(const RatFun< Pol > &lhs, const Monomial::Arg &rhs) const
expr_type operator()(const T &lhs, const U &rhs) const
expr_type operator()(const RatFun< Pol > &lhs, const RatFun< Pol > &rhs) const
expr_type operator()(const Formula< Pol > &lhs, const T &rhs) const
expr_type operator()(const CoeffType &lhs, const CoeffType &rhs) const
std::enable_if<!std::is_same< Formula< Pol >, T >::value, expr_type >::type operator()(const T &lhs, const RatFun< Pol > &rhs) const
std::enable_if<!std::is_same< Formula< Pol >, T >::value, expr_type >::type operator()(const RatFun< Pol > &lhs, const T &rhs) const
expr_type operator()(const RatFun< Pol > &lhs, const Term< CoeffType > &rhs) const
std::enable_if<!std::is_same< Formula< Pol >, T >::value, expr_type >::type operator()(const T &lhs, const U &rhs) const
expr_type operator()(const RatFun< Pol > &lhs, const Monomial::Arg &rhs) const
std::enable_if<!std::is_same< Formula< Pol >, T >::value, expr_type >::type operator()(const T &lhs, const RatFun< Pol > &rhs) const
expr_type operator()(const Formula< Pol > &lhs, const T &rhs) const
expr_type operator()(const Term< CoeffType > &lhs, const RatFun< Pol > &rhs) const
expr_type operator()(const Monomial::Arg &lhs, const RatFun< Pol > &rhs) const
std::enable_if<!std::is_same< Formula< Pol >, T >::value, expr_type >::type operator()(const T &lhs, const Formula< Pol > &rhs) const
expr_type operator()(const RatFun< Pol > &lhs, const Term< CoeffType > &rhs) const
std::enable_if<!std::is_same< Formula< Pol >, T >::value, expr_type >::type operator()(const T &lhs, const RatFun< Pol > &rhs) const
expr_type operator()(const RatFun< Pol > &lhs, const CoeffType &rhs) const
expr_type operator()(const RatFun< Pol > &lhs, const RatFun< Pol > &rhs) const
std::enable_if<!std::is_same< Formula< Pol >, T >::value, expr_type >::type operator()(const T &lhs, const U &rhs) const
expr_type operator()(const Formula< Pol > &lhs, const T &rhs) const
expr_type operator()(const RatFun< Pol > &lhs, const Term< CoeffType > &rhs) const
std::enable_if<!std::is_base_of< Formula< Pol >, T >::value, expr_type >::type operator()(const RatFun< Pol > &lhs, const T &rhs) const
std::enable_if<!std::is_same< Formula< Pol >, T >::value, expr_type >::type operator()(const T &lhs, const CoeffType &coeff) const
expr_type operator()(const RatFun< Pol > &lhs, const Monomial::Arg &rhs) const
std::enable_if<!std::is_same< Formula< Pol >, T >::value, expr_type >::type operator()(const T &lhs, const Formula< Pol > &rhs) const
expr_type operator()(const T &lhs) const
expr_type operator()(const Formula< Pol > &lhs) const
expr_type operator()(const Monomial::Arg &lhs) const
expr_type operator()(const RatFun< Pol > &lhs) const
expr_type operator()(const Variable &lhs) const
expr_type operator()(const CoeffType &lhs) const
perform_power(exponent exp)
expr_type operator()(const Formula< Pol > &lhs) const
expr_type operator()(const T &lhs) const
void operator()(const CoeffType &expr) const
void operator()(const Monomial::Arg &expr) const
void operator()(const Formula< Pol > &expr) const
void operator()(const Term< CoeffType > &expr) const
void operator()(const RatFun< Pol > &expr) const
void operator()(const Pol &expr) const
void operator()(const Variable &expr) const