Borderbasix

numexp.hpp
Go to the documentation of this file.
1 /***********************************************************************
2 History: Exponents for monomials are represented by element of E.
3  Writen by Ph. Trebuchet (10/12/99).
4 $Id: numexp.hpp,v 1.1.1.1 2006/10/06 08:01:40 trebuche Exp $
5 **********************************************************************/
6 /*
7  *pour etre type T valide on doit fournir:
8  * T >> int
9  * T<< int
10  *T + T
11  *T&T
12  *T > (int)
13  * T+= (inT)
14  *T &= T
15  * T += T
16  *T-=T
17  *T==T
18  *ostream << T
19  *added by moi :-)
20 */
21 // A verifier le D (decallage).
22 #ifndef numexp_H
23 #define numexp_H
24 static int mask=0;
25 template<char X, int D=2, class T=int>
26 struct numexp {
27  typedef T exponent_t;
28  typedef int degree_t;
30  // static T mask;
31  //Constructors
32  numexp():ind(0) {};
33  numexp(int t){};
34  numexp(const self_t &A): ind(A.ind) {};
35  numexp(int s, int *t)
36  {
37  for(int i=s-1;i>=0;i--)
38  {
39  ind+=t[i];
40  ind=(ind<<D);
41  }
42 
43  }
44 
45  //destructors // rien a faire ...
47  {
48  return ind!=m.ind;
49  }
50  int operator != (const numexp<X,D,T>&m) const
51  {
52  return ind!=m.ind;
53  }
54  exponent_t operator[](int i) const
55  {
56 #if 0
57  if (mask==0)
58  {
59  for(int j=0;j<D;j++)
60  mask=(mask<<1)+1;
61  }
62 #endif
63  return ((mask)&(ind>>(D*i)));
64  }
65 
66  void reserve(int d) {};
67 
68  void setExponent(int i,int d)
69  {
70  T tmp1=(ind>>(D*i+D))<<(D*i+D);
71  T tmp2=0;
72  if(mask==0)
73  {
74  for(int j=0;j<D;j++)
75  mask=(mask<<1)+1;
76  }
77  for(int j=0;j<i;j++) tmp2=(tmp2<<D)+mask;
78  tmp2&=ind;
79  ind=tmp1+tmp2+(((T)d)<<(D*i));
80  }
81 
82 
83  //operators
84  self_t & operator =(const numexp<X,D,T> &A)
85  {
86  ind=A.ind; return *this;
87  }
88 
89  self_t & operator += (const self_t & A)
90  {
91  ind+=A.ind; return *this;
92  }
93  self_t & operator *=(const self_t & A)
94  {
95  ind+=A.ind; return *this;
96  }
97  self_t & operator /=(const numexp<X,D,T> &A)
98  {
99  ind-=A.ind; return *this;
100  }
101 
102  bool operator == (const numexp<X,D,T> &A) const
103  {
104  return (ind==A.ind);
105  }
106 
107  bool operator <(const numexp<X,D,T> &A) const
108  {
109  return this->ind<A.ind;
110  }
111 
112  bool operator <(const numexp<X,D,T> &A)
113  {
114  return this->ind<A.ind;
115  }
116 
117  //data
118  T ind;
119 };
120 
121 template<char X,int D, class T>
122 inline int Degree(const numexp<X,D,T> & m)
123 {
124  int d=0;
125  T stock;
126  if(mask==0)
127  {
128  for(int j=0;j<D;j++)
129  mask=(mask<<1)+1;
130  }
131  for(stock=m.ind;stock>0;stock=stock>>D) d+=(stock&mask);
132  return d;
133 }
134 
135 template<char X,int D,class T>
136 inline int GDegree(const numexp<X,D,T> &A,int i)
137 {
138  // static T mask=0;
139  if(mask==0)
140  {
141  for(int j=0;j<D;j++)
142  mask=(mask<<1)+1;
143  }
144  return ((A.ind>>(D*i))&mask);
145 }
146 
147 template<char X,int D,class T>
148 inline int SDegree(numexp<X,D,T> &A,int i,int d)
149 {
150  T tmp1=(A.ind>>(D*i+D))<<(D*i+D);
151  T tmp2=0;
152  for(int j=0;j<i*D;j++) tmp2=(tmp2<<1)+1;
153  tmp2&=A.ind;
154  A.ind=tmp1+tmp2+(((T)d)<<(D*i));
155  return A.ind;
156 }
157 
158 template<char X,int D,class T>
159 inline
160 int lvar(const numexp<X,D,T> &A)
161 {
162  int i=0;
163  T stock=A.ind;
164  for(;stock>0;i++,stock=stock>>D);
165  return i-1;
166 }
167 
168 template<char X,int D,class T>
169 inline void erase(numexp<X,D,T> &A) {}
170 
171 template<char X,int D,class T>
173 {
174  r.ind=A.ind+B.ind;
175 }
176 
177 template<char X,int D,class T>
178 std::ostream & operator<<(std::ostream &os, const numexp<X,D,T> & rep)
179 {
180  // T mask=0;//3 tjrs pareil
181  T tmp;
182  if (mask==0){
183  for(int j=0;j<D;j++) mask=(mask<<1)+1;
184  }
185  for(int i=0;i<lvar(rep)+1;i++)
186  {
187  if((rep.ind>>(D*i))&mask)
188  {
189  os<<"*"<<X<<i;
190  if ((tmp=(rep.ind>>(D*i))&mask)>1)
191  os<<'^'<<tmp;
192  }
193  }
194  return os;
195 }
196 #endif // //numexp_H
197 
void reserve(int d)
Definition: numexp.hpp:66
numexp< X, D, T > self_t
Definition: numexp.hpp:29
int degree_t
Definition: numexp.hpp:28
void add(numexp< X, D, T > &r, const numexp< X, D, T > &A, const numexp< X, D, T > &B)
Definition: numexp.hpp:172
int Degree(const numexp< X, D, T > &m)
Definition: numexp.hpp:122
int lvar(const numexp< X, D, T > &A)
Definition: numexp.hpp:160
numexp(const self_t &A)
Definition: numexp.hpp:34
self_t & operator/=(const numexp< X, D, T > &A)
Definition: numexp.hpp:97
int SDegree(numexp< X, D, T > &A, int i, int d)
Definition: numexp.hpp:148
Definition: numexp.hpp:26
void erase(numexp< X, D, T > &A)
Definition: numexp.hpp:169
MSKconetypee MSKrealt MSKint32t MSKint32t j
Definition: mosek.h:2421
void setExponent(int i, int d)
Definition: numexp.hpp:68
bool operator==(const numexp< X, D, T > &A) const
Definition: numexp.hpp:102
self_t & operator+=(const self_t &A)
Definition: numexp.hpp:89
int operator!=(const numexp< X, D, T > &m)
Definition: numexp.hpp:46
T exponent_t
Definition: numexp.hpp:27
MSKint32t MSKint32t MSKint32t i
Definition: mosek.h:2278
MSKrescodee r
Definition: mosek.h:2321
T ind
Definition: numexp.hpp:118
numexp()
Definition: numexp.hpp:32
numexp(int s, int *t)
Definition: numexp.hpp:35
exponent_t operator[](int i) const
Definition: numexp.hpp:54
self_t & operator=(const numexp< X, D, T > &A)
Definition: numexp.hpp:84
int GDegree(const numexp< X, D, T > &A, int i)
Definition: numexp.hpp:136
self_t & operator*=(const self_t &A)
Definition: numexp.hpp:93
numexp(int t)
Definition: numexp.hpp:33
Home  |  Download & InstallContributions