carl  24.04
Computer ARithmetic Library
GiNaCAdaptor.h
Go to the documentation of this file.
1 /**
2  * @file GiNaCAdaptor.h
3  * @author Gereon Kremer <gereon.kremer@cs.rwth-aachen.de>
4  */
5 
6 #pragma once
7 
8 namespace carl {
9 
11 public:
12  static std::map<carl::Variable, GiNaC::symbol> vars;
13 };
14 
15 class ToGiNaC {
16 public:
17  typedef GiNaC::numeric Number;
18  typedef GiNaC::symbol Variable;
19  typedef GiNaC::ex VariablePower;
20  typedef GiNaC::ex Monomial;
21  typedef GiNaC::ex Term;
22  typedef GiNaC::ex MPolynomial;
23  typedef GiNaC::ex UPolynomial;
24 
25  Number operator()(const cln::cl_RA& n) {
26  return GiNaC::numeric(n);
27  }
28  Number operator()(const mpq_class& n) {
29  std::stringstream ss;
30  ss << n;
31  return GiNaC::numeric(ss.str().c_str());
32  }
34  auto it = GiNaCConversion::vars.find(v);
35  if (it == GiNaCConversion::vars.end()) {
36  it = GiNaCConversion::vars.insert(std::make_pair(v, GiNaC::symbol(carl::VariablePool::getInstance().get_name(v)))).first;
37  }
38  return it->second;
39  }
40  VariablePower operator()(GiNaC::symbol v, const carl::exponent& exp) {
41  return GiNaC::pow(v, exp);
42  }
43  Monomial operator()(const std::vector<GiNaC::ex>& vp) {
44  return std::accumulate(vp.begin(), vp.end(), GiNaC::ex(1), std::multiplies<GiNaC::ex>());
45  }
46  template<typename Coeff>
47  Term operator()(const GiNaC::numeric& n, const GiNaC::ex& mon) {
48  return n * mon;
49  }
50  template<typename Coeff>
51  MPolynomial operator()(const std::vector<GiNaC::ex>& terms) {
52  return std::accumulate(terms.begin(), terms.end(), GiNaC::ex(0), std::plus<GiNaC::ex>());
53  }
54 };
55 
56 template<typename C>
57 class FromGiNaC {
58 public:
59  typedef C Number;
60 };
61 
62 }
carl is the main namespace for the library.
std::size_t exponent
Type of an exponent.
Definition: Monomial.h:29
Interval< Number > exp(const Interval< Number > &i)
Definition: Exponential.h:10
Interval< Number > pow(const Interval< Number > &i, Integer exp)
Definition: Power.h:11
static std::map< carl::Variable, GiNaC::symbol > vars
Definition: GiNaCAdaptor.h:12
GiNaC::ex Term
Definition: GiNaCAdaptor.h:21
GiNaC::ex Monomial
Definition: GiNaCAdaptor.h:20
GiNaC::numeric Number
Definition: GiNaCAdaptor.h:17
GiNaC::ex VariablePower
Definition: GiNaCAdaptor.h:19
GiNaC::ex UPolynomial
Definition: GiNaCAdaptor.h:23
Number operator()(const cln::cl_RA &n)
Definition: GiNaCAdaptor.h:25
Number operator()(const mpq_class &n)
Definition: GiNaCAdaptor.h:28
Term operator()(const GiNaC::numeric &n, const GiNaC::ex &mon)
Definition: GiNaCAdaptor.h:47
Variable operator()(carl::Variable::Arg v)
Definition: GiNaCAdaptor.h:33
MPolynomial operator()(const std::vector< GiNaC::ex > &terms)
Definition: GiNaCAdaptor.h:51
VariablePower operator()(GiNaC::symbol v, const carl::exponent &exp)
Definition: GiNaCAdaptor.h:40
GiNaC::ex MPolynomial
Definition: GiNaCAdaptor.h:22
GiNaC::symbol Variable
Definition: GiNaCAdaptor.h:18
Monomial operator()(const std::vector< GiNaC::ex > &vp)
Definition: GiNaCAdaptor.h:43
A Variable represents an algebraic variable that can be used throughout carl.
Definition: Variable.h:85
static VariablePool & getInstance()
Returns the single instance of this class by reference.
Definition: Singleton.h:45