source: git/Singular/LIB/GND.lib @ 61fbaf

spielwiese
Last change on this file since 61fbaf was 82e5a3, checked in by Hans Schoenemann <hannes@…>, 3 years ago
more ringlist -> ring_list
  • Property mode set to 100644
File size: 28.4 KB
Line 
1////////////////////////////////////////////////////////////////////////////////
2version="version GND.lib 4.1.2.0 Feb_2019 ";
3category="Commutative Algebra";
4
5info="
6LIBRARY   :  GND.lib
7AUTHOR    :  Adrian Popescu, popescu@mathematik.uni-kl.de
8
9OVERVIEW  :
10A method to compute the General Neron Desingularization in the frame of
11one dimensional local domains
12
13REFERENCES:
14@* [1] A. Popescu, D. Popescu, \"A method to compute the General Neron Desingularization in the frame of one dimensional local domains\",  arxiv.org/abs/1508.05511
15
16KEYWORDS: desingularization; general neron.
17
18PROCEDURES:
19 desingularization()
20";
21
22///////////////////////////////////////////////////////////////////////////////////////////
23LIB "primdec.lib";
24LIB "linalg.lib";
25LIB "polylib.lib";
26///////////////////////////////////////////////////////////////////////////////////////////
27
28static proc deltaf(ideal i,int r,int howmanyy)
29"USAGE: computes delta_f = ideal generated by the r x r minors of the jacobian of i"
30{
31    matrix drond = jacob(i);
32    matrix drond2[size(i)][howmanyy] = drond[1..size(i),(nvars(basering)-howmanyy+1)..(nvars(basering))];
33    ideal d = minor(drond2,r);
34    return(d);
35}
36
37///////////////////////////////////////////////////////////////////////////////////////////
38
39static proc comb(int n, int r,int start,list l,list tot)
40"USAGE: returns combinations of n taken r, and saves it in tot and returns tot"
41{
42  int i;
43  if(size(l) == r)
44  {
45    tot[size(tot)+1] = l;
46    return(tot);
47  }
48  for(i=start+1;i<=n;i++)
49  {
50    list ll = l + list(i);
51    tot = comb(n,r,i,ll,tot);
52    kill ll;
53  }
54  return(tot);
55}
56
57///////////////////////////////////////////////////////////////////////////////////////////
58static proc H(ideal I, int howmanyy,ideal xid)
59"USAGE: returns H_{B/A} = radical(...)"
60{
61  I = std(I);
62  xid = std(xid);
63  list HBA;
64  int n=size(I);
65  int r,i,j,kk,found;
66  list total;
67  for(r = 1;r<=n && r<=howmanyy;r++)
68  {
69    list c;
70    total = total + comb(n,r,0,c,total);
71    kill c;
72  }
73  for(i = 1;i<=size(total);i++)
74  {
75    ideal f;
76    for(j = 1; j<= size(total[i]);j++)
77    {
78      f = f + I[total[i][j]];
79    }
80    ideal fx = f;
81    for(kk = 1;kk<=nvars(basering)-howmanyy;kk++)
82    {
83      fx = subst(fx,var(kk),1);
84    }
85    fx = fx + 0;
86    found = 0;
87    for(kk=1;(kk<=size(fx)) && (found == 0);kk++)
88    {
89      if(deg(fx[kk])>0)
90      {
91        found =1;
92      }
93    }
94    kill fx;
95    if((size(f)<=(howmanyy)) && found == 1)
96    {
97      list term;
98      attrib(xid,"isSB",1);
99      term[1] = reduce(quotient(f+xid,I),xid);
100      term[2] = deltaf(f,size(f),howmanyy);
101      term[3] = f;
102      term[4] = total[i];
103      if((term[1]!= 0) && (term[2] != 0) )
104      {
105        HBA[size(HBA)+1] = term;
106      }
107      kill term;
108    }
109    kill f;
110  }
111  //HBA = radical(HBA);
112  return(HBA);
113}
114
115///////////////////////////////////////////////////////////////////////////////////////////
116
117
118static proc extractP(list wP, ideal I)
119"USAGE: choose P from wP and save it's properties"
120{
121  list P;
122  int i,j,k;
123  poly f;
124  int found = 0;
125  for(i=1;(i<=size(wP)) && (found == 0);i++)
126  {
127    for(j=1;j<=size(wP[i][1]) && (found == 0);j++)
128    {
129      for(k = 1;k<=size(wP[i][2]) && (found == 0);k++)
130      {
131        f = wP[i][1][j] * wP[i][2][k];
132        /*if(size(std(f)) > 1)
133        {
134          //"Is this possible?";~;
135        }
136        f = std(f)[1];*/
137        if((f != 0) && (std(reduce(f,std(I))) != 0))
138        {
139          P[1] = f;
140          P[2] = wP[i][1][j];
141          P[3] = wP[i][2][k];
142          P[4] = wP[i][3];
143          P[5] = wP[i][4];
144          found = 1;
145        }
146      }
147    }
148  }
149  if(size(P) <1)
150  {
151    ERROR("No suitable P was found");
152  }
153  return(P);
154}
155
156///////////////////////////////////////////////////////////////////////////////////////////
157
158static proc isinList(string f, list L)
159"USAGE: tests if string f is in the list L"
160{
161  int i;
162  for(i=1;i<=size(L);i++)
163  {
164    if(L[i] == f)
165    {
166      return(1);
167    }
168  }
169  return(0);
170}
171
172///////////////////////////////////////////////////////////////////////////////////////////
173
174static proc findmc(ideal I,ideal m)
175"USAGE: finds the smallest c s.t. m^c is included in I"
176{
177  int i=1;
178  while(1)
179  {
180    if(std(reduce(I,std(m^i))) != 0)
181    {
182      return(i-1);
183    }
184    i++;
185  }
186}
187
188///////////////////////////////////////////////////////////////////////////////////////////
189
190static proc finddz(poly vp,int nra,int nrx)
191"USAGE: finds d and z"
192{
193    int i,j,k;
194    ideal x;
195    string xs;
196    //string as;
197    /*
198    for(i=1;i<=nra;i++)
199    {
200      as = as + ","+string(var(i));
201    }
202    as = as[2..size(as)];
203    */
204    for(i=1;i<=nrx;i++)
205    {
206      x[i] = var(i);
207      xs = xs + ","+string(var(i));
208    }
209    xs = xs[2..size(xs)];
210    /*
211    if(std(reduce(variables(vp), std(x))) == 0)
212    {
213      return(list(vp,poly(1)));
214    }
215    */
216    int c = findmc(vp,x);
217    ideal mc = x^c;
218    for(i=1; i<=ncols(mc);i++)
219    {
220      if(std(reduce(variables(mc[i]), std(x))) != 0)
221      {
222        mc[i] = 0;
223      }
224    }
225    mc = mc+0;
226    ideal mc2 = mc;
227    for(i=1;i<=ncols(mc2);i++)
228    {
229      if(std(reduce(mc2[i],std(vp))) != 0)
230      {
231        mc2[i] = 0;
232      }
233    }
234    mc2 = mc2 + 0;
235    if(mc2[1] != 0)
236    {
237    for(i=1;i<=ncols(mc2);i++)
238      {
239        if(mc2[i]/vp != 0)
240        {
241          return(list(mc2[i],mc2[i]/vp));
242        }
243      }
244      ideal vpid = std(vp);
245      for(i=1;i<=ncols(mc2);i++)
246      {
247        for(j=1;j<=ncols(vpid);j++)
248        {
249          if(vpid[j] != 0)
250          {
251            if(mc2[i]/vpid[j] != 0)
252            {
253              return(list(mc2[i],mc2[i]/vpid[j]));
254            }
255          }
256        }
257      }
258    }
259    else
260    {
261      ideal vpid = std(vp);
262      for(i=1;i<=ncols(mc);i++)
263      {
264        for(j=1;j<=ncols(vpid);j++)
265        {
266          if(vpid[j] != 0)
267          {
268            if(mc[i]/vpid[j] != 0)
269            {
270              return(list(mc[i],mc[i]/vpid[j]));
271            }
272          }
273        }
274      }
275    }
276    return(list(0,0));
277 }
278
279///////////////////////////////////////////////////////////////////////////////////////////
280
281static proc inY(poly p,int nrx,int nry)
282"USAGE: tests if poly p contains just the variables var(nrx+1),...,var(nry)"
283{
284  int i;
285  ideal y;
286  for(i=1;i<=nry;i++)
287  {
288    y[size(y)+1] = var(nrx+i);
289  }
290  y = std(y);
291  if(std(reduce(variables(p),y)) == 0)
292  {
293    return(1);
294  }
295  return(0);
296}
297
298///////////////////////////////////////////////////////////////////////////////////////////
299
300static proc myjet(ideal p, int bound,string param,string variab)
301"USAGE: computes the jet in the right ring (instead of switching it on and on)"
302{
303    def r = basering;
304    def R2 = ring(crl(param,variab,"ds"));
305    setring(R2);
306    ideal p = imap(r,p);
307    for(int i=1;i<=ncols(p);i++)
308    {
309      p[i] = jet(p[i],bound);
310    }
311    setring r;
312    return(imap(R2,p));
313}
314
315///////////////////////////////////////////////////////////////////////////////////////////
316
317proc invp(poly p, int bound,list param,list variab)
318"USAGE: computes the inverse in Q(param)[variab]"
319{
320    def r = basering;
321    def R2 = ring(crl(param,variab,"ds"));
322    setring(R2);
323    poly p = imap(r,p);
324    if(bound<=0)
325    {
326      ERROR("My inverse : negative bound in the inverse");
327    }
328    if(p == 0)
329    {
330      ERROR("My inverse : p is 0");
331    }
332    poly original,res;
333    original = p;
334    if(ord(p) != 0)
335    {
336      ERROR("My inverse : the power series is not a unit.");
337    }
338    poly q = 1/p[1];
339    res = q;
340    p = q * (p[1] - jet(p,bound));
341    poly s = p;
342    while(p != 0)
343    {
344      res = res + q * p;
345      p = jet(p*s,bound);
346    }
347    //res = division(poly(1),p,bound);
348
349    //TEST
350    if(jet(original*res,bound) != poly(1))
351    {
352      ERROR("Myinverse does not work properly.");
353    }
354    setring r;
355    poly res = imap(R2,res);
356    return(res);
357}
358
359///////////////////////////////////////////////////////////////////////////////////////////
360
361static proc findminor(int y, poly mr, ideal f)
362"USAGE: returns the entries from which the minor comes from"
363{
364  int n = ncols(f);
365  int max = y;
366  if(n > y)
367  {
368    max = n;
369  }
370  matrix drond = jacob(f);
371  matrix M[n][y] = drond[1..n,(nvars(basering)-y+1)..(nvars(basering))];
372  list resf,resy;
373  list total2;
374  for(int r = 1;r<=max;r++)
375  {
376    list c;
377    total2 = total2 + comb(max,r,0,c,total2);
378    kill c;
379  }
380  int i,j;
381  i=1;
382  while(i<=size(total2))
383  {
384    if(size(total2[i]) == n)
385      {break;}
386    i=i+1;
387  }
388  while(size(total2[i]) == n)
389  {
390    if(total2[i][n] <= n)
391    {
392      def dummy = total2[i];
393      resf[size(resf)+1] = intvec(dummy[1..size(total2[i])]);
394      kill dummy;
395    }
396    if(total2[i][n] <= y)
397    {
398      def dummy = total2[i];
399      resy[size(resy)+1] = intvec(dummy[1..size(total2[i])]);
400      kill dummy;
401    }
402    i = i+1;
403  }
404  matrix m[n][n];
405  for(i = 1; i<=size(resf); i++)
406  {
407    for(j = 1; j<=size(resy); j++)
408    {
409      m = M[resf[i],resy[j]];
410      if(det(m) == mr || det(m) == -mr)
411      {
412        return(resf[i],resy[j]);
413      }
414    }
415  }
416  ERROR("No such minor found!");
417}
418
419///////////////////////////////////////////////////////////////////////////////////////////
420
421
422proc findnewvar(string Z)
423"USAGE: Finds new unused variable Z,Z1,Z2,..."
424{
425  string S = "," + charstr(basering) + "," + varstr(basering) + ",";
426  Z = "," + Z + ",";
427  if(find(S,Z) == 0)
428  {
429    return(Z[2..size(Z)-1]);
430  }
431  int i=1;
432  while(find(S,Z+"("+string(i)+")") == 1)
433  {
434    i++;
435  }
436  Z = string(Z[2..size(Z)-1])+"("+string(i)+")";
437  return(Z);
438}
439
440///////////////////////////////////////////////////////////////////////////////////////////
441
442static proc mylcm(ideal id,list asl)
443"USAGE: computes the lcm of these numbers"
444{
445  int i;
446  def r1 = basering;
447  def r2 = ring(crl(list(),asl,"dp"));
448  setring(r2);
449  ideal id = imap(r1,id);
450  poly lcmi=1;
451  for(i=1;i<=size(id);i++)
452  {
453    lcmi = lcm(lcmi,id[i]);
454  }
455  setring r1;
456  return(imap(r2,lcmi));
457}
458
459///////////////////////////////////////////////////////////////////////////////////////////
460
461static proc mysubstpoly(poly p,int which,poly what,list #)
462"USAGE: substitutes parameters also for denominators (what is just a number)"
463{
464  if(size(#)!= 1)
465  {
466    return(p);
467  }
468  if(#[1]!= "par" && #[1] != "var")
469  {
470    return(p);
471  }
472  number lcm = denominator(content(p));
473  p = p*lcm;
474  if(#[1] == "par")
475  {
476    p = subst(p,par(which),what);
477    lcm = leadcoef(subst(lcm,par(which),what));
478  }
479  if(#[1] == "var")
480  {
481    p = subst(p, var(which), what);
482    lcm = leadcoef(subst(lcm,var(which),what));
483  }
484  p = p / lcm;
485  return(p);
486}
487
488///////////////////////////////////////////////////////////////////////////////////////////
489
490static proc mysubst(ideal i,int which,poly what,list #)
491"USAGE: substitutes parameters also for denominators (what is just a number)"
492{
493  if(size(#)!= 1)
494  {
495    return(i);
496  }
497  if(#[1]!= "par" && #[1] != "var")
498  {
499    return(i);
500  }
501  for(int j = 1; j<=size(i);j++)
502  {
503    i[j] = mysubstpoly(i[j], which, what, #);
504  }
505  return(i);
506}
507
508///////////////////////////////////////////////////////////////////////////////////////////
509
510static proc crl(list param, list variab, string order)
511"USAGE: construct the desired ringlist"
512{
513  list l;
514  if(size(param)==0)
515  {
516    l[1] = 0;
517  }
518  else
519  {
520    l[1] = list(0,param,list(list("lp",1)),ideal(0));
521  }
522  l[2] = variab;
523  l[3] = list(list(order,1),list("C",0));
524  l[4] = ideal(0);
525  return(l);
526}
527
528///////////////////////////////////////////////////////////////////////////////////////////
529
530proc desingularization(all, int nra, int nrx, int nry, ideal xid, ideal yid, ideal aid, ideal f,
531                        list #)
532"USAGE : Returns as output a General Neron Desingularization as in the Paper http://arxiv.org/abs/1508.05511"
533{
534
535//            First we construct everything
536
537  //def oldoption = option(get);
538  //option(notWarnSB);
539  if(ncols(f)!=nry || nra<0 || nrx<0 || nry<0 || nra+nrx+nry!=nvars(all))
540  {
541    ERROR("Input is wrong");
542  }
543  int computeker = 1;
544  int debug = 0;
545  if(size(#) > 0)
546  {
547    if(isinList("injective",#))
548    {
549      computeker = 0;
550    }
551    if(isinList("debug",#))
552    {
553      debug = 1;
554    }
555  }
556  string as,xs,ys;
557  list asl,xsl,ysl;
558  ideal a,x,y;
559  int i,j,k;
560  if(nra != 0)
561  {
562    as = string(var(1));
563    asl[1] = string(var(1));
564    a[1] = var(1);
565    for(i=2;i<=nra;i++)
566    {
567      as = as+","+string(var(i));
568      a[ncols(a)+1] = var(i);
569      asl[size(asl)+1] = string(var(i));
570    }
571  }
572  //as;
573  if(nrx!=0)
574  {
575    xs = string(var(nra+1));
576    x[1] = var(nra+1);
577    xsl[1] = string(var(nra+1));
578    for(i=nra+2;i<=nra+nrx;i++)
579    {
580      xs = xs+","+string(var(i));
581      x[ncols(x)+1] = var(i);
582      xsl[size(xsl)+1] = string(var(i));
583    }
584  }
585  //xs;
586  if(nry!=0)
587  {
588    ys = string(var(nra+nrx+1));
589    y[1] = var(nra+nrx+1);
590    ysl[1] = string(var(nra+nrx+1));
591    for(i=nra+nrx+2;i<=nra+nrx+nry;i++)
592    {
593      ys = ys+","+string(var(i));
594      y[ncols(y)+1] = var(i);
595      ysl[size(ysl)+1] = string(var(i));
596    }
597  }
598  //ys;
599  def Abase = ring(crl(list(),xsl,"dp"));
600  setring Abase;
601  qring A = std(imap(all,xid));
602  def Bbase = ring(crl(xsl,ysl,"dp"));
603  setring Bbase;
604  ideal yid = imap(all, yid);
605  i = ncols(yid);
606  yid = std(yid);
607  if(ncols(yid)!=i)
608  {
609    if(debug)
610    {
611      "yid is not a SB.";
612      "We change yid with its SB:";
613      yid;
614    }
615  }
616  qring B = yid;
617  def Bfalsebase = ring(crl(list(),xsl+ysl,"dp"));
618  setring(Bfalsebase);
619  qring Bfalse = std(imap(all,yid));
620  if(nra!=0)
621  {
622    def Apreal = ring(crl(asl,xsl,"dp"));
623    def Apbase = ring(crl(list(),asl+xsl,"dp"));
624    setring Apbase;
625    qring Ap = std(imap(all,xid)+imap(all,aid));
626  }
627  else
628  {
629    def Apbase = ring(crl(list(),xsl,"dp"));
630    setring Apbase;
631    qring Ap = std(imap(all,xid));
632  }
633  ideal vid;
634  for(i=1; i<=nrx; i++)
635  {
636    vid[ncols(vid)+1] = var(nra+i);
637  }
638  vid = vid + imap(all,f);
639  map vBfalse = Bfalse,vid;
640
641//            We start with the reduction to the case...
642
643  setring Bfalse;
644  if(computeker == 1)
645  {
646    if(debug)
647    {
648      "Computing the kernel:";
649    }
650    def ker = kernel(Ap, vBfalse);
651    if(debug)
652    {
653      ker;
654    }
655    Bfalse = std(ker);
656  }
657  else
658  {
659    if(debug)
660    {
661      "We do not compute the kernel since of \"injective\" argument in the input";
662    }
663  }
664  ideal I = ring_list(Bfalse)[4];
665  setring Bfalsebase;
666  list whereP = H(imap(Bfalse,I),nry,imap(all,xid));
667  if(debug)
668  {
669    //whereP[1];~;
670  }
671  def Plist = extractP(whereP,imap(Bfalse,I));
672  setring Bfalse;
673  def Plist = imap(Bfalsebase,Plist);
674  if(debug)
675  {
676    "This is Plist:";Plist;
677  }
678  list whichminor = findminor(nry, Plist[3], Plist[4]);
679  if(debug)
680  {
681    "The minor comes from these vars:";whichminor;
682  }
683  poly Pprim = Plist[1];
684  if(debug)
685  {
686    "P' = ",Pprim;
687  }
688  setring Ap;
689  poly vpprim = vBfalse(Pprim);
690  setring Apreal;
691  if(debug)
692  {
693    "v(P'):";imap(Ap,vpprim);
694  }
695  setring Apreal;
696  def dz = finddz(imap(Ap,vpprim),nra,nrx);
697  int secondstrategy = 0;
698  if(dz[1] == 0 && dz[2] == 0)
699  {
700    if(debug)
701    {
702      "The first strategy to find d and z failed";
703      "Try the second strategy (this may take longer)";
704    }
705    setring all;
706    secondstrategy = 1;
707    poly M = imap(Bfalse,Plist)[3];
708    ideal ff;
709    for(i=1;i<=nra+nrx;i++)
710    {
711      ff[i] = var(i);
712    }
713    ff = ff + f;
714    map v = basering,ff;
715    // It should be enough to consider the minor I have found.
716    int found = 0;
717    //ideal mino = minor(jacob(yid),min(nrows(jacob(yid)),ncols(jacob(yid))));
718    //mino;~;
719    //for(k = 1;size(mino);i++)
720    //{
721      //M = mino[k];
722      for(i=1;found == 0;i++)
723      {
724        for(j=1;j<=nrx && found == 0;j++)
725        {
726          a = var(nra+j);
727          if(reduce(a^i,std(v(M) + a^(2*i))) == 0)
728          {
729            dz[1] = a[1]^i;
730            dz[2] = v(M) /dz[1];
731            //z is actually 1/z so we have to construct it's invers
732            dz[2] = 1/leadcoef(dz[2])*invp(dz[2]/leadcoef(dz[2]),3*i,asl,xsl);
733            found = 1;
734          }
735        }
736      }
737    //}
738  }
739  poly d = dz[1];
740  poly z = dz[2];
741  // We have to truncate it:
742  z  = reduce(jet(z,deg(d^3)),std(reduce(d^3, std(imap(all,xid)))));
743  if(secondstrategy == 1)
744  {
745    setring Apreal;
746    def d = imap(all, d);
747    def z = imap(all, z);
748    setring all;
749  }
750  if(z == 0)
751  {
752     ERROR("Something went wrong in finddz since z=0");
753  }
754  if(debug)
755  {
756    "d' =",d;
757    "z =",z;
758  }
759  ideal denz;
760  for(i=1;i<=size(z);i++)
761  {
762    denz[size(denz)+1] = denominator(leadcoef(z[i]));
763  }
764  def den = mylcm(denz,asl);
765  z = z * den;
766  int newAptest = 0;
767  if(den != 1)
768  {
769    newAptest = 1;
770    string aa = "a";
771    list newpar;
772    newpar[1] = string(findnewvar(aa));
773    as = as + "," + findnewvar(aa);
774    nra = nra + 1;
775    def newApbase = ring(crl(list(),asl+xsl,"dp"));
776    setring newApbase;
777    poly p = var(nra)*imap(Apreal,den)-1;
778    qring newAp = std(imap(all,xid)+imap(all,aid)+p);
779    def d = imap(Apreal,d);
780    def z = imap(Apreal,z)*var(nra);
781    if(debug)
782    {
783      "new z = ",z;
784    }
785    def vid = imap(Ap,vid);
786    Apbase = newApbase;
787    Ap = newAp;
788    def newApreal = ring(crl(asl,xsl,"dp"));
789    setring newApreal;
790    def z = imap(Ap,z);
791    def d = imap(Apreal,d);
792    def den = imap(Apreal,den);
793    Apreal = newApreal;
794    def newaring = ring(crl(list(),newpar,"dp"));
795    setring newaring;
796  }
797  else
798  {
799    setring Ap;
800    def d = imap(Apreal,d);
801    setring Apreal;
802  }
803
804
805//            Construct B1 = B[Z]/d-pz and the maps
806
807  string Z = "Z";
808  list newvar;
809  newvar[1] = string(findnewvar(Z));
810  def newvarring = ring(crl(list(),newvar,"dp"));
811  def B1base = Bbase+newvarring;
812  def B1 = B+newvarring;
813  def B1falsebase = Bfalsebase + newvarring;
814  def B1false2 = Bfalse + newvarring;
815  setring B1false2;
816  poly frp1 = -imap(Apreal,d)+imap(Bfalse,Pprim)*var(nvars(B1false2));
817  qring B1false = std(fetch(B1false2,frp1) + ring_list(B1false2)[4]);
818  ideal B1falseideal = ring_list(B1false)[4];
819  setring Apreal;
820  def vid = imap(Ap,vid);
821  vid[ncols(vid)+1] = z;
822  setring B1false;
823  //If P is constant (i.e. no Y), than I can work with d = d' = P = P'
824  poly Pconst = reduce(imap(Bfalse,Pprim),std(imap(all,y)));
825
826  if(Pconst == imap(Bfalse,Pprim))
827  {
828    poly P =Pconst;
829    //This is the case if P is constant
830    if(debug)
831    {
832      "P is constant (no Y), so d = d' = P = P'";
833      "P = P' = ",P;
834    }
835    setring Apreal;
836    def dprim = imap(B1false,P);
837    d = dprim;
838  }
839  else
840  {
841    poly P = imap(Bfalse,Pprim)^2*var(nvars(B1false))^2;
842    if(debug)
843    {
844      "P = P'^2 * Z^2";P;
845    }
846    setring Apreal;
847    def dprim = d;
848    d = d^2;
849  }
850  if(debug)
851  {
852      "d = ",d;
853  }
854  int c = deg(d);
855  int s = deg(d^3);
856  ideal vidjet;
857  if(debug)
858  {
859    //vid;
860  }
861  for(i=1;i<=ncols(vid);i++)
862  {
863    vidjet[size(vidjet)+1] = reduce(jet(vid[i],s),std(reduce(d^3, std(imap(all,xid)))));
864  }
865  if(debug)
866  {
867    "vidjet:";vidjet;
868  }
869  map vBfalse = B1false,vidjet;
870  poly Py = vBfalse(P);
871  if(debug)
872  {
873      "Py =",Py;
874  }
875
876//            Prepare and build C, D and S
877
878  setring Apreal;
879  ideal lam;
880  poly pp;
881  for(i=1;i<=size(vidjet);i++)
882  {
883    pp = vidjet[i];
884    while(pp != 0)
885    {
886        if(leadcoef(vidjet[i]) != 1)
887        {
888            lam[size(lam)+1] = denominator(leadcoef(pp));
889            lam[size(lam)+1] = numerator(leadcoef(pp));
890        }
891        pp = pp-lead(pp);
892    }
893  }
894  setring Ap;
895  def lam = imap(Apreal,lam);
896  list newas;
897  int howmanyfinala;
898  if(size(lam) == 0)
899  {
900    def Cbase = ring(crl(list(),xsl,"dp"));
901    setring Cbase;
902  }
903  else
904  {
905    ideal varlam = variables(lam);
906    howmanyfinala = ncols(varlam);
907    for(i=1;i<=ncols(varlam);i++)
908    {
909      newas[size(newas)+1] = string(varlam[i]);
910    }
911    def Cbase = ring(crl(list(),newas+xsl,"dp"));
912    setring Cbase;
913  }
914  setring Ap;
915  def aid = imap(all,aid);
916  if(newAptest == 1)
917  {
918      ideal newaid = reduce(aid+imap(newApbase,p),std(varlam));
919  }
920  else
921  {
922    ideal newaid = reduce(aid,std(varlam));
923  }
924  for(i=1;i<=ncols(newaid)-1;i++)
925  {
926      if(newaid[i]!=0 )
927      {
928          newaid[i] = aid[i];
929      }
930  }
931  if(newAptest == 1)
932  {
933    newaid[size(newaid)+1] = imap(newApbase,p);
934  }
935  newaid = newaid+0;
936  setring Cbase;
937  qring C = std(imap(Ap,newaid) + imap(all,xid)+imap(Apreal,d)^3);
938  if(debug)
939  {
940      "This is C:";C;
941  }
942  setring Cbase;
943  qring D =  std(imap(Ap,newaid) + imap(all,xid));
944  if(debug)
945  {
946      "This is D:";D;
947  }
948  def vid = imap(Apreal,vid);
949  ideal vidjet = imap(Apreal,vidjet);
950
951
952//            Build the nice matrix
953
954  setring B1;
955  ideal wy,wf;
956  ideal I = imap(Bfalse,I);
957  for(i=1;i<=size(whichminor[1]);i++)
958  {
959    wf[size(wf)+1] = I[whichminor[1][i]];
960  }
961  for(i=1;i<=size(whichminor[2]);i++)
962  {
963    wy[size(wy)+1] = var(whichminor[2][i]);
964  }
965  wy = reduce(std(reduce(maxideal(1),std(var(nvars(B1))))),std(wy))+0;
966  poly frp1 = -imap(Apreal,d)+imap(Bfalse,Pprim)*var(nvars(B1));
967  ideal PMf = wf + wy + frp1;
968  matrix PM[size(PMf)][nvars(B1)];
969  PM = jacob(PMf);
970  matrix adj = adjoint(PM);
971  matrix G = imap(Bfalse,Plist)[2]*var(nvars(B1))^2*adj;
972  def seeGring = ring(crl(list(),list(string(ys[1])+string(nvars(B1))),"dp"));
973  def seeG = B1 + seeGring;
974  setring seeG;
975  matrix G =  imap(Bfalse,Plist)[2]*var(nvars(seeG))^2*imap(B1,adj);
976  matrix H = imap(B1,PM);
977  H = subst(H,var(nvars(seeG)-1),var(nvars(seeG)));
978  G = subst(G,var(nvars(seeG)-1),var(nvars(seeG)));
979  if(debug)
980  {
981    "This is the minor bordered matrix (H)";print(H);
982  }
983  if(debug)
984  {
985    "This is G: ";print(G);
986    G;
987  }
988  setring D;
989  def d = imap(Apreal,d);
990  def Py = imap(Apreal,Py);
991  poly ss = Py/d;
992  ideal ssid = std(ss);
993  for(i=1;i<=size(ssid);i++)
994  {
995    if(size(ssid[i]) < size(ss))
996    {
997      ss = ssid[i];
998    }
999  }
1000  //  Recall that a was a quotient
1001  /*if(newAptest == 1)
1002  {
1003    ss = reduce(ss, imap(Apreal, z)*imap(Apreal, den)-1);
1004  }*/
1005  if(debug)
1006  {
1007    if(newAptest == 1)
1008    {
1009      "s =",reduce(ss, std(var(nvars(basering)-nrx)*imap(Apreal, den)-1));
1010      //"s =",subst(ss, imap(Apreal, z),1/imap(Apreal, den));
1011    }
1012    else
1013    {
1014      "s =",ss;
1015    }
1016  }
1017  ideal dquot = ring_list(D)[4];
1018
1019//            Start constructing E
1020
1021  list ts,yz;
1022  yz = ysl + list(string(ys[1]) + string(nry+1));
1023  string t = "T";
1024  def newvart = findnewvar(t);
1025  for(i=1;i<=nry+1;i++)
1026  {
1027    ts[size(ts)+1] = newvart + string(i);
1028  }
1029  def Efalsebase = ring(crl(list(),newas+xsl+yz+ts,"dp"));
1030  setring Efalsebase;
1031  qring Efalse = std(imap(D,dquot));
1032  def f = imap(Bfalse,Plist)[4];
1033  f[size(f)+1] = -imap(Apreal,dprim)+imap(Bfalse,Pprim)*var(nvars(Efalsebase)-nry-1);
1034  def vidjet = imap(Apreal,vidjet);
1035  vidjet = vidjet[nrx+1..size(vidjet)];
1036  ideal id;
1037  for(i=1;i<=nvars(D);i++)
1038  {
1039    id[i] = var(i);
1040  }
1041  for(i=1;i<=size(vidjet);i++)
1042  {
1043    id[ncols(id)+1] = vidjet[i];
1044  }
1045  map mapvidjet = Efalse,id;
1046  f = mapvidjet(f);
1047  ideal cc;
1048  for(i=1;i<=ncols(f);i++)
1049  {
1050    cc[i] = f[i] / (imap(Ap,d)^2);
1051  }
1052  if(debug)
1053  {
1054      "This is cc";cc;
1055  }
1056  def E = ring(crl(newas+xsl,yz+ts,"dp"));
1057  setring E;
1058  def d = imap(D,d);
1059  number ss = leadcoef(imap(D,ss));
1060  def G = imap(seeG,G);
1061
1062  def vidjet = imap(Apreal,vidjet);
1063  map mapvidjet = E,vidjet[nrx+1..ncols(vidjet)];
1064  G = mapvidjet(G);
1065  execute("matrix T[nry+1][1] = "+string(ts)+";");
1066  execute("ideal tid = "+string(ts)+";");
1067  matrix ymy[nry+1][1];
1068  for(i=1;i<=nry+1;i++)
1069  {
1070    ymy[i,1] = var(i)-vidjet[i+nrx];
1071  }
1072  //ymy;
1073  //G;
1074  matrix hh = ss*ymy-d*G*T;
1075  ideal h;
1076  for(i=1;i<=nry+1;i++)
1077  {
1078    h[size(h)+1] = hh[i,1];
1079  }
1080  //if(debug)
1081  if(1)
1082  {
1083    if(newAptest == 1)
1084    {
1085      "h = ";mysubst(h, npars(basering)-nrx,1/imap(Apreal, den),"par");
1086    }
1087    else
1088    {
1089      "h = ";h;
1090    }
1091  }
1092  setring Apreal;
1093  /*
1094  matrix eps[nry+1][1];
1095  //def vid = imap(Ap,vid);
1096  ideal dummy;
1097  ideal d2 = std(d^2);
1098  for(i=1;i<=nry;i++)
1099  {
1100    dummy = std(vid[i+nrx]-vidjet[i+nrx]);
1101    for(j=1;j<=ncols(dummy);j++)
1102    {
1103      for(k=1;k<=size(d2);k++)
1104      {
1105        if(dummy[j] / d2[k] != 0)
1106        {
1107          eps[i,1] = dummy[j] / d2[k];
1108        }
1109      }
1110    }
1111    eps;
1112    if(eps[i,1] == 0 && vid[i+nrx] != vidjet[i+nrx])
1113    {
1114      ERROR("problem appeared at the construction of eps");
1115    }
1116  }
1117  if(debug)
1118  {
1119    "eps = ";eps;
1120  }
1121
1122  setring E;
1123  def eps = imap(Apreal,eps);
1124  def HH = imap(B1,PM);
1125  HH = mapvidjet(HH);
1126  def tm = HH * eps;
1127  ideal tid;
1128  for(i=1;i<=nry+1;i++)
1129  {
1130    tid[i] = tm[i,1];
1131  }
1132  if(debug)
1133  {
1134    "This is t:";tid;
1135  }
1136  */
1137  setring E;
1138  def f = imap(Bfalse,Plist)[4];
1139  f[size(f)+1] = -d+imap(Bfalse,Pprim)*var(nry+1);
1140  int m = deg(f[1]);
1141  for(i=2;i<=size(f);i++)
1142  {
1143    if(deg(f[i])>m)
1144    {
1145      m = deg(f[i]);
1146    }
1147  }
1148  if(debug)
1149  {
1150    "m =",m;
1151  }
1152  poly ff,ffx,fd;
1153  number ssm;
1154  ideal QT;
1155  ssm = ss^m;
1156  if(debug)
1157  {
1158    if(newAptest == 1)
1159    {
1160      "s^m =";mysubst(ssm, npars(basering)-nrx,1/imap(Apreal, den),"par");
1161    }
1162    else
1163    {
1164      "s^m =",ssm;
1165    }
1166  }
1167  poly ssmd2 = ssm*d^2;
1168  for(i=1;i<=size(f);i++)
1169  {
1170    ff = f[i];
1171    ffx = mapvidjet(ff);
1172    ffx = ssm*(ff-ffx);
1173    for(j=1;j<=nry+1;j++)
1174    {
1175      fd = diff(ff,var(j));
1176      fd = mapvidjet(fd);
1177      ffx = ffx - (ssm)*(var(j)-vidjet[j+nrx])*fd;
1178    }
1179    attrib(h,"isSB",1);
1180    ffx = reduce(ffx,h);
1181    QT[i] = ffx / ssmd2;
1182  }
1183  if(debug)
1184  {
1185    if(newAptest == 1)
1186    {
1187      "QT =";mysubst(QT, npars(basering)-nrx,1/imap(Apreal, den),"par");
1188    }
1189    else
1190    {
1191      "QT =";QT;
1192    }
1193    "f =";f;
1194  }
1195  ideal cc = imap(Efalse,cc);
1196  ideal g;
1197  for(i=1;i<=size(f);i++)
1198  {
1199    g[i] = ssm * cc[i] + ssm * var(nry+1+i) + QT[i];
1200  }
1201  if(debug)
1202  {
1203      "g = ";
1204      if(newAptest == 1)
1205      {
1206        mysubst(g, npars(basering)-nrx,1/imap(Apreal, den),"par");
1207        //reduce(mysubst(g, npars(basering)-nrx,1/imap(Apreal, den),"par"),std(x2^6,x1^4));
1208      }
1209      else
1210      {
1211        g;
1212      }
1213  }
1214  //  Activate this if the output is too big - in this way you could see a truncation.
1215  //  Remember to change myvar and mypar
1216
1217  if(0)
1218  {
1219    basering;
1220    poly gg;
1221    ideal p1,p2;
1222    string myvar = "x1,x2";
1223    string mypar = "a1,a2,T1,T2,T3,T4,T5,Y1,Y2,Y3,Y4,Y5";
1224    //QT = mysubst(QT, npars(basering)-nrx,1/imap(Apreal, den),"par");
1225    for(int kk = 1; kk<=3;kk++)
1226    {
1227      "Next one!";
1228      gg = QT[kk];
1229      while(gg!=0)
1230      {
1231        p1 = ideal(numerator(leadcoef(gg)));
1232        p2 = ideal(denominator(leadcoef(gg)));
1233        myjet(p1,10,mypar,myvar);
1234        myjet(p2,10,mypar,myvar);
1235        leadmonom(lead(gg));
1236        //lead(gg);
1237        ~;
1238        gg = gg-lead(gg);
1239      }
1240    }
1241    for(int kk = 1; kk<=3;kk++)
1242    {
1243      "Next one!";
1244      gg = g[kk];
1245      while(gg!=0)
1246      {
1247        p1 = ideal(numerator(leadcoef(gg)));
1248        p2 = ideal(denominator(leadcoef(gg)));
1249        myjet(p1,10,mypar,myvar);
1250        myjet(p2,10,mypar,myvar);
1251        leadmonom(lead(gg));
1252        //lead(gg);
1253        ~;
1254        gg = gg-lead(gg);
1255      }
1256    }
1257  }
1258  setring Efalse;
1259   if(0)
1260   {
1261      setring Efalse;
1262   "h";
1263   imap(E,h);
1264   "QT"
1265   imap(E,QT);
1266   "g";
1267   imap(E,g);
1268   //reduce(imap(E,g),poly(x2^5));
1269     def ggg = imap(E,g);
1270     ggg = reduce(ggg,x2^5);
1271     setring E;
1272     imap(Efalse,ggg);~;
1273     poly frp1 =  -imap(E,d)+imap(Bfalse,Pprim)*var(nry+1);
1274     "frp1";~;
1275     frp1;
1276    qring Eprefinal = imap(D,dquot)+imap(E,h)+imap(E,g)+imap(Bfalse,I)+frp1;
1277    Eprefinal;
1278    setring E;
1279    def drond = jacob(g);
1280    matrix drond2[size(g)][nry+1] = drond[1..(size(g)),(nry+2)..ncols(drond)];
1281    poly ssp = minor(drond2,size(g))[1];
1282    poly invssp = ss*ssp;
1283    for(i=1;i<=nvars(E) div 2;i++)
1284    {
1285      invssp = subst(invssp,var(i),vidjet[i+nrx]);
1286      invssp = subst(invssp, var(nvars(E)-i+1),tid[i]);
1287    }
1288    //invssp = 1/invssp;
1289    ideal e2 = std(g,h);
1290    if(debug)
1291    {
1292      "And this is the map:";
1293    }
1294    invssp = 1/invssp;
1295    if(debug)
1296    {
1297      themap;
1298    }
1299    string zz = "Z";
1300    def newvar2 = findnewvar(zz);
1301    def q = imap(E,e2);
1302    poly teta = var(nvars(Efinalbase)) * imap(E,ss)*imap(E,ssp) - 1;
1303    qring Efinal = std(q,teta);
1304    if(debug)
1305    {
1306      "This is final E:";
1307      basering;
1308    }
1309  }
1310  //option(set,oldoption);
1311}
1312example
1313{ "EXAMPLE:"; echo = 2;
1314//Example 1
1315  ring All = 0,(a1,a2,a3,x1,x2,x3,Y1,Y2,Y3),dp;
1316  int nra = 3;
1317  int nrx = 3;
1318  int nry = 3;
1319  ideal xid = x2^3-x3^2,x1^3-x3^2;
1320  ideal yid = Y1^3-Y2^3;
1321  ideal aid = a3^2-a1*a2;
1322  poly y;
1323  int i;
1324  for(i=0;i<=30;i++)
1325  {
1326    y = y + a1*x3^i/factorial(i);
1327  }
1328  for(i=31;i<=50;i++)
1329  {
1330    y = y + a2*x3^i/factorial(i);
1331  }
1332  ideal f = a3*x1,a3*x2,y;
1333  desingularization(All, nra,nrx,nry,xid,yid,aid,f);
1334  // With debug output
1335  desingularization(All, nra,nrx,nry,xid,yid,aid,f,"debug");
1336  kill All,nra,nrx,nry,i;
1337
1338//Example 4
1339
1340  ring All = 0,(a1,a2,a3,a4,x,Y1,Y2,Y3),dp;
1341  int nra = 4;
1342  int nrx = 1;
1343  int nry = 3;
1344  ideal xid = 0;
1345  ideal yid = Y1^3-Y2^3;
1346  ideal aid = a3^2-a1*a2,a4^2+a4+1;
1347  poly y;
1348  int i;
1349  for(i=0;i<=30;i++)
1350  {
1351    y = y + a1*x3^i/factorial(i);
1352  }
1353  for(i=31;i<=50;i++)
1354  {
1355    y = y + a2*x3^i/factorial(i);
1356  }
1357  ideal f = a3*x,a3*a4*x,y;
1358  desingularization(All, nra,nrx,nry,xid,yid,aid,f);
1359 }
Note: See TracBrowser for help on using the repository browser.