Developer documentation

polynomial_sparse_glue.hpp
Go to the documentation of this file.
1 #ifndef realroot_sparse_monomial_glue_hpp
2 #define realroot_sparse_monomial_glue_hpp
3 #include <basix/mmx_syntax.hpp>
4 #include <numerix/kernel.hpp>
7 #define TMPL template <class C>
8 #define RING ring<C, Sparse,DegRevLex >
9 #define Polynomial polynomial< C, with<Sparse,DegRevLex> >
10 
11 #define SparseDegRevLex with<Sparse,DegRevLex>
12 //======================================================================
13 namespace mmx {
14  TMPL unsigned hash(const RING& p){ return 1;}
15  TMPL unsigned exact_hash(const RING& p){ return 1;}
16  TMPL unsigned soft_hash(const RING& p){ return 1;}
17  TMPL bool exact_eq(const RING& p, const RING& q){ return true;}
18  TMPL bool exact_neq(const RING& p, const RING& q){ return false;}
19 
20  TMPL bool operator ==(const RING& p, const RING& q){ return true;}
21  TMPL bool operator !=(const RING& p, const RING& q){ return false;}
22 
23  TMPL syntactic flatten(const RING& rg) {
24  syntactic CF= flatten(scalar_set<C>());
25  vector<syntactic> Lv; Lv <<CF;
26  for(int i=0;i<rg.nbvar();i++)
27  Lv<<syntactic(RING::var[i].data());
28  return apply (GEN_ACCESS, Lv);
29  }
30 
31  TMPL RING
32  ring_sparse_string(const scalar_set<C>& rg, const vector<string>& s) {
33  string v;
34  for(nat i=0;i<N(s);i++) v <<" "<<s[i];
35  return RING(as_charp(v));
36  }
37 
38  TMPL RING
39  ring_sparse_generic(const scalar_set<C>& rg, const vector<generic>& s) {
40  string v;
41  for(nat i=0;i<N(s);i++) v <<" "<<as_mmx(s[i]);
42  return RING(as_charp(v));
43  }
44 
45  TMPL RING ring_sparse_extend_generic(const RING& R, const vector<generic>& s) {
46  int nv= RING::nbvar();
47  for(nat j=0;j<N(s);j++)
48  R[nv+j] = Polynomial(as_charp(as_mmx(s[j])));
49  return R;
50  }
51 
52  TMPL syntactic flatten(const Polynomial& p) {
53  typedef typename Polynomial::const_iterator iterator;
54  typedef typename Polynomial::Ring Ring;
55  syntactic r(0);
56  for(iterator it=p.begin(); it!=p.end();it++) {
57  syntactic m= flatten(it->coeff());
58  for(unsigned i=0;i<it->nbvar();i++) {
59  syntactic v = Ring::var[i].data();
60  m = m*pow(v,syntactic((*it)[i]));
61  }
62  r+=m;
63  }
64  return r;
65  }
66 
68  polynomial_sparse(const RING& r, const C& c) {
69  return Polynomial(c);
70  }
71 
73  polynomial_sparse(const RING& r, const C& c, const int& d, const int& v) {
74  return Polynomial(c,d,v);
75  }
77  polynomial_sparse(const RING& r, const string& s) {
78  return Polynomial(as_charp(s));
79  }
80 
82  polynomial_sparse(const RING& r, const generic& s) {
83  return Polynomial(as_charp(as_mmx(s)));
84  }
85 
86  TMPL vector<generic>
87  polynomial_sparse_coefficients(const Polynomial& f, const int & v) {
89  vector<generic> r;
90  for(unsigned i=0; i< l.size(); i++)
91  r<< as<generic>(l[i]);
92  return r;
93  }
94 
95  TMPL vector<generic>
97  typedef typename Polynomial::const_iterator const_iterator;
98  vector<generic> r;
99  for(const_iterator it=p.begin(); it!=p.end();it++)
100  r<< as<generic>(it->coeff());
101  return r;
102  }
103 
104  TMPL vector<generic>
106  typedef typename Polynomial::const_iterator const_iterator;
107  typedef typename Polynomial::Monomial Monomial;
108  vector<generic> r;
109  for(const_iterator it=p.begin(); it!=p.end();it++){
110  Monomial m(*it);
111  m.coeff()= C(1);
112  r<< as<generic>(Polynomial(m));
113  }
114  return r;
115  }
116 
117  TMPL generic
118  polynomial_sparse_eval_generic(const Polynomial& p, const vector<generic>& v) {
119  return sparse::eval<generic>(p.rep(),v);
120  }
121 
122 } //namespace mmx
123 //======================================================================
124 #undef TMPL
125 #undef RING
126 #undef Polynomial
127 #endif //realroot_sparse_monomial_glue_hpp
bool operator==(const extended< NT > &lhs, const extended< NT > &rhs)
Definition: extended.hpp:88
TMPL RING ring_sparse_string(const scalar_set< C > &rg, const vector< string > &s)
Definition: polynomial_sparse_glue.hpp:32
Sequence of terms with reference counter.
Definition: Seq.hpp:28
T pow(const T &a, int i)
Definition: binomials.hpp:12
TMPL generic polynomial_sparse_eval_generic(const Polynomial &p, const vector< generic > &v)
Definition: polynomial_sparse_glue.hpp:118
TMPL bool exact_neq(const Monomial &v1, const Monomial &v2)
Definition: monomial_glue.hpp:24
TMPL Polynomial polynomial_sparse(const RING &r, const C &c)
Definition: polynomial_sparse_glue.hpp:68
#define TMPL
Definition: polynomial_sparse_glue.hpp:7
#define Polynomial
Definition: polynomial_sparse_glue.hpp:9
#define Monomial
Definition: monomial.hpp:56
TMPL RING ring_sparse_generic(const scalar_set< C > &rg, const vector< generic > &s)
Definition: polynomial_sparse_glue.hpp:39
TMPL int N(const MONOMIAL &v)
Definition: monomial_glue.hpp:60
TMPL unsigned exact_hash(const Monomial &m)
Definition: monomial_glue.hpp:32
TMPL unsigned hash(const Monomial &v)
Definition: monomial_glue.hpp:26
TMPL vector< generic > polynomial_sparse_monomials(const Polynomial &p)
Definition: polynomial_sparse_glue.hpp:105
polynomial< COEFF, with< MonomialTensor > > Polynomial
Definition: solver_mv_cf.cpp:23
size_type size() const
Definition: Seq.hpp:166
#define RING
Definition: polynomial_sparse_glue.hpp:8
TMPL syntactic flatten(const MONOMIAL &v)
Definition: monomial_glue.hpp:36
char * as_charp(const scalar< MPZ > &b)
Definition: scalar_integer.hpp:444
TMPL bool exact_eq(const Monomial &v1, const Monomial &v2)
Definition: monomial_glue.hpp:23
TMPL RING ring_sparse_extend_generic(const RING &R, const vector< generic > &s)
Definition: polynomial_sparse_glue.hpp:45
const C & c
Definition: Interval_glue.hpp:45
double C
Definition: solver_mv_fatarcs.cpp:16
bool operator!=(const extended< NT > &lhs, const extended< NT > &rhs)
Definition: extended.hpp:95
TMPL int nbvar(const Polynomial &mp)
Definition: polynomial_fcts.hpp:43
TMPL vector< generic > polynomial_sparse_coefficients(const Polynomial &f, const int &v)
Definition: polynomial_sparse_glue.hpp:87
TMPL unsigned soft_hash(const Monomial &m)
Definition: monomial_glue.hpp:33
Definition: array.hpp:12
TMPL Seq< typename ring< C, Bernstein >::Polynomial > coefficients(const typename ring< C, Bernstein >::Polynomial &pol, int v)
Definition: polynomial_bernstein.hpp:74
Home