source: git/Singular/LIB/modstd.lib @ 96b9fdf

spielwiese
Last change on this file since 96b9fdf was 96b9fdf, checked in by Hans Schönemann <hannes@…>, 17 years ago
*hannes: use intvec git-svn-id: file:///usr/local/Singular/svn/trunk@10112 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 12.5 KB
Line 
1//GP, last modified 23.10.06
2///////////////////////////////////////////////////////////////////////////////
3version="$Id: modstd.lib,v 1.8 2007-06-19 09:11:59 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);  intvec 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  intvec 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=L[1..size(L)-1];
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,intvec L)
268"USAGE:  deleteUnluckyPrimes(T,L);T list of polys, L intvec of primes
269RETURN:  list L,T with T list of polys, L intvec 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        if(j==1) { L=L[2..size(L)]; }
310        else
311        {
312          if (j==size(L)) { L=L[1..size(L)-1]; }
313          else { L=L[1..j-1],L[j+1..size(L)]; }
314        }
315        j--;
316     }
317     j++;
318  }
319  return(list(T,L,lT));
320}
321example
322{ "EXAMPLE:"; echo = 2;
323   list L=2,3,5,7,11;
324   ring r=0,(y,x),Dp;
325   ideal I1=y2x,y6;
326   ideal I2=yx2,y3x,x5,y6;
327   ideal I3=y2x,x3y,x5,y6;
328   ideal I4=y2x,x3y,x5;
329   ideal I5=y2x,yx3,x5,y6;
330   list T=I1,I2,I3,I4,I5;
331   list TT=deleteUnluckyPrimes(T,L);
332   TT;
333}
334///////////////////////////////////////////////////////////////////////////////
335proc liftPoly(list T, intvec L)
336"USAGE:  liftPoly(T,L); T list of polys, L intvec of primes
337RETURN:  poly p in Q[x] such that p mod L[i]=T[i]
338EXAMPLE: example liftPoly; shows an example
339"
340{
341   poly result;
342   int i;
343   poly p;
344   list TT;
345   number n;
346
347   number N=L[1];
348   for(i=2;i<=size(L);i++)
349   {
350      N=N*L[i];
351   }
352   while(1)
353   {
354     p=leadmonom(T[1]);
355     for(i=2;i<=size(T);i++)
356     {
357        if(leadmonom(T[i])>p)
358        {
359          p=leadmonom(T[i]);
360        }
361     }
362     if (p==0) {return(result);}
363     for(i=1;i<=size(T);i++)
364     {
365       if(p==leadmonom(T[i]))
366       {
367          TT[i]=leadcoef(T[i]);
368          T[i]=T[i]-lead(T[i]);
369       }
370       else
371       {
372          TT[i]=0;
373       }
374     }
375     n=chineseR(TT,L,N);
376     n=Farey(N,n);
377     result=result+n*p;
378   }
379}
380example
381{ "EXAMPLE:"; echo = 2;
382   ring R = 0,(x,y),dp;
383   list L=32003,181,241,499;
384   list T=x2+7000x+13000,x2+100x+147y+40,x2+120x+191y+10,x2+x+67y+100;
385   liftPoly(T,L);
386}
387 ///////////////////////////////////////////////////////////////////////////////
388proc fareyIdeal(ideal I,intvec L)
389{
390   poly result,p;
391   int i,j;
392   number n;
393   number N=L[1];
394   for(i=2;i<=size(L);i++)
395   {
396      N=N*L[i];
397   }
398
399   for(i=1;i<=size(I);i++)
400   {
401     p=I[i];
402     result=lead(p);
403     while(1)
404     {
405        if (p==0) {break;}
406        p=p-lead(p);
407        n=Farey(N,leadcoef(p));
408        result=result+n*leadmonom(p);
409     }
410     I[i]=result;
411   }
412   return(I);
413}
414///////////////////////////////////////////////////////////////////////////////
415proc Farey (number P, number N)
416"USAGE:  Farey (P,N); P, N number;
417RETURN:  a rational number a/b such that a/b=N mod P
418         and |a|,|b|<(P/2)^{1/2}
419"
420{
421   if (P<0){P=-P;}
422   if (N<0){N=N+P;}
423   number A,B,C,D,E;
424   E=P;
425   B=1;
426   while (N!=0)
427   {
428        if (2*N^2<P)
429        {
430           return(N/B);
431        }
432        D=E mod N;
433        C=A-(E-E mod N)/N*B;
434        E=N;
435        N=D;
436        A=B;
437        B=C;
438   }
439   return(0);
440}
441example
442{ "EXAMPLE:"; echo = 2;
443   ring R = 0,x,dp;
444   Farey(32003,12345);
445}
446 ///////////////////////////////////////////////////////////////////////////////
447proc chineseR(list T,intvec L,number N)
448"USAGE:  chineseR(T,L,N);
449RETURN: x such that x = T[i] mod L[i], N=product(L[i])
450NOTE:   chinese remainder theorem
451EXAMPLE:example chineseR; shows an example
452"
453{
454   number x;
455   if(size(L)==1)
456   {
457      x=T[1] mod L[1];
458      return(x);
459   }
460   int i;
461   int n=size(L);
462   list M;
463   for(i=1;i<=n;i++)
464   {
465      M[i]=N/L[i];
466   }
467   list S=eexgcdN(M);
468   for(i=1;i<=n;i++)
469   {
470      x=x+S[i]*M[i]*T[i];
471   }
472   x=x mod N;
473   return(x);
474}
475example
476{ "EXAMPLE:"; echo = 2;
477   ring R = 0,x,dp;
478   chineseR(list(24,15,7),intvec(2,3,5),30);
479}
480
481///////////////////////////////////////////////////////////////////////////////
482proc primeList(int n)
483"USAGE:  primeList(n);
484RETURN: the intvec of n greatest primes  <= 2134567879
485EXAMPLE:example primList; shows an example
486"
487{
488  intvec L=0:n;
489  int i;
490  int p=2134567879;
491  for(i=1;i<=n;i++)
492  {
493    L[i]=p;
494    p=prime(p-1);
495  }
496  return(L);
497}
498example
499{ "EXAMPLE:"; echo = 2;
500   intvec L=primeList(10);
501   size(L);
502   L[size(L)];
503}
504///////////////////////////////////////////////////////////////////////////////
505/*
506ring r=0,(x,y,z),lp;
507poly s1 = 5x3y2z+3y3x2z+7xy2z2;
508poly s2 = 3xy2z2+x5+11y2z2;
509poly s3 = 4xyz+7x3+12y3+1;
510poly s4 = 3x3-4y3+yz2;
511ideal i =  s1, s2, s3, s4;
512
513ring r=0,(x,y,z),lp;
514poly s1 = 2xy4z2+x3y2z-x2y3z+2xyz2+7y3+7;
515poly s2 = 2x2y4z+x2yz2-xy2z2+2x2yz-12x+12y;
516poly s3 = 2y5z+x2y2z-xy3z-xy3+y4+2y2z;
517poly s4 = 3xy4z3+x2y2z-xy3z+4y3z2+3xyz3+4z2-x+y;
518ideal i =  s1, s2, s3, s4;
519
520ring r=0,(x,y,z),lp;
521poly s1 = 8x2y2 + 5xy3 + 3x3z + x2yz;
522poly s2 = x5 + 2y3z2 + 13y2z3 + 5yz4;
523poly s3 = 8x3 + 12y3 + xz2 + 3;
524poly s4 = 7x2y4 + 18xy3z2 +  y3z3;
525ideal i =  s1, s2, s3, s4;
526
527int n = 6;
528ring r = 0,(x(1..n)),lp;
529ideal i = cyclic(n);
530ring s=0,(x(1..n),t),lp;
531ideal i=imap(r,i);
532i=homog(i,t);
533
534ring r=0,(x(1..4),s),(dp(4),dp);
535poly s1 =1 + s^2*x(1)*x(3) + s^8*x(2)*x(3) + s^19*x(1)*x(2)*x(4);
536poly s2 = x(1) + s^8 *x(1)* x(2)* x(3) + s^19* x(2)* x(4);
537poly s3 = x(2) + s^10*x(3)*x(4) + s^11*x(1)*x(4);
538poly 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);
539poly s5 = x(4) + s^31* x(1)* x(2)* x(3)* x(4);
540ideal i =  s1, s2, s3, s4, s5;
541
542ring r=0,(x,y,z),ds;
543int a =16;
544int b =15;
545int c =4;
546int t =1;
547poly 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;
548ideal i= jacob(f);
549
550ring r=0,(x,y,z),ds;
551int a =25;
552int b =25;
553int c =5;
554int t =1;
555poly 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;
556ideal i= jacob(f),f;
557
558ring r=0,(x,y,z),ds;
559int a=10;
560poly f =xyz*(x+y+z)^2 +(x+y+z)^3 +x^a+y^a+z^a;
561ideal i= jacob(f);
562
563ring r=0,(x,y,z),ds;
564int a =6;
565int b =8;
566int c =10;
567int alpha =5;
568int beta= 5;
569int t= 1;
570poly 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;
571ideal i= jacob(f);
572
573*/
Note: See TracBrowser for help on using the repository browser.