source: git/ntl/src/GF2EXTest.c @ 6ce030f

spielwiese
Last change on this file since 6ce030f was de6a29, checked in by Hans Schönemann <hannes@…>, 19 years ago
* hannes: NTL-5.4 git-svn-id: file:///usr/local/Singular/svn/trunk@8693 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.0 KB
Line 
1
2#include <NTL/GF2XFactoring.h>
3#include <NTL/GF2EXFactoring.h>
4
5
6NTL_OPEN_NNS
7
8void PlainMul(GF2EX&, const GF2EX&, const GF2EX&);
9
10NTL_CLOSE_NNS
11
12NTL_CLIENT
13
14int main()
15{
16   GF2X p;
17
18   BuildIrred(p, 200);
19
20   GF2E::init(p);
21
22   GF2EX f;
23
24   SetCoeff(f, 41);
25   SetCoeff(f, 1);
26   SetCoeff(f, 0);
27
28   GF2X a;
29   SetCoeff(a, 117);
30   SetCoeff(a, 10);
31   SetCoeff(a, 0);
32
33   GF2EX g, h;
34   SetX(g);
35   SetCoeff(g, 0, to_GF2E(a));
36
37   MinPolyMod(h, g, f);
38
39   f = h;
40
41   vec_pair_GF2EX_long u;
42
43   CanZass(u, f, 1);
44
45   cerr << "factorization pattern:";
46   long i;
47
48   for (i = 0; i < u.length(); i++) {
49      cerr << " ";
50      long k = u[i].b;
51      if (k > 1)
52         cerr << k << "*";
53      cerr << deg(u[i].a);
54   }
55
56   cerr << "\n\n\n";
57
58   GF2EX ff;
59   mul(ff, u);
60
61   if (f != ff || u.length() != 11) {
62      cerr << "GF2EXTest NOT OK\n";
63      return 1;
64   }
65
66   {
67
68   cerr << "multiplication test...\n";
69
70   BuildIrred(p, 512);
71   GF2E::init(p);
72
73   GF2EX A, B, C, C1;
74
75
76   random(A, 512);
77   random(B, 512);
78
79   double t;
80   long i;
81
82   t = GetTime();
83   for (i = 0; i < 10; i++) PlainMul(C, A, B);
84   t = GetTime() - t;
85   cerr << "time for plain mul of degree 511 over GF(2^512): " << (t/10) << "s\n";
86
87   t = GetTime();
88   for (i = 0; i < 10; i++) mul(C1, A, B);
89   t = GetTime() - t;
90   cerr << "time for karatsuba mul of degree 511 over GF(2^512): " << (t/10) << "s\n";
91
92   if (C != C1) {
93      cerr << "GF2EXTest NOT OK\n";
94      return 1;
95   }
96
97   }
98
99   {
100
101   cerr << "multiplication test...\n";
102
103   BuildIrred(p, 16);
104   GF2E::init(p);
105
106   GF2EX A, B, C, C1;
107
108
109   random(A, 512);
110   random(B, 512);
111
112   double t;
113
114   t = GetTime();
115   for (i = 0; i < 10; i++) PlainMul(C, A, B);
116   t = GetTime() - t;
117   cerr << "time for plain mul of degree 511 over GF(2^16): " << (t/10) << "s\n";
118
119   t = GetTime();
120   for (i = 0; i < 10; i++) mul(C1, A, B);
121   t = GetTime() - t;
122   cerr << "time for karatsuba mul of degree 511 over GF(2^16): " << (t/10) << "s\n";
123
124   if (C != C1) {
125      cerr << "GF2EXTest NOT OK\n";
126      return 1;
127   }
128
129   }
130
131   cerr << "GF2EXTest OK\n";
132   return 0;
133}
Note: See TracBrowser for help on using the repository browser.