source: git/libpolys/coeffs/test.cc @ abb4787

spielwiese
Last change on this file since abb4787 was abb4787, checked in by Hans Schoenemann <hannes@…>, 13 years ago
conversion factory <->singular for poly fix coeff tests for factory
  • Property mode set to 100644
File size: 9.0 KB
Line 
1#include "config.h"
2#include <misc/auxiliary.h>
3#include <omalloc/omalloc.h>
4
5#include <reporter/reporter.h>
6
7#include <coeffs/coeffs.h>
8#include <coeffs/numbers.h>
9
10#include <coeffs/longrat.h>
11#include <coeffs/gnumpfl.h>
12#include <coeffs/gnumpc.h>
13#include <coeffs/shortfl.h>
14#include <coeffs/ffields.h>
15#include <coeffs/modulop.h>
16#include <coeffs/rmodulon.h>
17#include <coeffs/rmodulo2m.h>
18#include <coeffs/rintegers.h>
19#ifdef HAVE_FACTORY
20#include <factory/factory.h>
21#endif
22
23#include <iostream>
24
25using namespace std;
26
27// template stuff
28#ifdef HAVE_FACTORY
29  #include <factory/templates/ftmpl_list.cc>
30  #include <factory/templates/ftmpl_array.cc>
31  #include <factory/templates/ftmpl_factor.cc>
32  #include <factory/templates/ftmpl_functions.h>
33  #include <factory/templates/ftmpl_matrix.cc>
34  template class Factor<CanonicalForm>;
35  template class List<CFFactor>;
36  template class ListItem<CFFactor>;
37  template class ListItem<CanonicalForm>;
38  template class ListIterator<CFFactor>;
39  template class List<CanonicalForm>;
40  template class List<List<CanonicalForm> >;
41  template class ListIterator<CanonicalForm>;
42  template class Array<CanonicalForm>;
43  template class List<MapPair>;
44  template class ListItem<MapPair>;
45  template class ListIterator<MapPair>;
46  template class Matrix<CanonicalForm>;
47  template class SubMatrix<CanonicalForm>;
48  template class Array<REvaluation>;
49  template bool find ( const List<CanonicalForm> &, const CanonicalForm&);
50  template List<CFFactor> Union ( const List<CFFactor>&, const List<CFFactor>& );
51  template int operator == ( const Factor<CanonicalForm>&, const Factor<CanonicalForm>& );
52
53  template CanonicalForm tmax ( const CanonicalForm&, const CanonicalForm& );
54  template CanonicalForm tmin ( const CanonicalForm&, const CanonicalForm& );
55
56  template Variable tmax ( const Variable&, const Variable& );
57  template Variable tmin ( const Variable&, const Variable& );
58
59  template int tmax ( const int&, const int& );
60  template int tmin ( const int&, const int& );
61  template int tabs ( const int& );
62
63  int initializeGMP()
64  { return 1; }
65#endif
66
67#pragma GCC diagnostic ignored "-Wwrite-strings"
68
69void Print(/*const*/ number a, const coeffs r, BOOLEAN eoln = TRUE)
70{
71  n_Test(a,r);
72
73  StringSetS("");
74  n_Write(a, r);
75
76  char* s = NULL; 
77
78  if( eoln ) 
79    s = StringAppend("\n");
80  else
81    s = StringAppend("");
82
83  PrintS(s);
84
85  // free s?
86}
87
88
89void PrintSized(/*const*/ number a, const coeffs r, BOOLEAN eoln = TRUE)
90{
91  Print(a, r, FALSE);
92  Print(", of size: %d", n_Size(a, r));
93 
94  if( eoln ) 
95    PrintLn();
96}
97 
98
99
100bool TestArith(const coeffs r)
101{
102  number a = n_Init(66666, r);
103   
104  PrintS("a: "); PrintSized(a, r);
105
106  number two = n_Init(2, r);
107 
108  PrintS("two: "); PrintSized(two, r);
109
110  if (getCoeffType(r) == n_GF) //some special test for GF
111  {
112    number z = nfPar (0, r); // also any integer instead of 0//?
113
114    PrintS("Generator: "); PrintSized(z, r);
115   
116    n_Delete(&z, r);   
117  }
118 
119  number aa = n_Add(a, a, r);
120
121  PrintS("aa = a + a: "); PrintSized(aa, r);
122 
123  number aa2 = n_Mult(a, two, r);
124
125  PrintS("aa2 = a * 2: "); PrintSized(aa2, r);
126
127  number aa1 = n_Mult(two, a, r);
128 
129  PrintS("aa1 = 2 * a: "); PrintSized(aa1, r);
130
131  n_Delete(&a, r);
132  n_Delete(&two, r);
133
134
135  a = n_Sub( aa, aa1, r );
136 
137  PrintS("a = aa - aa1: "); PrintSized(a, r);
138
139  if( !n_IsZero(a, r) )
140    WarnS("TestArith: ERROR: a != 0 !!!\n");
141
142  n_Delete(&a, r);
143
144  a = n_Sub( aa, aa2, r );
145
146  PrintS("a = aa - aa2: "); PrintSized(a, r);
147
148  if( !n_IsZero(a, r) )
149    WarnS("TestArith: ERROR: a != 0 !!!\n");
150
151  n_Delete(&a, r);
152
153
154  a = n_Sub( aa1, aa2, r );
155
156  PrintS("a = aa1 - aa2: "); PrintSized(a, r);
157
158  if( !n_IsZero(a, r) )
159    WarnS("TestArith: ERROR: a != 0 !!!\n");
160
161  n_Delete(&a, r);
162
163
164 
165  if( !n_Equal(aa, aa1, r) )
166    WarnS("TestArith: ERROR: aa != aa1  !!!\n");
167
168  if( !n_Equal(aa, aa2, r) )
169    WarnS("TestArith: ERROR: aa != aa2  !!!\n");
170
171  if( !n_Equal(aa1, aa2, r) )
172    WarnS("TestArith: ERROR: aa1 != aa2  !!!\n");
173 
174
175 
176
177  n_Delete(&aa, r);
178  n_Delete(&aa1, r);
179  n_Delete(&aa2, r);
180
181  return false;
182}
183
184
185
186namespace
187{
188  static inline ostream& operator<< (ostream& o, const n_coeffType& type)
189  {
190#define CASE(A) case A: return o << (" " # A) << " ";
191    switch( type )
192    {
193      CASE(n_unknown);
194      CASE(n_Zp);
195      CASE(n_Q);
196      CASE(n_R);
197      CASE(n_GF);
198      CASE(n_long_R);
199      CASE(n_Ext);
200      CASE(n_long_C);
201      CASE(n_Z);
202      CASE(n_Zn);
203      CASE(n_Zpn);
204      CASE(n_Z2m);
205      CASE(n_CF);
206      default: return o << "Unknown type: [" << (const unsigned long) type << "]"; 
207    }   
208#undef CASE
209    return o;
210  }
211}
212 
213
214bool Test(const n_coeffType type, void* p = NULL)
215{
216  cout  << endl << "----------------------- Testing coeffs: [" << type << ", " << p << 
217                "]: -----------------------" << endl;
218
219  const coeffs r = nInitChar( type, p );
220
221  if( r == NULL ) { cout << "Test: could not get the specified coeff. domain for type: " << type << " and the parameter: " << p << endl; return false; };
222
223  assume( r != NULL );
224  nSetChar( r );
225  assume( getCoeffType(r) == type );
226
227  assume( r->cfInit != NULL );
228  assume( r->cfWrite != NULL );
229  assume( r->cfAdd != NULL );
230  assume( r->cfDelete != NULL );
231
232  if( type == n_Q )
233  {
234    assume( r->cfInit == nlInit );
235    assume( r->cfWrite == nlWrite );
236    assume( r->cfAdd == nlAdd );
237    assume( r->cfDelete == nlDelete );   
238  }
239  else if( type == n_long_R )
240  {
241    assume( r->cfInit == ngfInit );
242    assume( r->cfWrite == ngfWrite );
243    assume( r->cfAdd == ngfAdd );
244    assume( r->cfDelete == ngfDelete );
245  }
246  else if( type == n_long_C )
247  {
248    assume( r->cfInit == ngcInit );
249    assume( r->cfWrite == ngcWrite );
250    assume( r->cfAdd == ngcAdd );
251    assume( r->cfDelete == ngcDelete );   
252  }
253  else if( type == n_R )
254  {
255    assume( r->cfInit == nrInit );
256    assume( r->cfWrite == nrWrite );
257    assume( r->cfAdd == nrAdd );
258//    assume( r->cfDelete == nrDelete ); // No?
259  }
260#ifdef HAVE_RINGS
261  else if( type == n_Z2m )
262  {
263    assume( r->cfInit == nr2mInit );
264    assume( r->cfWrite == nr2mWrite );
265    assume( r->cfAdd == nr2mAdd );
266    assume( r->cfDelete == ndDelete );
267  }
268  else if( type == n_Zn )
269  {
270    assume( r->cfInit == nrnInit );
271    assume( r->cfWrite == nrnWrite );
272    assume( r->cfAdd == nrnAdd );
273    assume( r->cfDelete == nrnDelete );
274  }
275#endif
276  else if( type == n_GF )
277  {
278    assume( r->cfInit == nfInit );
279    assume( r->cfWrite == nfWrite );
280    assume( r->cfAdd == nfAdd );
281    //assume( r->cfDelete == nfDelete );
282  }
283  else
284  {
285    // ...
286  }
287
288  bool ret = TestArith( r );
289
290  nKillChar( r );
291
292  return ret;
293}
294
295
296
297
298int main()
299{
300  int c = 0;
301 
302  n_coeffType type;
303
304
305#ifdef HAVE_RINGS
306//  TODO(Frank, Segmentation fault! (if used wihout omalloc???). Please_ investigate!);
307  type = nRegister( n_Z2m, nr2mInitChar); assume( type == n_Z2m ); 
308  if( Test(type, (void*) 4) )
309    c ++;
310#endif
311
312  type = nRegister( n_Zp, npInitChar); assume( type == n_Zp );
313  if( Test(type, (void*) 101) )
314    c ++;
315
316#ifdef HAVE_RINGS
317//  TODO(Frank, memmory corruption_ if used wihout omalloc??? Please_ investigate!);
318
319  type = nRegister( n_Z2m, nr2mInitChar); assume( type == n_Z2m ); 
320  if( Test(type, (void*) 8) )
321    c ++;
322
323#endif
324
325 
326  type = nRegister( n_Q, nlInitChar); assume( type == n_Q );
327  if( Test(type) )
328    c ++;
329
330  type = nRegister( n_R, nrInitChar); assume( type == n_R );
331  if( Test(type) )
332    c ++;
333
334#ifdef HAVE_RINGS
335  type = nRegister( n_Z, nrzInitChar); assume( type == n_Z ); // No need in GMP?
336  if( Test(type) )
337    c ++;
338#endif
339   type = nRegister( n_GF, nfInitChar); assume( type == n_GF );
340
341
342   GFInfo* param = new GFInfo();
343
344   param->GFChar= 5;
345   param->GFDegree= 12;
346   param->GFPar_name= (const char*)"q";
347
348   if( Test(type, (void*) param) )
349     c ++;
350
351   // it should not be used by numbers... right?
352   // TODO: what is our policy wrt param-pointer-ownership?
353   delete param; 
354   // Q: no way to deRegister a type?
355
356   param = new GFInfo();
357
358   param->GFChar= 5;
359   param->GFDegree= 2;
360   param->GFPar_name= (const char*)"Q";
361
362   if( Test(type, (void*) param) )
363     c ++;
364
365   delete param;
366
367
368
369
370#ifdef HAVE_RINGS
371//  TODO(Somebody, This will result in memory corruption at Z_2^m later on (due to the succs. setGMPFloatDigits?)...!?); // ????
372
373  type = nRegister( n_Zn, nrnInitChar); assume( type == n_Zn );
374
375  if( Test(type, (void*) 3) )
376    c ++;
377
378#endif
379
380  TODO(Somebody, floating arithmetics via GMP rely on two global variables (see setGMPFloatDigits). Please fix it!);
381  setGMPFloatDigits( 10, 5 ); // Init global variables in mpr_complex.cc for gmp_float's... // Note that this seems also to be required for Z_2^m (and Zn?)!????
382
383
384  type = nRegister( n_long_C, ngcInitChar); assume( type == n_long_C );
385  if( Test(type) )
386    c ++;
387
388  type = nRegister( n_long_R, ngfInitChar); assume( type == n_long_R );
389  if( Test(type) )
390    c ++;
391
392#ifdef HAVE_RINGS
393  type = nRegister( n_Z2m, nr2mInitChar); assume( type == n_Z2m ); 
394  if( Test(type, (void*) 2) )
395    c ++;
396#endif
397
398
399#ifdef HAVE_RINGS
400  type = nRegister( n_Zn, nrnInitChar); assume( type == n_Zn );
401
402  if( Test(type, (void*) 3) )
403    c ++;
404#endif
405 
406  // polynomial rings needed for: n_Ext !
407 
408  return c;
409
410}
Note: See TracBrowser for help on using the repository browser.