Developer documentation

monomial_glue.hpp
Go to the documentation of this file.
1 /******************************************************************************
2 * MODULE : monomial_glue.hpp
3 * DESCRIPTION: Glue for monomials
4 * COPYRIGHT : (C) 2008 Bernard Mourrain
5 *******************************************************************************
6 * This software falls under the GNU general public license and comes WITHOUT
7 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
8 * If you don't have this file, write to the Free Software Foundation, Inc.,
9 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
10 ******************************************************************************/
11 #ifndef __MMX_MONOMIAL_GLUE_HPP
12 #define __MMX_MONOMIAL_GLUE_HPP
13 #include <basix/category_meta.hpp>
14 #include <basix/tuple.hpp>
15 #include <basix/vector.hpp>
16 #include <realroot/monomial.hpp>
17 
18 #define TMPL
19 //template<typename C>
20 #define MONOMIAL monom<int>
21 
22 namespace mmx {
23 TMPL bool exact_eq (const Monomial& v1, const Monomial& v2) {return v1==v2;}
24 TMPL bool exact_neq(const Monomial& v1, const Monomial& v2) {return v1!=v2;}
25 
26 TMPL unsigned hash (const Monomial& v) {
27  register unsigned i, h= 214365^hash(v.coeff()), n= v.size();
28  for (i=0; i<n; i++)
29  h= (h<<1) ^ (h<<5) ^ (h>>27) ^ hash(v[i]);
30  return h;
31 }
32 TMPL unsigned exact_hash (const Monomial& m) {return hash(m);}
33 TMPL unsigned soft_hash (const Monomial& m) {return hash(m);}
34 
35 TMPL syntactic
36 flatten (const MONOMIAL& v) {
37  syntactic m= flatten(v.coeff());
38  for(unsigned i=0;i<v.nbvar();i++)
39  m = m*pow(syntactic(MONOMIAL::var[i].data()),v[i]);
40  return m;
41 }
42 
43 
45 monomial_from_vector (const vector<int> & t) {
46  nat sz=N(t);
47  MONOMIAL r(1,sz, AsSize());
48  for(nat i=0;i<sz;i++)
49  r.set_expt(i,t[i]);
50  return r;
51 }
52 
53 TMPL vector<int>
55  vector<int> res;
56  for(nat i=0;i<m.size();i++) res<<m[i];
57  return res;
58 }
59 
60 TMPL inline int N(const MONOMIAL& v) { return v.size(); }
61 TMPL inline int size (const MONOMIAL& v) { return N(v); }
62 
63 template<typename T, typename F, typename TR, typename FR>
64 struct as_helper<monom<T,TR>, monom<F,FR> >
65 {
66  static inline monom<T,TR>
67  cv (const monom<F,FR>& x) {
68  monom<T,TR> r(as<T>(x.coeff()),x.size(),AsSize());
69  for (unsigned i=0; i<x.size(); i++)
70  r.set_expt(i,x[i]);
71  return r;
72  }
73 };
74 
75 //====================================================================
76 } // namespace mmx
77 #undef TMPL
78 #undef Monomial
79 #endif // __MMX_MONOMIAL_GLUE_HPP
T pow(const T &a, int i)
Definition: binomials.hpp:12
#define TMPL
Definition: monomial_glue.hpp:18
unsigned size() const
Definition: monomial.hpp:135
Definition: assign.hpp:48
TMPL bool exact_neq(const Monomial &v1, const Monomial &v2)
Definition: monomial_glue.hpp:24
self_t & set_expt(size_type i, exponent_t d)
Definition: monomial.hpp:144
#define Monomial
Definition: monomial.hpp:56
TMPL int N(const MONOMIAL &v)
Definition: monomial_glue.hpp:60
#define MONOMIAL
Definition: monomial_glue.hpp:20
TMPL unsigned exact_hash(const Monomial &m)
Definition: monomial_glue.hpp:32
TMPL unsigned hash(const Monomial &v)
Definition: monomial_glue.hpp:26
TMPL MONOMIAL monomial_from_vector(const vector< int > &t)
Definition: monomial_glue.hpp:45
static monom< T, TR > cv(const monom< F, FR > &x)
Definition: monomial_glue.hpp:67
Definition: shared_object.hpp:61
TMPL syntactic flatten(const MONOMIAL &v)
Definition: monomial_glue.hpp:36
ZZ size(const ZZ &z)
Definition: GMPXX.hpp:67
TMPL bool exact_eq(const Monomial &v1, const Monomial &v2)
Definition: monomial_glue.hpp:23
const C & coeff() const
Definition: monomial.hpp:128
Monomial class.
Definition: monomial.hpp:62
TMPL unsigned soft_hash(const Monomial &m)
Definition: monomial_glue.hpp:33
Definition: array.hpp:12
TMPL vector< int > vector_from_monomial(const MONOMIAL &m)
Definition: monomial_glue.hpp:54
Home