source: git/Singular/LIB/numerAlg.lib @ 33b509

spielwiese
Last change on this file since 33b509 was 1e1ec4, checked in by Oleksandr Motsak <motsak@…>, 11 years ago
Updated LIBs according to master add: new LIBs from master fix: updated LIBs due to minpoly/(de)numerator changes fix: -> $Id$ fix: Fixing wrong rebase of SW on master (LIBs)
  • Property mode set to 100644
File size: 11.7 KB
Line 
1///////////////////////////////////////////////////////////////////////////////
2version="$Id$";
3category="Algebraic Geometry";
4info="
5LIBRARY:  NumerAlg.lib    Numerical Algebraic Algorithm
6OVERVIEW:
7        The library contains procedures to
8        test the inclusion, the equality of two ideals defined by polynomial systems,
9        compute the degree of a pure i-dimensional component of an algebraic variety
10         defined by a polynomial system,
11        compute the local dimension of an algebraic variety defined by a polynomial
12         system at a point computed as an approximate value. The use of the library
13         requires to install Bertini (http://www.nd.edu/~sommese/bertini).
14
15AUTHOR: Shawki AlRashed, rashed@mathematik.uni-kl.de; sh.shawki@yahoo.de
16PROCEDURES:
17
18 Incl(ideal I, ideal J);   test if I containes J
19
20 Equal(ideal I, ideal J);  test if I equals to J
21
22 Degree(ideal I, int i);   computes the degree of a pure i-dimensional
23
24 NumLocalDim(ideal I, p);  numerical local dimension at a point computed as
25                                  an approximate value
26";
27
28LIB "numerDecom.lib";
29
30///////////////////////////////////////////////////////////////////////////////
31///////////////////////////////////////////////////////////////////////////////
32proc Degree(ideal I,int i)
33"USAGE:  Degree(ideal I,int i); I ideal,  i positive integer
34RETURN:  the degree of the pure i-dimensional component of the algebraic
35          variety defined by I
36EXAMPLE: example Degree; shows an example
37"
38{
39 def S=basering;
40 def W=WitSet(I);
41 setring W;
42 int j;
43 if(size(W(i)[1])>1)
44 {
45  j=size(W(i));
46 }
47 else
48 {
49  j=-1; // no component of dimension i
50 }
51 "The Degree of Component";
52 j;
53 setring S;
54 return (W);
55}
56example
57{ "EXAMPLE:"; echo = 2;
58   ring r=0,(x,y,z),dp;
59   poly f1=(x2+y2+z2-6)*(x-y)*(x-1);
60   poly f2=(x2+y2+z2-6)*(x-z)*(y-2);
61   poly f3=(x2+y2+z2-6)*(x-y)*(x-z)*(z-3);
62   ideal I=f1,f2,f3;
63   def W=Degree(I,1);
64        ==>
65           The Degree of Component
66           3
67   def W=Degree(I,2);
68        ==>
69           The Degree of Component
70           2
71}
72///////////////////////////////////////////////////////////////////////////////
73
74proc Incl(ideal I, ideal J)
75"USAGE:  Incl(ideal I, ideal J); I, J ideals
76RETURN:  t=1 if the algebraic variety defined by I contains the algebraic
77           variety defined by J, otherwise t=0
78EXAMPLE: example Incl; shows an example
79"
80{
81 def S=basering;
82 int n=nvars(basering);
83 int i,j,ii,k,z,zi,dd;
84 if(dim(std(I))==0)
85 {
86  def W=solve(I,"nodisplay");
87  setring W;
88  ideal J=imap(S,J);
89  ideal I=imap(S,I);
90  list w;
91  poly tj;
92  number al,ar,ai,ri,jj;
93  zi=size(SOL);
94  for(j=1;j<=zi;j++)
95  {
96   w=SOL[j];
97   for(k=1;k<=size(J);k++)
98   {
99    tj=J[k];
100    for(ii=1;ii<=n;ii++)
101    {
102     tj=subst(tj,var(ii),w[ii]);
103    }
104    al=leadcoef(tj);
105    ar=repart(al);
106    ai=impart(al);
107    ri=ar^2+ai^2;
108    if(ri>0.000000000000001)
109    {
110     jj=0;
111     k=size(I)+1;
112     j=zi+1;
113    }
114    else
115    {
116     jj=1;
117     ri=0;
118    }
119   }
120  }
121 }
122 else
123 {
124  def W=WitSupSet(I);
125  setring W;
126  ideal J=imap(S,J);
127  ideal I=imap(S,I);
128  list w;
129  number al,ar,ai,ri,jj;
130  poly tj;
131  dd=size(L);
132  for(i=0;i<=dd;i++)
133  {
134   z=size(W(i)[1]);
135   zi=size(W(i));
136   if(z>1)
137   {
138    for(j=1;j<=zi;j++)
139    {
140     w=W(i)[j];
141     for(k=1;k<=size(J);k++)
142     {
143      tj=J[k];
144      for(ii=1;ii<=n;ii++)
145      {
146       tj=subst(tj,var(ii),w[ii]);
147      }
148      al=leadcoef(tj);
149      ar=repart(al);
150      ai=impart(al);
151      ri=ar^2+ai^2;
152      if(ri>0.000000000000001)
153      {
154       jj=-1;
155       k=size(J)+1;
156       j=zi+1;
157       z=0;
158       i=dd+1;
159      }
160      else
161      {
162       jj=1;
163       ri=0;
164      }
165     }
166    }
167   }
168  }
169 }
170 if(ri>0.000000000000001)
171 {
172  jj=0;
173 }
174 else
175 {
176  jj=1;
177 }
178"================================================";
179 "Inclusion:";
180 jj;
181"================================================";
182 export(jj);
183 export(J);
184 export(I);
185   system("sh","rm singular_solutions");
186   system("sh","rm nonsingular_solutions");
187   system("sh","rm real_solutions");
188   system("sh","rm raw_solutions");
189   system("sh","rm raw_data");
190   system("sh","rm output");
191   system("sh","rm midpath_data");
192   system("sh","rm main_data");
193   system("sh","rm input");
194   system("sh","rm failed_paths");
195 setring S;
196 return (W);
197}
198example
199{ "EXAMPLE:"; echo = 2;
200   ring r=0,(x,y,z),dp;
201   poly f1=(x2+y2+z2-6)*(x-y)*(x-1);
202   poly f2=(x2+y2+z2-6)*(x-z)*(y-2);
203   poly f3=(x2+y2+z2-6)*(x-y)*(x-z)*(z-3);
204   ideal I=f1,f2,f3;
205   poly g1=(x2+y2+z2-6)*(x-1);
206   poly g2=(x2+y2+z2-6)*(y-2);
207   poly g3=(x2+y2+z2-6)*(z-3);
208   ideal J=g1,g2,g3;
209   def W=Incl(I,J);
210      ==>
211         Inclusion:
212         0
213 def W=Incl(J,I);
214      ==>
215         Inclusion:
216         1
217}
218///////////////////////////////////////////////////////////////////////////////
219proc Equal(ideal I, ideal J)
220"USAGE:  Equal(ideal I, ideal J); I, J ideals
221RETURN:  t=1 if the algebraic variety defined by I equals to the algebraic
222           variety defined by J, otherwise t=0
223EXAMPLE: example Equal; shows an example
224"
225{
226 def S=basering;
227 int n=nvars(basering);
228 def W1=Incl(J,I);
229 setring W1;
230 number j1=jj;
231 execute("ring q=(real,0),("+varstr(S)+"),dp;");
232 ideal I=imap(W1,I);
233 ideal J=imap(W1,J);
234 execute("ring qq=0,("+varstr(S)+"),dp;");
235 ideal I=imap(S,I);
236 ideal J=imap(S,J);
237 def W2=Incl(I,J);
238 setring W2;
239 number j2=jj;
240 number j;
241 number j1=imap(W1,j1);
242 if(j2==1)
243 {
244  if(j1==1)
245  {
246   j=1/1;
247  }
248  else
249  {
250   j=0/1;
251  }
252 }
253 else
254 {
255  j=0/1;
256 }
257"================================================";
258 "Equality:";
259 j;
260"================================================";
261 setring S;
262 return (W2);
263}
264example
265{ "EXAMPLE:"; echo = 2;
266   ring r=0,(x,y,z),dp;
267   poly f1=(x2+y2+z2-6)*(x-y)*(x-1);
268   poly f2=(x2+y2+z2-6)*(x-z)*(y-2);
269   poly f3=(x2+y2+z2-6)*(x-y)*(x-z)*(z-3);
270   ideal I=f1,f2,f3;
271   poly g1=(x2+y2+z2-6)*(x-1);
272   poly g2=(x2+y2+z2-6)*(y-2);
273   poly g3=(x2+y2+z2-6)*(z-3);
274   ideal J=g1,g2,g3;
275   def W=Equal(I,J);
276        ==>
277           Equality:
278           0
279
280
281  def W=Equal(J,J);
282        ==>
283           Equality:
284           1
285}
286///////////////////////////////////////////////////////////////////////////////
287proc NumLocalDim(ideal J, list w, int e)
288"USAGE:  NumLocalDim(ideal J, list w, int e); J ideal,
289           w list of an approximate value of a point v in the algebraic variety defined by J,
290               e integer
291RETURN: the local dimension of the algebraic variety defined by J at v
292EXAMPLE: example NumLocalDim; shows an example
293"
294{
295 def S=basering;
296 int n=nvars(basering);
297 int sI=size(J);
298 int i,j,jj,t,tt,sz1,sz2,ii,ph,ci,k;
299 poly p,pp;
300 list rw,iw;
301 for(i=1;i<=sI;i++)
302 {
303  p=J[i];
304  for(j=1;j<=n;j++)
305  {
306   w[j]=w[j]+I*0;
307   rw[j]=repart(w[j]);
308   iw[j]=impart(w[j]);
309   p=subst(p,var(j),w[j]);
310  }
311  pp=pp+p;
312 }
313 number u=leadcoef(pp);
314 if((u^2)==0)
315 {
316  execute("ring A=(real,e-1),("+varstr(S)+",I),ds;");
317  ideal II=imap(S,J);
318  list rw=imap(S,rw);
319  list iw=imap(S,iw);
320  poly p(1..n);
321  for(j=1;j<=n;j++)
322  {
323   p(j)=var(j)+rw[j]+I*iw[j];
324  }
325  map f=A,p(1..n);
326  ideal T=f(II);
327  tt=dim(std(T));
328  t=tt-1;
329 }
330 else
331 {
332  int d=dim(std(J));
333  execute("ring R=(complex,e-1,I),("+varstr(S)+"),ds;");
334  list w=imap(S,w);
335  ideal II=imap(S,J);
336  ideal JJ;
337  poly p, p(1..n);
338  for(i=1;i<=sI;i++)
339  {
340   p=II[i];
341   for(j=1;j<=n;j++)
342   {
343    p=subst(p,var(j),w[j]);
344   }
345   JJ[i]=II[i]-p;
346  }
347  for(j=1;j<=n;j++)
348  {
349   p(j)=var(j)+w[j];
350  }
351  map f=R,p(1..n);
352  ideal T=f(JJ);
353  tt=dim(std(T));
354  if(tt==d)
355  {
356   execute("ring A=(complex,e,I),("+varstr(S)+"),dp;");
357   t=tt;
358  }
359  else
360  {
361   execute("ring RR=(real,e-2),("+varstr(S)+",I),dp;");
362   ideal II=imap(S,J);
363   list rw=imap(S,rw);
364   list iw=imap(S,iw);
365   ideal L,LL,H,HH;
366   poly l(1..d),ll(1..d);
367   int c;
368   for(i=1;i<=d;i++)
369   {
370    for(j=1;j<=n;j++)
371    {
372     c=random(1,100);
373     l(i)=l(i)+c*(var(j));
374     ll(i)=ll(i)+c*(var(j)-rw[j]-I*iw[j]);
375    }
376    l(i)=l(i)+random(101,200);
377    L[i]=l(i);
378    LL[i]=ll(i);
379   }
380   poly pi=I^2+1;
381   H=L,II,pi;
382   ideal JJ;
383   poly p, p(1..n);
384   for(i=1;i<=sI;i++)
385   {
386    p=II[i];
387    for(j=1;j<=n;j++)
388    {
389     p=subst(p,var(j),rw[j]+I*iw[j]);
390    }
391    JJ[i]=II[i]-p;
392   }
393   HH=LL,JJ,pi;
394   if(dim(std(H))==0)
395   {
396    def M=solve(H,100,"nodisplay");
397    setring M;
398    sz1=size(SOL);
399    execute("ring RRRQ=(real,e-1),("+varstr(S)+",I),dp;");
400    ideal HH=imap(RR,HH);
401    if(dim(std(HH))==0)
402    {
403     def MM=solve(HH,100,"nodisplay");
404     setring MM;
405     sz2=size(SOL);
406    }
407   }
408   else
409   {
410    sz1=1;
411   }
412   if(sz1==sz2)
413   {
414    execute("ring A=(complex,e,I),("+varstr(S)+"),dp;");
415    t=d;
416   }
417   else
418   {
419    execute("ring RQ=(real,e-1),("+varstr(S)+"),dp;");
420    ideal II=imap(S,J);
421    def RW=WitSet(II);
422    setring RW;
423    list v;
424    list w=imap(S,w);
425    number nr,ni;
426    if(tt<0)
427    {
428     tt=0;
429    }
430    for(ii=tt;ii<=d;ii++)
431    {
432     list W(ii)=imap(RW,W(ii));
433     if(size(W(ii)[1])>1)
434     {
435      if(ii==0)
436      {
437       for(i=1;i<=size(W(0));i++)
438       {
439        v=W(ii)[i];
440        nr=0;
441        ni=0;
442        for(j=1;j<=n;j++)
443        {
444         nr=nr+(repart(v[j])-repart(w[j]))^2;
445         ni=ni+(impart(v[j])-impart(w[j]))^2;
446        }
447        if((ni+nr)<1/10^(2*e-3))
448        {
449         execute("ring A=(complex,e,I),("+varstr(S)+"),dp;");
450         list W(ii)=imap(RW,W(ii));
451         t=0;
452         i=size(W(ii))+1;
453         ii=d+1;
454        }
455       }
456      }
457      else
458      {
459       def SS=Singular2bertini(W(ii));
460       execute("ring D=(complex,e,I),("+varstr(S)+",s,gamma),dp;");
461       string nonsin;
462       ideal H,L;
463       ideal J=imap(RW,N(0));
464       ideal LL=imap(RW,L);
465       list w=imap(S,w);
466       poly p;
467       for(j=1;j<=ii;j++)
468       {
469        p=0;
470        for(jj=1;jj<=n;jj++)
471        {
472         p=p+random(1,100)*(var(jj)-w[jj]);
473        }
474        L[j]=p;
475       }
476       for(jj=1;jj<=size(J);jj++)
477       {
478        H[jj]=s*gamma*J[jj]+(1-s)*J[jj];
479       }
480       for(jj=1;jj<=ii;jj++)
481       {
482        H[size(J)+jj]=s*gamma*LL[jj]+(1-s)*L[jj];
483       }
484       string sv=varstr(S);
485       def Q(ii)=UseBertini(H,sv);
486       system("sh","rm start");
487       nonsin=read("nonsingular_solutions");
488       if(size(nonsin)>=52)
489       {
490        def T(ii)=bertini2Singular("nonsingular_solutions",nvars(basering)-2);
491        setring T(ii);
492        list C=re;
493        ci=size(C);
494        number tr;
495        list w=imap(S,w);
496        for(jj=1;jj<=ci;jj++)
497        {
498         tr=0;
499         for(k=1;k<=n;k++)
500         {
501          tr=tr+(repart(w[k])-repart(C[jj][k]))^2+(impart(w[k])-impart(C[jj][k]))^2;
502         }
503         if(tr<=1/10^(2*e-3))
504         {
505          execute("ring A=(complex,e,I),("+varstr(S)+"),dp;");
506          t=ii;
507          ii=d+1;
508          jj=ci+1;
509         }
510        }
511       }
512      }
513     }
514    }
515    system("sh","rm singular_solutions");
516    system("sh","rm nonsingular_solutions");
517    system("sh","rm real_solutions");
518    system("sh","rm raw_solutions");
519    system("sh","rm raw_data");
520    system("sh","rm output");
521    system("sh","rm midpath_data");
522    system("sh","rm main_data");
523    system("sh","rm input");
524    system("sh","rm failed_paths");
525   }
526  }
527 }
528 "=============================================";
529 "The Local Dimension:";
530 t;
531 setring S;
532 return(A);
533}
534example
535{ "EXAMPLE:"; echo = 2;
536   int e=14;
537   ring r=(complex,e,I),(x,y,z),dp;
538   poly f1=(x2+y2+z2-6)*(x-y)*(x-1);
539   poly f2=(x2+y2+z2-6)*(x-z)*(y-2);
540   poly f3=(x2+y2+z2-6)*(x-y)*(x-z)*(z-3);
541   ideal J=f1,f2,f3;
542   list p0=0.99999999999999+I*0.00000000000001,2,3+I*0.00000000000001;
543   list p2=1,0.99999999999998,2;
544   list p1=5+I,4.999999999999998+I,5+I;
545   def D=NumLocalDim(J,p0,e);
546             ==>
547               The Local Dimension:
548                0
549   def D=NumLocalDim(J,p1,e);
550             ==>
551               The Local Dimension:
552                1
553   def D=NumLocalDim(J,p2,e);
554             ==>
555               The Local Dimension:
556                2
557}
558
559///////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.