source: git/Singular/LIB/gitfan.lib @ 80f146c

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