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

fieker-DuValspielwiese
Last change on this file since e74fb8 was c1d47bd, checked in by Oliver Wienand <wienand@…>, 16 years ago
Zerored nun auch für beliebige große "Charakteristik" git-svn-id: file:///usr/local/Singular/svn/trunk@10878 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 6.4 KB
Line 
1//(GMG/BM, last modified 22.06.96)
2///////////////////////////////////////////////////////////////////////////////
3version="$Id: ringgb.lib,v 1.16 2001/01/16 13:48:40 Singular Exp $";
4category="Beta Testing";
5info="
6LIBRARY:  ringgb.lib     Examples and tests for ringgb development
7
8PROCEDURES:
9 findZeroPoly(f);        finds a zero polynomial for reducing f
10 zeroReduce(f);          normal form of f concerning the ideal of zero polynomials
11 zeroReduceProt(f);          normal form of f concerning the ideal of zero polynomials
12";
13
14LIB "general.lib";
15///////////////////////////////////////////////////////////////////////////////
16
17proc findZeroPoly (poly f)
18"USAGE:   findZeroPolyWrap(f); f - a polynomial
19RETURN:  zero polynomial with the same leading term as f if exists, otherwise 0
20NOTE:    just a wrapper, work only in Z/2^n with n < int_machine_size - 1
21EXAMPLE: example findZeroPoly; shows an example
22"
23{
24  return(system("findZeroPoly", f));
25}
26example
27{ "EXAMPLE:"; echo = 2;
28  option(teach);
29  ring r = 65536, (y,x), dp;
30  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;
31  findZeroPoly(f);
32}
33
34proc findZeroPoly (poly f)
35"USAGE:   findZeroPoly(f); f - a polynomial
36RETURN:  zero polynomial with the same leading term as f if exists, otherwise 0
37EXAMPLE: example findZeroPoly; shows an example
38"
39{
40  list data = getZeroCoef(f);
41  if (data[1] == 0)
42  {
43    return(0);
44  }
45  number q = leadcoef(f) / data[1];
46  if (q == 0)
47  {
48    return(0);
49  }
50  poly g = getZeroPolyRaw(data[2]);
51  g = leadmonom(f) / leadmonom(g) * g;
52  return(q * data[1] * g);
53  //return(system("findZeroPoly", f));
54}
55example
56{ "EXAMPLE:"; echo = 2;
57  option(teach);
58  ring r = 65536, (y,x), dp;
59  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;
60  findZeroPoly(f);
61}
62
63proc zeroReduceExt (poly f , int i)
64"USAGE:   zeroReduceExt(f, i); f - a polynomial, i - noisy level
65RETURN:  reduced normal form of f modulo zero polynomials
66EXAMPLE: example zeroReduceExt; shows an example
67"
68{
69   poly h = f;
70   poly n = 0;
71   poly g = findZeroPoly(h);
72   while ( h <> 0 ) {
73      while ( g <> 0 ) {
74         h = h - g;
75         if (i == 1) {
76            printf("reduce with: %s", g);
77            printf("to: %s", h);
78         }
79         g = findZeroPoly(h);
80      }
81      n = lead(h) + n;
82      h = h - lead(h);
83      g = findZeroPoly(h);
84   }
85   return(n);
86}
87example
88{ "EXAMPLE:"; echo = 2;
89  option(teach);
90  ring r = 65536, (y,x), dp;
91  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;
92  zeroReduceExt(f,0);
93  zeroReduceExt(f,1);
94}
95
96proc zeroReduce (poly f)
97"USAGE:   zeroReduce(f); f - a polynomial
98RETURN:  reduced normal form of f modulo zero polynomials
99EXAMPLE: example zeroReduce; shows an example
100"
101{
102   return(zeroReduceExt(f, 0));
103}
104example
105{ "EXAMPLE:"; echo = 2;
106  option(teach);
107  ring r = 65536, (y,x), dp;
108  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;
109  zeroReduce(f);
110}
111
112proc zeroReduceProt (poly f)
113"USAGE:   zeroReduceProt(f); f - a polynomial
114RETURN:  reduced normal form of f modulo zero polynomials and describes the way *g*
115EXAMPLE: example zeroReduceProt; shows an example
116"
117{
118   return(zeroReduceExt(f, 1));
119}
120example
121{ "EXAMPLE:"; echo = 2;
122  option(teach);
123  ring r = 65536, (y,x), dp;
124  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;
125  zeroReduceProt(f);
126}
127
128proc getZeroCoef(poly f)
129{
130  if (f == 0)
131  {
132    return(0, leadexp(f))
133  }
134  list data = sort(leadexp(f));
135  intvec exp = data[1];
136  intvec index = data[2];
137  intvec nec = 0:size(exp);
138  int i = 1;
139  int j = 2;
140  bigint g;
141  bigint G = 1;
142  bigint B = noElements(basering);
143
144  for (; exp[i] < 2; i++) {if (i == size(exp)) break;}
145  for (; i <= size(exp); i++)
146  {
147    g = gcd(B, G);
148    G = G * g;
149    B = B / g;
150    if (g != 1)
151    {
152      nec[index[i]] = j - 1;
153    }
154    if (B == 1)
155    {
156      return(B, nec);
157    }
158    for (; j <= exp[i]; j++)
159    {
160      g = gcd(B, bigint(j));
161      G = G * g;
162      B = B / g;
163      if (g != 1)
164      {
165        nec[index[i]] = j;
166      }
167      if (B == 1)
168      {
169        return(B, nec);
170      }
171    }
172  }
173  return(B, nec);
174}
175
176proc getZeroPolyRaw(intvec fexp)
177{
178  list data = sort(fexp);
179  intvec exp = data[1];
180  intvec index = data[2];
181  int j = 0;
182  poly res = 1;
183  poly tillnow = 1;
184  int i = 1;
185  for (; exp[i] < 2; i++) {if (i == size(exp)) break;}
186  for (; i <= size(exp); i++)
187  {
188    for (; j < exp[i]; j++)
189    {
190      tillnow = tillnow * (var(1) - j);
191    }
192    res = res * subst(tillnow, var(1), var(index[i]));
193  }
194  return(res);
195}
196
197proc getZeroPoly(poly f)
198{
199  list data = getZeroCoef(f);
200  poly g = getZeroPolyRaw(data[2]);
201  g = leadmonom(f) / leadmonom(g) * g;
202  return(data[1] * g);
203}
204
205proc testZero(poly f)
206{
207  poly g;
208  int j;
209  bigint i = 0;
210  bigint modul = noElements(basering);
211  printf("Teste %s Belegungen ...", modul^nvars(basering));
212  for (; i < modul^nvars(basering); i = i + 1)
213  {
214    if (i % modul == 0)
215    {
216      printf("bisher: %s", i);
217    }
218    g = f;
219    for (j = 1; j <= nvars(basering); j++)
220    {
221      g = subst(g, var(j), number((i / modul^(j-1)) % modul));
222    }
223    if (g != 0)
224    {
225      list counter = g;
226      for (j = 1; j <= nvars(basering); j++)
227      {
228        counter = insert(counter, (i / modul^(j-1)) % modul);
229      }
230      return(counter);
231    }
232  }
233  return(1);
234}
235
236proc noElements(def r)
237{
238  list l = ringlist(basering);
239  return(l[1][2][1]^l[1][2][2]);
240}
Note: See TracBrowser for help on using the repository browser.