source: git/libpolys/tests/polys_test.h @ 6ccdd3a

fieker-DuValspielwiese
Last change on this file since 6ccdd3a was 6ccdd3a, checked in by Frank Seelisch <seelisch@…>, 13 years ago
renamed algring; comments; transext.* added
  • Property mode set to 100644
File size: 21.5 KB
Line 
1#include "config.h"
2
3#include "common.h"
4using namespace std;
5
6// the following headers are private...
7#include <coeffs/longrat.h>
8#include <coeffs/gnumpfl.h>
9#include <coeffs/gnumpc.h>
10#include <coeffs/shortfl.h>
11#include <coeffs/ffields.h>
12#include <coeffs/modulop.h>
13#include <coeffs/rmodulon.h>
14#include <coeffs/rmodulo2m.h>
15#include <coeffs/rintegers.h>
16
17#include <polys/ext_fields/algext.h>
18#include <polys/monomials/ring.h>
19#include <polys/monomials/p_polys.h>
20
21#include <polys/simpleideals.h>
22
23#ifdef HAVE_FACTORY
24#include <polys/clapsing.h>
25#include <factory/factory.h>
26#endif
27
28class MyGlobalPrintingFixture : public GlobalPrintingFixture
29{
30  public:
31    virtual bool setUpWorld()
32    {
33   
34      GlobalPrintingFixture::setUpWorld();
35     
36
37      TS_ASSERT_EQUALS( nRegister( n_Zp, npInitChar), n_Zp );
38      TS_ASSERT_EQUALS( nRegister( n_GF, nfInitChar), n_GF );
39      TS_ASSERT_EQUALS( nRegister( n_R, nrInitChar), n_R );
40      TS_ASSERT_EQUALS( nRegister( n_Q, nlInitChar), n_Q );
41      TS_ASSERT_EQUALS( nRegister( n_R, nrInitChar), n_R );
42     
43#ifdef HAVE_RINGS
44      TS_ASSERT_EQUALS( nRegister( n_Z, nrzInitChar), n_Z ); // these are UNusable at the moment!
45#endif
46     
47      return true;
48    }
49};
50
51
52//
53// We can rely on this file being included exactly once
54// and declare this global variable in the header file.
55//
56static MyGlobalPrintingFixture globalPrintingFixture;
57
58
59namespace
60{
61 
62  void PrintRing(const ring r)
63  {
64    rWrite(r); PrintLn();
65  #ifdef  RDEBUG
66    rDebugPrint(r); PrintLn();
67  #endif
68  }
69
70  static inline std::string _2S(poly a, const ring r)
71  {
72    p_Test(a,r);
73   
74    StringSetS("");
75    p_Write(a, r);
76
77    const char* s = StringAppendS("");
78
79    std::stringstream ss;  ss << s;
80
81    StringSetS(""); 
82    return ss.str();
83  }
84
85  static inline void PrintSized(/*const*/ poly a, const ring r, BOOLEAN eoln = TRUE)
86  {
87    std::clog << _2S(a, r) << ", of size: " << p_Size(a, r);
88
89    if( eoln ) 
90      std::clog << std::endl; 
91  }
92
93static inline void Delete(poly &p, const ring r)
94{
95  if( p != NULL )
96    p_Delete(&p, r);
97
98  p = NULL;
99}
100
101void TestSum(const ring r, const int N)
102{
103  TS_ASSERT_DIFFERS( r    , NULLp);
104  TS_ASSERT_DIFFERS( r->cf, NULLp);
105 
106 
107  clog << ( _2S("TEST: sum[0..") + _2S(N) + "]: ");
108  clog << endl;
109
110  assume( N > 0 ); // just for now...
111
112  const int ssss = (N * (N+1)) / 2;
113 
114  poly sum1 = p_ISet(ssss, r);
115  clog<< "poly(N*(N+1)/2) (int: " << ssss << "): "; PrintSized(sum1, r);
116
117  poly s=NULL, ss=NULL, i=NULL, res=NULL;
118
119  s = p_ISet(, r);
120  i = p_ISet(N+1, r);
121
122  i = p_Mult_q(s, i, r); s = NULL;
123
124  clog<< "poly(N)*poly(N+1): (int: "<< N*(N+1) << "): "; PrintSized(i, r); 
125
126  number t = n_Init(2, r->cf);
127  clog<< "number(2): "; PrintSized(t, r->cf); 
128
129  if( !n_IsZero( t, r->cf) )
130  {
131    if( i != NULL )
132    {
133      number ii = p_GetCoeff(i, r);
134      clog<< "number(poly(N)*poly(N+1)): "; PrintSized(ii, r->cf); 
135
136#ifdef HAVE_RINGS
137      TS_ASSERT( n_DivBy(ii, t, r->cf) );
138#endif
139       res = p_Div_nn(i, t, r); i = NULL;
140    }
141   
142     
143
144    clog<< "(poly(N)*poly(N+1))/number(2): "; PrintSized(res, r);
145    poly d = p_Sub(p_Copy(res, r), p_Copy(sum1, r), r);
146
147    if( d != NULL )
148      TS_ASSERT( n_IsZeroDivisor(p_GetCoeff(d, r), r->cf) );
149
150    Delete(d, r);
151
152    if( n_GetChar(r->cf) == 0 )
153    {
154      TS_ASSERT( p_EqualPolys(sum1, res, r) );
155      TS_ASSERT( p_EqualPolys(res, sum1, r) );
156    }
157  } else
158    TS_ASSERT_EQUALS( n_GetChar(r->cf), 2);
159 
160  n_Delete(&t, r->cf);
161
162
163  s = NULL;
164  ss = NULL;
165  for( int k = N; k >= 0; k-- )
166  {
167    i = p_ISet(k, r);
168    s = p_Add_q(s, i, r); // s += i
169
170    i = p_Neg( p_ISet(k, r), r );
171    ss = p_Add_q(ss, i, r); // ss -= i
172  }
173 
174  clog<< "ss(-sum): "; PrintSized(ss, r); 
175
176  ss = p_Neg(ss, r); // ss = -ss
177 
178  clog<< "real sum    : "; PrintSized(s, r);
179  clog<< "real sum(--): "; PrintSized(ss, r); 
180
181  TS_ASSERT( p_EqualPolys(s, ss, r) );
182  TS_ASSERT( p_EqualPolys(ss, s, r) );
183
184  TODO(somebody, fix the delete method!);
185
186  Delete(sum1, r); 
187  Delete(res, r);
188
189  Delete(s, r);   
190  Delete(ss, r);   
191
192  clog << ( " >>> TEST DONE!" );
193  clog << endl;
194
195}
196   
197void Test(const ring r)
198{
199  if( r == NULL )
200      TS_FAIL("Could not get needed ring");
201  else
202  {
203    TestSum( r, 10 );
204    TestSum( r, 100 );
205    TestSum( r, 101 );
206    TestSum( r, 1001 );
207    TestSum( r, 9000 );
208  }
209}
210
211}
212
213class PolysTestSuite : public CxxTest::TestSuite
214{
215private:
216  /* replaces p by p + c * var(i)^exp (in-place);
217     expects exp >= 0 */
218  void plusTerm(poly &p, int c, int i, int exp, const ring r)
219  {
220    poly t = p_ISet(c, r); p_SetExp(t, i, exp, r); p_Setm(t, r);
221    p = p_Add_q(p, t, r);
222  }
223  void checkInverse(number n, const coeffs cf)
224  {
225    clog << "n = "; n_Write(n, cf);
226    number n1 = n_Invers(n, cf);
227    clog << "==> n^(-1) = "; n_Write(n1, cf);
228    number n2 = n_Mult(n, n1, cf);
229    clog << "(check: n * n^(-1) = "; n_Write(n2, cf);
230    TS_ASSERT( n_IsOne(n2, cf) );
231    n_Delete(&n1, cf); n_Delete(&n2, cf);
232  }
233  void TestArithCf(const coeffs r)
234  {
235    clog << ("TEST: Simple Arithmetics: ");
236    clog << endl;
237
238    number two = n_Init(2, r);
239
240    number t = n_Init(1, r); 
241    ndInpAdd(t, t, r); 
242    TS_ASSERT( n_Equal(two, t, r) );
243    n_Delete(&t, r);
244 
245    if( getCoeffType(r) == n_Q )
246    {
247      number t = n_Init(1, r); 
248      nlInpAdd(t, t, r);
249      TS_ASSERT( n_Equal(two, t, r) );
250      n_Delete(&t, r);
251    }
252 
253    const int N = 66666;
254
255    number a = n_Init(N, r);
256   
257    clog<< "a: "; PrintSized(a, r);
258
259    clog<< "two: "; PrintSized(two, r);
260
261    number aa0 = n_Init(N*2, r);
262
263    number aa = n_Add(a, a, r);
264
265    clog<< "aa = a + a: "; PrintSized(aa, r);
266 
267    number aa2 = n_Mult(a, two, r);
268
269    clog<< "aa2 = a * 2: "; PrintSized(aa2, r);
270
271    number aa1 = n_Mult(two, a, r);
272 
273    clog<< "aa1 = 2 * a: "; PrintSized(aa1, r);
274
275    n_Delete(&a, r);
276    n_Delete(&two, r);
277
278    a = n_Sub( aa, aa1, r );
279 
280    clog<< "a = aa - aa1: "; PrintSized(a, r);
281
282    TS_ASSERT( n_IsZero(a, r) );
283
284    n_Delete(&a, r);
285
286    a = n_Sub( aa, aa2, r );
287
288    clog<< "a = aa - aa2: "; PrintSized(a, r);
289
290    TS_ASSERT( n_IsZero(a, r) );
291
292    n_Delete(&a, r);
293
294    a = n_Sub( aa1, aa2, r );
295
296    clog<< "a = aa1 - aa2: "; PrintSized(a, r);
297
298    TS_ASSERT( n_IsZero(a, r) );
299
300    n_Delete(&a, r);
301
302    TS_ASSERT( n_Equal(aa, aa1, r) );
303    TS_ASSERT( n_Equal(aa, aa2, r) );
304    TS_ASSERT( n_Equal(aa1, aa2, r) );
305 
306    TS_ASSERT( n_Equal(aa0, aa, r) );
307    TS_ASSERT( n_Equal(aa0, aa1, r) );
308    TS_ASSERT( n_Equal(aa0, aa2, r) );
309
310    n_Delete(&aa, r);
311    n_Delete(&aa1, r);
312    n_Delete(&aa2, r);
313
314    n_Delete(&aa0, r);
315
316    clog << ( " >>> TEST DONE!" );
317    clog << endl;
318  }
319  void TestSumCf(const coeffs r, const unsigned long N)
320  {
321    clog << ( _2S("TEST: sum[0..") + _2S(N) + "]: ");
322    clog << endl;
323
324    assume( N > 0 ); // just for now...
325
326    const unsigned long ssss = (N * (N+1)) / 2;
327   
328    number sum1 = n_Init(ssss, r);
329    clog<< "N*(N+1)/2 (int: " << ssss << "): "; PrintSized(sum1, r);
330
331    number s, ss, i, res;
332
333    s = n_Init(, r);
334    i = n_Init(N+1, r);
335    ndInpMult(s, i, r);
336    n_Delete(&i, r);
337   
338    clog<< "N*(N+1): ("<< N*(N+1) << ")"; PrintSized(s, r); 
339   
340    i = n_Init(2, r);
341    clog<< "2: "; PrintSized(i, r); 
342
343    if( !n_IsZero( i, r) )
344    {
345  #ifdef HAVE_RINGS
346      TS_ASSERT( n_DivBy(s, i, r) );
347  #endif
348       
349      res = n_Div(s, i, r);
350   
351      clog<< "N*(N+1)/2: "; PrintSized(res, r);
352
353
354      number d = n_Sub(res, sum1, r);
355      TS_ASSERT( n_IsZeroDivisor(d, r) );
356      n_Delete(&d, r);
357     
358      if( n_GetChar(r) == 0 )
359      {
360        TS_ASSERT( n_Equal(sum1, res, r) );
361        TS_ASSERT( n_Equal(res, sum1, r) );
362      }
363    } else
364      TS_ASSERT_EQUALS( n_GetChar(r), 2);
365   
366
367    n_Delete(&s, r);  n_Delete(&i, r);
368   
369    n_Delete(&sum1, r); n_Delete(&res, r);   
370   
371
372    s = n_Init(0  , r);
373    ss = n_Init(0 , r);
374    for( int k = N; k >= 0; k-- )
375    {
376      i = n_Init(k, r);
377      ndInpAdd(s, i, r); // s += i
378
379      i = n_Neg(i, r);
380      ndInpAdd(ss, i, r); // ss -= i
381     
382      n_Delete(&i, r);   
383    }
384    clog<< "ss: "; PrintSized(ss, r); 
385
386    ss = n_Neg(ss, r); // ss = -ss
387   
388    clog<< "real sum    : "; PrintSized(s, r);
389    clog<< "real sum(--): "; PrintSized(ss, r); 
390
391    TS_ASSERT( n_Equal(s, ss, r) );
392    TS_ASSERT( n_Equal(ss, s, r) );
393
394    n_Delete(&s, r);   
395    n_Delete(&ss, r);   
396
397    clog << ( " >>> TEST DONE!" );
398    clog << endl;
399
400  }
401public:
402  void test_Z13_t()
403  {
404    clog << "Creating  Z/13[t]: " << endl;
405
406    char* n[] = {"t"};
407    ring r = rDefault( 13, 1, n);     
408    TS_ASSERT_DIFFERS( r, NULLp );
409
410    PrintRing(r);
411
412    TS_ASSERT( rField_is_Domain(r) );
413    TS_ASSERT( !rField_is_Q(r) );
414
415    TS_ASSERT( rField_is_Zp(r) );
416    TS_ASSERT( !rField_is_Zp(r, 11) );
417    TS_ASSERT( rField_is_Zp(r, 13) );
418
419    TS_ASSERT_EQUALS( rVar(r), 1);
420
421    Test(r);
422     
423    rDelete(r);
424  }
425
426  void test_QQ_t()
427  {
428    clog << "Creating  Q[s]: " << endl;
429
430    char* n[] = {"s"};
431    ring r = rDefault( 0, 1, n);     
432    TS_ASSERT_DIFFERS( r, NULLp );
433
434    PrintRing(r);
435
436    TS_ASSERT( rField_is_Domain(r) );
437    TS_ASSERT( rField_is_Q(r) );
438   
439    TS_ASSERT( !rField_is_Zp(r) );
440    TS_ASSERT( !rField_is_Zp(r, 11) );
441
442    TS_ASSERT_EQUALS( rVar(r), 1);
443
444    Test(r);
445
446    rDelete(r);
447  }
448 
449  void test_Z11_x_y_z()
450  {
451     clog << "Creating  Z/11[x, y, z]: " << endl;
452     
453     char* n[] = {"x", "y", "z"};
454     ring r = rDefault( 11, 3, n);     
455     TS_ASSERT_DIFFERS( r, NULLp );
456
457     PrintRing(r);
458     
459     TS_ASSERT( rField_is_Domain(r) );
460     TS_ASSERT( !rField_is_Q(r) );
461
462     TS_ASSERT( rField_is_Zp(r) );
463     TS_ASSERT( rField_is_Zp(r, 11) );
464     TS_ASSERT( !rField_is_Zp(r, 13) );
465
466     TS_ASSERT_EQUALS( rVar(r), 3);
467
468     Test(r);
469     
470     rDelete(r);
471  }
472   void test_QQ_x_y_z()
473   {
474     clog << "Creating  QQ[x, y, z, u]: " << endl;
475
476     char* n[] = {"x", "y", "z", "u"};
477     ring r = rDefault( 0, 4, n);     
478     TS_ASSERT_DIFFERS( r, NULLp );
479
480     PrintRing(r);
481
482     TS_ASSERT( rField_is_Domain(r) );
483     TS_ASSERT( rField_is_Q(r) );
484
485     TS_ASSERT( !rField_is_Zp(r) );
486     TS_ASSERT( !rField_is_Zp(r, 11) );
487
488     TS_ASSERT_EQUALS( rVar(r), 4);
489
490     Test(r);
491     
492     rDelete(r);
493   }
494
495
496   void test_Z13_t_GF()
497   {
498     clog << "Creating  GF[t]: " << endl;
499
500     char* n[] = {"t"};
501
502     GFInfo param;
503
504     param.GFChar= 5;
505     param.GFDegree= 2;
506     param.GFPar_name= (const char*)"Q";
507
508     const coeffs cf = nInitChar( n_GF, &param );
509
510     if( cf == NULL )
511       TS_FAIL("Could not get needed coeff. domain");
512
513     TS_ASSERT_DIFFERS( cf, NULLp );
514
515     ring r = rDefault( cf, 1, n);  // now cf belongs to r!
516     TS_ASSERT_DIFFERS( r, NULLp );
517
518     PrintRing(r);
519
520     TS_ASSERT( rField_is_Domain(r) );
521     TS_ASSERT( !rField_is_Q(r) );
522
523     TS_ASSERT( !rField_is_Zp(r) );
524     TS_ASSERT( !rField_is_Zp(r, 11) );
525     TS_ASSERT( !rField_is_Zp(r, 13) );
526     TS_ASSERT( rField_is_GF(r) );
527
528     TS_ASSERT( rField_is_GF(r, 5) );
529     TS_ASSERT( !rField_is_GF(r, 25) );
530
531     TS_ASSERT_EQUALS( rVar(r), 1);
532
533     Test(r);
534
535     rDelete(r); // kills 'cf' as well!
536   }
537   
538  void test_Q_Ext_a()
539  {
540    clog << "Start by creating Q[a]..." << endl;
541
542    char* n[] = {"a"};
543    ring r = rDefault( 0, 1, n);   // Q[a]
544    TS_ASSERT_DIFFERS( r, NULLp );
545
546    PrintRing(r);
547
548    TS_ASSERT( rField_is_Domain(r) );
549    TS_ASSERT( rField_is_Q(r) );
550   
551    TS_ASSERT( !rField_is_Zp(r) );
552    TS_ASSERT( !rField_is_Zp(r, 11) );
553
554    TS_ASSERT_EQUALS( rVar(r), 1);
555
556    poly minPoly = p_ISet(1, r);                    // minPoly = 1
557    p_SetExp(minPoly, 1, 2, r); p_Setm(minPoly, r); // minPoly = a^2
558    minPoly = p_Add_q(minPoly, p_ISet(1, r), r);    // minPoly = a^2 + 1
559    ideal minIdeal = idInit(1);                     // minIdeal = < 0 >
560    minIdeal->m[0] = minPoly;                       // minIdeal = < a^2 + 1 >
561
562    n_coeffType type = nRegister(n_algExt, naInitChar); 
563    TS_ASSERT(type == n_algExt);
564
565    AlgExtInfo extParam;
566    extParam.r = r;
567    extParam.i = minIdeal;
568   
569    clog << "Next create the extension field Q[a]/<a2+1>..." << endl;
570
571    const coeffs cf = nInitChar(type, &extParam);   // Q[a]/<a2+1>
572   
573    if( cf == NULL )
574      TS_FAIL("Could not get needed coeff. domain");
575
576    TS_ASSERT_DIFFERS( cf->cfCoeffWrite, NULLp );
577 
578    if( cf->cfCoeffWrite != NULL )
579    {
580      clog << "Coeff-domain: "  << endl; 
581      n_CoeffWrite(cf); PrintLn();
582    }
583   
584    TS_ASSERT( nCoeff_is_algExt(cf) );
585    TS_ASSERT( !nCoeff_is_transExt(cf) );
586   
587    // some tests for the coefficient field represented by cf:
588    TestArithCf(cf);
589    TestSumCf(cf, 10);
590    TestSumCf(cf, 100);
591    TestSumCf(cf, 101);
592    TestSumCf(cf, 1001);
593    TestSumCf(cf, 2000);
594
595    clog << "Finally create the polynomial ring (Q[a]/<a2+1>)[x, y]..."
596         << endl;
597   
598    char* m[] = {"x", "y"};
599    ring s = rDefault(cf, 2, m);   // (Q[a]/<a2+1>)[x, y]
600    TS_ASSERT_DIFFERS(s, NULLp);
601
602    PrintRing(s);
603
604    TS_ASSERT( rField_is_Domain(s) );
605    TS_ASSERT( !rField_is_Q(s) );
606    TS_ASSERT( !rField_is_Zp(s) );
607    TS_ASSERT( !rField_is_Zp(s, 11) );
608    TS_ASSERT( !rField_is_Zp(s, 13) );
609    TS_ASSERT( !rField_is_GF(s) );
610    TS_ASSERT( rField_is_Extension(s) );
611    TS_ASSERT( !rField_is_GF(s, 25) );
612    TS_ASSERT_EQUALS(rVar(s), 2);
613
614    Test(s);
615   
616    clog << endl
617         << "Now let's compute some inverses in Q[a]/<a^2+1>..."
618         << endl;
619   
620    poly u;
621    u = NULL; plusTerm(u, 1, 1, 1, cf->extRing);
622    plusTerm(u, 1, 1, 0, cf->extRing);  // a + 1
623    checkInverse((number)u, cf); p_Delete(&u, cf->extRing);
624    u = NULL; plusTerm(u, 1, 1, 1, cf->extRing);
625    plusTerm(u, -1, 1, 0, cf->extRing); // a - 1
626    checkInverse((number)u, cf); p_Delete(&u, cf->extRing);
627    u = NULL; plusTerm(u, 1, 1, 1, cf->extRing);
628    plusTerm(u, 5, 1, 0, cf->extRing);  // a + 5
629    checkInverse((number)u, cf); p_Delete(&u, cf->extRing);
630    u = NULL; plusTerm(u, 1, 1, 1, cf->extRing);
631    plusTerm(u, -5, 1, 0, cf->extRing); // a - 5
632    checkInverse((number)u, cf); p_Delete(&u, cf->extRing);
633    u = NULL; plusTerm(u, 17, 1, 1, cf->extRing);
634    plusTerm(u, 5, 1, 0, cf->extRing); // 17a + 5
635    checkInverse((number)u, cf); p_Delete(&u, cf->extRing);
636
637    rDelete(s); // kills 'cf' and 'r' as well
638  }
639  void test_Q_Ext_b()
640  {
641    clog << "Start by creating Q[b]..." << endl;
642
643    char* n[] = {"b"};
644    ring r = rDefault( 0, 1, n);   // Q[b]
645    TS_ASSERT_DIFFERS( r, NULLp );
646
647    PrintRing(r);
648
649    TS_ASSERT( rField_is_Domain(r) );
650    TS_ASSERT( rField_is_Q(r) );
651   
652    TS_ASSERT( !rField_is_Zp(r) );
653    TS_ASSERT( !rField_is_Zp(r, 11) );
654
655    TS_ASSERT_EQUALS( rVar(r), 1);
656
657    poly minPoly = p_ISet(1, r);                    // minPoly = 1
658    p_SetExp(minPoly, 1, 7, r); p_Setm(minPoly, r); // minPoly = b^7
659    minPoly = p_Add_q(minPoly, p_ISet(17, r), r);   // minPoly = b^7 + 17
660    ideal minIdeal = idInit(1);                     // minIdeal = < 0 >
661    minIdeal->m[0] = minPoly;                       // minIdeal = < b^7 + 17 >
662
663    n_coeffType type = nRegister(n_algExt, naInitChar); 
664    TS_ASSERT(type == n_algExt);
665
666    AlgExtInfo extParam;
667    extParam.r = r;
668    extParam.i = minIdeal;
669   
670    clog << "Next create the extension field Q[b]/<b^7+17>..." << endl;
671
672    const coeffs cf = nInitChar(type, &extParam);   // Q[b]/<b^7+17>
673   
674    if( cf == NULL )
675      TS_FAIL("Could not get needed coeff. domain");
676
677    TS_ASSERT_DIFFERS( cf->cfCoeffWrite, NULLp );
678 
679    if( cf->cfCoeffWrite != NULL )
680    {
681      clog << "Coeff-domain: "  << endl; 
682      n_CoeffWrite(cf); PrintLn();
683    }
684   
685    TS_ASSERT( nCoeff_is_algExt(cf) );
686    TS_ASSERT( !nCoeff_is_transExt(cf) );
687   
688    // some tests for the coefficient field represented by cf:
689    TestArithCf(cf);
690    TestSumCf(cf, 10);
691    TestSumCf(cf, 100);
692    TestSumCf(cf, 101);
693    TestSumCf(cf, 1001);
694    TestSumCf(cf, 9000);
695
696    clog << "Finally create the polynomial ring (Q[b]/<b^7+17>)[u, v, w]..."
697         << endl;
698   
699    char* m[] = {"u", "v", "w"};
700    ring s = rDefault(cf, 3, m);   // (Q[b]/<b^7+17>)[u, v, w]
701    TS_ASSERT_DIFFERS(s, NULLp);
702
703    PrintRing(s);
704
705    TS_ASSERT( rField_is_Domain(s) );
706    TS_ASSERT( !rField_is_Q(s) );
707    TS_ASSERT( !rField_is_Zp(s) );
708    TS_ASSERT( !rField_is_Zp(s, 11) );
709    TS_ASSERT( !rField_is_Zp(s, 13) );
710    TS_ASSERT( !rField_is_GF(s) );
711    TS_ASSERT( rField_is_Extension(s) );
712    TS_ASSERT( !rField_is_GF(s, 25) );
713    TS_ASSERT_EQUALS(rVar(s), 3);
714
715    Test(s);
716   
717    clog << endl
718         << "Now let's compute some inverses in Q[b]/<b^7+17>..."
719         << endl;
720         
721    poly u;
722    u = NULL; plusTerm(u, 1, 1, 2, cf->extRing);
723    plusTerm(u, 33, 1, 0, cf->extRing);     // b^2 + 33
724    checkInverse((number)u, cf); p_Delete(&u, cf->extRing);
725    u = NULL; plusTerm(u, 1, 1, 5, cf->extRing);
726    plusTerm(u, -137, 1, 0, cf->extRing);   // b^5 - 137
727    checkInverse((number)u, cf); p_Delete(&u, cf->extRing);
728
729    clog << endl
730         << "Now let's check a gcd computation in Q[b]..."
731         << endl;
732   
733    poly v;
734    v = NULL; plusTerm(v, 1, 1, 2, cf->extRing);
735    plusTerm(v, 7, 1, 1, cf->extRing);
736    plusTerm(v, 1, 1, 0, cf->extRing);            // b^2 + 7b + 1
737    number w = n_Mult((number)v, (number)v, cf);  // (b^2 + 7b + 1)^2
738    number y = n_Mult((number)v, (number)w, cf);  // (b^2 + 7b + 1)^3
739    p_Delete(&v, cf->extRing);
740    v = NULL; plusTerm(v, 2, 1, 2, cf->extRing);
741    plusTerm(v, -61, 1, 1, cf->extRing);          // 2b^2 - 61b
742    number z = n_Mult((number)w,
743                      (number)v, cf);   // (b^2 + 7b + 1)^2 * (2b^2 - 61b)
744    p_Delete(&v, cf->extRing);
745   
746    clog << "z = "; p_Write((poly)z, cf->extRing);
747    clog << "y = "; p_Write((poly)y, cf->extRing);
748    number theGcd = n_Gcd(z, y, cf);   // should yield w = (b^2 + 7b + 1)^2
749    clog << "gcd(z, y) = "; p_Write((poly)theGcd, cf->extRing);
750   
751    v = (poly)n_Sub(theGcd, w, cf);
752    TS_ASSERT( v == NULL );
753    p_Delete(&v, cf->extRing);
754   
755    clog << endl
756         << "Now let's check an ext_gcd computation in Q[b]..."
757         << endl;
758         
759    poly zFactor; poly yFactor;
760    poly ppp = p_ExtGcd((poly)z, zFactor, (poly)y, yFactor, cf->extRing);
761    v = (poly)n_Sub(theGcd, (number)ppp, cf);
762    TS_ASSERT( v == NULL );
763    clog << "z = "; p_Write((poly)z, cf->extRing);
764    clog << "zFactor = "; p_Write(zFactor, cf->extRing);
765    clog << "y = "; p_Write((poly)y, cf->extRing);
766    clog << "yFactor = "; p_Write((poly)yFactor, cf->extRing);
767    number v1 = n_Mult(z, (number)zFactor, cf);
768    number v2 = n_Mult(y, (number)yFactor, cf);
769    number v3 = n_Add(v1, v2, cf);
770    clog << "z * zFactor + y * yFactor = "; p_Write((poly)v3, cf->extRing);
771    clog << "gcd(z, y) = "; p_Write(ppp, cf->extRing);
772    number v4 = n_Sub(v3, w, cf);
773    TS_ASSERT( v4 == NULL );
774   
775    p_Delete(&ppp, cf->extRing); p_Delete(&zFactor, cf->extRing);
776    p_Delete(&yFactor, cf->extRing);
777    n_Delete(&z, cf); n_Delete(&y, cf); n_Delete(&w, cf);
778    n_Delete(&theGcd, cf); p_Delete(&v, cf->extRing); n_Delete(&v1, cf);
779    n_Delete(&v2, cf); n_Delete(&v3, cf); n_Delete(&v4, cf);
780
781    rDelete(s); // kills 'cf' and 'r' as well
782  }
783  void test_Z_17_Ext_a()
784  {
785    clog << "Start by creating Z_17[a]..." << endl;
786
787    char* n[] = {"a"};
788    ring r = rDefault( 17, 1, n);   // Z/17Z[a]
789    TS_ASSERT_DIFFERS( r, NULLp );
790
791    PrintRing(r);
792
793    TS_ASSERT( rField_is_Domain(r) );
794    TS_ASSERT( !rField_is_Q(r) );
795   
796    TS_ASSERT( rField_is_Zp(r) );
797    TS_ASSERT( rField_is_Zp(r, 17) );
798
799    TS_ASSERT_EQUALS( rVar(r), 1);
800
801    poly minPoly = p_ISet(1, r);                    // minPoly = 1
802    p_SetExp(minPoly, 1, 2, r); p_Setm(minPoly, r); // minPoly = a^2
803    minPoly = p_Add_q(minPoly, p_ISet(3, r), r);    // minPoly = a^2 + 3
804    ideal minIdeal = idInit(1);                     // minIdeal = < 0 >
805    minIdeal->m[0] = minPoly;                       // minIdeal = < a^2 + 3 >
806
807    n_coeffType type = nRegister(n_algExt, naInitChar); 
808    TS_ASSERT(type == n_algExt);
809
810    AlgExtInfo extParam;
811    extParam.r = r;
812    extParam.i = minIdeal;
813   
814    clog << "Next create the extension field Z_17[a]/<a^2+3>..." << endl;
815
816    const coeffs cf = nInitChar(type, &extParam);   // Z_17[a]/<a^2+3>
817   
818    if( cf == NULL )
819      TS_FAIL("Could not get needed coeff. domain");
820
821    TS_ASSERT_DIFFERS( cf->cfCoeffWrite, NULLp );
822   
823    if( cf->cfCoeffWrite != NULL )
824    {
825      clog << "Coeff-domain: "  << endl; 
826      n_CoeffWrite(cf); PrintLn();
827    }
828   
829    TS_ASSERT( nCoeff_is_algExt(cf) );
830    TS_ASSERT( !nCoeff_is_transExt(cf) );
831   
832    // some tests for the coefficient field represented by cf:
833    TestArithCf(cf);
834    TestSumCf(cf, 10);
835    TestSumCf(cf, 100);
836    TestSumCf(cf, 101);
837    TestSumCf(cf, 1001);
838    TestSumCf(cf, 9000);
839
840    clog << "Finally create the polynomial ring (Z_17[a]/<a^2+3>)[u, v, w]..."
841         << endl;
842   
843    char* m[] = {"u", "v", "w"};
844    ring s = rDefault(cf, 3, m);   // (Z_17[a]/<a^2+3>)[u, v, w]
845    TS_ASSERT_DIFFERS(s, NULLp);
846
847    PrintRing(s);
848
849    TS_ASSERT( rField_is_Domain(s) );
850    TS_ASSERT( !rField_is_Q(s) );
851    TS_ASSERT( !rField_is_Zp(s) );
852    TS_ASSERT( !rField_is_Zp(s, 11) );
853    TS_ASSERT( !rField_is_Zp(s, 17) );
854    TS_ASSERT( !rField_is_GF(s) );
855    TS_ASSERT( rField_is_Extension(s) );
856    TS_ASSERT( !rField_is_GF(s, 25) );
857    TS_ASSERT_EQUALS(rVar(s), 3);
858
859    Test(s);
860    /*
861#ifdef HAVE_FACTORY
862    poly f = p_ISet(3, s);
863    p_SetExp(f, 1, 3, s);
864    p_SetExp(f, 2, 1, s);
865    p_SetExp(f, 3, 5, s);
866    p_Setm(f, r);   // 3*u^3*v*w^5
867    plusTerm(f, -2, 1, 6, s); // -2*u^6 + 3*u^3*v*w^5
868    p_Write(f, s);
869    poly g = p_ISet(7, s);
870    p_SetExp(g, 1, 5, s);
871    p_SetExp(g, 2, 6, s);
872    p_SetExp(g, 3, 2, s);
873    p_Setm(g, r);   // 7*u^5*v^6*w^2
874    plusTerm(g, 8, 1, 4, s); // 7*u^5*v^6*w^2 + 8*u^4
875    p_Write(g, s);
876    poly h = singclap_gcd(f, g, s);   // at least u^3, destroys f and g
877    p_Write(h, s);
878    p_Test(h, s);
879    p_Delete(&h, s);
880#endif
881    */
882    rDelete(s); // kills 'cf' and 'r' as well
883  }
884};
885
Note: See TracBrowser for help on using the repository browser.