source: git/Singular/LIB/ringgb.lib @ 334c21f

spielwiese
Last change on this file since 334c21f was 7f3ad4, checked in by Hans Schönemann <hannes@…>, 15 years ago
*hannes: format git-svn-id: file:///usr/local/Singular/svn/trunk@11306 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 10.6 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}
260
261///////////////////////////////////////////////////////////////////////////////
262
263/*
264                           Examples:
265
266
267// POLYNOMIAL EXAMPLES (Singular ready)
268// ===================
269//
270// For each of the examples below, there are three equivalent polynomials. 'm' indicates the bit-widths of the
271// input/output variables. For some of the polynomials, I have attached the RTL as well.
272//
273//
274// 1) VOLTERRA MODELS:
275//
276//        A) CUBIC FILTER: (m = 32, 3 Vars)
277
278LIB "ringgb.lib";
279ring r = (integer, 2, 32), (x,y,z), dp;
280poly p1 = 3795162112*x^3+587202566*x^2*y+2936012853*x*y*z+2281701376*x+548767119*y^3+16777216*y^2+268435456*y*z \
281         +1107296256*y+4244635648*z^3+4244635648*z^2+16777216*z;
282poly p2 = 1647678464*x^3+587202566*x^2*y+2936012853*x*y*z+134217728*x+548767119*y^3+16777216*y^2+268435456*y*z \
283         +1107296256*y+2097152000*z^3+2097152000*z^2+16777216*z;
284poly p3 = 1647678464*x^3+587202566*x^2*y+2936012853*x*y*z+134217728*x+548767119*y^3+16777216*y^2+268435456*y*z \
285         +1107296256*y+2097152000*z^3+2097152000*z^2+16777216*z;
286zeroReduce(p1-p2);
287zeroReduce(p1-p3);
288zeroReduce(p2-p3);
289
290//        B) DEGREE-4 FILTER: (m=16 , 3 Vars)
291
292LIB "ringgb.lib";
293ring r = (integer, 2, 16), (x,y,z), dp;
294poly p1 = 16384*x^4+y^4+57344*z^4+64767*x*y^3+16127*y^2*z^2+8965*x^3*z+19275*x^2*y*z+51903*x*y*z+32768*x^2*y  \
295         +40960*z^2+32768*x*y^2+49152*x^2+4869*y;
296poly p2 = 8965*x^3*z+19275*x^2*y*z+31999*x*y^3+51903*x*y*z+32768*x*y+y^4+32768*y^3+16127*y^2*z^2+32768*y^2 \
297         +4869*y+57344*z^4+40960*z^2;
298poly p3 = 8965*x^3*z+19275*x^2*y*z+31999*x*y^3+51903*x*y*z+32768*x*y+y^4+16127*y^2*z^2+4869*y+16384*z^3+16384*z;
299zeroReduce(p1-p2);
300zeroReduce(p1-p3);
301zeroReduce(p2-p3);
302
303
304// 2) Savitzsky Golay filter(m=16,5 Vars)
305
306LIB "ringgb.lib";
307ring r = (integer, 2, 16), (v,w,x,y,z), dp;
308poly p1 = 25000*v^2*y+37322*v^2+22142*v*w*z+50356*w^3+58627*w^2+17797*w+17797*x^3+62500*x^2*z+41667*x \
309         +22142*y^3+23870*y^2+59464*y+41667*z+58627;
310poly p2 = 25000*v^2*y+4554*v^2+22142*v*w*z+32768*v+17588*w^3+25859*w^2+17797*w+17797*x^3+29732*x^2*z+32768*x^2 \
311         +32768*x*z+8899*x+22142*y^3+23870*y^2+59464*y+41667*z+58627;
312poly p3 = 25000*v^2*y+4554*v^2+22142*v*w*z+32768*v+17588*w^3+25859*w^2+17797*w+17797*x^3+29732*x^2*z+32768*x*z \
313         +41667*x+22142*y^3+23870*y^2+59464*y+41667*z+58627;
314zeroReduce(p1-p2);
315zeroReduce(p1-p3);
316zeroReduce(p2-p3);
317
318
319// 3) Anti-alias filter:(m=16, 1 Var)
320
321LIB "ringgb.lib";
322ring r = (integer, 2, 16), c, dp;
323poly p1 = 156*c^6+62724*c^5+17968*c^4+18661*c^3+43593*c^2+40224*c+13281;
324poly p2 = 156*c^6+5380*c^5+1584*c^4+43237*c^3+27209*c^2+40224*c+13281;
325poly p3 = 156*c^6+5380*c^5+1584*c^4+10469*c^3+27209*c^2+7456*c+13281;
326zeroReduce(p1-p2);
327zeroReduce(p1-p3);
328zeroReduce(p2-p3);
329
330
331// 4) PSK:(m=16, 2 Var)
332
333LIB "ringgb.lib";
334ring r = (integer, 2, 16), (x,y), dp;
335poly p1 = 4166*x^4+16666*x^3*y+25000*x^2*y^2+15536*x^2+16666*x*y^4+31072*x*y+4166*y^4+15536*y^2+34464;
336poly p2 = 4166*x^4+16666*x^3*y+8616*x^2*y^2+16384*x^2*y+15536*x^2+282*x*y^4+47456*x*y+53318*y^4+31920*y^2+34464;
337poly p3 = 4166*x^4+16666*x^3*y+8616*x^2*y^2+16384*x^2*y+15536*x^2+282*x*y^4+47456*x*y+4166*y^4+15536*y^2+34464;
338zeroReduce(p1-p2);
339zeroReduce(p1-p3);
340zeroReduce(p2-p3);
341
342// Ref: A. Peymandoust G. De Micheli, “Application of Symbolic Computer Algebra in High-Level Data-Flow
343// Synthesis,” IEEE Transactions on CAD/ICAS, Vol. 22, No. 9, September 2003, pp.1154-1165.
344
345*/
Note: See TracBrowser for help on using the repository browser.