carl  24.04
Computer ARithmetic Library
Converter.h
Go to the documentation of this file.
1 /**
2  * @file Converter.h
3  * @author Gereon Kremer <gereon.kremer@cs.rwth-aachen.de>
4  */
5 
6 #pragma once
7 
8 #include <algorithm>
9 #include <functional>
10 #include <map>
11 #include <sstream>
12 #include <vector>
13 
14 #include "ginac.h"
15 
22 
23 #include "GiNaCAdaptor.h"
24 
25 namespace carl {
26 
27 template<typename C>
28 class ConvertTo {
29  C c;
30 public:
31  test
32  template<typename N>
33  typename C::Number number(const N& n) {
34  return c(n);
35  }
36  typename C::Variable variable(Variable::Arg v) {
37  return c(v);
38  }
39  typename C::VariablePower varpower(Variable::Arg v, std::size_t exp) {
40  return c(variable(v), exp);
41  }
42  typename C::Monomial monomial(const Monomial::Arg& m) {
43  std::vector<typename C::VariablePower> tmp;
44  if (m != nullptr) {
45  for (const auto& vp: *m) tmp.push_back(varpower(vp.first, vp.second));
46  }
47  return c(tmp);
48  }
49  template<typename N>
50  typename C::Term term(const Term<N>& t) {
51  return c(number(t.coeff()), monomial(t.monomial()));
52  }
53  template<typename N, typename O, typename P>
54  typename C::MPolynomial mpolynomial(const MultivariatePolynomial<N,O,P>& p) {
55  std::vector<typename C::Term> tmp;
56  for (const auto& t: p) tmp.push_back(term(t));
57  return c(tmp);
58  }
59 };
60 
61 template<typename C>
62 class ConvertFrom {
63  C c;
64 public:
65  template<typename N>
66  typename C::Number number(const N& n) {
67  return c(n);
68  }
69  template<typename V>
70  Variable variable(const V& v) {
71  return c(v);
72  }
73  template<typename V>
74  Monomial::Arg varpower(const V& v, std::size_t exp) {
75  return c(variable(v), exp);
76  }
77  template<typename M>
78  Monomial::Arg monomial(const M& m) {
79  auto tmp = c(m);
80  for (const auto& t: tmp) {
81 
82  }
83  return std::accumulate(tmp.begin(), tmp.end(), nullptr, std::multiplies<Monomial::Arg>());
84  }
85  template<typename T>
87  auto tmp = c(t);
88  return c(tmp.first) * c(tmp.second);
89  }
90  template<typename P>
92  auto tmp = c(p);
93  return std::accumulate(tmp.begin(), tmp.end(), nullptr, std::plus<Term<typename C::Number>>());
94  }
95 };
96 
97 }
carl is the main namespace for the library.
Interval< Number > exp(const Interval< Number > &i)
Definition: Exponential.h:10
C::Term term(const Term< N > &t)
Definition: Converter.h:50
C::Variable variable(Variable::Arg v)
Definition: Converter.h:36
C::VariablePower varpower(Variable::Arg v, std::size_t exp)
Definition: Converter.h:39
test C::Number number(const N &n)
Definition: Converter.h:33
C::MPolynomial mpolynomial(const MultivariatePolynomial< N, O, P > &p)
Definition: Converter.h:54
C::Monomial monomial(const Monomial::Arg &m)
Definition: Converter.h:42
MultivariatePolynomial< typename C::Number > mpolynomial(const P &p)
Definition: Converter.h:91
Monomial::Arg varpower(const V &v, std::size_t exp)
Definition: Converter.h:74
Term< typename C::Number > term(const T &t)
Definition: Converter.h:86
C::Number number(const N &n)
Definition: Converter.h:66
Variable variable(const V &v)
Definition: Converter.h:70
Monomial::Arg monomial(const M &m)
Definition: Converter.h:78
A Variable represents an algebraic variable that can be used throughout carl.
Definition: Variable.h:85
The general-purpose multivariate polynomial class.
std::shared_ptr< const Monomial > Arg
Definition: Monomial.h:62
Represents a single term, that is a numeric coefficient and a monomial.
Definition: Term.h:23
Coefficient & coeff()
Get the coefficient.
Definition: Term.h:80
Monomial::Arg & monomial()
Get the monomial.
Definition: Term.h:91