source: git/Singular/LIB/modstd.lib @ d6374d

spielwiese
Last change on this file since d6374d was d6374d, checked in by Hans Schönemann <hannes@…>, 17 years ago
*hannes: LIB fix git-svn-id: file:///usr/local/Singular/svn/trunk@9731 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 12.3 KB
Line 
1//GP, last modified 23.10.06
2///////////////////////////////////////////////////////////////////////////////
3version="$Id: modstd.lib,v 1.4 2007-01-16 14:52:58 Singular Exp $";
4category="Commutative Algebra";
5info="
6LIBRARY: modstd.lib  Grobner basis of ideals
7AUTHORS: A. Hashemi,     Amir.Hashemi@lip6.fr
8@*       G. Pfister      pfister@mathematik.uni-kl.de
9@*       H. Schoenemann  hannes@mathematik.uni-kl.de
10
11NOTE:
12 A library for computing the Grobner basis of an ideal in the polynomial
13 ring over the rational numbers using modular methods.The procedures are
14 inspired by the following paper:
15 Elizabeth A. Arnold:
16 Modular Algorithms for Computing Groebner Bases , Journal of Symbolic
17 Computation , April 2003, Volume 35, (4), p. 403-419.
18
19
20
21PROCEDURES:
22modStd(I);     compute a standard basis of I using modular methods
23modS(I,L);     liftings to Q of standard bases of I mod p for p in L
24primeList(n);  list of n primes  <= 2134567879 in decreasing order
25";
26
27LIB "poly.lib";
28LIB "crypto.lib";
29///////////////////////////////////////////////////////////////////////////////
30proc modStd(ideal I)
31"USAGE:  modStd(I);
32RETURN:  a standard basis of I if no warning appears;
33NOTE:    the procedure computes a standard basis of I (over the
34         rational numbers) by using  modular methods. If a
35         warning appears then the result is a standard basis with no defined
36         relation to I; this is a sign that not enough prime numbers have
37         been used. For further experiments see procedure modS.
38EXAMPLE: example modStd; shows an example
39"
40{
41  def R0=basering;
42  list rl=ringlist(R0);
43  if((npars(R0)>0)||(rl[1]>0))
44  {
45     ERROR("characteristic of basering should be zero");
46  }
47  int l,j,k,q;
48  int en=2134567879;
49  int an=1000000000;
50  intvec hi,hl,hc,hpl,hpc;
51  list T,TT;
52  list L=primeList(5);
53  L[6]=prime(random(an,en));
54  ideal J,cT,lT,K;
55  ideal I0=I;
56  int h=homog(I);
57  if((!h)&&(ord_test(R0)==0))
58  {
59     ERROR("input is not homogeneous and ordering is not local");
60  }
61  if(h)
62  {
63     execute("ring gn="+string(L[6])+",x(1.."+string(nvars(R0))+"),dp;");
64     ideal I=fetch(R0,I);
65     ideal J=std(I);
66     hi=hilb(J,1);
67     setring R0;
68  }
69  for (j=1;j<=size(L);j++)
70  {
71    rl[1]=L[j];
72    def oro=ring(rl);
73    setring oro;
74    ideal I=fetch(R0,I);
75    option(redSB);
76    if(h)
77    {
78       ideal I1=std(I,hi);
79    }
80    else
81    {
82      if(ord_test(R0)==-1)
83      {
84         ideal I1=std(I);
85      }
86      else
87      {
88         matrix M;
89         ideal I1=liftstd(I,M);
90      }
91    }
92    setring R0;
93    T[j]=fetch(oro,I1);
94    kill oro;
95  }
96  //================= delete unlucky primes ====================
97  // unlucky iff the leading ideal is wrong
98  list LL=deleteUnluckyPrimes(T,L);
99  T=LL[1];
100  L=LL[2];
101  lT=LL[3];
102  //============ now all leading ideals are the same ============
103  for(j=1;j<=ncols(T[1]);j++)
104  {
105    for(k=1;k<=size(L);k++)
106    {
107      TT[k]=T[k][j];
108    }
109    J[j]=liftPoly(TT,L);
110  }
111  //=========== chooses more primes up to the moment the result becomes stable
112  while(1)
113  {
114     k=0;
115     q=prime(random(an,en));
116     while(k<size(L))
117     {
118        k++;
119        if(L[k]==q)
120        {
121           k=0;
122           q=prime(random(an,en));
123        }
124     }
125     L[size(L)+1]=q;
126     rl[1]=L[size(L)];
127     def @r=ring(rl);
128     setring @r;
129     ideal i=fetch(R0,I);
130     option(redSB);
131     if(h)
132     {
133       i=std(i,hi);
134     }
135     else
136     {
137       if(ord_test(R0)==-1)
138       {
139          i=std(i);
140       }
141       else
142       {
143          matrix M;
144          i=liftstd(i,M);
145       }
146     }
147     setring R0;
148     T[size(T)+1]=fetch(@r,i);
149     kill @r;
150     cT=lead(T[size(T)]);
151     attrib(cT,"isSB",1);
152     if((size(reduce(cT,lT))!=0)||(size(reduce(lT,cT))!=0))
153     {
154        T=delete(T,size(T));
155        L=delete(L,size(L));
156        k=0;
157     }
158     else
159     {
160        for(j=1;j<=ncols(T[1]);j++)
161        {
162           for(k=1;k<=size(L);k++)
163           {
164              TT[k]=T[k][j];
165           }
166           K[j]=liftPoly(TT,L);
167        }
168        k=1;
169        for(j=1;j<=size(K);j++)
170        {
171           if(K[j]-J[j]!=0)
172           {
173              k=0;
174              J=K;
175              break;
176           }
177        }
178     }
179     if(k){break;}
180  }
181  //============  test for standard basis and I=J =======
182  J=std(J);
183  I0=reduce(I0,J);
184  if(size(I0)>0)
185  {
186     "WARNING: The input ideal is not contained
187                        in the ideal generated by the standardbasis";
188     "list of primes used:";
189     L;
190  }
191  attrib(J,"isSB",1);
192  return(J);
193}
194example
195{ "EXAMPLE:"; echo = 2;
196   ring r=0,(x,y,z),dp;
197   ideal I=3x3+x2+1,11y5+y3+2,5z4+z2+4;
198   ideal J=modStd(I);
199   J;
200}   
201///////////////////////////////////////////////////////////////////////////////
202proc modS(ideal I, list L, list #)
203"USAGE:  modS(I,L); I ideal, L list of primes
204         if size(#)>0 std is used instead of groebner
205RETURN:  an ideal which is with high probability a standard basis
206NOTE:    This procedure is designed for fast experiments.
207         It is not tested whether the result is a standard basis.
208         It is not tested whether the result generates I.
209EXAMPLE: example modS; shows an example
210"
211{
212  int j,k;
213  list T,TT;
214  def R0=basering;
215  ideal J,cT,lT,K;
216  ideal I0=I;
217  list rl=ringlist(R0);
218  if((npars(R0)>0)||(rl[1]>0))
219  {
220     ERROR("characteristic of basering should be zero");
221  }
222  for (j=1;j<=size(L);j++)
223  {
224    rl[1]=L[j];
225    def @r=ring(rl);
226    setring @r;
227    ideal i=fetch(R0,I);
228    option(redSB);
229    if(size(#)>0)
230    {
231       i=std(i);
232    }
233    else
234    {
235       i=groebner(i)
236    }
237    setring R0;
238    T[j]=fetch(@r,i);
239    kill @r;
240  }
241  //================= delete unlucky primes ====================
242  // unlucky iff the leading ideal is wrong
243  list LL=deleteUnluckyPrimes(T,L);
244  T=LL[1];
245  L=LL[2];
246  //============ now all leading ideals are the same ============
247  for(j=1;j<=ncols(T[1]);j++)
248  {
249    for(k=1;k<=size(L);k++)
250    {
251      TT[k]=T[k][j];
252    }
253    J[j]=liftPoly(TT,L); 
254  }
255  attrib(J,"isSB",1);
256  return(J);
257}
258example
259{ "EXAMPLE:"; echo = 2;
260   list L=3,5,11,13,181;
261   ring r=0,(x,y,z),dp;
262   ideal I=3x3+x2+1,11y5+y3+2,5z4+z2+4;
263   ideal J=modS(I,L);
264   J;
265
266///////////////////////////////////////////////////////////////////////////////
267proc deleteUnluckyPrimes(list T,list L)
268"USAGE:  deleteUnluckyPrimes(T,L);T list of polys, L list of primes 
269RETURN:  list L,T with T list of polys, L list of primes
270EXAMPLE: example deleteUnluckyPrimes; shows an example
271NOTE:    works only for homogeneous ideals with global orderings or
272         for ideals with local orderings
273"
274{
275  int j,k;
276  intvec hl,hc;
277  ideal cT,lT;
278
279  lT=lead(T[size(T)]);
280  attrib(lT,"isSB",1);
281  hl=hilb(lT,1);
282  for (j=1;j<size(T);j++)
283  {
284     cT=lead(T[j]);
285     attrib(cT,"isSB",1);
286     hc=hilb(cT,1);
287     if(hl==hc)
288     {
289        for(k=1;k<=size(lT);k++)
290        {
291           if(lT[k]<cT[k]){lT=cT;break;}
292           if(lT[k]>cT[k]){break;}
293        }
294     }
295     else
296     {
297        if(hc<hl){lT=cT;hl=hilb(lT,1);}
298     }
299  }
300  j=1;
301  attrib(lT,"isSB",1);
302  while(j<=size(T))
303  {
304     cT=lead(T[j]);
305     attrib(cT,"isSB",1);
306     if((size(reduce(cT,lT))!=0)||(size(reduce(lT,cT))!=0))
307     {
308        T=delete(T,j);
309        L=delete(L,j);
310        j--;
311     }
312     j++;
313  }
314  return(list(T,L,lT));
315}
316example
317{ "EXAMPLE:"; echo = 2;
318   list L=2,3,5,7,11;
319   ring r=0,(y,x),Dp;
320   ideal I1=y2x,y6;
321   ideal I2=yx2,y3x,x5,y6;
322   ideal I3=y2x,x3y,x5,y6;
323   ideal I4=y2x,x3y,x5;
324   ideal I5=y2x,yx3,x5,y6;
325   list T=I1,I2,I3,I4,I5;
326   list TT=deleteUnluckyPrimes(T,L);
327   TT;
328
329///////////////////////////////////////////////////////////////////////////////
330proc liftPoly(list T, list L)
331"USAGE:  liftPoly(T,L); T list of polys, L list of primes
332RETURN:  poly p in Q[x] such that p mod L[i]=T[i]
333EXAMPLE: example liftPoly; shows an example
334"
335{
336   poly result;
337   int i;
338   poly p;
339   list TT;
340   number n;
341 
342   number N=L[1];
343   for(i=2;i<=size(L);i++)
344   {
345      N=N*L[i];
346   }
347   while(1)
348   {
349     p=leadmonom(T[1]);
350     for(i=2;i<=size(T);i++)
351     {
352        if(leadmonom(T[i])>p)
353        {
354          p=leadmonom(T[i]);
355        }
356     }
357     if (p==0) {return(result);}
358     for(i=1;i<=size(T);i++)
359     {
360       if(p==leadmonom(T[i]))
361       {
362          TT[i]=leadcoef(T[i]);
363          T[i]=T[i]-lead(T[i]);
364       }
365       else
366       {
367          TT[i]=0;
368       }
369     }
370     n=chineseR(TT,L,N);
371     n=Farey(N,n);
372     result=result+n*p;
373   }
374}
375example
376{ "EXAMPLE:"; echo = 2;
377   ring R = 0,(x,y),dp;
378   list L=32003,181,241,499;
379   list T=x2+7000x+13000,x2+100x+147y+40,x2+120x+191y+10,x2+x+67y+100;
380   liftPoly(T,L);
381}
382 ///////////////////////////////////////////////////////////////////////////////
383proc fareyIdeal(ideal I,list L)
384{
385   poly result,p;
386   int i,j;
387   number n;
388   number N=L[1];
389   for(i=2;i<=size(L);i++)
390   {
391      N=N*L[i];
392   }
393
394   for(i=1;i<=size(I);i++)
395   {
396     p=I[i];
397     result=lead(p);
398     while(1)
399     {
400        if (p==0) {break;}
401        p=p-lead(p);
402        n=Farey(N,leadcoef(p));
403        result=result+n*leadmonom(p);
404     }
405     I[i]=result;
406   }
407   return(I);
408}
409///////////////////////////////////////////////////////////////////////////////
410proc Farey (number P, number N)
411"USAGE:  Farey (P,N); P, N number;
412RETURN:  a rational number a/b such that a/b=N mod P
413         and |a|,|b|<(P/2)^{1/2}
414"
415{
416   if (P<0){P=-P;}
417   if (N<0){N=N+P;}
418   number A,B,C,D,E;
419   E=P;
420   B=1;
421   while (N!=0)
422   {
423        if (2*N^2<P)
424        {           
425           return(N/B);
426        }
427        D=E mod N;
428        C=A-(E-E mod N)/N*B;
429        E=N;
430        N=D;
431        A=B;
432        B=C;
433   }
434   return(0);
435}
436example
437{ "EXAMPLE:"; echo = 2;
438   ring R = 0,x,dp;
439   Farey(32003,12345);
440}
441 ///////////////////////////////////////////////////////////////////////////////
442proc chineseR(list T,list L,number N)
443"USAGE:  chineseR(T,L);
444RETURN: x such that x = T[i] mod L[i]
445NOTE:   chinese remainder theorem
446EXAMPLE:example chineseR; shows an example
447"
448{
449   number x;
450   if(size(L)==1)
451   {
452      x=T[1] mod L[1];
453      return(x);
454   }
455   int i;
456   int n=size(L);
457   list M;
458   for(i=1;i<=n;i++)
459   {
460      M[i]=N/L[i];
461   }
462   list S=eexgcdN(M);
463   for(i=1;i<=n;i++)
464   {
465      x=x+S[i]*M[i]*T[i];
466   }
467   x=x mod N;
468   return(x);
469}
470example
471{ "EXAMPLE:"; echo = 2;
472   ring R = 0,x,dp;
473   chineseR(list(24,15,7),list(2,3,5));
474}
475 
476///////////////////////////////////////////////////////////////////////////////
477proc primeList(int n)
478"USAGE:  primeList(n);
479RETURN: the list of n greatest primes  <= 2134567879   
480EXAMPLE:example primList; shows an example
481"
482{
483  list L;
484  int i;
485  int p=2134567879;
486  for(i=1;i<=n;i++)
487  {
488    L[i]=p;
489    p=prime(p-1);
490  }
491  return(L);
492}
493example
494{ "EXAMPLE:"; echo = 2;
495   list L=primeList(10);
496   size(L);
497   L[size(L)];
498}   
499///////////////////////////////////////////////////////////////////////////////
500/*
501ring r=0,(x,y,z),lp;
502poly s1 = 5x3y2z+3y3x2z+7xy2z2;
503poly s2 = 3xy2z2+x5+11y2z2;
504poly s3 = 4xyz+7x3+12y3+1;
505poly s4 = 3x3-4y3+yz2;
506ideal i =  s1, s2, s3, s4;
507
508ring r=0,(x,y,z),lp;
509poly s1 = 2xy4z2+x3y2z-x2y3z+2xyz2+7y3+7;
510poly s2 = 2x2y4z+x2yz2-xy2z2+2x2yz-12x+12y;
511poly s3 = 2y5z+x2y2z-xy3z-xy3+y4+2y2z;
512poly s4 = 3xy4z3+x2y2z-xy3z+4y3z2+3xyz3+4z2-x+y;
513ideal i =  s1, s2, s3, s4;
514
515ring r=0,(x,y,z),lp;
516poly s1 = 8x2y2 + 5xy3 + 3x3z + x2yz;
517poly s2 = x5 + 2y3z2 + 13y2z3 + 5yz4;
518poly s3 = 8x3 + 12y3 + xz2 + 3;
519poly s4 = 7x2y4 + 18xy3z2 +  y3z3;
520ideal i =  s1, s2, s3, s4;
521
522int n = 6;
523ring r = 0,(x(1..n)),lp;
524ideal i = cyclic(n);
525ring s=0,(x(1..n),t),lp;
526ideal i=imap(r,i);
527i=homog(i,t);
528
529ring r=0,(x(1..4),s),(dp(4),dp);
530poly s1 =1 + s^2*x(1)*x(3) + s^8*x(2)*x(3) + s^19*x(1)*x(2)*x(4);
531poly s2 = x(1) + s^8 *x(1)* x(2)* x(3) + s^19* x(2)* x(4);
532poly s3 = x(2) + s^10*x(3)*x(4) + s^11*x(1)*x(4);
533poly s4 = x(3) + s^4*x(1)*x(2) + s^19*x(1)*x(3)*x(4) +s^24*x(2)*x(3)*x(4);
534poly s5 = x(4) + s^31* x(1)* x(2)* x(3)* x(4);
535ideal i =  s1, s2, s3, s4, s5;
536
537ring r=0,(x,y,z),ds;
538int a =16;
539int b =15;
540int c =4;
541int t =1;
542poly f =x^a+y^b+z^(3*c)+x^(c+2)*y^(c-1)+x^(c-1)*y^(c-1)*z3+x^(c-2)*y^c*(y2+t*x)^2;
543ideal i= jacob(f);
544
545ring r=0,(x,y,z),ds;
546int a =25;
547int b =25;
548int c =5;
549int t =1;
550poly f =x^a+y^b+z^(3*c)+x^(c+2)*y^(c-1)+x^(c-1)*y^(c-1)*z3+x^(c-2)*y^c*(y2+t*x)^2;
551ideal i= jacob(f),f;
552
553ring r=0,(x,y,z),ds;
554int a=10;
555poly f =xyz*(x+y+z)^2 +(x+y+z)^3 +x^a+y^a+z^a;
556ideal i= jacob(f);
557
558ring r=0,(x,y,z),ds;
559int a =6;
560int b =8;
561int c =10;
562int alpha =5;
563int beta= 5;
564int t= 1;
565poly f =x^a+y^b+z^c+x^alpha*y^(beta-5)+x^(alpha-2)*y^(beta-3)+x^(alpha-3)*y^(beta-4)*z^2+x^(alpha-4)*y^(beta-4)*(y^2+t*x)^2;
566ideal i= jacob(f);
567
568*/
Note: See TracBrowser for help on using the repository browser.