source: git/Singular/LIB/gitfan.lib @ f52bd59

spielwiese
Last change on this file since f52bd59 was f52bd59, checked in by Hans Schoenemann <hannes@…>, 9 years ago
fix: tr. #721
  • Property mode set to 100644
File size: 12.3 KB
Line 
1///////////////////////////////////////////////////////////////////
2version="version gitfan.lib 4.0.2.0 Apr_2015 ";  // $Id$
3category="Algebraic Geometry";
4info="
5LIBRARY:  gitfan.lib       Compute GIT-fans.
6
7AUTHORS:  Janko Boehm      boehm@mathematik.uni-kl.de
8@*        Simon Keicher    keicher@mail.mathematik.uni-tuebingen.de
9@*        Yue Ren          ren@mathematik.uni-kl.de
10
11OVERVIEW:
12This library computes GIT-fans, torus orbits and GKZ-fans.
13It uses the package 'gfanlib' by Anders N. Jensen
14and some algorithms have been outsourced to C++ to improve the performance.
15Check https://github.com/skeicher/gitfan_singular for updates.
16
17KEYWORDS: library; gitfan; GIT; geometric invariant theory; quotients
18
19PROCEDURES:
20afaces(ideal);                      Returns a list of intvecs that correspond to all a-faces
21gitCone(ideal,bigintmat,bigintmat); Returns the GIT-cone around the given weight vector w
22gitFan(ideal,bigintmat);            Returns the GIT-fan of the H-action defined by Q on V(a)
23gkzFan(bigintmat);                  Returns the GKZ-fan of the matrix Q
24isAface(ideal,intvec);              Checks whether intvec corresponds to an ideal-face
25orbitCones(ideal,bigintmat);        Returns the list of all projected a-faces
26";
27
28LIB "parallel.lib"; // for parallelWaitAll
29
30////////////////////////////////////////////////////
31proc mod_init()
32{
33  LIB"gfanlib.so";
34}
35
36static proc int2face(int n, int r)
37{
38  int k = r-1;
39  intvec v;
40  int n0 = n;
41
42  while(n0 > 0)
43  {
44    while(2^k > n0)
45    {
46      k--;
47      //v[size(v)+1] = 0;
48    }
49
50    v = k+1,v;
51    n0 = n0 - 2^k;
52    k--;
53  }
54  v = v[1..size(v)-1];
55  return(v);
56}
57
58/////////////////////////////////
59
60proc isAface(ideal a, intvec gam0)
61"USAGE:  isAface(a,gam0); a: ideal, gam0:intvec
62PURPOSE: Checks whether the face of the positive orthant,
63         that is spanned by all i-th unit vectors,
64         where i ranges amongst the entries of gam0,
65         is an a-face.
66RETURN:  int
67EXAMPLE: example isaface; shows an example
68"
69{
70  poly pz;
71
72  // special case: gam0 is the zero-cone:
73  if (size(gam0) == 1 and gam0[1] == 0)
74  {
75    ideal G;
76
77    // is an a-face if and only if RL0(0,...,0) = const
78    // set all entries to 0:
79    int i;
80    for (int k = 1; k <= ncols(a); k++)
81    {
82      pz = subst(a[k], var(1), 0);
83      for (i = 2; i <= nvars(basering); i++)
84      {
85        pz = subst(pz, var(i), 0);
86      }
87      G = G, pz;
88    }
89
90    G = std(G);
91
92    // monomial inside?:
93    if(1 == G)
94    {
95      return(0);
96    }
97
98    return(1);
99  }
100
101
102  // ring is too big: Switch to KK[T_i; e_i\in gam0] instead:
103  def R = basering;
104  string initNewRing = "ring Rgam0 = 0,(";
105  for (int i=1; i<size(gam0); i++)
106  {
107    initNewRing = initNewRing + string(var(gam0[i])) + ",";
108  }
109  initNewRing = initNewRing + string(var(gam0[size(gam0)])) + "),dp;";
110  execute(initNewRing);
111  kill i;
112
113  ideal agam0 = imap(R,a);
114
115  poly p = var(1); // first entry of g; p = prod T_i with i element of g
116  for (int i = 2; i <= nvars(basering); i++ )
117  {
118    p = p * var(i);
119  }
120  // p is now the product over all T_i, with e_i in gam0
121
122  agam0 = agam0, p - 1; // rad-membership
123  ideal G = std(agam0);
124
125  // does G contain 1?, i.e. is G = 1?
126  if(G <> 1)
127  {
128    return(1); // true
129  }
130
131  return(0); // false
132}
133example
134{
135  echo = 2;
136
137  ring R = 0,(T(1..4)),dp;
138  ideal I = T(1)*T(2)-T(4);
139
140  intvec w = 1,4;
141  intvec v = 1,2,4;
142
143  isAface(I,w); // should be 0
144  "-----------";
145  isAface(I,v); // should be 1
146}
147
148////////////////////////////////////////////////////
149
150proc afacesPart(ideal a, int d, int start, int end, int r)
151{
152  intvec gam0;
153  int i;
154  list AF;
155
156  for(i = start; i <= end; i++)
157  {
158    if(i < 2^r)
159    {
160      gam0 = int2face(i,r);
161
162      // take gam0 only if it has
163      // at least d rays:
164      if(size(gam0) >= d)
165      {
166        if (isAface(a,gam0))
167        {
168          AF[size(AF) + 1] = gam0;
169        }
170      }
171    }
172  }
173  return(AF);
174}
175
176////////////////////////////////////////////////////
177
178proc afaces(ideal a, list #)
179"USAGE:  afaces(a, b, c); a: ideal, d: int, c: int
180PURPOSE: Returns a list of all a-faces (represented by intvecs).
181         Moreover, it is possible to specify a dimensional bound b,
182         upon which only cones of that dimension and above are returned.
183         Lastly, as the computation is parallizable, one can specify c,
184         the number of cores to be used by the computation.
185RETURN:  a list of intvecs
186EXAMPLE: example afaces; shows an example
187"
188{
189  int d = 1;
190  int ncores = 1;
191
192  if ((size(#) > 0) and (typeof(#[1]) == "int"))
193  {
194    d = #[1];
195  }
196
197  if ((size(#) > 1) and (typeof(#[2]) == "int"))
198  {
199    ncores = #[2];
200  }
201
202  list AF;
203  intvec gam0;
204  int r = nvars(basering);
205
206  // check if 0 is an a-face:
207  gam0 = 0;
208  if (isAface(a,gam0))
209  {
210      AF[size(AF) + 1] = gam0;
211  }
212
213  // check for other a-faces:
214  // make ncores processes:
215  int step = 2^r div ncores;
216  int i;
217
218  list args;
219  for(int k = 0; k < ncores; k++)
220  {
221    args[size(args) + 1] = list(a, d, k * step + 1, (k+1) * step, r);
222  }
223
224  string command = "afacesPart";
225  list out = parallelWaitAll(command, args);
226
227  // do remaining ones:
228  for(i = ncores * step +1; i < 2^r; i++)
229  {
230    "another one needed";
231    gam0 = int2face(i,r);
232
233    // take gam0 only if it has
234    // at least d rays:
235    if(size(gam0) >= d)
236    {
237      if (isAface(a,gam0))
238      {
239        AF[size(AF) + 1] = gam0;
240      }
241    }
242  }
243
244  // read out afaces of out into AF:
245  for(i = 1; i <= size(out); i++)
246  {
247    AF = AF + out[i];
248  }
249
250  return(AF);
251}
252example
253{
254
255  echo = 2;
256  ring R = 0,T(1..3),dp;
257  ideal a = T(1)+T(2)+T(3);
258
259  list F = afaces(a,3,4);
260  print(F);
261  print(size(F));
262
263  // 2nd ex //
264  ring R2 = 0,T(1..3),dp;
265  ideal a2 = T(2)^2*T(3)^2+T(1)*T(3);
266
267  list F2 = afaces(a2,3,4);
268  print(F2);
269  print(size(F2));
270
271  // 3rd ex //
272  ring R3 = 0,T(1..3),dp;
273  ideal a3 = 0;
274
275  list F3 = afaces(a3,3,4);
276  print(F3);
277  print(size(F3));
278
279  // bigger example //
280  ring R = 0,T(1..15),dp;
281  ideal a =
282    T(1)*T(10)-T(2)*T(7)+T(3)*T(6),
283    T(1)*T(11)-T(2)*T(8)+T(4)*T(6),
284    T(1)*T(12)-T(2)*T(9)+T(5)*T(6),
285    T(1)*T(13)-T(3)*T(8)+T(4)*T(7),
286    T(1)*T(14)-T(3)*T(9)+T(5)*T(7),
287    T(1)*T(15)-T(4)*T(9)+T(5)*T(8),
288    T(2)*T(13)-T(3)*T(11)+T(4)*T(10),
289    T(2)*T(14)-T(3)*T(12)+T(5)*T(10),
290    T(2)*T(15)-T(4)*T(12)+T(5)*T(11),
291    T(3)*T(15)-T(4)*T(14)+T(5)*T(13),
292    T(6)*T(13)-T(7)*T(11)+T(8)*T(10),
293    T(6)*T(14)-T(7)*T(12)+T(9)*T(10),
294    T(6)*T(15)-T(8)*T(12)+T(9)*T(11),
295    T(7)*T(15)-T(8)*T(14)+T(9)*T(13),
296    T(10)*T(15)-T(11)*T(14)+T(12)*T(13);
297
298  int t = timer;
299  list F4 = afaces(a,0,2);
300  print(size(F4));
301  timer - t;
302
303  int t = timer;
304  list F4 = afaces(a,0);
305  print(size(F4));
306  timer - t;
307
308}
309
310///////////////////////////////////////
311
312proc orbitCones(ideal a, bigintmat Q, list #)
313"USAGE:  orbitCones(a, Q, b, c); a: ideal, Q: bigintmat, b: int, c: int
314PURPOSE: Returns a list consisting of all cones Q(gam0) where gam0 is an a-face.
315         Moreover, it is possible to specify a dimensional bound b,
316         upon which only cones of that dimension and above are returned.
317         Lastly, as the computation is parallizable, one can specify c,
318         the number of cores to be used by the computation.
319RETURN:  a list of cones
320EXAMPLE: example orbitCones; shows an example
321"
322{
323  list AF;
324
325  if((size(#) > 1) and (typeof(#[2]) == "int"))
326  {
327    AF = afaces(a, nrows(Q), #[2]);
328  }
329  else
330  {
331    AF = afaces(a, nrows(Q));
332  }
333
334  int dimensionBound = 0;
335  if((size(#) > 0) and (typeof(#[1]) == "int"))
336  {
337    dimensionBound = #[1];
338  }
339
340  list OC;
341  intvec gam0;
342  int j;
343
344  for(int i = 1; i <= size(AF); i++)
345  {
346    gam0 = AF[i];
347
348    if(gam0 == 0)
349    {
350      bigintmat M[1][nrows(Q)];
351    }
352    else
353    {
354      bigintmat M[size(gam0)][nrows(Q)];
355      for (j = 1; j <= size(gam0); j++)
356      {
357        M[j,1..ncols(M)] = Q[1..nrows(Q),gam0[j]];
358      }
359    }
360    cone c = coneViaPoints(M);
361
362    if((dimension(c) >= dimensionBound) and (!(listContainsCone(OC, c))))
363    {
364      OC[size(OC)+1] = c;
365    }
366
367    kill M, c;
368  }
369
370  return(OC);
371}
372example
373{
374  echo=2;
375  intmat Q[3][4] =
376    1,0,1,0,
377    0,1,0,1,
378    0,0,1,1;
379
380  ring R = 0,T(1..4),dp;
381  ideal a = 0;
382
383  orbitCones(a, Q);
384}
385
386///////////////////////////////////////
387
388proc gitCone(ideal a, bigintmat Q, bigintmat w)
389"USAGE: gitCone(a, Q, w); a: ideal, Q:bigintmat, w:bigintmat
390PURPOSE: Returns the GIT-cone lambda(w), i.e. the intersection of all
391orbit cones containing the vector w.
392NOTE: call this only if you are interested in a single GIT-cone.
393RETURN: a cone.
394EXAMPLE: example gitCone; shows an example
395"
396{
397  list OC =  orbitCones(a, Q);
398  cone lambda = nrows(Q);
399
400  for(int i = 1; i <= size(OC); i++)
401  {
402    cone c = OC[i];
403
404    if(containsInSupport(c, w))
405    {
406      lambda = convexIntersection(lambda, c);
407    }
408
409    kill c;
410  }
411
412  return(lambda);
413}
414example
415{
416  echo=2;
417  intmat Q[3][4] =
418    1,0,1,0,
419    0,1,0,1,
420    0,0,1,1;
421
422  ring R = 0,T(1..4),dp;
423  ideal a = 0;
424
425  bigintmat w[1][3] = 3,3,1;
426  cone lambda = gitCone(a, Q, w);
427  rays(lambda);
428
429  bigintmat w2[1][3] = 1,1,1;
430  cone lambda2 = gitCone(a, Q, w2);
431  rays(lambda2);
432}
433
434/////////////////////////////////////
435
436proc gitFan(ideal a, bigintmat Q, list #)
437"USAGE: gitFan(a, Q); a: ideal, Q:bigintmat
438PURPOSE: Returns the GIT-fan of the H-action defined by Q on V(a).
439An optional third parameter of type 'int' is interpreted as the
440number of CPU-cores you would like to use.
441Note that 'system("--cpus");' returns the number of cpu available
442in your system.
443RETURN: a fan.
444EXAMPLE: example gitFan; shows an example
445"
446{
447  list OC = orbitCones(a, Q, #);
448
449  fan f = refineCones(OC, Q);
450  return(f);
451}
452example
453{
454  echo=2;
455  intmat Q[3][4] =
456    1,0,1,0,
457    0,1,0,1,
458    0,0,1,1;
459
460  ring R = 0,T(1..4),dp;
461  ideal a = 0;
462
463  gitFan(a, Q);
464
465  // 2nd example //
466  kill Q;
467  intmat Q[3][6] =
468    1,1,0,0,-1,-1,
469    0,1,1,-1,-1,0,
470    1,1,1,1,1,1;
471
472  ring R = 0,T(1..6),dp;
473  ideal a = T(1)*T(6) + T(2)*T(5) + T(3)*T(4);
474
475  int t = rtimer;
476  fan F = gitFan(a, Q);
477  t = rtimer - t;
478
479  int tt = rtimer;
480  fan F = gitFan(a, Q, 4);
481  tt = rtimer - tt;
482
483  t;
484  tt;
485  "--------";
486  kill R, Q, t, tt;
487  // next example //
488  ring R = 0,T(1..10),dp;
489  ideal a = T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
490    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
491    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
492    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
493    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
494
495  bigintmat Q[4][10] =
496    1,0,0,0,1,1,1,0,0,0,
497    0,1,0,0,1,0,0,1,1,0,
498    0,0,1,0,0,1,0,1,0,1,
499    0,0,0,1,0,0,1,0,1,1;
500
501  int t = rtimer;
502  fan F = gitFan(a, Q);
503  t = rtimer - t;
504
505  int tt = rtimer;
506  fan F = gitFan(a, Q, 4);
507  tt = rtimer - tt;
508
509  t;
510  tt;
511
512  "--------";
513  kill R, Q, t, tt;
514  // next example //
515  ring R = 0,T(1..15),dp;
516  ideal a =
517    T(1)*T(10)-T(2)*T(7)+T(3)*T(6),
518    T(1)*T(11)-T(2)*T(8)+T(4)*T(6),
519    T(1)*T(12)-T(2)*T(9)+T(5)*T(6),
520    T(1)*T(13)-T(3)*T(8)+T(4)*T(7),
521    T(1)*T(14)-T(3)*T(9)+T(5)*T(7),
522    T(1)*T(15)-T(4)*T(9)+T(5)*T(8),
523    T(2)*T(13)-T(3)*T(11)+T(4)*T(10),
524    T(2)*T(14)-T(3)*T(12)+T(5)*T(10);
525
526  bigintmat Q[5][15] =
527    1,0,0,0,0,1,1,1,1,0,0,0,0,0,0,
528    0,1,0,0,0,1,0,0,0,1,1,1,0,0,0,
529    0,0,1,0,0,0,1,0,0,1,0,0,1,1,0,
530    0,0,0,1,0,0,0,1,0,0,1,0,1,0,1,
531    0,0,0,0,1,0,0,0,1,0,0,1,0,1,1;
532
533  int t = rtimer;
534  fan F = gitFan(a, Q);
535  t = rtimer - t;
536
537  int tt = rtimer;
538  fan F = gitFan(a, Q, 4);
539  tt = rtimer - tt;
540
541  t;
542  tt;
543
544}
545
546/////////////////////////////////////
547// Computes all simplicial orbit cones
548// w.r.t. the 0-ideal:
549
550static proc simplicialToricOrbitCones(bigintmat Q)
551{
552  intvec gam0;
553  list OC;
554  cone c;
555  int r = ncols(Q);
556  int j;
557
558  for(int i = 1; i < 2^r; i++ )
559  {
560    gam0 = int2face(i,r);
561
562    // each simplicial cone is generated by
563    // exactly nrows(Q) many columns of Q:
564    if(size(gam0) == nrows(Q))
565    {
566      bigintmat M[size(gam0)][nrows(Q)];
567
568      for(j = 1; j <= size(gam0); j++)
569      {
570        M[j,1..ncols(M)] = Q[1..nrows(Q),gam0[j]];
571      }
572
573      c = coneViaPoints(M);
574
575      if((dimension(c) == nrows(Q)) and (!(listContainsCone(OC, c))))
576      {
577        OC[size(OC)+1] = c;
578      }
579
580      kill M;
581    }
582  }
583
584  return(OC);
585}
586
587/////////////////////////////////////
588
589proc gkzFan(bigintmat Q)
590"USAGE: gkzFan(Q); a: ideal, Q:bigintmat
591PURPOSE: Returns the GKZ-fan of the matrix Q.
592RETURN: a fan.
593EXAMPLE: example gkzFan; shows an example
594"
595{
596  // only difference to gitFan:
597  // it suffices to consider all faces
598  // that are simplicial:
599  list OC = simplicialToricOrbitCones(Q);
600
601  fan f = refineCones(OC, Q);
602  return(f);
603}
604example
605{
606  echo=2;
607  intmat Q[3][4] =
608    1,0,1,0,
609    0,1,0,1,
610    0,0,1,1;
611
612  gkzFan(Q);
613}
Note: See TracBrowser for help on using the repository browser.