source: git/Singular/LIB/ringgb.lib @ d097d0

spielwiese
Last change on this file since d097d0 was d097d0, checked in by Oliver Wienand <wienand@…>, 16 years ago
*** empty log message *** git-svn-id: file:///usr/local/Singular/svn/trunk@10881 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 7.2 KB
Line 
1// Singular-library
2///////////////////////////////////////////////////////////////////////////////
3// version string automatically expanded by CVS
4version="$Id: ringgb.lib,v 1.16 2001/01/16 13:48:40 Singular Exp $";
5category="Miscellaneous";
6info="
7LIBRARY:  ringgb.lib     Functions for coefficient rings
8AUTHOR:  Oliver Wienand, email: wienand@mathematik.uni-kl.de
9
10KEYWORDS: vanishing polynomial; zeroreduce; polynomial functions; library, ringgb.lib; ringgb.lib, functions for coefficient rings
11
12PROCEDURES:
13 findZeroPoly(f);        finds a vanishing polynomial for reducing f
14 zeroReduce(f);          normal form of f concerning the ideal of vanishing polynomials
15 testZero(poly f);       tests f defines the constant zero function
16 noElements(def r);      the number of elements of the coefficient ring, if of type (integer, ...)
17";
18
19LIB "general.lib";
20///////////////////////////////////////////////////////////////////////////////
21
22proc findZeroPoly (poly f)
23"USAGE:   findZeroPoly(f); f - a polynomial
24RETURN:  zero polynomial with the same leading term as f if exists, otherwise 0
25EXAMPLE: example findZeroPoly; shows an example
26"
27{
28  list data = getZeroCoef(f);
29  if (data[1] == 0)
30  {
31    return(0);
32  }
33  number q = leadcoef(f) / data[1];
34  if (q == 0)
35  {
36    return(0);
37  }
38  poly g = getZeroPolyRaw(data[2]);
39  g = leadmonom(f) / leadmonom(g) * g;
40  return(q * data[1] * g);
41  //return(system("findZeroPoly", f));
42}
43example
44{ "EXAMPLE:"; echo = 2;
45  ring r = (integer, 65536), (y,x), dp;
46  poly f = 1024*x^8*y^2+11264*x^8*y+28672*x^8+45056*x^7*y^2+36864*x^7*y+16384*x^7+40960*x^6*y^2+57344*x^6*y+32768*x^6+30720*x^5*y^2+10240*x^5*y+8192*x^5+35840*x^4*y^2+1024*x^4*y+20480*x^4+30720*x^3*y^2+10240*x^3*y+8192*x^3+4096*x^2*y^2+45056*x^2*y+49152*x^2+40960*x*y^2+57344*x*y+32768*x;
47  findZeroPoly(f);
48}
49
50proc zeroReduce(poly f, list #)
51"USAGE:   zeroReduce(f, [i = 0]); f - a polynomial, i - noise level (if != 0 prints all steps)
52RETURN:  reduced normal form of f modulo zero polynomials
53EXAMPLE: example zeroReduce; shows an example
54"
55{
56   int i = 0;
57   if (size(#) > 0)
58   {
59     i = #[1];
60   }
61   poly h = f;
62   poly n = 0;
63   poly g = findZeroPoly(h);
64   if (i <> 0) {
65     printf("reducing polyfct  : %s", h);
66   }
67   while ( h <> 0 ) {
68      while ( g <> 0 ) {
69         h = h - g;
70         if (i <> 0) {
71            printf(" reduce with: %s", g);
72            printf(" to: %s", h);
73         }
74         g = findZeroPoly(h);
75      }
76      n = lead(h) + n;
77      if (i <> 0) {
78         printf("head irreducible  : %s", lead(h));
79         printf("irreducible start : %s", n);
80         printf("remains to check  : %s", h - lead(h));
81      }
82      h = h - lead(h);
83      g = findZeroPoly(h);
84   }
85   return(n);
86}
87example
88{ "EXAMPLE:"; echo = 2;
89  ring r = (integer, 65536), (y,x), dp;
90  poly f = 1024*x^8*y^2+11264*x^8*y+28672*x^8+45056*x^7*y^2+36864*x^7*y+16384*x^7+40960*x^6*y^2+57344*x^6*y+32768*x^6+30720*x^5*y^2+10240*x^5*y+8192*x^5+35840*x^4*y^2+1024*x^4*y+20480*x^4+30720*x^3*y^2+10240*x^3*y+8192*x^3+4096*x^2*y^2+45056*x^2*y+49152*x^2+40960*x*y^2+57344*x*y+32768*x;
91  zeroReduce(f);
92  kill r;
93  ring r = (integer, 2, 32), (x,y,z), dp;
94  // Polynomial 1:
95  poly p1 = 3795162112*x^3+587202566*x^2*y+2936012853*x*y*z+2281701376*x+548767119*y^3+16777216*y^2+268435456*y*z+1107296256*y+4244635648*z^3+4244635648*z^2+16777216*z;
96  // Polynomial 2:
97  poly p2 = 1647678464*x^3+587202566*x^2*y+2936012853*x*y*z+134217728*x+548767119*y^3+16777216*y^2+268435456*y*z+1107296256*y+2097152000*z^3+2097152000*z^2+16777216*z;
98  zeroReduce(p1-p2);
99}
100
101proc testZero(poly f)
102"USAGE:   testZero(f); f - a polynomial
103RETURN:  returns 1 if f is zero as a function and otherwise a counterexample as a list [f(x_1, ..., x_n), x_1, ..., x_n]
104EXAMPLE: example testZero; shows an example
105"
106{
107  poly g;
108  int j;
109  bigint i = 0;
110  bigint modul = noElements(basering);
111  printf("Teste %s Belegungen ...", modul^nvars(basering));
112  for (; i < modul^nvars(basering); i = i + 1)
113  {
114    if ((i + 1) % modul^(nvars(basering)/2) == 0)
115    {
116      printf("bisher: %s", i);
117    }
118    g = f;
119    for (j = 1; j <= nvars(basering); j++)
120    {
121      g = subst(g, var(j), number((i / modul^(j-1)) % modul));
122    }
123    if (g != 0)
124    {
125      list counter = g;
126      for (j = 1; j <= nvars(basering); j++)
127      {
128        counter = insert(counter, (i / modul^(j-1)) % modul);
129      }
130      return(counter);
131    }
132  }
133  return(1);
134}
135example
136{ "EXAMPLE:"; echo = 2;
137  ring r = (integer, 12), (y,x), dp;
138  poly f = 1024*x^8*y^2+11264*x^8*y+28672*x^8+45056*x^7*y^2+36864*x^7*y+16384*x^7+40960*x^6*y^2+57344*x^6*y+32768*x^6+30720*x^5*y^2+10240*x^5*y+8192*x^5+35840*x^4*y^2+1024*x^4*y+20480*x^4+30720*x^3*y^2+10240*x^3*y+8192*x^3+4096*x^2*y^2+45056*x^2*y+49152*x^2+40960*x*y^2+57344*x*y+32768*x;
139  zeroReduce(f);
140  testZero(f);
141  poly g = findZeroPoly(x2y3);
142  g;
143  testZero(g);
144}
145
146proc noElements(def r)
147"USAGE:   noElements(r); r - a ring with a finite coefficient ring of type integer
148RETURN:  returns the number of elements of the coefficient ring of r
149EXAMPLE: example noElements; shows an example
150"
151
152{
153  list l = ringlist(basering);
154  return(l[1][2][1]^l[1][2][2]);
155}
156example
157{ "EXAMPLE:"; echo = 2;
158  ring r = (integer, 233,6), (y,x), dp;
159  noElements(r);
160}
161
162static proc getZeroCoef(poly f)
163{
164  if (f == 0)
165  {
166    return(0, leadexp(f))
167  }
168  list data = sort(leadexp(f));
169  intvec exp = data[1];
170  intvec index = data[2];
171  intvec nec = 0:size(exp);
172  int i = 1;
173  int j = 2;
174  bigint g;
175  bigint G = 1;
176  bigint modul = noElements(basering);
177  bigint B = modul;
178
179  for (; exp[i] < 2; i++) {if (i == size(exp)) break;}
180  for (; i <= size(exp); i++)
181  {
182    g = gcd(B, G);
183    G = G * g;
184    B = B / g;
185    if (g != 1)
186    {
187      nec[index[i]] = j - 1;
188    }
189    if (B == 1)
190    {
191      return(B, nec);
192    }
193    for (; j <= exp[i]; j++)
194    {
195      g = gcd(B, bigint(j));
196      G = G * g;
197      B = B / g;
198      if (g != 1)
199      {
200        nec[index[i]] = j;
201      }
202      if (B == 1)
203      {
204        return(B, nec);
205      }
206    }
207  }
208  if (B == modul)
209  {
210    nec = 0;
211    return(0, nec);
212  }
213  return(B, nec);
214}
215
216static proc getZeroPolyRaw(intvec fexp)
217{
218  list data = sort(fexp);
219  intvec exp = data[1];
220  intvec index = data[2];
221  int j = 0;
222  poly res = 1;
223  poly tillnow = 1;
224  int i = 1;
225  for (; exp[i] < 2; i++) {if (i == size(exp)) break;}
226  for (; i <= size(exp); i++)
227  {
228    for (; j < exp[i]; j++)
229    {
230      tillnow = tillnow * (var(1) - j);
231    }
232    res = res * subst(tillnow, var(1), var(index[i]));
233  }
234  return(res);
235}
236
237static proc getZeroPoly(poly f)
238{
239  list data = getZeroCoef(f);
240  poly g = getZeroPolyRaw(data[2]);
241  g = leadmonom(f) / leadmonom(g) * g;
242  return(data[1] * g);
243}
244
245static proc findZeroPolyWrap (poly f)
246"USAGE:   findZeroPolyWrap(f); f - a polynomial
247RETURN:  zero polynomial with the same leading term as f if exists, otherwise 0
248NOTE:    just a wrapper, work only in Z/2^n with n < int_machine_size - 1
249EXAMPLE: example findZeroPoly; shows an example
250"
251{
252  return(system("findZeroPoly", f));
253}
254example
255{ "EXAMPLE:"; echo = 2;
256  ring r = (integer, 2, 16), (y,x), dp;
257  poly f = 1024*x^8*y^2+11264*x^8*y+28672*x^8+45056*x^7*y^2+36864*x^7*y+16384*x^7+40960*x^6*y^2+57344*x^6*y+32768*x^6+30720*x^5*y^2+10240*x^5*y+8192*x^5+35840*x^4*y^2+1024*x^4*y+20480*x^4+30720*x^3*y^2+10240*x^3*y+8192*x^3+4096*x^2*y^2+45056*x^2*y+49152*x^2+40960*x*y^2+57344*x*y+32768*x;
258  findZeroPoly(f);
259}
Note: See TracBrowser for help on using the repository browser.