Changeset 3c03e6 in git


Ignore:
Timestamp:
Jun 12, 2017, 2:01:49 PM (7 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
20c7ed2e60c9fae3e96e2ca7e3e9d23371e70c27
Parents:
12de090bb5f6e76f1ab307a2fea467c80b9023e14f73ae72a8e0ce7f2f9d7bfa2e9ead56cd4d0097
Message:
Merge branch 'gitfan.so' of https://github.com/YueRen/Sources into YueRen-gitfan.so
Files:
8 added
1 deleted
11 edited
1 moved

Legend:

Unmodified
Added
Removed
  • Singular/LIB/gitfan.lib

    r12de09 r3c03e6  
    1 ///////////////////////////////////////////////////////////////////
    2 version="version gitfan.lib 4.0.2.0 Apr_2015 ";  // $Id$
    3 category="Algebraic Geometry";
    4 info="
    5 LIBRARY:  gitfan.lib       Compute GIT-fans.
    6 
    7 AUTHORS:  Janko Boehm      boehm@mathematik.uni-kl.de
    8 @*        Simon Keicher    keicher@mail.mathematik.uni-tuebingen.de
    9 @*        Yue Ren          ren@mathematik.uni-kl.de
     1////////////////////////////////////////////////////////////////////
     2//
     3version = "(v0.2, 2015-10-01)";
     4category = "Algebraic Geometry";
     5info = "
     6LIBRARY:   gitfan.lib       Compute GIT-fans.
     7
     8AUTHORS: Janko Boehm, boehm at mathematik.uni-kl.de @*
     9         Simon Keicher, keicher at mail.mathematik.uni-tuebingen.de @*
     10         Yue Ren, ren at mathematik.uni-kl.de @*
    1011
    1112OVERVIEW:
    12 This library computes GIT-fans, torus orbits and GKZ-fans.
    13 It uses the package 'gfanlib' by Anders N. Jensen
    14 and some algorithms have been outsourced to C++ to improve the performance.
    15 Check https://github.com/skeicher/gitfan_singular for updates.
    16 
    17 KEYWORDS: library; gitfan; GIT; geometric invariant theory; quotients
     13This library allows you to calculate GIT-fans, torus orbits and GKZ-fans.
     14
     15In provides features to make use of symmetries of the torus action under consideration.
     16
     17The main procedure is GITfan which can be directly applied to an ideal and a grading matrix encoding the torus action, and returns a fan, the associated GIT-fan. We also provide various procedures implementing substeps of the algorithm to deal with large computations.
     18
     19The library uses the package 'gfanlib' by Anders N. Jensen.
     20
     21For notation, background, and algorithms see [BKR16].
     22
     23Functions produce debug output if printlevel is positive.
     24
     25Elements of the symmetric group Sn of type permutation can be created by the function permutationFromIntvec. The images of 1,...,n can be obtained by permutationToIntvec. Composition of permutations can be done by the *-Operator, also powers can be computed in the usual way.
     26
     27
     28REFERENCES:
     29
     30[BKR16] J. Boehm, S. Keicher, Y. Ren: Computing GIT-Fans with Symmetry and the Mori Chamber Decomposition of M06bar,  https://arxiv.org/abs/1603.09241
     31
     32TYPES:
     33  permutation; Permutation in map representation.
    1834
    1935PROCEDURES:
    20 afaces(ideal);                      Returns a list of intvecs that correspond to all a-faces
    21 gitCone(ideal,bigintmat,bigintmat); Returns the GIT-cone around the given weight vector w
    22 gitFan(ideal,bigintmat);            Returns the GIT-fan of the H-action defined by Q on V(a)
    23 gkzFan(bigintmat);                  Returns the GKZ-fan of the matrix Q
    24 isAface(ideal,intvec);              Checks whether intvec corresponds to an ideal-face
    25 orbitCones(ideal,bigintmat);        Returns the list of all projected a-faces
     36  isAface(ideal, intvec); Checks whether the given face is an a-face.
     37  afaces(ideal); Returns a list of intvecs that correspond to the set of all a-faces, optionally for given list of simplex faces.
     38  fullDimImages(list, intmat); Finds the afaces which have a full-dimensional projection.
     39  minimalAfaces(list); compute the minimal a-faces among the a-faces with full dimensional projection.
     40  orbitCones(list, intmat); Returns the list of all orbit cones.
     41  GITcone(list, bigintmat); Returns the GIT-cone containing the given weight vector.
     42  GITfan(ideal, intmat); Compute GIT-fan.
     43  GITfanFromOrbitCones(list, intmat, cone); Compute GIT-fan from orbit cones.
     44  GITfanParallel(list, intmat, cone); Compute GIT-fan in parallel from orbit cones.
     45  GKZfan(intmat); Returns the GKZ-fan of the matrix Q.
     46  movingCone(intmat); Compute the moving cone.
     47  computeAfaceOrbits(list, list); Compute orbits of a-faces under a permutation group action.
     48  minimalAfaceOrbits(list); Find the minimal a-face orbits.
     49  orbitConeOrbits(list, intmat); Project the a-face orbits to orbit cone orbits.
     50  minimalOrbitConeOrbits(list); Find the minimal orbit cone orbits.
     51  intersectOrbitsWithMovingCone(list, cone); Intersect orbit cone orbits with moving cone.
     52  groupActionOnQImage(list, intmat); Determine the induced group action in the target of the grading matrix.
     53  groupActionOnHashes(list, list); Determine the induced group action on the set of orbit cones.
     54  storeActionOnOrbitConeIndices(list, string); Write the group action on the set of orbit cones to a file.
     55  permutationFromIntvec(intvec); Create a permutation from an intvec of images.
     56  permutationToIntvec(permutation); Return the intvec of images.
     57  evaluateProduct(list,list); Evaluate a list of products of group elements in terms of a given representation of the elements as permutations.
     58  GITfanSymmetric(list, intmat, cone, list); Compute GIT-fan from orbit cones by determining a minimal representing set for the orbits of maximal dimensional GIT-cones.
     59  GITfanParallelSymmetric(list, intmat, cone, list); Compute GIT-fan in parallel from orbit cones by determining a minimal representing set for the orbits of maximal dimensional GIT-cones.
     60  bigintToBinary(bigint, int); Convert bigint into a sparse binary represenation specifying the indices of the one-entries
     61  binaryToBigint(intvec); Convert sparse binary represenation specifying the indices of the one-entries to bigint
     62  applyPermutationToIntvec(intvec, permutation); Apply permutation to a set of integers represented as an intvec
     63  hashToCone(bigint, list); Convert a bigint hash to a GIT-cone
     64  hashesToFan(list hashes, list OC)
     65
     66KEYWORDS: library, gitfan, GIT, geometric invariant theory, quotients
    2667";
    2768
    28 LIB "parallel.lib"; // for parallelWaitAll
     69
     70LIB "customstd.lib";
     71LIB "linalg.lib";
     72LIB "multigrading.lib";
     73LIB "parallel.lib";
     74
     75proc mod_init()
     76{
     77  LIB "gfanlib.so";
     78  LIB "gitfan.so";
     79  newstruct("permutation","intvec image");
     80  system("install","permutation","*",composePermutations,2);
     81  system("install","permutation","^",permutationPower,2);
     82  system("install","permutation","print",printPermutation,1);
     83}
     84
     85static proc emptyString(int n)
     86{
     87string st;
     88for (int i = 1; i<=n;i++){
     89  st=st+" ";
     90}
     91return(st);}
     92
     93proc printPermutation(permutation sigma)
     94{
     95 intvec v = permutationToIntvec(sigma);
     96 string vsrc,vimg;
     97 for (int i = 1; i<=size(v);i++){
     98   vsrc=vsrc+emptyString(1+size(string(size(v)))-size(string(i)))+string(i);
     99 }
     100 for (i = 1; i<=size(v);i++){
     101   vimg=vimg+emptyString(1+size(string(size(v)))-size(string(v[i])))+string(v[i]);
     102 }
     103 print("|"+vsrc+"|");
     104 print("|"+vimg+"|");
     105}
     106
    29107
    30108////////////////////////////////////////////////////
    31 proc mod_init()
    32 {
    33   LIB"customstd.so";
    34   LIB"gfanlib.so";
    35 }
    36 
     109// converts e.g. n=5 to its binary representation, i.e. 0,1,0,1
     110// if r = 3.
     111// and stores it in an intvec.
     112// r gives the bound for n <= 2^r:
    37113static proc int2face(int n, int r)
    38114{
     
    41117  int n0 = n;
    42118
    43   while(n0 > 0)
    44   {
    45     while(2^k > n0)
    46     {
     119  while(n0 > 0){
     120    while(2^k > n0){
    47121      k--;
    48122      //v[size(v)+1] = 0;
     
    56130  return(v);
    57131}
    58 
    59 /////////////////////////////////
     132example
     133{
     134  echo = 2;
     135  int n = 5;
     136  int r = 4;
     137  int2face(n, r);
     138
     139  n = 1;
     140  r = 1;
     141  int2face(n,r);
     142}
     143
     144////////
     145
     146
     147
     148////////////////////////////////////////////////////
     149
     150proc afaces(ideal a, list #)
     151"USAGE: afaces(a [,L]); a: ideal, L: list of intvecs
     152PURPOSE: Returns a list of all a-faces (considered as intvecs of 0 and 1, where the i-th entry is 1 if the cone has the i-th unit basis vector as a generator), if L is specified only the faces of the simplex listed in L are considered (e.g. representatives with respect to a group action).
     153RETURN: a list of intvecs
     154EXAMPLE: example afaces; shows an example
     155"
     156{
     157  list AF;
     158  if ((size(#)>0) and (typeof(#[1])=="intvec")){
     159    list L = #;
     160    for(int i = 1; i<=size(L); i++ ){
     161      dbprint("representative "+string(i)+" of "+string(size(L)));
     162      if (isAface(a,L[i])){
     163        AF[size(AF) + 1] = L[i];
     164      }
     165    }
     166    return(AF);
     167  }
     168
     169  intvec gam0;
     170  int r = nvars(basering);
     171
     172  // check if 0 is an a-face:
     173  int bd;
     174  if (size(#)>0){bd=#[1];}
     175  gam0 = 0;
     176  if (size(gam0)>=bd){
     177    if (isAface(a,gam0)){
     178      AF[size(AF) + 1] = gam0;
     179    }
     180  }
     181  // check for other a-faces:
     182  for(int i = 1; i < 2^r; i++ ){
     183    gam0 = int2face(i,r);
     184    if (size(gam0)>=bd){
     185      if (isAface(a,gam0)){
     186        AF[size(AF) + 1] = gam0;
     187      }
     188    }
     189  }
     190
     191  //"done checking a-faces!";
     192  return(AF);
     193}
     194example
     195{
     196
     197  echo = 2;
     198  ring R = 0,T(1..3),dp;
     199  ideal a = T(1)+T(2)+T(3);
     200
     201  list F = afaces(a);
     202  print(F);
     203  print(size(F));
     204
     205  // 2nd ex //
     206  ring R2 = 0,T(1..3),dp;
     207  ideal a2 = T(2)^2*T(3)^2+T(1)*T(3);
     208
     209  list F2 = afaces(a2);
     210  print(F2);
     211  print(size(F2));
     212
     213  // 3rd ex //
     214  ring R3 = 0,T(1..3),dp;
     215  ideal a3 = 0;
     216
     217  list F3 = afaces(a3);
     218  print(F3);
     219  print(size(F3));
     220
     221
     222  // 4th ex //
     223  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     224  ideal J =
     225    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     226    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     227    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     228    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     229    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     230  list F4 = afaces(J);
     231  print(size(F4));
     232}
     233
     234
     235
     236static proc saturateWithRespectToVariable(ideal I, int k)
     237{
     238  // "saturating with respect to variable "+string(k);
     239  ASSUME(1,k>=1);
     240  ASSUME(1,k<=nvars(basering));
     241
     242  def origin = basering;
     243  int n = nvars(basering);
     244  intvec weightVector = ringlist(origin)[3][1][2];
     245
     246  string newVars;
     247  intvec newWeightVector;
     248  for (int i=1; i<k; i++)
     249  {
     250    newVars = newVars+string(var(i))+",";
     251    newWeightVector[i]=weightVector[i];
     252  }
     253  for (i=k+1; i<=n; i++)
     254  {
     255    newVars = newVars+string(var(i))+",";
     256    newWeightVector[i-1]=weightVector[i];
     257  }
     258  newVars = newVars+string(var(k));
     259  newWeightVector[n]=weightVector[k];
     260  execute("ring ringForSaturation = ("+charstr(origin)+"),("+newVars+"),(wp(newWeightVector));");
     261
     262  ideal I = satstd(imap(origin,I));
     263  I = simplify(I,2+4+32);
     264
     265  // "finished saturating with respect to variable "+string(k);
     266  setring origin;
     267  return (imap(ringForSaturation,I));
     268}
     269
     270static proc stepwiseSaturation(ideal I)
     271{
     272  if (I!=1)
     273  {
     274    list variablesToBeSaturated;
     275    int l = nvars(basering);
     276    for (int i=1; i<=l; i++)
     277    { variablesToBeSaturated[i]=l-i+1; }
     278
     279    while (size(variablesToBeSaturated)>0)
     280    {
     281      I = saturateWithRespectToVariable(I,variablesToBeSaturated[1]);
     282      variablesToBeSaturated = delete(variablesToBeSaturated,1);
     283      if ((I==1) || (I==-1))
     284      {
     285        break;
     286      }
     287    }
     288  }
     289
     290  return (I);
     291}
     292
     293
     294
     295
     296
    60297
    61298proc isAface(ideal a, intvec gam0)
    62 "USAGE:  isAface(a,gam0); a: ideal, gam0:intvec
    63 PURPOSE: Checks whether the face of the positive orthant,
    64          that is spanned by all i-th unit vectors,
    65          where i ranges amongst the entries of gam0,
    66          is an a-face.
    67 RETURN:  int
     299  "USAGE: isAface(a,gam0); a: ideal, gam0:intvec
     300PURPOSE: Checks whether gam0 is an a-face w.r.t. the ideal a.
     301RETURN: int
    68302EXAMPLE: example isaface; shows an example
    69303"
    70304{
    71   poly pz;
    72 
    73305  // special case: gam0 is the zero-cone:
    74   if (size(gam0) == 1 and gam0[1] == 0)
    75   {
     306  if (size(gam0) == 1 and gam0[1] == 0){
     307    poly pz;
    76308    ideal G;
    77 
    78     // is an a-face if and only if RL0(0,...,0) = const
    79     // set all entries to 0:
    80309    int i;
    81     for (int k = 1; k <= ncols(a); k++)
    82     {
     310    for (int k = 1; k <= size(a); k++) {
    83311      pz = subst(a[k], var(1), 0);
    84       for (i = 2; i <= nvars(basering); i++)
    85       {
     312      for (i = 2; i <= nvars(basering); i++) {
    86313        pz = subst(pz, var(i), 0);
    87314      }
    88315      G = G, pz;
    89316    }
    90 
    91317    G = std(G);
    92 
    93318    // monomial inside?:
    94     if(1 == G)
    95     {
     319    if(G == 1){
    96320      return(0);
    97321    }
    98 
    99322    return(1);
    100323  }
    101324
    102 
    103   // ring is too big: Switch to KK[T_i; e_i\in gam0] instead:
    104   def R = basering;
    105325  string initNewRing = "ring Rgam0 = 0,(";
     326
     327  intvec w = ringlist(basering)[3][1][2];
     328  intvec w0;
    106329  for (int i=1; i<size(gam0); i++)
    107330  {
     331    // take only entries i of w0 with i in gam0
    108332    initNewRing = initNewRing + string(var(gam0[i])) + ",";
    109   }
    110   initNewRing = initNewRing + string(var(gam0[size(gam0)])) + "),dp;";
     333    w0[i] = w[gam0[i]];
     334  }
     335  w0[size(gam0)] = w[gam0[size(gam0)]];
     336
     337  initNewRing = initNewRing + string(var(gam0[size(gam0)])) + "),wp(w0);";
     338  def R = basering;
    111339  execute(initNewRing);
    112   kill i;
    113340
    114341  ideal agam0 = imap(R,a);
    115342
    116   poly p = var(1); // first entry of g; p = prod T_i with i element of g
    117   for (int i = 2; i <= nvars(basering); i++ )
     343  ideal G = stepwiseSaturation(agam0);
     344
     345  if(G == 1)
    118346  {
    119     p = p * var(i);
    120   }
    121   // p is now the product over all T_i, with e_i in gam0
    122 
    123   agam0 = agam0, p - 1; // rad-membership
    124   ideal G = std(agam0);
    125 
    126   // does G contain 1?, i.e. is G = 1?
    127   if(G <> 1)
    128   {
    129     return(1); // true
    130   }
    131 
    132   return(0); // false
     347    return(0); // true
     348  }
     349  return(1); // false
    133350}
    134351example
     
    143360
    144361  isAface(I,w); // should be 0
    145   "-----------";
    146362  isAface(I,v); // should be 1
    147363}
    148364
    149 ////////////////////////////////////////////////////
    150 
    151 proc afacesPart(ideal a, int d, int start, int end, int r)
    152 {
    153   intvec gam0;
    154   int i;
    155   list AF;
    156 
    157   for(i = start; i <= end; i++)
     365
     366proc applyPermutationToIntvec(intvec v, permutation g)
     367"USAGE: applyPermutationToIntvec(v,g); v: intvec, g:permutation
     368PURPOSE: Apply g to the set of entries of v. The result is a sorted intvec. We assume that the entries of v are valid arguments of g. We do not require that the input is sorted.
     369RETURN: intvec.
     370EXAMPLE: example applyPermutationToIntvec; shows an example
     371"
     372{
     373  intvec gv = composeIntvecs(permutationToIntvec(g),v);
     374  //for (int i=1;i<=size(v);i++){
     375  //  gv[i]=g[v[i]];
     376  //}
     377  return(sort(gv)[1]);
     378}
     379example
     380{
     381permutation g = permutationFromIntvec(intvec(10, 9, 7, 4, 8, 6, 3, 5, 2, 1));
     382applyPermutationToIntvec(intvec(1, 3, 4, 6, 8),g);
     383}
     384
     385static proc isContained(intvec v, list orbit){
     386  for (int i=1;i<=size(orbit);i++){
     387    if (v==orbit[i]){return(1);}
     388  }
     389  return(0);
     390}
     391
     392
     393static proc computeSimplexOrbit(intvec v, list G){
     394  list orbit;
     395  intvec gv;
     396  for (int i=1;i<=size(G);i++){
     397    gv=applyPermutationToIntvec(v,G[i]);
     398    if (isContained(gv,orbit)==0){orbit[size(orbit)+1]=gv;}
     399  }
     400  return(orbit);
     401}
     402
     403
     404proc computeAfaceOrbits(list AF, list G)
     405  "USAGE: computeAfaceOrbits(AF,G); AF list of intvecs, G: list of permutations
     406PURPOSE: Computes the orbits of the afaces in the list AF under the group action in G, where G is a list of permutations. We assume that the elements of G form a group and the first entry corresponds to the neutral element.
     407RETURN: a list of lists of intvecs
     408EXAMPLE: example computeAfaceOrbits; shows an example
     409"
     410{
     411  list listorbits;
     412  for (int i=1;i<=size(AF);i++){
     413    dbprint(i);
     414    listorbits[i]=computeSimplexOrbit(AF[i],G);
     415  }
     416  return(listorbits);}
     417example
     418{
     419  echo = 2;
     420LIB "gitfan.lib";
     421  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     422  ideal J =
     423    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     424    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     425    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     426    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     427    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     428  intmat Q[5][10] =
     429    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     430    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     431    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     432    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     433    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     434  list simplexSymmetryGroup = G25Action();
     435  list simplexOrbitRepresentatives = intvec( 1, 2, 3, 4, 5 ),
     436  intvec( 1, 2, 3, 5, 6 ),
     437  intvec( 1, 2, 3, 5, 7 ),
     438  intvec( 1, 2, 3, 5, 10 ),
     439  intvec( 1, 2, 3, 7, 9 ),
     440  intvec( 1, 2, 6, 9, 10 ),
     441  intvec( 1, 2, 3, 4, 5, 6 ),
     442  intvec( 1, 2, 3, 4, 5, 10 ),
     443  intvec( 1, 2, 3, 5, 6, 8 ),
     444  intvec( 1, 2, 3, 5, 6, 9 ),
     445  intvec( 1, 2, 3, 5, 7, 10 ),
     446  intvec( 1, 2, 3, 7, 9, 10 ),
     447  intvec( 1, 2, 3, 4, 5, 6, 7 ),
     448  intvec( 1, 2, 3, 4, 5, 6, 8 ),
     449  intvec( 1, 2, 3, 4, 5, 6, 9 ),
     450  intvec( 1, 2, 3, 5, 6, 9, 10 ),
     451  intvec( 1, 2, 3, 4, 5, 6, 7, 8 ),
     452  intvec( 1, 2, 3, 4, 5, 6, 9, 10 ),
     453  intvec( 1, 2, 3, 4, 5, 6, 7, 8, 9 ),
     454  intvec( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );
     455  list afaceOrbitRepresentatives=afaces(J,simplexOrbitRepresentatives);
     456  list fulldimAfaceOrbitRepresentatives=fullDimImages(afaceOrbitRepresentatives,Q);
     457  list afaceOrbits=computeAfaceOrbits(fulldimAfaceOrbitRepresentatives,simplexSymmetryGroup);
     458  apply(afaceOrbits,size);}
     459
     460
     461
     462
     463static proc isSubset(intvec v, intvec w)
     464{
     465  int i,j;
     466  int jStart=1;
     467  for (i=1; i<=size(v); i++)
    158468  {
    159     if(i < 2^r)
     469    for (j=jStart; j<=size(w); j++)
    160470    {
    161       gam0 = int2face(i,r);
    162 
    163       // take gam0 only if it has
    164       // at least d rays:
    165       if(size(gam0) >= d)
     471      if (v[i]==w[j])
    166472      {
    167         if (isAface(a,gam0))
     473        break;
     474      }
     475    }
     476    if (j<=size(w))
     477    {
     478      jStart = j+1;
     479    }
     480    else
     481    {
     482      return (0);
     483    }
     484  }
     485  return (1);
     486}
     487
     488
     489
     490static proc containsOrbitd(list A, list B)
     491{
     492  intvec a = A[1];
     493  for (int i=1; i<=size(B); i++)
     494  {
     495    if (isSubset(a,B[i]))
     496    {
     497      return (1);
     498    }
     499  }
     500  return (0);
     501}
     502
     503
     504proc minimalAfaceOrbits(list listOfOrbits)
     505"USAGE: minimalAfaceOrbits(afaceOrbits); afaceOrbits: list
     506PURPOSE: Returns a list of all minimal a-face orbits.
     507RETURN: a list of intvecs
     508EXAMPLE: example minimalAfaceOrbits; shows an example
     509"
     510{
     511  int i,j;
     512  list L = listOfOrbits;
     513  for (i=1; i<=size(L); i++)
     514  {
     515    dbprint(string(i)+" of "+string(size(L)));
     516    for (j=1; j<=size(L); j++)
     517    {
     518      if (i!=j)
     519      {
     520        if (containsOrbitd(L[i],L[j]))
    168521        {
    169           AF[size(AF) + 1] = gam0;
     522          dbprint("werfe raus (Laenge):  " + string(size(L[j])));
     523          L = delete(L,j);
     524          if (j<i)
     525          {
     526            i = i-1;
     527          }
     528          j = j-1;
    170529        }
    171530      }
    172531    }
    173532  }
    174   return(AF);
    175 }
    176 
    177 ////////////////////////////////////////////////////
    178 
    179 proc afaces(ideal a, list #)
    180 "USAGE:  afaces(a, b, c); a: ideal, d: int, c: int
    181 PURPOSE: Returns a list of all a-faces (represented by intvecs).
    182          Moreover, it is possible to specify a dimensional bound b,
    183          upon which only cones of that dimension and above are returned.
    184          Lastly, as the computation is parallizable, one can specify c,
    185          the number of cores to be used by the computation.
    186 RETURN:  a list of intvecs
    187 EXAMPLE: example afaces; shows an example
    188 "
    189 {
    190   int d = 1;
    191   int ncores = 1;
    192 
    193   if ((size(#) > 0) and (typeof(#[1]) == "int"))
     533  return(L);
     534}
     535example
     536{
     537  echo = 2;
     538  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     539  ideal J =
     540    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     541    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     542    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     543    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     544    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     545  intmat Q[5][10] =
     546    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     547    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     548    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     549    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     550    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     551  list simplexSymmetryGroup = G25Action();
     552  list simplexOrbitRepresentatives = intvec( 1, 2, 3, 4, 5 ),
     553  intvec( 1, 2, 3, 5, 6 ),
     554  intvec( 1, 2, 3, 5, 7 ),
     555  intvec( 1, 2, 3, 5, 10 ),
     556  intvec( 1, 2, 3, 7, 9 ),
     557  intvec( 1, 2, 6, 9, 10 ),
     558  intvec( 1, 2, 3, 4, 5, 6 ),
     559  intvec( 1, 2, 3, 4, 5, 10 ),
     560  intvec( 1, 2, 3, 5, 6, 8 ),
     561  intvec( 1, 2, 3, 5, 6, 9 ),
     562  intvec( 1, 2, 3, 5, 7, 10 ),
     563  intvec( 1, 2, 3, 7, 9, 10 ),
     564  intvec( 1, 2, 3, 4, 5, 6, 7 ),
     565  intvec( 1, 2, 3, 4, 5, 6, 8 ),
     566  intvec( 1, 2, 3, 4, 5, 6, 9 ),
     567  intvec( 1, 2, 3, 5, 6, 9, 10 ),
     568  intvec( 1, 2, 3, 4, 5, 6, 7, 8 ),
     569  intvec( 1, 2, 3, 4, 5, 6, 9, 10 ),
     570  intvec( 1, 2, 3, 4, 5, 6, 7, 8, 9 ),
     571  intvec( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );
     572  list afaceOrbitRepresentatives=afaces(J,simplexOrbitRepresentatives);
     573  list fulldimAfaceOrbitRepresentatives=fullDimImages(afaceOrbitRepresentatives,Q);
     574  list afaceOrbits=computeAfaceOrbits(fulldimAfaceOrbitRepresentatives,simplexSymmetryGroup);
     575  apply(afaceOrbits,size);
     576  list minAfaceOrbits = minimalAfaceOrbits(afaceOrbits);
     577  apply(minAfaceOrbits,size);
     578}
     579
     580
     581static proc list2string(list L){
     582  string s = "";
     583
     584  for(int i = 1; i <=size(L); i++){
     585    s = s + string(size(L[i])) + ", ";
     586  }
     587
     588  return(s);
     589}
     590
     591
     592
     593proc fullDimImages(list afaces,intmat Q)
     594"USAGE: fullDimImages(afaces, Q); afaces: list, Q: intmat
     595PURPOSE: Determines the a-faces (represented as intvecs) from the list afaces which have a full-dimensional projection with respect to Q.
     596RETURN: a list of intvecs
     597EXAMPLE: example fullDimImages; shows an example
     598"
     599{
     600  list L;
     601  for (int i=1; i<=size(afaces); i++)
    194602  {
    195     d = #[1];
    196   }
    197 
    198   if ((size(#) > 1) and (typeof(#[2]) == "int"))
     603          intvec gam0 = afaces[i];
     604          intmat Qgam0[nrows(Q)][size(gam0)] = Q[intvec(1..nrows(Q)),gam0];
     605          //cone c = coneViaPoints(Qgam0);
     606          if(rank(Qgam0) == nrows(Q)){
     607      L[size(L)+1]=afaces[i];
     608    }
     609    kill gam0,Qgam0;
     610  }
     611  return(L);
     612}
     613example
     614{
     615  echo=2;
     616  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     617  ideal J =
     618    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     619    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     620    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     621    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     622    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     623  intmat Q[5][10] =
     624    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     625    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     626    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     627    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     628    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     629
     630  list AF= afaces(J,nrows(Q));
     631  size(AF);
     632  size(fullDimImages(AF,Q));
     633}
     634
     635
     636
     637
     638proc orbitConeOrbits(list F, intmat Q)
     639"USAGE: orbitConeOrbits(F, Q); F: list, Q: intmat
     640PURPOSE: Projects a list F of a-face orbits to the orbit cones with respect to Q. The function checks whether the projections are of full dimension and returns an error otherwise.
     641RETURN: a list of lists of cones
     642EXAMPLE: example orbitConeOrbits; shows an example
     643"
     644{
     645  list OC;
     646  int j;
     647  intmat Qt = transpose(Q);
     648  for(int i = 1; i <= size(F); i++){
     649    list Orbit = F[i];
     650    list U;
     651    for(j = 1; j <= size(Orbit); j++){
     652      intvec aface = Orbit[j];
     653      intmat Qgam0[size(aface)][ncols(Qt)] = Qt[aface,intvec(1..ncols(Qt))];
     654      cone c = coneViaPoints(Qgam0);
     655      if (dimension(c)!=ncols(Qt)){ERROR("cone should have full dimension");}
     656      // insert it even if it is already inside (mincones will take care of this)
     657      U[size(U)+1] = c;
     658      kill aface;
     659      kill Qgam0;
     660      kill c;
     661    }
     662    OC[size(OC)+1] = U;
     663    dbprint("current size of OC:");
     664    dbprint(size(OC));
     665    kill U;
     666    kill Orbit;
     667  }
     668  return(OC);
     669}
     670example
     671{
     672  echo = 2;
     673  // Note that simplexOrbitRepresentatives and simplexSymmetryGroup are subsets of the actual sets for G25. For the full example see the examples in the documentation
     674  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     675  ideal J =
     676    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     677    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     678    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     679    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     680    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     681  intmat Q[5][10] =
     682    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     683    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     684    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     685    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     686    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     687  list simplexOrbitRepresentatives = intvec( 1, 2, 3, 4, 5 ),
     688    intvec( 1, 2, 3, 5, 6 ),
     689    intvec( 1, 2, 3, 5, 7 ),
     690    intvec( 1, 2, 3, 5, 10 ),
     691    intvec( 1, 2, 3, 7, 9 ),
     692    intvec( 1, 2, 3, 4, 5, 6, 9, 10 ),
     693    intvec( 1, 2, 3, 4, 5, 6, 7, 8, 9 ),
     694    intvec( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );
     695  list afaceOrbitRepresentatives=afaces(J,simplexOrbitRepresentatives);
     696  list simplexSymmetryGroup = permutationFromIntvec(intvec( 1 .. 10 )),
     697    permutationFromIntvec(intvec( 1, 2, 4, 3, 5, 7, 6, 9, 8, 10 )),
     698    permutationFromIntvec(intvec( 1, 3, 2, 4, 6, 5, 7, 8, 10, 9 )),
     699    permutationFromIntvec(intvec( 1, 3, 4, 2, 6, 7, 5, 10, 8, 9 )),
     700    permutationFromIntvec(intvec( 1, 4, 2, 3, 7, 5, 6, 9, 10, 8 )),
     701    permutationFromIntvec(intvec( 1, 4, 3, 2, 7, 6, 5, 10, 9, 8 ));
     702  list fulldimAfaceOrbitRepresentatives=fullDimImages(afaceOrbitRepresentatives,Q);
     703  list afaceOrbits=computeAfaceOrbits(fulldimAfaceOrbitRepresentatives,simplexSymmetryGroup);
     704  apply(afaceOrbits,size);
     705  list minAfaceOrbits = minimalAfaceOrbits(afaceOrbits);
     706  apply(minAfaceOrbits,size);
     707  list listOfOrbitConeOrbits = orbitConeOrbits(minAfaceOrbits,Q);
     708}
     709
     710
     711proc minimalOrbitConeOrbits(list listOfOrbits)
     712"USAGE: minimalOrbitConeOrbits(listOfOrbits); listOfOrbits: list of lists of cones
     713PURPOSE: Minimizes a list of orbit cone orbits.
     714RETURN: a list of lists of cones
     715EXAMPLE: example minimalOrbitConeOrbits; shows an example
     716"
     717{
     718  int i,j;
     719  list L = listOfOrbits;
     720
     721
     722  for (i=1; i<=size(L); i++)
    199723  {
    200     ncores = #[2];
    201   }
    202 
    203   list AF;
    204   intvec gam0;
    205   int r = nvars(basering);
    206 
    207   // check if 0 is an a-face:
    208   gam0 = 0;
    209   if (isAface(a,gam0))
     724    dbprint("::::: " + string(i)+" of "+string(size(L)));
     725
     726    for (j=1; j<=size(L); j++)
     727    {
     728      dbprint("outer: "+string(i)+"  inner: " + string(j));
     729      if (i!=j)
     730      {
     731        if (containsOrbitdCone(L[i],L[j]))
     732        {
     733          dbprint("werfe raus, i="+string(i)+",  j="+string(j)+" (Laenge):  " + string(size(L[j])));
     734          L = delete(L,j);
     735          if (j<i)
     736          {
     737            i = i-1;
     738          }
     739          j = j-1;
     740        }
     741      }
     742    }
     743  }
     744  return(L);
     745}
     746example
     747{
     748  echo = 2;
     749  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     750  ideal J =
     751    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     752    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     753    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     754    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     755    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     756  intmat Q[5][10] =
     757    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     758    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     759    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     760    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     761    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     762  list simplexSymmetryGroup = G25Action();
     763  list simplexOrbitRepresentatives = intvec( 1, 2, 3, 4, 5 ),
     764  intvec( 1, 2, 3, 5, 6 ),
     765  intvec( 1, 2, 3, 5, 7 ),
     766  intvec( 1, 2, 3, 5, 10 ),
     767  intvec( 1, 2, 3, 7, 9 ),
     768  intvec( 1, 2, 6, 9, 10 ),
     769  intvec( 1, 2, 3, 4, 5, 6 ),
     770  intvec( 1, 2, 3, 4, 5, 10 ),
     771  intvec( 1, 2, 3, 5, 6, 8 ),
     772  intvec( 1, 2, 3, 5, 6, 9 ),
     773  intvec( 1, 2, 3, 5, 7, 10 ),
     774  intvec( 1, 2, 3, 7, 9, 10 ),
     775  intvec( 1, 2, 3, 4, 5, 6, 7 ),
     776  intvec( 1, 2, 3, 4, 5, 6, 8 ),
     777  intvec( 1, 2, 3, 4, 5, 6, 9 ),
     778  intvec( 1, 2, 3, 5, 6, 9, 10 ),
     779  intvec( 1, 2, 3, 4, 5, 6, 7, 8 ),
     780  intvec( 1, 2, 3, 4, 5, 6, 9, 10 ),
     781  intvec( 1, 2, 3, 4, 5, 6, 7, 8, 9 ),
     782  intvec( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );
     783  list afaceOrbitRepresentatives=afaces(J,simplexOrbitRepresentatives);
     784  list fulldimAfaceOrbitRepresentatives=fullDimImages(afaceOrbitRepresentatives,Q);
     785  list afaceOrbits=computeAfaceOrbits(fulldimAfaceOrbitRepresentatives,simplexSymmetryGroup);
     786  apply(afaceOrbits,size);
     787  list minAfaceOrbits = minimalAfaceOrbits(afaceOrbits);
     788  apply(minAfaceOrbits,size);
     789  list listOfOrbitConeOrbits = orbitConeOrbits(minAfaceOrbits,Q);
     790  apply(listOfOrbitConeOrbits,size);
     791  list listOfMinimalOrbitConeOrbits = minimalOrbitConeOrbits(listOfOrbitConeOrbits);
     792  size(listOfMinimalOrbitConeOrbits);
     793}
     794
     795
     796static proc containsOrbitdCone(list A, list B)
     797{
     798  cone a = A[1];
     799  for (int i=1; i<=size(B); i++)
    210800  {
    211       AF[size(AF) + 1] = gam0;
    212   }
    213 
    214   // check for other a-faces:
    215   // make ncores processes:
    216   int step = 2^r div ncores;
     801    if (isSubcone(a,B[i]))
     802    {
     803      dbprint("found subcone i="+string(i));
     804      return (1);
     805    }
     806  }
     807  return (0);
     808}
     809
     810static proc isSubcone(cone c1, cone c2)
     811{
     812  return(containsInSupport(c2, c1));
     813}
     814
     815
     816
     817
     818
     819
     820proc intersectOrbitsWithMovingCone(list OCmin,cone mov)
     821"USAGE: intersectOrbitsWithMovingCone(OCmin, mov); OCmin: list of lists of cones, mov: cone
     822PURPOSE: Intersects all cones in the orbits in OCmin with mov discarting all orbits of cones which are not of full dimension. The resulting orbits are duplicate free.
     823RETURN: a list of lists of cones
     824EXAMPLE: example intersectOrbitsWithMovingCone; shows an example
     825"
     826{
     827  list OCmov;
     828  cone ocmov;
     829  int i,j;
     830  int fulldim=dimension(mov);
     831  for (i=1; i<=size(OCmin); i++)
     832  {
     833    dbprint("intersecting orbit "+string(i)+" with moving cone");
     834    ocmov = convexIntersection(OCmin[i][1],mov);
     835    if (dimension(ocmov)==fulldim)
     836    {
     837      list currentOrbit;
     838      for (j=1; j<=size(OCmin[i]); j++)
     839      {
     840        dbprint("checking cone "+string(j)+" of "+string(size(OCmin[i])));
     841        ocmov = convexIntersection(OCmin[i][j],mov);
     842        ocmov = canonicalizeCone(ocmov);
     843        if (!listContainsCone(currentOrbit,ocmov))
     844        {
     845          dbprint("inserting cone");
     846          currentOrbit[size(currentOrbit)+1] = ocmov;
     847        }
     848      }
     849      OCmov[size(OCmov)+1] = currentOrbit;
     850      kill currentOrbit;
     851    }
     852    else
     853    {
     854      dbprint("intersection with moving cone lower-dimensional, abandoning orbit");
     855    }
     856  }
     857  return(OCmov);
     858}
     859example {
     860  echo=2;
     861  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     862  ideal J =
     863    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     864    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     865    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     866    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     867    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     868  intmat Q[5][10] =
     869    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     870    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     871    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     872    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     873    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     874  list simplexSymmetryGroup = G25Action();
     875  list simplexOrbitRepresentatives = intvec( 1, 2, 3, 4, 5 ),
     876  intvec( 1, 2, 3, 5, 6 ),
     877  intvec( 1, 2, 3, 5, 7 ),
     878  intvec( 1, 2, 3, 5, 10 ),
     879  intvec( 1, 2, 3, 7, 9 ),
     880  intvec( 1, 2, 6, 9, 10 ),
     881  intvec( 1, 2, 3, 4, 5, 6 ),
     882  intvec( 1, 2, 3, 4, 5, 10 ),
     883  intvec( 1, 2, 3, 5, 6, 8 ),
     884  intvec( 1, 2, 3, 5, 6, 9 ),
     885  intvec( 1, 2, 3, 5, 7, 10 ),
     886  intvec( 1, 2, 3, 7, 9, 10 ),
     887  intvec( 1, 2, 3, 4, 5, 6, 7 ),
     888  intvec( 1, 2, 3, 4, 5, 6, 8 ),
     889  intvec( 1, 2, 3, 4, 5, 6, 9 ),
     890  intvec( 1, 2, 3, 5, 6, 9, 10 ),
     891  intvec( 1, 2, 3, 4, 5, 6, 7, 8 ),
     892  intvec( 1, 2, 3, 4, 5, 6, 9, 10 ),
     893  intvec( 1, 2, 3, 4, 5, 6, 7, 8, 9 ),
     894  intvec( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );
     895  list afaceOrbitRepresentatives=afaces(J,simplexOrbitRepresentatives);
     896  list fulldimAfaceOrbitRepresentatives=fullDimImages(afaceOrbitRepresentatives,Q);
     897  list afaceOrbits=computeAfaceOrbits(fulldimAfaceOrbitRepresentatives,simplexSymmetryGroup);
     898  apply(afaceOrbits,size);
     899  list minAfaceOrbits = minimalAfaceOrbits(afaceOrbits);
     900  apply(minAfaceOrbits,size);
     901  list listOfOrbitConeOrbits = orbitConeOrbits(minAfaceOrbits,Q);
     902  cone mov = movingCone(Q);
     903  intersectOrbitsWithMovingCone(listOfOrbitConeOrbits,mov);
     904}
     905
     906
     907static proc coneToString(cone C){
     908  bigintmat F = facets(C);
     909  ring R=0,(x),dp;
     910  matrix FF[nrows(F)][ncols(F)];
     911  int i,j;
     912  for (i=1; i<=nrows(F);i++){
     913    for (j=1; j<=ncols(F);j++){
     914      FF[i,j]=number(F[i,j]);
     915    }
     916  }
     917  return("bigintmat F["+string(nrows(F))+"]["+string(ncols(F))+"]="+string(FF)+";cone C=canonicalizeCone(coneViaInequalities(F));");
     918}
     919
     920proc storeOrbitConeOrbits(list OC, string fn)
     921"USAGE: storeOrbitConeOrbits(OC, fn); OC: list of lists of cones, fn: string
     922PURPOSE: Writes OC to file fn in Singular readable format. Can be importet using <.
     923RETURN: nothing
     924"
     925{
     926  int i,j;
     927  write(":w "+fn,"list OC;");
     928  for (i=1;i<=size(OC);i++){
     929    write(":a "+fn,"list OCj;");
     930    for (j=1;j<=size(OC[i]);j++){
     931      write(":a "+fn,coneToString(OC[i][j]));
     932      write(":a "+fn,"OCj[size(OCj)+1]=C;");
     933      write(":a "+fn,"kill C;kill F;");
     934    }
     935    write(":a "+fn,"OC[size(OC)+1]=OCj;");
     936    write(":a "+fn,"kill OCj;");
     937  }
     938}
     939
     940static proc storeCone(cone C,string fn){
     941  intmat H = intmat(inequalities(C));
     942  write(":w "+fn,"bigintmat H["+string(nrows(H))+"]["+string(ncols(H))+"] =");
     943  write(":w "+fn,string(H)+";");
     944  write(":a "+fn,"cone C= coneViaInequalities(H); kill H;");
     945}
     946
     947static proc listToIntvec(list L){
     948  intvec v;
     949  for (int i = 1;i<=size(L);i++){
     950    v[i]=L[i];}
     951  return(v);
     952}
     953
     954static proc intvecToList(intvec L){
     955  list v;
     956  for (int i = 1;i<=size(L);i++){
     957    v[i]=L[i];}
     958  return(v);
     959}
     960
     961static proc stackMatrices(bigintmat M, bigintmat N){
     962  if (ncols(M)!=ncols(N)){ERROR("matrices should have the same number of columns");}
     963  bigintmat MN[nrows(M)+nrows(N)][ncols(N)];
     964  MN[1..nrows(M),1..ncols(M)]=M[1..nrows(M),1..ncols(M)];
     965  MN[(nrows(M)+1)..(nrows(M)+nrows(N)),1..ncols(M)]=N[1..nrows(N),1..ncols(N)];
     966  return(MN);
     967}
     968
     969
     970proc movingCone(intmat Q)
     971"USAGE: movingCone(Q); Q: intmat
     972PURPOSE: Computes the moving cone from the grading matrix, with the degrees in the columns of Q.
     973RETURN: a cone
     974EXAMPLE: example movingCone; shows an example
     975"
     976{
     977  cone Qgammadual = coneViaInequalities(transpose(Q));
     978  bigintmat R = facets(Qgammadual);
     979  list idx1=intvecToList(intvec(1..nrows(R)));
     980  intvec idx2=1..ncols(R);
     981  intvec idx1iv;
     982  bigintmat Ri[nrows(R)-1][ncols(R)];
     983  list C;
     984  for (int i = 1; i<=nrows(R);i++){
     985    idx1iv = listToIntvec(delete(idx1,i));
     986    Ri=R[idx1iv,idx2];
     987    C[i]=coneViaPoints(Ri);
     988    dbprint(string(i)+"   "+string(nrows(facets(C[i]))));
     989  }
     990  cone mov = convexIntersection(C);
     991  return(mov);
     992}
     993example
     994{
     995  echo=2;
     996  intmat Q[5][10] =
     997    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     998    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     999    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     1000    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     1001    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     1002  cone mov = movingCone(Q);
     1003  mov;
     1004  rays(mov);
     1005}
     1006
     1007
     1008static proc pivotIndices(matrix H)
     1009{
     1010  intvec p;
     1011  int pp;
     1012  int i,j;
     1013  int l=1;
     1014  for (i=1; i<=ncols(H); i++)
     1015  {
     1016    for (j=nrows(H); j>=0; j--)
     1017    {
     1018      if (H[j,i]!=0)
     1019      {
     1020        if (j>pp)
     1021        {
     1022          p[l] = i;
     1023          l++;
     1024          pp = j;
     1025        }
     1026        break;
     1027      }
     1028    }
     1029  }
     1030  return (p);
     1031}
     1032
     1033
     1034
     1035proc groupActionOnQImage(list G,intmat Q)
     1036"USAGE: groupActionOnQImage(G,Q); G: list of permutations, Q: intmat
     1037PURPOSE: Given the group G of permutations acting on the simplex on ncols(Q) objects, computes the corresponding group action on the image of Q. We assume that the basering has characteristic 0.
     1038RETURN: list of matrices
     1039EXAMPLE: example groupActionOnQImage; shows an example
     1040"
     1041{
     1042  matrix Qmat = transpose(matrix(Q));
     1043  matrix H = gauss_nf(Qmat);
     1044  intvec indices = pivotIndices(H);
     1045  intmat Qbasis[nrows(Q)][size(indices)]=Q[1..nrows(Q),indices];
     1046  matrix QbasisInv = inverse(Qbasis);
     1047  list L;
     1048  intmat Qt = transpose(Q);
     1049  for(int i = 1; i <= size(G); i++){
     1050    intvec sig = permutationToIntvec(G[i]);
     1051    intmat Bsig = perm2mat(sig, indices,Qt);
     1052    matrix Asig = Bsig * QbasisInv;
     1053    L[size(L)+1] = matrixToIntmat(Asig);
     1054    kill sig;
     1055    kill Bsig;
     1056    kill Asig;
     1057  }
     1058  return(L);
     1059}
     1060example {
     1061  echo=2;
     1062  ring R = 0,(x),dp;
     1063  intmat Q[5][10] =
     1064    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     1065    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     1066    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     1067    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     1068    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     1069list generatorsG = permutationFromIntvec(intvec( 1, 3, 2, 4, 6, 5, 7, 8, 10, 9 )),
     1070permutationFromIntvec(intvec( 5, 7, 1, 6, 9, 2, 8, 4, 10, 3 ));
     1071groupActionOnQImage(generatorsG,Q);
     1072}
     1073
     1074
     1075
     1076static proc perm2mat(intvec sig, intvec indices, intmat Q){
     1077  intvec sigind = 1:size(indices);
     1078  for(int i = 1; i <= size(indices); i++){
     1079    if(indices[i] > size(sig)){
     1080      sigind[i] = indices[i];
     1081    } else {
     1082      sigind[i] = sig[indices[i]];
     1083    }
     1084  }
     1085  intmat Asig[size(indices)][ncols(Q)];
     1086  for(i = 1; i <= size(sigind); i++){
     1087    Asig[i,1..ncols(Q)] = Q[sigind[i], 1..ncols(Q)];
     1088  }
     1089  // the new basis must be in the cols:
     1090  return(transpose(Asig));
     1091}
     1092
     1093///////
     1094
     1095
     1096
     1097
     1098static proc imageCone(cone c, intmat A){
     1099  bigintmat ineqs = inequalities(c);
     1100  cone cc = coneViaInequalities (ineqs * A);
     1101  return(cc);
     1102}
     1103
     1104
     1105static proc matrixToIntmat(matrix A){
     1106  int i,j;
     1107  intmat Aint[nrows(A)][ncols(A)];
     1108  for(i = 1; i<=nrows(A); i++){
     1109    for(j = 1; j<=ncols(A); j++){
     1110      if (deg(A[i,j])>0){ERROR("entries should be constants");}
     1111      if (denominator(number(A[i,j]))!=1){ERROR("entries should be integers");}
     1112      Aint[i,j]=int(number(A[i,j]));
     1113    }
     1114  }
     1115  return(Aint);
     1116}
     1117
     1118
     1119proc groupActionOnHashes(list Asigma, list OCmov)
     1120"USAGE: groupActionOnHashes(Asigma,OCmov); Asigma: list, OCmov: list of list of cones
     1121PURPOSE: From the list of orbits of orbitcones, and the symmetry group represenation given by the matrices in Asigma, compute the corresponding permutation representation of the symmetry group on the orbit cones. The permutations are specified in a map representation of length the sum of the size of the orbits of OCmov.
     1122RETURN: list of permutations
     1123EXAMPLE: example groupActionOnHashes; shows an example
     1124"
     1125{
     1126// for each A in S6:
     1127// for each c in OC90:
     1128// store index of A*c
     1129// --> intvec v_A
     1130// store this in the list Ind
     1131  list Ind;
     1132  int i,j,b,k,sizepreviousorbits;
     1133  list remaining;
     1134  intmat A;
     1135  cone c,Ac;
     1136  for(i = 1; i<=size(Asigma); i++){
     1137    intvec vA;
     1138    A = intmat(Asigma[i]);
     1139    dbprint("element "+string(i)+" of symmetry group");
     1140    sizepreviousorbits=0;
     1141    for(b = 1; b <= size(OCmov); b++){
     1142      remaining = intvecToList(intvec(1..size(OCmov[b])));
     1143      for(j = 1; j <= size(OCmov[b]); j++){
     1144        Ac = imageCone(OCmov[b][j], A);
     1145
     1146        // find out index:
     1147        for(k= 1; k <= size(remaining); k++){
     1148          if(OCmov[b][remaining[k]] == Ac){
     1149            vA[j+sizepreviousorbits] = remaining[k]+sizepreviousorbits;
     1150            remaining = delete(remaining,k);
     1151            break;
     1152          }
     1153        }
     1154      }
     1155
     1156      sizepreviousorbits=size(vA);
     1157    }
     1158    Ind[size(Ind)+1] = permutationFromIntvec(vA);
     1159    dbprint("vA: "+string(vA));
     1160    kill vA;
     1161  }
     1162  return(Ind);
     1163}
     1164example
     1165{
     1166  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     1167  ideal J =
     1168    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     1169    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     1170    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     1171    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     1172    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     1173  intmat Q[5][10] =
     1174    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     1175    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     1176    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     1177    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     1178    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     1179  list AF= afaces(J);
     1180  list OC = orbitCones(AF,Q);
     1181  list generatorsG = permutationFromIntvec(intvec( 1, 3, 2, 4, 6, 5, 7, 8, 10, 9 )),
     1182                     permutationFromIntvec(intvec( 5, 7, 1, 6, 9, 2, 8, 4, 10, 3 ));
     1183  list Asigmagens = groupActionOnQImage(generatorsG,Q);
     1184groupActionOnHashes(Asigmagens,list(OC));
     1185
     1186
     1187  list orb = findOrbits(simplexSymmetryGroup,nrows(Q));
     1188  list simplexOrbitRepresentatives;
     1189  for (int i=1;i<=size(orb);i++){simplexOrbitRepresentatives[i]=orb[i][1];}
     1190  list afaceOrbitRepresentatives=afaces(J,simplexOrbitRepresentatives);
     1191  list fulldimAfaceOrbitRepresentatives=fullDimImages(afaceOrbitRepresentatives,Q);
     1192  list afaceOrbits=computeAfaceOrbits(fulldimAfaceOrbitRepresentatives,simplexSymmetryGroup);
     1193  list minAfaceOrbits = minimalAfaceOrbits(afaceOrbits);
     1194  list listOfOrbitConeOrbits = orbitConeOrbits(minAfaceOrbits,Q);
     1195  list listOfMinimalOrbitConeOrbits = minimalOrbitConeOrbits(listOfOrbitConeOrbits);
     1196  list Asigma = groupActionOnQImage(simplexSymmetryGroup,Q);
     1197  groupActionOnHashes(Asigma,listOfOrbitConeOrbits);
     1198
     1199}
     1200
     1201
     1202
     1203
     1204
     1205
     1206
     1207
     1208static proc composePermutationsGAP(permutation sigma, permutation tau){
     1209  intvec sigmaTauImage;
     1210
     1211  for (int i=1;i<=size(sigma.image);i++){
     1212    sigmaTauImage[i]=tau.image[sigma.image[i]];
     1213  }
     1214
     1215  permutation sigmaTau;
     1216  sigmaTau.image = sigmaTauImage;
     1217  return(sigmaTau);
     1218}
     1219
     1220static proc composePermutations(permutation sigma, permutation tau){
     1221  intvec sigmaTauImage;
     1222
     1223  for (int i=1;i<=size(sigma.image);i++){
     1224    sigmaTauImage[i]=sigma.image[tau.image[i]];
     1225  }
     1226
     1227  permutation sigmaTau;
     1228  sigmaTau.image = sigmaTauImage;
     1229  return(sigmaTau);
     1230}
     1231
     1232
     1233static proc permutationPower(permutation sigma, int k){
    2171234  int i;
    218 
    219   list args;
    220   for(int k = 0; k < ncores; k++)
     1235  if (k==0)
    2211236  {
    222     args[size(args) + 1] = list(a, d, k * step + 1, (k+1) * step, r);
    223   }
    224 
    225   string command = "afacesPart";
    226   list out = parallelWaitAll(command, args);
    227 
    228   // do remaining ones:
    229   for(i = ncores * step +1; i < 2^r; i++)
     1237    permutation identity;
     1238    identity.image = intvec(1..size(sigma.image));
     1239    return (identity);
     1240  }
     1241  if (k<0)
    2301242  {
    231     "another one needed";
    232     gam0 = int2face(i,r);
    233 
    234     // take gam0 only if it has
    235     // at least d rays:
    236     if(size(gam0) >= d)
     1243    // if k<0 invert sigma and replace k with -k
     1244    intvec sigmaImage = sigma.image;
     1245    for (i=1; i<=size(sigmaImage); i++)
    2371246    {
    238       if (isAface(a,gam0))
     1247      sigma.image[sigmaImage[i]] = i;
     1248    }
     1249    k = -k;
     1250  }
     1251  permutation sigmaToPowerK = sigma;
     1252  for (i=2; i<=k; i++)
     1253  {
     1254    sigmaToPowerK = composePermutations(sigmaToPowerK, sigma);
     1255  }
     1256  return (sigmaToPowerK);
     1257}
     1258
     1259proc permutationFromIntvec(intvec sigmaImage)
     1260"USAGE: permutationFromIntvec(sigmaImage); sigmaImage: intvec
     1261PURPOSE: Create a permutation from an intvec of images.
     1262RETURN: permutation
     1263EXAMPLE: example permutationFromIntvec; shows an example
     1264"
     1265{
     1266  permutation sigma;
     1267  sigma.image = sigmaImage;
     1268  return (sigma);
     1269}
     1270
     1271
     1272proc evaluateProduct(list generatorsGperm, string st)
     1273"USAGE: evaluateProduct(generatorsGperm,st); generatorsGperm: list, st: string
     1274PURPOSE: Evaluates a formal product of variables xi in st, where xi corresponds to the permutation generatorsGperm[i].
     1275RETURN: permutation
     1276EXAMPLE: example evaluateProduct; shows an example
     1277"
     1278{
     1279  for (int i=1;i<=size(generatorsGperm);i++){
     1280    execute("permutation x"+string(i)+"= generatorsGperm[i];");
     1281  }
     1282  if (st==""){
     1283    st="x1^0";
     1284  }
     1285  execute("permutation sigma = "+st);
     1286  return(sigma);}
     1287example
     1288{
     1289  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     1290  ideal J =
     1291    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     1292    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     1293    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     1294    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     1295    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     1296  intmat Q[5][10] =
     1297    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     1298    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     1299    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     1300    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     1301    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     1302  list AF= afaces(J);
     1303  list OC = orbitCones(AF,Q);
     1304  list generatorsG = permutationFromIntvec(intvec( 1, 3, 2, 4, 6, 5, 7, 8, 10, 9 )),
     1305                     permutationFromIntvec(intvec( 5, 7, 1, 6, 9, 2, 8, 4, 10, 3 ));
     1306  list Asigmagens = groupActionOnQImage(generatorsG,Q);
     1307list actionOnOrbitconeIndicesForGenerators = groupActionOnHashes(Asigmagens,OC);
     1308string elementInTermsOfGenerators =
     1309"(x2^-1*x1^-1)^3*x1^-1";
     1310evaluateProduct(actionOnOrbitconeIndicesForGenerators, elementInTermsOfGenerators);
     1311}
     1312
     1313
     1314proc permutationToIntvec(permutation sigma)
     1315"USAGE: permutationToIntvec(sigma); sigma: permutation
     1316PURPOSE: Convert a permutation to an intvec of images.
     1317RETURN: intvec
     1318EXAMPLE: example permutationToIntvec; shows an example
     1319"
     1320{return(sigma.image);}
     1321example
     1322{
     1323permutation sigma = permutationFromIntvec(intvec( 1, 2, 4, 3, 5, 7, 6, 9, 8, 10 ));
     1324sigma;
     1325permutationToIntvec(sigma);
     1326}
     1327
     1328
     1329
     1330
     1331
     1332
     1333
     1334
     1335
     1336
     1337
     1338
     1339proc storeActionOnOrbitConeIndices(list Ind,string fn)
     1340"USAGE: storeActionOnOrbitConeIndices(generatorsGperm,st); generatorsGperm: list, fn: string
     1341PURPOSE: Write the action on the set of orbit cones to the file fn in Singular readable format.
     1342RETURN: nothing
     1343"
     1344{
     1345  string s = "list actionOnOrbitconeIndices;";
     1346  for(int i =1; i <= size(Ind); i++){
     1347    s = s + "intvec v = " + string(Ind[i]) + ";" + newline;
     1348    s = s + "actionOnOrbitconeIndices[size(actionOnOrbitconeIndices)+1] = permutationFromIntvec(v);" + newline + "kill v;" + newline;
     1349  }
     1350  write(":w "+fn, s);
     1351}
     1352
     1353
     1354
     1355
     1356
     1357static proc getNeighborHash(list OC, bigintmat w, bigintmat v, int mu)
     1358{
     1359  int success = 0;
     1360  int zz;
     1361  intvec Jtmp;
     1362  bigintmat wtmp;
     1363
     1364  while(!success)
     1365  {
     1366    mu = mu*2;
     1367    wtmp = mu*w - v;
     1368    success = 1;
     1369    for(zz = 1; zz <= size(OC); zz++)
     1370    {
     1371      if(containsInSupport(OC[zz], wtmp))
    2391372      {
    240         AF[size(AF) + 1] = gam0;
     1373        if(!containsInSupport(OC[zz], w))
     1374        {
     1375          success = 0;
     1376          Jtmp = 0;
     1377          break;
     1378        }
     1379        // insert index zz:
     1380        if(size(Jtmp) ==1 && Jtmp[1] == 0)
     1381        {
     1382          Jtmp[1] = zz;
     1383        }
     1384        else
     1385        {
     1386          Jtmp[size(Jtmp)+1] = zz;
     1387        }
    2411388      }
    2421389    }
    2431390  }
    2441391
    245   // read out afaces of out into AF:
    246   for(i = 1; i <= size(out); i++)
     1392  return(Jtmp);
     1393}
     1394
     1395
     1396
     1397
     1398///////////////////////////////////////
     1399
     1400proc GITfanSymmetric(list OC, bigintmat Q, cone Qgamma, list actiononorbitcones, list #)
     1401  "USAGE: GITfanSymmetric(OC, Q, Qgamma, actiononorbitcones [, file1, file2]); OC:list, Q:bigintmat, Qgamma:cone, actiononorbitcones: list of intvec, file1:string, file2:string
     1402PURPOSE: Returns the common refinement of the cones given in
     1403the list OC which is supposed to contain the orbit cones intersected with Qgamma. The list actiononorbitcones is supposed to contain the symmetry group acting as permutations of on the list of orbit cones in OC. The optional argument can be used to specify one or two strings with file names, where the first file will contain the hashes of the GIT-cones and the second argument the actual cones in their H-representation.
     1404To obtain the whole GIT-fan Qgamma has to be take the cone generated by the columns of Q.
     1405RETURN: a list containing the bigint hashes of the GIT cones.
     1406EXAMPLE: example GITfanSymmetric; shows an example
     1407"
     1408{
     1409  actiononorbitcones=apply(actiononorbitcones,permutationToIntvec);
     1410  /**
     1411   * stores the hashes of all maximal GIT cones computed
     1412   */
     1413  list hashesOfCones;
     1414  /**
     1415   * stores to the corresponding maximal GIT cone in hashesOfCones
     1416   * - 0, if guaranteed that all adjacent GIT cones are known
     1417   *        or are to be computed in the next iteration       (*)
     1418   * - hash as intvec, otherwise
     1419   */
     1420  list workingList;
     1421
     1422
     1423  /**
     1424   * compute starting cone
     1425   */
     1426  bigintmat w,v;
     1427  cone lambda;
     1428  intvec lambdaHash;
     1429  while(dimension(lambda) <> nrows(Q)){
     1430    w = randConeEl(transpose(Q),100);
     1431    dbprint("testing "+string(w));
     1432    if (containsRelatively(Qgamma,w)) {
     1433      lambda,lambdaHash = GITcone(OC,w);
     1434      dbprint("computed cone of dimension "+string(dimension(lambda)));
     1435    }
     1436  }
     1437  int nCones = 1;     // essentially size(hashesOfCones)
     1438  int nConesOpen = 1; // essentially size(workingList)+1, see (*) above
     1439
     1440
     1441  /**
     1442   * initialize lists
     1443   */
     1444  int posToInsert = 1;
     1445  bigint hashToInsert = binaryToBigint(lambdaHash);
     1446  intvec sigLambdaHash;
     1447  for(int i = 2; i <= size(actiononorbitcones); i++){
     1448    sigLambdaHash = composeIntvecs(actiononorbitcones[i],lambdaHash);
     1449    hashToInsert = min(hashToInsert,binaryToBigint(sigLambdaHash));
     1450  }
     1451  hashesOfCones[1] = hashToInsert;
     1452  workingList[1] = int(0);
     1453  if (size(#)>0) {write(":w "+#[1],string(hashesOfCones[1]) + ",");}
     1454  if (size(#)>1) {write(":w "+#[2],"");writeGitconeToFile(lambda,#[2]);}
     1455
     1456
     1457  /**
     1458   * traverse fan
     1459   */
     1460  int t,tt;
     1461  list FL;
     1462  intvec neighbourHash;
     1463  int mu = 1024;
     1464  while (lambdaHash>0)
    2471465  {
    248     AF = AF + out[i];
    249   }
    250 
    251   return(AF);
     1466    tt=timer;
     1467
     1468    /**
     1469     * compute all facets of lambda
     1470     */
     1471    t = timer;
     1472    FL = listOfFacetsAndInteriorVectors(lambda, Qgamma);
     1473    dbprint("time for facets: "+string(timer - t));
     1474
     1475    /**
     1476     * compute all neighbours of lambda
     1477     */
     1478    for (i=size(FL[1]); i>0; i--)
     1479    {
     1480      v = FL[1][i][1]; // interior facet normal
     1481      w = FL[1][i][2]; // interior facet point
     1482      neighbourHash = getNeighborHash(OC,w,v,mu);
     1483      posToInsert,hashToInsert = findPosToInsertSymmetric(hashesOfCones,neighbourHash,actiononorbitcones);
     1484      if(posToInsert > 0)
     1485      {
     1486        if (size(#)>0){write(":a "+#[1],string(binaryToBigint(neighbourHash)) + ",");}
     1487        hashesOfCones = insertToList(hashesOfCones,hashToInsert,posToInsert);
     1488        workingList = insertToList(workingList,neighbourHash,posToInsert);
     1489        nConesOpen++;
     1490        nCones++;
     1491      }
     1492    }
     1493
     1494    /**
     1495     * pick lambdaHash and lambda for next iteration,
     1496     * set respective entry in workingList to 0
     1497     */
     1498    lambdaHash = 0;
     1499    for (i=size(workingList); i>0; i--)
     1500    {
     1501      if (typeof(workingList[i])=="intvec")
     1502      {
     1503        lambdaHash = workingList[i];
     1504        lambda = gitConeFromHash(OC,lambdaHash);
     1505        if (size(#)>1) {writeGitconeToFile(lambda,#[2]);}
     1506        workingList[i] = int(0);
     1507        break;
     1508      }
     1509    }
     1510    nConesOpen--;
     1511
     1512    dbprint("overall: "+string(nCones)+"   open: "+string(nConesOpen)+"   time for loop: "+string(timer-tt));
     1513  }
     1514  return(hashesOfCones);
    2521515}
    2531516example
    2541517{
    255 
    256   echo = 2;
    257   ring R = 0,T(1..3),dp;
    258   ideal a = T(1)+T(2)+T(3);
    259 
    260   list F = afaces(a,3,4);
    261   print(F);
    262   print(size(F));
    263 
    264   // 2nd ex //
    265   ring R2 = 0,T(1..3),dp;
    266   ideal a2 = T(2)^2*T(3)^2+T(1)*T(3);
    267 
    268   list F2 = afaces(a2,3,4);
    269   print(F2);
    270   print(size(F2));
    271 
    272   // 3rd ex //
    273   ring R3 = 0,T(1..3),dp;
    274   ideal a3 = 0;
    275 
    276   list F3 = afaces(a3,3,4);
    277   print(F3);
    278   print(size(F3));
    279 
    280   // bigger example //
    281   ring R = 0,T(1..15),dp;
    282   ideal a =
    283     T(1)*T(10)-T(2)*T(7)+T(3)*T(6),
    284     T(1)*T(11)-T(2)*T(8)+T(4)*T(6),
    285     T(1)*T(12)-T(2)*T(9)+T(5)*T(6),
    286     T(1)*T(13)-T(3)*T(8)+T(4)*T(7),
    287     T(1)*T(14)-T(3)*T(9)+T(5)*T(7),
    288     T(1)*T(15)-T(4)*T(9)+T(5)*T(8),
    289     T(2)*T(13)-T(3)*T(11)+T(4)*T(10),
    290     T(2)*T(14)-T(3)*T(12)+T(5)*T(10),
    291     T(2)*T(15)-T(4)*T(12)+T(5)*T(11),
    292     T(3)*T(15)-T(4)*T(14)+T(5)*T(13),
    293     T(6)*T(13)-T(7)*T(11)+T(8)*T(10),
    294     T(6)*T(14)-T(7)*T(12)+T(9)*T(10),
    295     T(6)*T(15)-T(8)*T(12)+T(9)*T(11),
    296     T(7)*T(15)-T(8)*T(14)+T(9)*T(13),
    297     T(10)*T(15)-T(11)*T(14)+T(12)*T(13);
    298 
    299   int t = timer;
    300   list F4 = afaces(a,0,2);
    301   print(size(F4));
    302   timer - t;
    303 
    304   int t = timer;
    305   list F4 = afaces(a,0);
    306   print(size(F4));
    307   timer - t;
    308 
    309 }
    310 
    311 ///////////////////////////////////////
    312 
    313 proc orbitCones(ideal a, bigintmat Q, list #)
    314 "USAGE:  orbitCones(a, Q, b, c); a: ideal, Q: bigintmat, b: int, c: int
    315 PURPOSE: Returns a list consisting of all cones Q(gam0) where gam0 is an a-face.
    316          Moreover, it is possible to specify a dimensional bound b,
    317          upon which only cones of that dimension and above are returned.
    318          Lastly, as the computation is parallizable, one can specify c,
    319          the number of cores to be used by the computation.
    320 RETURN:  a list of cones
     1518  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     1519  ideal J =
     1520    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     1521    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     1522    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     1523    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     1524    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     1525  intmat Q[5][10] =
     1526    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     1527    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     1528    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     1529    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     1530    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     1531  list simplexSymmetryGroup = G25Action();
     1532  list simplexOrbitRepresentatives = intvec( 1, 2, 3, 4, 5 ),
     1533  intvec( 1, 2, 3, 5, 6 ),
     1534  intvec( 1, 2, 3, 5, 7 ),
     1535  intvec( 1, 2, 3, 5, 10 ),
     1536  intvec( 1, 2, 3, 7, 9 ),
     1537  intvec( 1, 2, 6, 9, 10 ),
     1538  intvec( 1, 2, 3, 4, 5, 6 ),
     1539  intvec( 1, 2, 3, 4, 5, 10 ),
     1540  intvec( 1, 2, 3, 5, 6, 8 ),
     1541  intvec( 1, 2, 3, 5, 6, 9 ),
     1542  intvec( 1, 2, 3, 5, 7, 10 ),
     1543  intvec( 1, 2, 3, 7, 9, 10 ),
     1544  intvec( 1, 2, 3, 4, 5, 6, 7 ),
     1545  intvec( 1, 2, 3, 4, 5, 6, 8 ),
     1546  intvec( 1, 2, 3, 4, 5, 6, 9 ),
     1547  intvec( 1, 2, 3, 5, 6, 9, 10 ),
     1548  intvec( 1, 2, 3, 4, 5, 6, 7, 8 ),
     1549  intvec( 1, 2, 3, 4, 5, 6, 9, 10 ),
     1550  intvec( 1, 2, 3, 4, 5, 6, 7, 8, 9 ),
     1551  intvec( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );
     1552  list afaceOrbitRepresentatives=afaces(J,simplexOrbitRepresentatives);
     1553  list fulldimAfaceOrbitRepresentatives=fullDimImages(afaceOrbitRepresentatives,Q);
     1554  list afaceOrbits=computeAfaceOrbits(fulldimAfaceOrbitRepresentatives,simplexSymmetryGroup);
     1555  apply(afaceOrbits,size);
     1556  list minAfaceOrbits = minimalAfaceOrbits(afaceOrbits);
     1557  apply(minAfaceOrbits,size);
     1558  list listOfOrbitConeOrbits = orbitConeOrbits(minAfaceOrbits,Q);
     1559  apply(listOfOrbitConeOrbits,size);
     1560  list listOfMinimalOrbitConeOrbits = minimalOrbitConeOrbits(listOfOrbitConeOrbits);
     1561  size(listOfMinimalOrbitConeOrbits);
     1562  list Asigma = groupActionOnQImage(simplexSymmetryGroup,Q);
     1563  list actionOnOrbitconeIndices = groupActionOnHashes(Asigma,listOfOrbitConeOrbits);
     1564  list OClist = listOfOrbitConeOrbits[1];
     1565  for (int i =2;i<=size(listOfOrbitConeOrbits);i++){
     1566    OClist = OClist + listOfOrbitConeOrbits[i];
     1567  }
     1568cone mov = coneViaPoints(transpose(Q));
     1569mov = canonicalizeCone(mov);
     1570printlevel = 3;
     1571list Sigma = GITfanSymmetric(OClist, Q, mov, actionOnOrbitconeIndices);
     1572Sigma;
     1573}
     1574
     1575
     1576proc GITfanParallelSymmetric(list OC, bigintmat Q, cone Qgamma, list actiononorbitcones, list #)
     1577  "USAGE: GITfanParallelSymmetric(OC, Q, Qgamma, actiononorbitcones [, file1]); OC:list, Q:bigintmat, Qgamma:cone, actiononorbitcones: list of intvec, file1:string
     1578PURPOSE: Returns the common refinement of the cones given in
     1579the list OC which is supposed to contain the orbit cones intersected with Qgamma. The list actiononorbitcones is supposed to contain the symmetry group acting as permutations of on the list of orbit cones in OC. The optional argument can be used to specify a name for a file which will contain the hashes of the GIT-cones.
     1580To obtain the whole GIT-fan Qgamma has to be take the cone generated by the columns of Q.
     1581RETURN: a list containing the bigint hashes of the GIT cones.
     1582NOTE: The proceduce uses parallel computation for the construction of the GIT-cones.
     1583EXAMPLE: example GITfanParallelSymmetric; shows an example
     1584"
     1585{
     1586  actiononorbitcones=apply(actiononorbitcones,permutationToIntvec);
     1587  /**
     1588   * stores the hashes of all maximal GIT cones computed
     1589   */
     1590  list hashesOfCones;
     1591  /**
     1592   * stores to the corresponding maximal GIT cone in hashesOfCones
     1593   * - 0, if guaranteed that all adjacent GIT cones are known
     1594   *        or are to be computed in the next iteration       (*)
     1595   * - hash as intvec, otherwise
     1596   */
     1597  list workingList;
     1598
     1599
     1600  /**
     1601   * compute starting cone
     1602   */
     1603  bigintmat w,v;
     1604  cone lambda;
     1605  intvec lambdaHash;
     1606  while(dimension(lambda) <> nrows(Q)){
     1607    w = randConeEl(transpose(Q),100);
     1608    dbprint("testing "+string(w));
     1609    if (containsRelatively(Qgamma,w)) {
     1610      lambda,lambdaHash = GITcone(OC,w);
     1611      dbprint("computed cone of dimension "+string(dimension(lambda)));
     1612    }
     1613  }
     1614  int nCones = 1;     // essentially size(hashesOfCones)
     1615  int nConesOpen = 1; // essentially size(workingList)+1, see (*) above
     1616
     1617
     1618  /**
     1619   * initialize lists
     1620   */
     1621  bigint hashToInsert = binaryToBigint(lambdaHash);
     1622  int posToInsert = 1;
     1623  intvec sigLambdaHash;
     1624  for(int i = 2; i <= size(actiononorbitcones); i++){
     1625    sigLambdaHash = composeIntvecs(actiononorbitcones[i],lambdaHash);
     1626    hashToInsert = min(hashToInsert,binaryToBigint(sigLambdaHash));
     1627  }
     1628  hashesOfCones[1] = hashToInsert;
     1629  workingList[1] = int(0);
     1630  if (size(#)>0) {write(":w "+#[1],string(binaryToBigint(lambdaHash)) + ",");}
     1631  //if (size(#)>1) {write(":w "+#[2],"list listOfMaximalCones;");writeGitconeToFile(lambda,#[2]);}
     1632
     1633
     1634  list iterationArgs = list(list(lambdaHash,OC,Qgamma,actiononorbitcones));
     1635  list iterationRes;
     1636
     1637  /**
     1638   * traverse fan
     1639   */
     1640  int j,t,tloop;
     1641  list FL;
     1642  list neighbourHashes;
     1643  intvec neighbourHash;
     1644  while (size(iterationArgs)>0)
     1645  {
     1646    tloop=rtimer;
     1647
     1648    /**
     1649     * compute all neighbours of lambda
     1650     */
     1651    t = rtimer;
     1652    iterationRes = parallelWaitAll("computeNeighbourMinimalHashes",iterationArgs);
     1653    dbprint("time neighbours: "+string(rtimer - t));
     1654
     1655    /**
     1656     * central book keeping
     1657     */
     1658    t = rtimer;
     1659    for (i=1; i<=size(iterationRes); i++)
     1660    {
     1661      neighbourHashes = iterationRes[i];
     1662      for (j=1; j<=size(neighbourHashes); j++)
     1663      {
     1664        neighbourHash = neighbourHashes[j];
     1665        hashToInsert = binaryToBigint(neighbourHash);
     1666        posToInsert = findPlaceToInsert(hashesOfCones,hashToInsert);
     1667        if(posToInsert > 0)
     1668        {
     1669          if (size(#)>0){write(":a "+#[1],string(binaryToBigint(neighbourHash)) + ",");}
     1670          hashesOfCones = insertToList(hashesOfCones,hashToInsert,posToInsert);
     1671          workingList = insertToList(workingList,neighbourHash,posToInsert);
     1672          nConesOpen++;
     1673          nCones++;
     1674        }
     1675      }
     1676    }
     1677    nConesOpen = nConesOpen - size(iterationArgs);
     1678    dbprint("time bookkeeping: "+string(rtimer - t));
     1679
     1680    /**
     1681     * pick arguments for next iteration,
     1682     * set respective entry in workingList to 0
     1683     */
     1684    t = rtimer;
     1685    iterationArgs = list();
     1686    for (i=size(workingList); i>0; i--)
     1687    {
     1688      if (typeof(workingList[i])=="intvec")
     1689      {
     1690        iterationArgs[size(iterationArgs)+1] = list(workingList[i],OC,Qgamma,actiononorbitcones);
     1691        workingList[i] = int(0);
     1692        if (size(iterationArgs) >= getcores())
     1693        {
     1694          break;
     1695        }
     1696      }
     1697    }
     1698    dbprint("time preparation: "+string(rtimer - t));
     1699
     1700    dbprint("overall: "+string(nCones)+"   open: "+string(nConesOpen)+"   time loop: "+string(rtimer-tloop));
     1701  }
     1702  return(hashesOfCones);
     1703}
     1704example
     1705{
     1706  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     1707  ideal J =
     1708    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     1709    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     1710    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     1711    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     1712    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     1713  intmat Q[5][10] =
     1714    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     1715    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     1716    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     1717    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     1718    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     1719  list simplexSymmetryGroup = G25Action();
     1720  list simplexOrbitRepresentatives = intvec( 1, 2, 3, 4, 5 ),
     1721  intvec( 1, 2, 3, 5, 6 ),
     1722  intvec( 1, 2, 3, 5, 7 ),
     1723  intvec( 1, 2, 3, 5, 10 ),
     1724  intvec( 1, 2, 3, 7, 9 ),
     1725  intvec( 1, 2, 6, 9, 10 ),
     1726  intvec( 1, 2, 3, 4, 5, 6 ),
     1727  intvec( 1, 2, 3, 4, 5, 10 ),
     1728  intvec( 1, 2, 3, 5, 6, 8 ),
     1729  intvec( 1, 2, 3, 5, 6, 9 ),
     1730  intvec( 1, 2, 3, 5, 7, 10 ),
     1731  intvec( 1, 2, 3, 7, 9, 10 ),
     1732  intvec( 1, 2, 3, 4, 5, 6, 7 ),
     1733  intvec( 1, 2, 3, 4, 5, 6, 8 ),
     1734  intvec( 1, 2, 3, 4, 5, 6, 9 ),
     1735  intvec( 1, 2, 3, 5, 6, 9, 10 ),
     1736  intvec( 1, 2, 3, 4, 5, 6, 7, 8 ),
     1737  intvec( 1, 2, 3, 4, 5, 6, 9, 10 ),
     1738  intvec( 1, 2, 3, 4, 5, 6, 7, 8, 9 ),
     1739  intvec( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );
     1740  list afaceOrbitRepresentatives=afaces(J,simplexOrbitRepresentatives);
     1741  list fulldimAfaceOrbitRepresentatives=fullDimImages(afaceOrbitRepresentatives,Q);
     1742  list afaceOrbits=computeAfaceOrbits(fulldimAfaceOrbitRepresentatives,simplexSymmetryGroup);
     1743  apply(afaceOrbits,size);
     1744  list minAfaceOrbits = minimalAfaceOrbits(afaceOrbits);
     1745  apply(minAfaceOrbits,size);
     1746  list listOfOrbitConeOrbits = orbitConeOrbits(minAfaceOrbits,Q);
     1747  apply(listOfOrbitConeOrbits,size);
     1748  list listOfMinimalOrbitConeOrbits = minimalOrbitConeOrbits(listOfOrbitConeOrbits);
     1749  size(listOfMinimalOrbitConeOrbits);
     1750  list Asigma = groupActionOnQImage(simplexSymmetryGroup,Q);
     1751  list actionOnOrbitconeIndices = groupActionOnHashes(Asigma,listOfOrbitConeOrbits);
     1752  list OClist = listOfOrbitConeOrbits[1];
     1753  for (int i =2;i<=size(listOfOrbitConeOrbits);i++){
     1754    OClist = OClist + listOfOrbitConeOrbits[i];
     1755  }
     1756  cone mov = coneViaPoints(transpose(Q));
     1757  mov = canonicalizeCone(mov);
     1758  list Sigma = GITfanParallelSymmetric(OClist, Q, mov, actionOnOrbitconeIndices);
     1759  Sigma;
     1760}
     1761
     1762
     1763// not static to be used in parallel.lib
     1764proc computeNeighbourMinimalHashes(intvec lambdaHash, list OC, cone Qgamma, list actiononorbitcones)
     1765{
     1766  /**
     1767   * compute all facets of lambda
     1768   */
     1769  cone lambda = gitConeFromHash(OC,lambdaHash);
     1770  list FL = listOfFacetsAndInteriorVectors(lambda, Qgamma);
     1771
     1772  /**
     1773   * compute all minimal hashes of neighbours of lambda
     1774   */
     1775  int i,j;
     1776  bigintmat v,w;
     1777  intvec neighbourHash;
     1778  intvec neighbourHashPerm;
     1779  bigint nPerm;
     1780  intvec neighbourHashMin;
     1781  bigint nMin;
     1782  list neighbourHashes;
     1783  for (i=size(FL[1]); i>0; i--)
     1784  {
     1785    v = FL[1][i][1]; // interior facet normal
     1786    w = FL[1][i][2]; // interior facet point
     1787    neighbourHash = getNeighborHash(OC,w,v,1024);
     1788    neighbourHashMin = neighbourHash;
     1789    nMin = binaryToBigint(neighbourHash);
     1790    for (j=size(actiononorbitcones); j>1; j--)
     1791    {
     1792      neighbourHashPerm = composeIntvecs(actiononorbitcones[j],neighbourHash);
     1793      nPerm = binaryToBigint(neighbourHashPerm);
     1794      if (nPerm < nMin)
     1795      {
     1796        nMin = nPerm;
     1797        neighbourHashMin = neighbourHashPerm;
     1798      }
     1799    }
     1800    neighbourHashes[i] = neighbourHashMin;
     1801  }
     1802
     1803  return (neighbourHashes);
     1804}
     1805
     1806
     1807
     1808static proc writeGitconeToFile(cone lambda,string fn)
     1809{
     1810  bigintmat H = facets(lambda);
     1811
     1812  int rows = nrows(H);
     1813  int cols = ncols(H);
     1814  string toBeWritten = "bigintmat H["+string(rows)+"]["+string(cols)+"]=";
     1815  int i,j;
     1816  for (i=1; i<=rows; i++)
     1817  {
     1818    for (j=1; j<=cols; j++)
     1819    {
     1820      toBeWritten = toBeWritten + string(H[i,j]) + ",";
     1821    }
     1822  }
     1823  toBeWritten = toBeWritten[1..size(toBeWritten)-1];
     1824  toBeWritten = toBeWritten + ";";
     1825  write(":a "+fn,toBeWritten);
     1826
     1827  toBeWritten = "listOfMaximalCones[size(listOfMaximalCones)+1] = coneViaInequalities(V);";
     1828  write(":a "+fn,toBeWritten);
     1829
     1830  toBeWritten = "kill V;";
     1831  write(":a "+fn,toBeWritten);
     1832
     1833  toBeWritten = "";
     1834  write(":a "+fn,toBeWritten);
     1835}
     1836
     1837
     1838
     1839static proc listOfFacetsAndInteriorVectors(cone lambda, cone Qgamma, list #){
     1840  list FL;
     1841  int numboundary;
     1842
     1843  bigintmat FL0 = facets(lambda);
     1844  bigintmat H[1][ncols(FL0)];
     1845  bigintmat FL1[nrows(FL0)-1][ncols(FL0)]; // delete row of H from FL0
     1846
     1847  bigintmat w;
     1848  cone facetCone;
     1849  for(int i = 1; i <= nrows(FL0); i++){
     1850    H = FL0[i,1..ncols(FL0)];
     1851
     1852    if(i > 1 and i < nrows(FL0)){
     1853      FL1 = FL0[1..i-1, 1..ncols(FL0)], FL0[i+1..nrows(FL0), 1..ncols(FL0)];
     1854    } else {
     1855      if(i == nrows(FL0)){
     1856        FL1 = FL0[1..i-1, 1..ncols(FL0)];
     1857      } else { // i = 1:
     1858        FL1 = FL0[2..nrows(FL0), 1..ncols(FL0)];
     1859      }
     1860    }
     1861
     1862    facetCone = coneViaInequalities(FL1, H);
     1863
     1864    if (size(#)>0)
     1865    {
     1866      if (containsInSupport(facetCone,#[1]))
     1867      {
     1868        i++;
     1869        continue;
     1870      }
     1871    }
     1872
     1873    w = relativeInteriorPoint(facetCone);
     1874
     1875    if(containsRelatively(Qgamma,w)){
     1876      FL[size(FL) + 1] = list(H,w);
     1877    } else {
     1878      numboundary=numboundary+1;
     1879    }
     1880  }
     1881
     1882  return(list(FL,numboundary));
     1883}
     1884
     1885
     1886
     1887
     1888
     1889////////////////////////////////
     1890
     1891// CAREFUL: we assume that actiononorbitcones[1] = id.
     1892static proc findPosToInsertSymmetric(list hashesOfCones, intvec J, list actiononorbitcones){
     1893
     1894  // 1.: compute minimal hash sigJ
     1895  bigint n = binaryToBigint(J);
     1896  intvec sigJ;
     1897  for(int i = 2; i <= size(actiononorbitcones); i++){
     1898    sigJ = composeIntvecs(actiononorbitcones[i],J);
     1899    n = min(n,binaryToBigint(sigJ));
     1900  }
     1901
     1902  // 2.:check if minimal hash is already in list
     1903  return(findPlaceToInsert(hashesOfCones,n),n);
     1904}
     1905
     1906//////////////////////
     1907
     1908// insert n at position pos and move bigger elements by one index
     1909proc insertToList(list L, def elementToInsert, int posToInsert){
     1910  if(posToInsert == 1){
     1911    return(list(elementToInsert)+L);
     1912  }
     1913  if(posToInsert == size(L)+1){
     1914    return(L+list(elementToInsert));
     1915  }
     1916  return(list(L[1..(posToInsert-1)],elementToInsert,L[posToInsert..size(L)]));
     1917}
     1918
     1919proc GITcone(list OCcones, bigintmat w)
     1920"USAGE: GITcone(OCcones, w); OCcones: list of orbit cones, w: bigintmat with one row
     1921PURPOSE: Returns the intersection of all orbit cones containing w.
     1922RETURN: cone,intvec with the GIT cone containing w, and the hash of this cone (the indices of the orbit cones contributing to the intersection)
     1923EXAMPLE: example GITcone; shows an example
     1924"
     1925{
     1926  list OCrelcones;
     1927  intvec Hash;
     1928  for(int i = 1; i <= size(OCcones); i++){
     1929    if(containsInSupport(OCcones[i], w)){
     1930      OCrelcones[size(OCrelcones)+1]=OCcones[i];
     1931      Hash[size(Hash)+1] = i;
     1932    }
     1933  }
     1934  Hash = intvec(Hash[2..size(Hash)]);
     1935  return(convexIntersection(OCrelcones),Hash);
     1936}
     1937example {
     1938  echo=2;
     1939  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     1940  ideal J =
     1941    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     1942    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     1943    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     1944    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     1945    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     1946  intmat Q[5][10] =
     1947    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     1948    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     1949    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     1950    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     1951    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     1952
     1953  list AF= afaces(J,nrows(Q));
     1954  AF=fullDimImages(AF,Q);
     1955  AF = minimalAfaces(AF);
     1956  list OC = orbitCones(AF,Q);
     1957  bigintmat w[1][nrows(Q)];
     1958  for(int i = 1; i <= nrows(Q); i++){
     1959    w = w + Q[1..nrows(Q),i];
     1960  }
     1961  GITcone(OC,w);
     1962}
     1963
     1964
     1965static proc gitConeFromHash(list OC, intvec Hash)
     1966{
     1967  list OCtoIntersect = OC[Hash];
     1968  return (convexIntersection(OCtoIntersect));
     1969}
     1970
     1971
     1972
     1973
     1974
     1975static proc randConeEl(bigintmat Q, int bound){
     1976  bigintmat w[1][ncols(Q)];
     1977
     1978  for(int i = 1; i <= nrows(Q); i++){
     1979    bigintmat v[1][ncols(Q)] = Q[i,1..ncols(Q)];
     1980
     1981    w = w + random(1,bound) * v;
     1982
     1983    kill v;
     1984  }
     1985
     1986  return(w);
     1987}
     1988
     1989
     1990
     1991static proc subdividelist(list OC,int ncores){
     1992  if (ncores>size(OC)){ncores=size(OC);}
     1993  int percore = size(OC) div (ncores);
     1994  int lastcore = size(OC) mod (ncores);
     1995  list OCLL;
     1996  int j=1;
     1997  int starti=1;
     1998  int endi;
     1999  for (int i=1;i<=ncores;i++){
     2000    endi = starti+percore-1;
     2001    if (i<=lastcore) {endi=endi+1;}
     2002    list OCLLi=OC[starti..endi];
     2003    starti=endi+1;
     2004    OCLL[i]=OCLLi;
     2005    kill OCLLi;
     2006  }
     2007  return(OCLL);
     2008}
     2009//list OC = 1,2,3,4,5,6,7,8,9,10,11,12;
     2010//subdividelist(OC,4);
     2011
     2012
     2013
     2014
     2015
     2016
     2017
     2018
     2019
     2020
     2021
     2022
     2023proc orbitCones(list AF, intmat Q, list #)
     2024"USAGE: orbitCones(AF, Q[, d]); AF: list of intvecs, Q: intmat, d: int
     2025PURPOSE: Returns the list consisting of all cones Q(gam0) where gam0 in AF. If the optional argument d is given then the function returns only the orbit cones of dimension at least d
     2026RETURN: a list of cones
    3212027EXAMPLE: example orbitCones; shows an example
    3222028"
    3232029{
    324   list AF;
    325 
    326   if((size(#) > 1) and (typeof(#[2]) == "int"))
    327   {
    328     AF = afaces(a, nrows(Q), #[2]);
    329   }
    330   else
    331   {
    332     AF = afaces(a, nrows(Q));
    333   }
    334 
    335   int dimensionBound = 0;
    336   if((size(#) > 0) and (typeof(#[1]) == "int"))
    337   {
    338     dimensionBound = #[1];
    339   }
    340 
    3412030  list OC;
    3422031  intvec gam0;
    3432032  int j;
    344 
    345   for(int i = 1; i <= size(AF); i++)
    346   {
     2033  cone c;
     2034  int d = 0;
     2035  if (size(#)>0) {
     2036    d = #[1];
     2037  }
     2038
     2039  for(int i = 1; i <= size(AF); i++){
    3472040    gam0 = AF[i];
    3482041
    349     if(gam0 == 0)
    350     {
     2042    if(gam0 == 0){
    3512043      bigintmat M[1][nrows(Q)];
    352     }
    353     else
    354     {
     2044    } else {
    3552045      bigintmat M[size(gam0)][nrows(Q)];
    356       for (j = 1; j <= size(gam0); j++)
    357       {
     2046
     2047      for (j = 1; j <= size(gam0); j++){
    3582048        M[j,1..ncols(M)] = Q[1..nrows(Q),gam0[j]];
    3592049      }
    3602050    }
    361     cone c = coneViaPoints(M);
    362 
    363     if((dimension(c) >= dimensionBound) and (!(listContainsCone(OC, c))))
     2051
     2052    c = coneViaPoints(M);
     2053
     2054    if(listContainsCone(OC, c) == 0 && dimension(c)>=d){
     2055      OC[size(OC)+1] = c;
     2056    }
     2057
     2058    kill M;
     2059  }
     2060
     2061  return(OC);
     2062}
     2063example
     2064{
     2065  echo=2;
     2066  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     2067  ideal J =
     2068    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     2069    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     2070    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     2071    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     2072    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     2073  intmat Q[5][10] =
     2074    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     2075    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     2076    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     2077    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     2078    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     2079
     2080  list AF= afaces(J);
     2081  print(size(AF));
     2082  list OC = orbitCones(AF,Q);
     2083  size(OC);
     2084}
     2085
     2086
     2087
     2088///////////////////////////////////////
     2089
     2090proc GITfanFromOrbitCones(list OC, bigintmat Q, cone Qgamma, list #)
     2091  "USAGE: GITfanFromOrbitCones(OC, Q, Qgamma [, file1, file2]); OC:list, Q:bigintmat, Qgamma:cone, file1:string, file2:string
     2092PURPOSE: Returns the common refinement of the cones given in
     2093the list OC which is supposed to contain the orbit cones intersected with Qgamma. The optional argument can be used
     2094to specify one or two strings with file names, where the first file will contain the hashes of the
     2095GIT-cones and the second argument the actual cones in their H-representation.
     2096To obtain the whole GIT-fan Qgamma has to be take the cone generated by the columns of Q.
     2097RETURN: a list containing the bigint hashes of the GIT cones.
     2098EXAMPLE: example GITfanFromOrbitCones; shows an example
     2099"
     2100{
     2101  /**
     2102   * stores the hashes of all maximal GIT cones computed
     2103   */
     2104  list hashesOfCones;
     2105  /**
     2106   * stores to the corresponding maximal GIT cone in hashesOfCones
     2107   * - 0, if guaranteed that all adjacent GIT cones are known
     2108   *        or are to be computed in the next iteration       (*)
     2109   * - hash as intvec, otherwise
     2110   */
     2111  list workingList;
     2112
     2113
     2114  /**
     2115   * compute starting cone
     2116   */
     2117  bigintmat w,v;
     2118  cone lambda;
     2119  intvec lambdaHash;
     2120  while(dimension(lambda) <> nrows(Q)){
     2121    w = randConeEl(transpose(Q),100);
     2122    dbprint("testing "+string(w));
     2123    if (containsRelatively(Qgamma,w)) {
     2124      lambda,lambdaHash = GITcone(OC,w);
     2125      dbprint("computed cone of dimension "+string(dimension(lambda)));
     2126    }
     2127  }
     2128  int nCones = 1;     // essentially size(hashesOfCones)
     2129  int nConesOpen = 1; // essentially size(workingList)+1, see (*) above
     2130
     2131
     2132  /**
     2133   * initialize lists
     2134   */
     2135  int posToInsert = 1;
     2136  bigint hashToInsert = binaryToBigint(lambdaHash);
     2137  hashesOfCones[1] = hashToInsert;
     2138  workingList[1] = int(0);
     2139  if (size(#)>0) {write(":w "+#[1],string(hashesOfCones[1]) + ",");}
     2140  if (size(#)>1) {write(":w "+#[2],"list listOfMaximalCones;");writeGitconeToFile(lambda,#[2]);}
     2141
     2142
     2143  /**
     2144   * traverse fan
     2145   */
     2146  int i,t,tt;
     2147  list FL;
     2148  intvec neighbourHash;
     2149  int mu = 1024;
     2150  while (lambdaHash>0)
     2151  {
     2152    tt=timer;
     2153
     2154    /**
     2155     * compute all facets of lambda
     2156     */
     2157    t = timer;
     2158    FL = listOfFacetsAndInteriorVectors(lambda, Qgamma);
     2159    dbprint("time for facets: "+string(timer - t));
     2160
     2161    /**
     2162     * compute all neighbours of lambda
     2163     */
     2164    for (i=size(FL[1]); i>0; i--)
    3642165    {
    365       OC[size(OC)+1] = c;
    366     }
    367 
    368     kill M, c;
    369   }
    370 
    371   return(OC);
     2166      v = FL[1][i][1]; // interior facet normal
     2167      w = FL[1][i][2]; // interior facet point
     2168      neighbourHash = getNeighborHash(OC,w,v,mu);
     2169      hashToInsert = binaryToBigint(neighbourHash);
     2170      posToInsert = findPlaceToInsert(hashesOfCones,hashToInsert);
     2171
     2172      if(posToInsert > 0)
     2173      {
     2174        if (size(#)>0){write(":a "+#[1],string(binaryToBigint(neighbourHash)) + ",");}
     2175        hashesOfCones = insertToList(hashesOfCones,hashToInsert,posToInsert);
     2176        workingList = insertToList(workingList,neighbourHash,posToInsert);
     2177        nConesOpen++;
     2178        nCones++;
     2179      }
     2180    }
     2181
     2182    /**
     2183     * pick lambdaHash and lambda for next iteration,
     2184     * set respective entry in workingList to 0
     2185     */
     2186    lambdaHash = 0;
     2187    for (i=size(workingList); i>0; i--)
     2188    {
     2189      if (typeof(workingList[i])=="intvec")
     2190      {
     2191        lambdaHash = workingList[i];
     2192        lambda = gitConeFromHash(OC,lambdaHash);
     2193        if (size(#)>1) {writeGitconeToFile(lambda,#[2]);}
     2194        workingList[i] = int(0);
     2195        break;
     2196      }
     2197    }
     2198    nConesOpen--;
     2199
     2200    dbprint("overall: "+string(nCones)+"   open: "+string(nConesOpen)+"   time for loop: "+string(timer-tt));
     2201  }
     2202  return(hashesOfCones);
     2203}
     2204example
     2205{
     2206  echo=2;
     2207  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     2208  ideal J =
     2209    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     2210    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     2211    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     2212    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     2213    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     2214  intmat Q[5][10] =
     2215    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     2216    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     2217    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     2218    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     2219    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     2220
     2221  list AF= afaces(J,nrows(Q));
     2222  AF=fullDimImages(AF,Q);
     2223  AF = minimalAfaces(AF);
     2224  list OC = orbitCones(AF,Q);
     2225  cone Qgamma = coneViaPoints(transpose(Q));
     2226  list GIT = GITfanFromOrbitCones(OC,Q,Qgamma);
     2227  size(GIT);
     2228}
     2229
     2230
     2231
     2232
     2233
     2234proc GITfanParallel(list OC, intmat Q, cone Qgamma, list #)
     2235  "USAGE: GITfanParallel(OC, Q, Qgamma [, file1]); OC:list, Q:intmat, Qgamma:cone, file1:string
     2236PURPOSE: Returns the common refinement of the cones given in
     2237the list OC which is supposed to contain the orbit cones intersected with Qgamma. The optional argument can be used to specify a name for a file which will contain the hashes of the GIT-cones.
     2238To obtain the whole GIT-fan Qgamma has to be take the cone generated by the columns of Q.
     2239RETURN: a list containing the bigint hashes of the GIT cones.
     2240NOTE: The proceduce uses parallel computation for the construction of the GIT-cones.
     2241EXAMPLE: example GITfanParallel; shows an example
     2242"
     2243{
     2244  /**
     2245   * stores the hashes of all maximal GIT cones computed
     2246   */
     2247  list hashesOfCones;
     2248  /**
     2249   * stores to the corresponding maximal GIT cone in hashesOfCones
     2250   * - 0, if guaranteed that all adjacent GIT cones are known
     2251   *        or are to be computed in the next iteration       (*)
     2252   * - hash as intvec, otherwise
     2253   */
     2254  list workingList;
     2255
     2256
     2257  /**
     2258   * compute starting cone
     2259   */
     2260  bigintmat w,v;
     2261  cone lambda;
     2262  intvec lambdaHash;
     2263  while(dimension(lambda) <> nrows(Q)){
     2264    w = randConeEl(transpose(Q),100);
     2265    dbprint("testing "+string(w));
     2266    if (containsRelatively(Qgamma,w)) {
     2267      lambda,lambdaHash = GITcone(OC,w);
     2268      dbprint("computed cone of dimension "+string(dimension(lambda)));
     2269    }
     2270  }
     2271  int nCones = 1;     // essentially size(hashesOfCones)
     2272  int nConesOpen = 1; // essentially size(workingList)+1, see (*) above
     2273
     2274
     2275  /**
     2276   * initialize lists
     2277   */
     2278  bigint hashToInsert = binaryToBigint(lambdaHash);
     2279  int posToInsert = 1;
     2280  hashesOfCones[1] = hashToInsert;
     2281  workingList[1] = int(0);
     2282  if (size(#)>0) {write(":w "+#[1],string(binaryToBigint(lambdaHash)) + ",");}
     2283  //if (size(#)>1) {write(":w "+#[2],"list listOfMaximalCones;");writeGitconeToFile(lambda,#[2]);}
     2284
     2285
     2286  list iterationArgs = list(list(lambdaHash,OC,Qgamma));
     2287  list iterationRes;
     2288
     2289  /**
     2290   * traverse fan
     2291   */
     2292  int i,j,t,tloop;
     2293  list FL;
     2294  list neighbourHashes;
     2295  intvec neighbourHash;
     2296  while (size(iterationArgs)>0)
     2297  {
     2298    tloop=rtimer;
     2299
     2300    /**
     2301     * compute all neighbours of lambda
     2302     */
     2303    t = rtimer;
     2304    iterationRes = parallelWaitAll("computeNeighbourHashes",iterationArgs);
     2305    dbprint("time neighbours: "+string(rtimer - t));
     2306
     2307    /**
     2308     * central book keeping
     2309     */
     2310    t = rtimer;
     2311    for (i=1; i<=size(iterationRes); i++)
     2312    {
     2313      neighbourHashes = iterationRes[i];
     2314      for (j=1; j<=size(neighbourHashes); j++)
     2315      {
     2316        neighbourHash = neighbourHashes[j];
     2317        hashToInsert = binaryToBigint(neighbourHash);
     2318        posToInsert = findPlaceToInsert(hashesOfCones,hashToInsert);
     2319        if(posToInsert > 0)
     2320        {
     2321          if (size(#)>0){write(":a "+#[1],string(binaryToBigint(neighbourHash)) + ",");}
     2322          hashesOfCones = insertToList(hashesOfCones,hashToInsert,posToInsert);
     2323          workingList = insertToList(workingList,neighbourHash,posToInsert);
     2324          nConesOpen++;
     2325          nCones++;
     2326        }
     2327      }
     2328    }
     2329    nConesOpen = nConesOpen - size(iterationArgs);
     2330    dbprint("time bookkeeping: "+string(rtimer - t));
     2331
     2332    /**
     2333     * pick arguments for next iteration,
     2334     * set respective entry in workingList to 0
     2335     */
     2336    t = rtimer;
     2337    iterationArgs = list();
     2338    for (i=size(workingList); i>0; i--)
     2339    {
     2340      if (typeof(workingList[i])=="intvec")
     2341      {
     2342        iterationArgs[size(iterationArgs)+1] = list(workingList[i],OC,Qgamma);
     2343        workingList[i] = int(0);
     2344        if (size(iterationArgs) >= getcores())
     2345        {
     2346          break;
     2347        }
     2348      }
     2349    }
     2350    dbprint("time preparation: "+string(rtimer - t));
     2351
     2352    dbprint("overall: "+string(nCones)+"   open: "+string(nConesOpen)+"   time loop: "+string(rtimer-tloop));
     2353  }
     2354
     2355  if (size(#)==0)
     2356  {
     2357    return(hashesOfCones);
     2358  }
     2359}
     2360example
     2361{
     2362  echo=2;
     2363  setcores(4);
     2364  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     2365  ideal J =
     2366    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     2367    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     2368    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     2369    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     2370    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     2371  intmat Q[5][10] =
     2372    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     2373    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     2374    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     2375    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     2376    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     2377
     2378  list AF= afaces(J);
     2379  print(size(AF));
     2380  list OC = orbitCones(AF,Q);
     2381  cone Qgamma = coneViaPoints(transpose(Q));
     2382  list GIT = GITfanParallel(OC,Q,Qgamma);
     2383  size(GIT);
     2384}
     2385
     2386// not static to be used in parallel.lib
     2387proc computeNeighbourHashes(intvec lambdaHash, list OC, cone Qgamma)
     2388{
     2389  /**
     2390   * compute all facets of lambda
     2391   */
     2392  cone lambda = gitConeFromHash(OC,lambdaHash);
     2393  list FL = listOfFacetsAndInteriorVectors(lambda, Qgamma);
     2394
     2395  /**
     2396   * compute all minimal hashes of neighbours of lambda
     2397   */
     2398  bigintmat v,w;
     2399  intvec neighbourHash;
     2400  list neighbourHashes;
     2401  for (int i=size(FL[1]); i>0; i--)
     2402  {
     2403    v = FL[1][i][1]; // interior facet normal
     2404    w = FL[1][i][2]; // interior facet point
     2405    neighbourHash = getNeighborHash(OC,w,v,1024);
     2406    neighbourHashes[i] = neighbourHash;
     2407  }
     2408
     2409  return (neighbourHashes);
     2410}
     2411
     2412
     2413
     2414proc minimalAfaces(list listOfAfaces)
     2415"USAGE: minimalAfaces(listOfAfaces); listOfAfaces: list
     2416PURPOSE: Returns a list of all minimal a-faces. Note that listOfAfaces must only contain
     2417afaces which project to full dimension.
     2418RETURN: a list of intvecs
     2419EXAMPLE: example minimalAfaces; shows an example
     2420"
     2421{
     2422  int i,j;
     2423  for (i=1; i<=size(listOfAfaces); i++)
     2424  {
     2425    for (j=1; j<=size(listOfAfaces); j++)
     2426    {
     2427      if (i!=j)
     2428      {
     2429        if (isSubset(listOfAfaces[i],listOfAfaces[j]))
     2430        {
     2431          listOfAfaces = delete(listOfAfaces,j);
     2432          if (j<i)
     2433          {
     2434            i = i-1;
     2435          }
     2436          j = j-1;
     2437        }
     2438      }
     2439    }
     2440  }
     2441  return(listOfAfaces);
     2442}
     2443example
     2444{
     2445  echo=2;
     2446  setcores(4);
     2447  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     2448  ideal J =
     2449    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     2450    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     2451    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     2452    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     2453    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     2454  intmat Q[5][10] =
     2455    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     2456    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     2457    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     2458    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     2459    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     2460  list AF= afaces(J,nrows(Q));
     2461  size(AF);
     2462  AF=fullDimImages(AF,Q);
     2463  size(AF);
     2464  AF=minimalAfaces(AF);
     2465  size(AF);
     2466}
     2467
     2468
     2469
     2470proc GITfan(ideal J, intmat Q, list #)
     2471"USAGE: GITfan(J,Q [, G]); J:ideal, Q:intmat, G:list
     2472PURPOSE: Computes the GIT fan associated to J and Q. Optionally a symmetry group action on the column space of Q can be specified.
     2473RETURN: a fan, the GIT fan.
     2474NOTE: The proceduce uses parallel computation for the construction of the GIT-cones. The a-faces are not computed in parallel. This can be done by calling the aface procedure specifying a list of simplex faces. If used with the optional argument G, the orbit decomposition of the simplex of columns of Q is computed. Refer to the Singular documentation on how to do this more efficiently using GAP.
     2475EXAMPLE: example GITfan; shows an example
     2476"
     2477{
     2478  list GIT;
     2479  list OC;
     2480  if (size(#)>0){
     2481      (GIT,OC) = GITfanWrapperWithSymmetry(J,Q,#);
     2482  } else {
     2483  list AF= afaces(J,nrows(Q));
     2484  AF=fullDimImages(AF,Q);
     2485  AF = minimalAfaces(AF);
     2486  OC = orbitCones(AF,Q);
     2487  cone Qgamma = coneViaPoints(transpose(Q));
     2488  GIT = GITfanParallel(OC,Q,Qgamma);
     2489  }
     2490  fan Sigma = hashesToFan(GIT,OC);
     2491  return(Sigma);
     2492}
     2493example
     2494{
     2495  echo=2;
     2496  setcores(4);
     2497  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     2498  ideal J =
     2499    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     2500    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     2501    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     2502    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     2503    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     2504  intmat Q[5][10] =
     2505    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     2506    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     2507    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     2508    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     2509    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     2510  fan GIT = GITfan(J,Q);
     2511
     2512  intmat Q[5][10] =
     2513    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     2514    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     2515    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     2516    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     2517    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     2518  list simplexSymmetryGroup = G25Action();
     2519  fan GIT2 = GITfan(J,Q,simplexSymmetryGroup);
     2520
     2521}
     2522
     2523
     2524proc hashToCone(bigint v, list OC)
     2525"USAGE: hashToCone(v, OC): v bigint, OC list of cones.
     2526ASSUME: the elements of OC are the orbit cones used in the hash representation of the GIT cones.
     2527RETURN: a cone, the intersection of the cones in OC according to the binary representation of the hash v.
     2528EXAMPLE: example hashToCone; shows an example
     2529"
     2530{
     2531  intvec J = bigintToBinary(v, size(OC));
     2532  return(convexIntersection(list(OC[J])));
     2533}
     2534example
     2535{
     2536  echo = 2;
     2537  setcores(4);
     2538  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     2539  ideal J =
     2540    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     2541    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     2542    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     2543    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     2544    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     2545  intmat Q[5][10] =
     2546    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     2547    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     2548    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     2549    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     2550    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     2551  list AF= afaces(J,nrows(Q));
     2552  AF=fullDimImages(AF,Q);
     2553  AF = minimalAfaces(AF);
     2554  list OC = orbitCones(AF,Q);
     2555  bigint v = 21300544;
     2556  hashToCone(v, OC);
     2557}
     2558
     2559
     2560proc bigintToBinary(bigint n, int r)
     2561"
     2562USAGE: bigintToBinary(n, r): n bigint, r int.
     2563ASSUME: n is smaller then 2^r.
     2564RETURN: an intvec, with entries the positions of 1 in the binary representation of n with r bits.
     2565EXAMPLE: example bigintToBinary; shows an example
     2566"
     2567{
     2568  int k = r-1;
     2569
     2570  intvec v;
     2571  bigint n0 = n;
     2572
     2573  while(n0 > 0){
     2574    bigint tmp = bigint(2)^k;
     2575
     2576    while(tmp > n0){
     2577      k--;
     2578      tmp = bigint(2)^k;
     2579    }
     2580
     2581    v = k+1,v;
     2582    n0 = n0 - tmp;
     2583    k--;
     2584
     2585    kill tmp;
     2586  }
     2587
     2588  v = v[1..size(v)-1];
     2589  return(v);
     2590}
     2591example
     2592{
     2593  echo = 2;
     2594  bigintToBinary(bigint(2)^90-1, 90);
     2595}
     2596
     2597
     2598
     2599
     2600proc hashesToFan(list hashes, list OC)
     2601"USAGE: hashesToFan(hashes, OC): hashes list of bigint, OC list of cones.
     2602ASSUME: the elements of OC are the orbit cones used in the hash representation of the GIT cones.
     2603RETURN: a fan, with maximal cones the intersections of the cones in OC according to the binary representation of the hashes.
     2604EXAMPLE: example hashesToFan; shows an example
     2605"
     2606{
     2607  fan Sigma = emptyFan(ambientDimension(OC[1]));
     2608  for (int i=1;i<=size(hashes);i++){
     2609    insertCone(Sigma,hashToCone(hashes[i],OC),0);
     2610  }
     2611  return(Sigma);
     2612}
     2613example
     2614{
     2615  echo = 2;
     2616  setcores(4);
     2617  ring R = 0,T(1..10),wp(1,1,1,1,1,1,1,1,1,1);
     2618  ideal J =
     2619    T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
     2620    T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
     2621    T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
     2622    T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
     2623    T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
     2624  intmat Q[5][10] =
     2625    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
     2626    1, 0, 0, 0, 1, 1, 1, 0, 0, 0,
     2627    0, 1, 1, 0, 0, 0, -1, 1, 0, 0,
     2628    0, 1, 0, 1, 0, -1, 0, 0, 1, 0,
     2629    0, 0, 1, 1, -1, 0, 0, 0, 0, 1;
     2630  list AF= afaces(J,nrows(Q));
     2631  AF=fullDimImages(AF,Q);
     2632  AF = minimalAfaces(AF);
     2633  list OC = orbitCones(AF,Q);
     2634  cone Qgamma = coneViaPoints(transpose(Q));
     2635  list GIT = GITfanParallel(OC,Q,Qgamma);
     2636  fan Sigma = hashesToFan(GIT,OC);
     2637}
     2638
     2639
     2640
     2641
     2642/////////////////////////////////////
     2643
     2644proc gkzFan(intmat Q)
     2645"USAGE: gkzFan(Q); a: ideal, Q:intmat
     2646PURPOSE: Returns the GKZ-fan of the matrix Q.
     2647RETURN: a fan.
     2648EXAMPLE: example gkzFan; shows an example
     2649"
     2650{
     2651  // only difference to gitFan:
     2652  // it suffices to consider all faces
     2653  // that are simplicial:
     2654  list OC = simplicialToricOrbitCones(Q);
     2655  print(size(OC));
     2656  cone Qgamma = coneViaPoints(transpose(Q));
     2657  list GIT = GITfanParallel(OC,Q,Qgamma);
     2658  fan Sigma = hashesToFan(GIT,OC);
     2659  return(Sigma);
    3722660}
    3732661example
     
    3792667    0,0,1,1;
    3802668
    381   ring R = 0,T(1..4),dp;
    382   ideal a = 0;
    383 
    384   orbitCones(a, Q);
    385 }
    386 
    387 ///////////////////////////////////////
    388 
    389 proc gitCone(ideal a, bigintmat Q, bigintmat w)
    390 "USAGE: gitCone(a, Q, w); a: ideal, Q:bigintmat, w:bigintmat
    391 PURPOSE: Returns the GIT-cone lambda(w), i.e. the intersection of all
    392 orbit cones containing the vector w.
    393 NOTE: call this only if you are interested in a single GIT-cone.
    394 RETURN: a cone.
    395 EXAMPLE: example gitCone; shows an example
    396 "
    397 {
    398   list OC =  orbitCones(a, Q);
    399   cone lambda = nrows(Q);
    400 
    401   for(int i = 1; i <= size(OC); i++)
    402   {
    403     cone c = OC[i];
    404 
    405     if(containsInSupport(c, w))
    406     {
    407       lambda = convexIntersection(lambda, c);
    408     }
    409 
    410     kill c;
    411   }
    412 
    413   return(lambda);
     2669  gkzFan(Q);
     2670}
     2671
     2672
     2673
     2674/////////////////////////////////////
     2675
     2676// Computes all simplicial orbit cones
     2677// w.r.t. the 0-ideal:
     2678static proc simplicialToricOrbitCones(bigintmat Q){
     2679  intvec gam0;
     2680  list OC;
     2681  cone c;
     2682  int r = ncols(Q);
     2683  int j;
     2684
     2685  for(int i = 1; i < 2^r; i++ ){
     2686    gam0 = int2face(i,r);
     2687
     2688    // each simplicial cone is generated by
     2689    // exactly nrows(Q) many columns of Q:
     2690    if(size(gam0) == nrows(Q)){
     2691      bigintmat M[size(gam0)][nrows(Q)];
     2692
     2693      for(j = 1; j <= size(gam0); j++){
     2694        M[j,1..ncols(M)] = Q[1..nrows(Q),gam0[j]];
     2695      }
     2696   
     2697      c = coneViaPoints(M); 
     2698
     2699      if((dimension(c) == nrows(Q)) and (!(listContainsCone(OC, c)))){
     2700        OC[size(OC)+1] = c;
     2701      }
     2702
     2703      kill M;
     2704    }
     2705  }
     2706
     2707  return(OC);
    4142708}
    4152709example
    4162710{
    417   echo=2;
    418   intmat Q[3][4] =
    419     1,0,1,0,
    420     0,1,0,1,
    421     0,0,1,1;
    422 
    423   ring R = 0,T(1..4),dp;
    424   ideal a = 0;
    425 
    426   bigintmat w[1][3] = 3,3,1;
    427   cone lambda = gitCone(a, Q, w);
    428   rays(lambda);
    429 
    430   bigintmat w2[1][3] = 1,1,1;
    431   cone lambda2 = gitCone(a, Q, w2);
    432   rays(lambda2);
    433 }
    434 
    435 /////////////////////////////////////
    436 
    437 proc gitFan(ideal a, bigintmat Q, list #)
    438 "USAGE: gitFan(a, Q); a: ideal, Q:bigintmat
    439 PURPOSE: Returns the GIT-fan of the H-action defined by Q on V(a).
    440 An optional third parameter of type 'int' is interpreted as the
    441 number of CPU-cores you would like to use.
    442 Note that 'system("--cpus");' returns the number of cpu available
    443 in your system.
    444 RETURN: a fan.
    445 EXAMPLE: example gitFan; shows an example
    446 "
    447 {
    448   list OC = orbitCones(a, Q, #);
    449 
    450   fan f = refineCones(OC, Q);
    451   return(f);
    452 }
    453 example
    454 {
    455   echo=2;
    456   intmat Q[3][4] =
    457     1,0,1,0,
    458     0,1,0,1,
    459     0,0,1,1;
    460 
    461   ring R = 0,T(1..4),dp;
    462   ideal a = 0;
    463 
    464   gitFan(a, Q);
    465 
    466   // 2nd example //
    467   kill Q;
    468   intmat Q[3][6] =
    469     1,1,0,0,-1,-1,
    470     0,1,1,-1,-1,0,
    471     1,1,1,1,1,1;
    472 
    473   ring R = 0,T(1..6),dp;
    474   ideal a = T(1)*T(6) + T(2)*T(5) + T(3)*T(4);
    475 
    476   int t = rtimer;
    477   fan F = gitFan(a, Q);
    478   t = rtimer - t;
    479 
    480   int tt = rtimer;
    481   fan F = gitFan(a, Q, 4);
    482   tt = rtimer - tt;
    483 
    484   t;
    485   tt;
    486   "--------";
    487   kill R, Q, t, tt;
    488   // next example //
    489   ring R = 0,T(1..10),dp;
    490   ideal a = T(5)*T(10)-T(6)*T(9)+T(7)*T(8),
    491     T(1)*T(9)-T(2)*T(7)+T(4)*T(5),
    492     T(1)*T(8)-T(2)*T(6)+T(3)*T(5),
    493     T(1)*T(10)-T(3)*T(7)+T(4)*T(6),
    494     T(2)*T(10)-T(3)*T(9)+T(4)*T(8);
    495 
    496   bigintmat Q[4][10] =
    497     1,0,0,0,1,1,1,0,0,0,
    498     0,1,0,0,1,0,0,1,1,0,
    499     0,0,1,0,0,1,0,1,0,1,
    500     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   kill R, Q, t, tt;
    515   // next example //
    516   ring R = 0,T(1..15),dp;
    517   ideal a =
    518     T(1)*T(10)-T(2)*T(7)+T(3)*T(6),
    519     T(1)*T(11)-T(2)*T(8)+T(4)*T(6),
    520     T(1)*T(12)-T(2)*T(9)+T(5)*T(6),
    521     T(1)*T(13)-T(3)*T(8)+T(4)*T(7),
    522     T(1)*T(14)-T(3)*T(9)+T(5)*T(7),
    523     T(1)*T(15)-T(4)*T(9)+T(5)*T(8),
    524     T(2)*T(13)-T(3)*T(11)+T(4)*T(10),
    525     T(2)*T(14)-T(3)*T(12)+T(5)*T(10);
     2711  echo = 2;
     2712  bigintmat Q[3][4] =
     2713  1,0,1,0,
     2714  0,1,0,1,
     2715  0,0,1,1;
     2716
     2717  list OC = simplicialToricOrbitCones(Q);
     2718  print(OC);
    5262719
    5272720  bigintmat Q[5][15] =
     
    5322725    0,0,0,0,1,0,0,0,1,0,0,1,0,1,1;
    5332726
    534   int t = rtimer;
    535   fan F = gitFan(a, Q);
    536   t = rtimer - t;
    537 
    538   int tt = rtimer;
    539   fan F = gitFan(a, Q, 4);
    540   tt = rtimer - tt;
    541 
    542   t;
    543   tt;
    544 
    545 }
    546 
    547 /////////////////////////////////////
    548 // Computes all simplicial orbit cones
    549 // w.r.t. the 0-ideal:
    550 
    551 static proc simplicialToricOrbitCones(bigintmat Q)
    552 {
    553   intvec gam0;
    554   list OC;
    555   cone c;
    556   int r = ncols(Q);
    557   int j;
    558 
    559   for(int i = 1; i < 2^r; i++ )
    560   {
    561     gam0 = int2face(i,r);
    562 
    563     // each simplicial cone is generated by
    564     // exactly nrows(Q) many columns of Q:
    565     if(size(gam0) == nrows(Q))
    566     {
    567       bigintmat M[size(gam0)][nrows(Q)];
    568 
    569       for(j = 1; j <= size(gam0); j++)
    570       {
    571         M[j,1..ncols(M)] = Q[1..nrows(Q),gam0[j]];
     2727  list OC = simplicialToricOrbitCones(Q);
     2728  print(size(OC));
     2729}
     2730
     2731
     2732proc G25Action()
     2733"USAGE: G25Action(Q);
     2734PURPOSE: Returns a representation of S5 as a subgroup of S10 with the action on the Grassmannian G25.
     2735RETURN: list of with elements of type permutation.
     2736EXAMPLE: example G25Action; shows an example
     2737"
     2738{
     2739list simplexSymmetryGroup = permutationFromIntvec(intvec( 1 .. 10 )),
     2740permutationFromIntvec(intvec( 1, 2, 4, 3, 5, 7, 6, 9, 8, 10 )),
     2741permutationFromIntvec(intvec( 1, 3, 2, 4, 6, 5, 7, 8, 10, 9 )),
     2742permutationFromIntvec(intvec( 1, 3, 4, 2, 6, 7, 5, 10, 8, 9 )),
     2743permutationFromIntvec(intvec( 1, 4, 2, 3, 7, 5, 6, 9, 10, 8 )),
     2744permutationFromIntvec(intvec( 1, 4, 3, 2, 7, 6, 5, 10, 9, 8 )),
     2745permutationFromIntvec(intvec( 1, 5, 6, 7, 2, 3, 4, 8, 9, 10 )),
     2746permutationFromIntvec(intvec( 1, 5, 7, 6, 2, 4, 3, 9, 8, 10 )),
     2747permutationFromIntvec(intvec( 1, 6, 5, 7, 3, 2, 4, 8, 10, 9 )),
     2748permutationFromIntvec(intvec( 1, 6, 7, 5, 3, 4, 2, 10, 8, 9 )),
     2749permutationFromIntvec(intvec( 1, 7, 5, 6, 4, 2, 3, 9, 10, 8 )),
     2750permutationFromIntvec(intvec( 1, 7, 6, 5, 4, 3, 2, 10, 9, 8 )),
     2751permutationFromIntvec(intvec( 2, 1, 3, 4, 5, 8, 9, 6, 7, 10 )),
     2752permutationFromIntvec(intvec( 2, 1, 4, 3, 5, 9, 8, 7, 6, 10 )),
     2753permutationFromIntvec(intvec( 2, 3, 1, 4, 8, 5, 9, 6, 10, 7 )),
     2754permutationFromIntvec(intvec( 2, 3, 4, 1, 8, 9, 5, 10, 6, 7 )),
     2755permutationFromIntvec(intvec( 2, 4, 1, 3, 9, 5, 8, 7, 10, 6 )),
     2756permutationFromIntvec(intvec( 2, 4, 3, 1, 9, 8, 5, 10, 7, 6 )),
     2757permutationFromIntvec(intvec( 2, 5, 8, 9, 1, 3, 4, 6, 7, 10 )),
     2758permutationFromIntvec(intvec( 2, 5, 9, 8, 1, 4, 3, 7, 6, 10 )),
     2759permutationFromIntvec(intvec( 2, 8, 5, 9, 3, 1, 4, 6, 10, 7 )),
     2760permutationFromIntvec(intvec( 2, 8, 9, 5, 3, 4, 1, 10, 6, 7 )),
     2761permutationFromIntvec(intvec( 2, 9, 5, 8, 4, 1, 3, 7, 10, 6 )),
     2762permutationFromIntvec(intvec( 2, 9, 8, 5, 4, 3, 1, 10, 7, 6 )),
     2763permutationFromIntvec(intvec( 3, 1, 2, 4, 6, 8, 10, 5, 7, 9 )),
     2764permutationFromIntvec(intvec( 3, 1, 4, 2, 6, 10, 8, 7, 5, 9 )),
     2765permutationFromIntvec(intvec( 3, 2, 1, 4, 8, 6, 10, 5, 9, 7 )),
     2766permutationFromIntvec(intvec( 3, 2, 4, 1, 8, 10, 6, 9, 5, 7 )),
     2767permutationFromIntvec(intvec( 3, 4, 1, 2, 10, 6, 8, 7, 9, 5 )),
     2768permutationFromIntvec(intvec( 3, 4, 2, 1, 10, 8, 6, 9, 7, 5 )),
     2769permutationFromIntvec(intvec( 3, 6, 8, 10, 1, 2, 4, 5, 7, 9 )),
     2770permutationFromIntvec(intvec( 3, 6, 10, 8, 1, 4, 2, 7, 5, 9 )),
     2771permutationFromIntvec(intvec( 3, 8, 6, 10, 2, 1, 4, 5, 9, 7 )),
     2772permutationFromIntvec(intvec( 3, 8, 10, 6, 2, 4, 1, 9, 5, 7 )),
     2773permutationFromIntvec(intvec( 3, 10, 6, 8, 4, 1, 2, 7, 9, 5 )),
     2774permutationFromIntvec(intvec( 3, 10, 8, 6, 4, 2, 1, 9, 7, 5 )),
     2775permutationFromIntvec(intvec( 4, 1, 2, 3, 7, 9, 10, 5, 6, 8 )),
     2776permutationFromIntvec(intvec( 4, 1, 3, 2, 7, 10, 9, 6, 5, 8 )),
     2777permutationFromIntvec(intvec( 4, 2, 1, 3, 9, 7, 10, 5, 8, 6 )),
     2778permutationFromIntvec(intvec( 4, 2, 3, 1, 9, 10, 7, 8, 5, 6 )),
     2779permutationFromIntvec(intvec( 4, 3, 1, 2, 10, 7, 9, 6, 8, 5 )),
     2780permutationFromIntvec(intvec( 4, 3, 2, 1, 10, 9, 7, 8, 6, 5 )),
     2781permutationFromIntvec(intvec( 4, 7, 9, 10, 1, 2, 3, 5, 6, 8 )),
     2782permutationFromIntvec(intvec( 4, 7, 10, 9, 1, 3, 2, 6, 5, 8 )),
     2783permutationFromIntvec(intvec( 4, 9, 7, 10, 2, 1, 3, 5, 8, 6 )),
     2784permutationFromIntvec(intvec( 4, 9, 10, 7, 2, 3, 1, 8, 5, 6 )),
     2785permutationFromIntvec(intvec( 4, 10, 7, 9, 3, 1, 2, 6, 8, 5 )),
     2786permutationFromIntvec(intvec( 4, 10, 9, 7, 3, 2, 1, 8, 6, 5 )),
     2787permutationFromIntvec(intvec( 5, 1, 6, 7, 2, 8, 9, 3, 4, 10 )),
     2788permutationFromIntvec(intvec( 5, 1, 7, 6, 2, 9, 8, 4, 3, 10 )),
     2789permutationFromIntvec(intvec( 5, 2, 8, 9, 1, 6, 7, 3, 4, 10 )),
     2790permutationFromIntvec(intvec( 5, 2, 9, 8, 1, 7, 6, 4, 3, 10 )),
     2791permutationFromIntvec(intvec( 5, 6, 1, 7, 8, 2, 9, 3, 10, 4 )),
     2792permutationFromIntvec(intvec( 5, 6, 7, 1, 8, 9, 2, 10, 3, 4 )),
     2793permutationFromIntvec(intvec( 5, 7, 1, 6, 9, 2, 8, 4, 10, 3 )),
     2794permutationFromIntvec(intvec( 5, 7, 6, 1, 9, 8, 2, 10, 4, 3 )),
     2795permutationFromIntvec(intvec( 5, 8, 2, 9, 6, 1, 7, 3, 10, 4 )),
     2796permutationFromIntvec(intvec( 5, 8, 9, 2, 6, 7, 1, 10, 3, 4 )),
     2797permutationFromIntvec(intvec( 5, 9, 2, 8, 7, 1, 6, 4, 10, 3 )),
     2798permutationFromIntvec(intvec( 5, 9, 8, 2, 7, 6, 1, 10, 4, 3 )),
     2799permutationFromIntvec(intvec( 6, 1, 5, 7, 3, 8, 10, 2, 4, 9 )),
     2800permutationFromIntvec(intvec( 6, 1, 7, 5, 3, 10, 8, 4, 2, 9 )),
     2801permutationFromIntvec(intvec( 6, 3, 8, 10, 1, 5, 7, 2, 4, 9 )),
     2802permutationFromIntvec(intvec( 6, 3, 10, 8, 1, 7, 5, 4, 2, 9 )),
     2803permutationFromIntvec(intvec( 6, 5, 1, 7, 8, 3, 10, 2, 9, 4 )),
     2804permutationFromIntvec(intvec( 6, 5, 7, 1, 8, 10, 3, 9, 2, 4 )),
     2805permutationFromIntvec(intvec( 6, 7, 1, 5, 10, 3, 8, 4, 9, 2 )),
     2806permutationFromIntvec(intvec( 6, 7, 5, 1, 10, 8, 3, 9, 4, 2 )),
     2807permutationFromIntvec(intvec( 6, 8, 3, 10, 5, 1, 7, 2, 9, 4 )),
     2808permutationFromIntvec(intvec( 6, 8, 10, 3, 5, 7, 1, 9, 2, 4 )),
     2809permutationFromIntvec(intvec( 6, 10, 3, 8, 7, 1, 5, 4, 9, 2 )),
     2810permutationFromIntvec(intvec( 6, 10, 8, 3, 7, 5, 1, 9, 4, 2 )),
     2811permutationFromIntvec(intvec( 7, 1, 5, 6, 4, 9, 10, 2, 3, 8 )),
     2812permutationFromIntvec(intvec( 7, 1, 6, 5, 4, 10, 9, 3, 2, 8 )),
     2813permutationFromIntvec(intvec( 7, 4, 9, 10, 1, 5, 6, 2, 3, 8 )),
     2814permutationFromIntvec(intvec( 7, 4, 10, 9, 1, 6, 5, 3, 2, 8 )),
     2815permutationFromIntvec(intvec( 7, 5, 1, 6, 9, 4, 10, 2, 8, 3 )),
     2816permutationFromIntvec(intvec( 7, 5, 6, 1, 9, 10, 4, 8, 2, 3 )),
     2817permutationFromIntvec(intvec( 7, 6, 1, 5, 10, 4, 9, 3, 8, 2 )),
     2818permutationFromIntvec(intvec( 7, 6, 5, 1, 10, 9, 4, 8, 3, 2 )),
     2819permutationFromIntvec(intvec( 7, 9, 4, 10, 5, 1, 6, 2, 8, 3 )),
     2820permutationFromIntvec(intvec( 7, 9, 10, 4, 5, 6, 1, 8, 2, 3 )),
     2821permutationFromIntvec(intvec( 7, 10, 4, 9, 6, 1, 5, 3, 8, 2 )),
     2822permutationFromIntvec(intvec( 7, 10, 9, 4, 6, 5, 1, 8, 3, 2 )),
     2823permutationFromIntvec(intvec( 8, 2, 5, 9, 3, 6, 10, 1, 4, 7 )),
     2824permutationFromIntvec(intvec( 8, 2, 9, 5, 3, 10, 6, 4, 1, 7 )),
     2825permutationFromIntvec(intvec( 8, 3, 6, 10, 2, 5, 9, 1, 4, 7 )),
     2826permutationFromIntvec(intvec( 8, 3, 10, 6, 2, 9, 5, 4, 1, 7 )),
     2827permutationFromIntvec(intvec( 8, 5, 2, 9, 6, 3, 10, 1, 7, 4 )),
     2828permutationFromIntvec(intvec( 8, 5, 9, 2, 6, 10, 3, 7, 1, 4 )),
     2829permutationFromIntvec(intvec( 8, 6, 3, 10, 5, 2, 9, 1, 7, 4 )),
     2830permutationFromIntvec(intvec( 8, 6, 10, 3, 5, 9, 2, 7, 1, 4 )),
     2831permutationFromIntvec(intvec( 8, 9, 2, 5, 10, 3, 6, 4, 7, 1 )),
     2832permutationFromIntvec(intvec( 8, 9, 5, 2, 10, 6, 3, 7, 4, 1 )),
     2833permutationFromIntvec(intvec( 8, 10, 3, 6, 9, 2, 5, 4, 7, 1 )),
     2834permutationFromIntvec(intvec( 8, 10, 6, 3, 9, 5, 2, 7, 4, 1 )),
     2835permutationFromIntvec(intvec( 9, 2, 5, 8, 4, 7, 10, 1, 3, 6 )),
     2836permutationFromIntvec(intvec( 9, 2, 8, 5, 4, 10, 7, 3, 1, 6 )),
     2837permutationFromIntvec(intvec( 9, 4, 7, 10, 2, 5, 8, 1, 3, 6 )),
     2838permutationFromIntvec(intvec( 9, 4, 10, 7, 2, 8, 5, 3, 1, 6 )),
     2839permutationFromIntvec(intvec( 9, 5, 2, 8, 7, 4, 10, 1, 6, 3 )),
     2840permutationFromIntvec(intvec( 9, 5, 8, 2, 7, 10, 4, 6, 1, 3 )),
     2841permutationFromIntvec(intvec( 9, 7, 4, 10, 5, 2, 8, 1, 6, 3 )),
     2842permutationFromIntvec(intvec( 9, 7, 10, 4, 5, 8, 2, 6, 1, 3 )),
     2843permutationFromIntvec(intvec( 9, 8, 2, 5, 10, 4, 7, 3, 6, 1 )),
     2844permutationFromIntvec(intvec( 9, 8, 5, 2, 10, 7, 4, 6, 3, 1 )),
     2845permutationFromIntvec(intvec( 9, 10, 4, 7, 8, 2, 5, 3, 6, 1 )),
     2846permutationFromIntvec(intvec( 9, 10, 7, 4, 8, 5, 2, 6, 3, 1 )),
     2847permutationFromIntvec(intvec( 10, 3, 6, 8, 4, 7, 9, 1, 2, 5 )),
     2848permutationFromIntvec(intvec( 10, 3, 8, 6, 4, 9, 7, 2, 1, 5 )),
     2849permutationFromIntvec(intvec( 10, 4, 7, 9, 3, 6, 8, 1, 2, 5 )),
     2850permutationFromIntvec(intvec( 10, 4, 9, 7, 3, 8, 6, 2, 1, 5 )),
     2851permutationFromIntvec(intvec( 10, 6, 3, 8, 7, 4, 9, 1, 5, 2 )),
     2852permutationFromIntvec(intvec( 10, 6, 8, 3, 7, 9, 4, 5, 1, 2 )),
     2853permutationFromIntvec(intvec( 10, 7, 4, 9, 6, 3, 8, 1, 5, 2 )),
     2854permutationFromIntvec(intvec( 10, 7, 9, 4, 6, 8, 3, 5, 1, 2 )),
     2855permutationFromIntvec(intvec( 10, 8, 3, 6, 9, 4, 7, 2, 5, 1 )),
     2856permutationFromIntvec(intvec( 10, 8, 6, 3, 9, 7, 4, 5, 2, 1 )),
     2857permutationFromIntvec(intvec( 10, 9, 4, 7, 8, 3, 6, 2, 5, 1 )),
     2858permutationFromIntvec(intvec( 10, 9, 7, 4, 8, 6, 3, 5, 2, 1 ));
     2859return(simplexSymmetryGroup);
     2860}
     2861example
     2862{
     2863  echo = 2;
     2864  G25Action();
     2865}
     2866
     2867
     2868proc findOrbits(list G, int #)
     2869"USAGE: findOrbits(G [,d]); G list of permutations in a subgroup of the symmetric group; d int minimum cardinality of simplices to be considered; if d is not specified all orbits are computed.
     2870PURPOSE: Computes the orbit decomposition of the action of G.
     2871RETURN: list of intvec.
     2872EXAMPLE: example findOrbits; shows an example
     2873"
     2874{
     2875int d;
     2876if (size(#)>0){d=#;}
     2877int n = size(permutationToIntvec(G[1]));
     2878list listOrbits;
     2879list finished;
     2880int tst;
     2881bigint startel;
     2882intvec startelbin;
     2883list neworbit,neworbitint;
     2884int i,posToInsert;
     2885bigint nn;
     2886while (size(finished)<2^n){
     2887   startel=0;
     2888   if (size(finished)>0){
     2889      tst=0;
     2890      while ((tst==0) and (startel+1<=size(finished))){
     2891        if (finished[int(startel+1)]<>startel){
     2892          tst=1;
     2893        } else {
     2894          startel=startel+1;
     2895        }
    5722896      }
    573 
    574       c = coneViaPoints(M);
    575 
    576       if((dimension(c) == nrows(Q)) and (!(listContainsCone(OC, c))))
    577       {
    578         OC[size(OC)+1] = c;
    579       }
    580 
    581       kill M;
    582     }
    583   }
    584 
    585   return(OC);
    586 }
    587 
    588 /////////////////////////////////////
    589 
    590 proc gkzFan(bigintmat Q)
    591 "USAGE: gkzFan(Q); a: ideal, Q:bigintmat
    592 PURPOSE: Returns the GKZ-fan of the matrix Q.
    593 RETURN: a fan.
    594 EXAMPLE: example gkzFan; shows an example
    595 "
    596 {
    597   // only difference to gitFan:
    598   // it suffices to consider all faces
    599   // that are simplicial:
    600   list OC = simplicialToricOrbitCones(Q);
    601 
    602   fan f = refineCones(OC, Q);
    603   return(f);
    604 }
     2897   }
     2898   if (startel==0){
     2899     neworbit[1]= list();
     2900     neworbitint[1]=0;
     2901   } else {
     2902      startelbin=bigintToBinary(startel,n);
     2903       neworbitint=list(startel);
     2904       for (i=2;i<=size(G);i++){
     2905         nn=binaryToBigint(applyPermutationToIntvec(startelbin,G[i]));
     2906         //nn;neworbitint;
     2907         //"place to insert";
     2908         posToInsert = findPlaceToInsert(neworbitint,nn);
     2909         //"pos";posToInsert;
     2910         if(posToInsert > 0)
     2911         {
     2912          //"vorher";neworbitint;
     2913          neworbitint = insertToList(neworbitint,nn,posToInsert);
     2914          //"nachher";neworbitint;
     2915         }
     2916       }
     2917       for (i=1;i<=size(neworbitint);i++){
     2918          neworbit[i]=bigintToBinary(neworbitint[i],n);
     2919       }
     2920   }
     2921   if (size(neworbit[1])>=d){
     2922     listOrbits[size(listOrbits)+1]=neworbit;
     2923   }
     2924   finished=sort(finished+neworbitint)[1];
     2925}
     2926return(listOrbits);}
    6052927example
    6062928{
    607   echo=2;
    608   intmat Q[3][4] =
    609     1,0,1,0,
    610     0,1,0,1,
    611     0,0,1,1;
    612 
    613   gkzFan(Q);
    614 }
     2929list G = G25Action();
     2930list orb = findOrbits(G);
     2931for (int i=1;i<=size(orb);i++){orb[i][1];}
     2932}
     2933
     2934
     2935
     2936static proc GITfanWrapperWithSymmetry(ideal J, intmat Q, list simplexSymmetryGroup){
     2937  list orb = findOrbits(simplexSymmetryGroup,nrows(Q));
     2938  list simplexOrbitRepresentatives;
     2939  for (int i=1;i<=size(orb);i++){simplexOrbitRepresentatives[i]=orb[i][1];}
     2940  list afaceOrbitRepresentatives=afaces(J,simplexOrbitRepresentatives);
     2941  list fulldimAfaceOrbitRepresentatives=fullDimImages(afaceOrbitRepresentatives,Q);
     2942  list afaceOrbits=computeAfaceOrbits(fulldimAfaceOrbitRepresentatives,simplexSymmetryGroup);
     2943  list minAfaceOrbits = minimalAfaceOrbits(afaceOrbits);
     2944  list listOfOrbitConeOrbits = orbitConeOrbits(minAfaceOrbits,Q);
     2945  list listOfMinimalOrbitConeOrbits = minimalOrbitConeOrbits(listOfOrbitConeOrbits);
     2946  list Asigma = groupActionOnQImage(simplexSymmetryGroup,Q);
     2947  list actionOnOrbitconeIndices = groupActionOnHashes(Asigma,listOfOrbitConeOrbits);
     2948  list OClist = listOfOrbitConeOrbits[1];
     2949  for (i =2;i<=size(listOfOrbitConeOrbits);i++){
     2950    OClist = OClist + listOfOrbitConeOrbits[i];
     2951  }
     2952  cone mov = coneViaPoints(transpose(Q));
     2953  mov = canonicalizeCone(mov);
     2954  list Sigma = GITfanParallelSymmetric(OClist, Q, mov, actionOnOrbitconeIndices);
     2955  return(Sigma, OClist);
     2956}
  • Singular/dyn_modules/Makefile.am

    r12de09 r3c03e6  
    11ACLOCAL_AMFLAGS = -I ../m4
    22
    3 SUBDIRS=staticdemo bigintm syzextra pyobject customstd gfanlib python polymake singmathic Order
     3SUBDIRS=staticdemo bigintm syzextra pyobject customstd gfanlib python gitfan polymake singmathic Order
  • Singular/dyn_modules/gfanlib/Makefile.am

    r12de09 r3c03e6  
    11ACLOCAL_AMFLAGS = -I ../../m4
    22
    3 SOURCES = singularWishlist.cc singularWishlist.h gfanlib_exceptions.h callgfanlib_conversion.cc callgfanlib_conversion.h bbcone.cc bbcone.h bbfan.cc bbfan.h bbpolytope.cc bbpolytope.h gfan.h gitfan.cc gitfan.h std_wrapper.cc std_wrapper.h tropicalDebug.h tropicalDebug.cc tropicalVarietyOfPolynomials.h tropicalVarietyOfPolynomials.cc ppinitialReduction.cc ppinitialReduction.h containsMonomial.cc containsMonomial.h adjustWeights.cc adjustWeights.h tropicalStrategy.cc tropicalStrategy.h initial.cc initial.h witness.cc witness.h lift.cc lift.h flip.cc flip.h tropicalCurves.cc tropicalCurves.h groebnerCone.cc groebnerCone.h startingCone.cc startingCone.h tropicalTraversal.cc tropicalTraversal.h tropicalVarietyOfIdeals.cc tropicalVarietyOfIdeals.h tropicalVariety.cc tropicalVariety.h groebnerFan.cc groebnerFan.h groebnerComplex.cc groebnerComplex.h tropical.cc tropical.h gfanlib.cc
     3SOURCES = singularWishlist.cc singularWishlist.h gfanlib_exceptions.h callgfanlib_conversion.cc callgfanlib_conversion.h bbcone.cc bbcone.h bbfan.cc bbfan.h bbpolytope.cc bbpolytope.h gfan.h std_wrapper.cc std_wrapper.h tropicalDebug.h tropicalDebug.cc tropicalVarietyOfPolynomials.h tropicalVarietyOfPolynomials.cc ppinitialReduction.cc ppinitialReduction.h containsMonomial.cc containsMonomial.h adjustWeights.cc adjustWeights.h tropicalStrategy.cc tropicalStrategy.h initial.cc initial.h witness.cc witness.h lift.cc lift.h flip.cc flip.h tropicalCurves.cc tropicalCurves.h groebnerCone.cc groebnerCone.h startingCone.cc startingCone.h tropicalTraversal.cc tropicalTraversal.h tropicalVarietyOfIdeals.cc tropicalVarietyOfIdeals.h tropicalVariety.cc tropicalVariety.h groebnerFan.cc groebnerFan.h groebnerComplex.cc groebnerComplex.h tropical.cc tropical.h gfanlib.cc
    44
    55MY_CPPFLAGS = -I${srcdir} -I${top_srcdir} -I${top_builddir} \
  • Singular/dyn_modules/gfanlib/bbcone.cc

    r12de09 r3c03e6  
    12371237    }
    12381238  }
     1239  if ((u != NULL) && (u->Typ() == LIST_CMD))
     1240  {
     1241    if (u->next == NULL)
     1242    {
     1243      lists l = (lists) u->Data();
     1244
     1245      // find the total number of inequalities and equations
     1246      int r1=0; // total number of inequalities
     1247      int r2=0; // total number of equations
     1248      int c=0;  // ambient dimension
     1249      for (int i=0; i<=lSize(l); i++)
     1250      {
     1251        if (l->m[i].Typ() != coneID)
     1252        {
     1253          WerrorS("convexIntersection: entries of wrong type in list");
     1254          return TRUE;
     1255        }
     1256        gfan::ZCone* ll = (gfan::ZCone*) l->m[i].Data();
     1257        r1 = r1 + ll->getInequalities().getHeight();
     1258        r2 = r2 + ll->getEquations().getHeight();
     1259      }
     1260      if (lSize(l)>=0)
     1261      {
     1262        gfan::ZCone* ll = (gfan::ZCone*) l->m[0].Data();
     1263        c = ll->getInequalities().getWidth();
     1264      }
     1265      gfan::ZMatrix totalIneqs(r1,c);
     1266      gfan::ZMatrix totalEqs(r2,c);
     1267
     1268      // concat all inequalities and equations
     1269      r1=0; // counter for inequalities
     1270      r2=0; // counter for equations
     1271      for (int i=0; i<=lSize(l); i++)
     1272      {
     1273        gfan::ZCone* ll = (gfan::ZCone*) l->m[i].Data();
     1274        gfan::ZMatrix ineqs = ll->getInequalities();
     1275        for (int j=0; j<ineqs.getHeight(); j++)
     1276        {
     1277          totalIneqs[r1]=ineqs[j];
     1278          r1 = r1+1;
     1279        }
     1280        gfan::ZMatrix eqs = ll->getEquations();
     1281        for (int j=0; j<eqs.getHeight(); j++)
     1282        {
     1283          totalEqs[r2]=eqs[j];
     1284          r2 = r2+1;
     1285        }
     1286      }
     1287
     1288      gfan::ZCone* zc = new gfan::ZCone(totalIneqs,totalEqs);
     1289      zc->canonicalize();
     1290      res->rtyp = coneID;
     1291      res->data = (void *) zc;
     1292      return FALSE;
     1293    }
     1294  }
    12391295  if ((u != NULL) && (u->Typ() == polytopeID))
    12401296  {
     
    14451501
    14461502      delete zv;
    1447       if (v->Typ() == INTMAT_CMD)
     1503      if (v->Typ() == INTVEC_CMD)
    14481504        delete iv;
    14491505      gfan::deinitializeCddlibIfRequired();
     
    15091565
    15101566      delete zv;
    1511       if (v->Typ() == INTMAT_CMD)
     1567      if (v->Typ() == INTVEC_CMD)
    15121568        delete iv;
    15131569      gfan::deinitializeCddlibIfRequired();
     
    15461602        res->data = (void *) b;
    15471603        delete zv;
    1548         if (v->Typ() == INTMAT_CMD)
     1604        if (v->Typ() == INTVEC_CMD)
    15491605          delete iv;
    15501606        gfan::deinitializeCddlibIfRequired();
     
    15521608      }
    15531609      delete zv;
    1554       if (v->Typ() == INTMAT_CMD)
     1610      if (v->Typ() == INTVEC_CMD)
    15551611        delete iv;
    15561612      gfan::deinitializeCddlibIfRequired();
  • Singular/dyn_modules/gfanlib/bbfan.cc

    r12de09 r3c03e6  
    410410
    411411      leftv w=v->next;
    412       int n;
     412      int n=1;
    413413      if ((w != NULL) && (w->Typ() == INT_CMD))
    414         n = (int)(long) w;
     414        n = (int)(long) w->Data();
    415415
    416416      if (n != 0)
  • Singular/dyn_modules/gfanlib/gfanlib.cc

    r12de09 r3c03e6  
    66#include "bbfan.h"
    77#include "bbpolytope.h"
    8 #include "gitfan.h"
    98#include "tropical.h"
    109
     
    2423  bbfan_setup(p);
    2524  bbpolytope_setup(p);
    26   gitfan_setup(p);
    2725  tropical_setup(p);
    2826  return MAX_TOK;
  • Singular/dyn_modules/gitfan/gitfan.h

    r12de09 r3c03e6  
    66#if HAVE_GFANLIB
    77
    8 #include "bbcone.h"
    9 #include "bbfan.h"
     8#include <Singular/dyn_modules/gfanlib/bbcone.h>
     9#include <Singular/dyn_modules/gfanlib/bbfan.h>
    1010
    1111#include "Singular/ipid.h"
  • configure.ac

    r12de09 r3c03e6  
    244244AC_CONFIG_FILES([Singular/dyn_modules/singmathic/Makefile])
    245245AC_CONFIG_FILES([Singular/dyn_modules/staticdemo/Makefile])
     246AC_CONFIG_FILES([Singular/dyn_modules/gitfan/Makefile])
    246247
    247248AC_CONFIG_FILES([Singular/Makefile])
  • libpolys/polys/matpol.cc

    r4f73ae7 r3c03e6  
    544544  {
    545545    i = 1;
    546     j = p_GetComp(v, R);
     546    j = __p_GetComp(v, R);
    547547    loop
    548548    {
     
    17091709  {
    17101710    poly hh=pNext(h);
    1711     pNext(h)=a[p_GetComp(h,r)-1];
    1712     a[p_GetComp(h,r)-1]=h;
     1711    pNext(h)=a[__p_GetComp(h,r)-1];
     1712    a[__p_GetComp(h,r)-1]=h;
    17131713    p_SetComp(h,0,r);
    17141714    p_SetmComp(h,r);
  • libpolys/polys/simpleideals.cc

    r4f73ae7 r3c03e6  
    13121312    {
    13131313      p=F[i];
    1314       while ((p!=NULL) && (iscom[p_GetComp(p,R)]==0)) pIter(p);
     1314      while ((p!=NULL) && (iscom[__p_GetComp(p,R)]==0)) pIter(p);
    13151315    }
    13161316    if ((p==NULL) && (i<length))
     
    13321332      //  order = p->order;
    13331333      //  order = pFDeg(p,currRing);
    1334       order = d(p,R) +diff[p_GetComp(p,R)];
     1334      order = d(p,R) +diff[__p_GetComp(p,R)];
    13351335      //order += diff[pGetComp(p)];
    13361336      p = F[i];
     
    13461346      //  ord = p->order;
    13471347        ord = R->pFDeg(p,R);
    1348       if (iscom[p_GetComp(p,R)]==0)
    1349       {
    1350         diff[p_GetComp(p,R)] = order-ord;
    1351         iscom[p_GetComp(p,R)] = 1;
     1348      if (iscom[__p_GetComp(p,R)]==0)
     1349      {
     1350        diff[__p_GetComp(p,R)] = order-ord;
     1351        iscom[__p_GetComp(p,R)] = 1;
    13521352/*
    13531353*PrintS("new diff: ");
     
    13681368*Print("order %d, ord %d, diff %d\n",order,ord,diff[pGetComp(p)]);
    13691369*/
    1370         if (order != (ord+diff[p_GetComp(p,R)]))
     1370        if (order != (ord+diff[__p_GetComp(p,R)]))
    13711371        {
    13721372          omFreeSize((ADDRESS) iscom,cmax*sizeof(int));
     
    14491449    while (p!=NULL)
    14501450    {
    1451       j = p_GetComp(p,r);
     1451      j = __p_GetComp(p,r);
    14521452      if (componentIsUsed[j]==0)
    14531453      {
     
    16201620    {
    16211621      poly h=p_Head(p, rRing);
    1622       int co=p_GetComp(h, rRing)-1;
     1622      int co=__p_GetComp(h, rRing)-1;
    16231623      p_SetComp(h, i, rRing);
    16241624      p_Setm(h, rRing);
     
    16871687      poly h = p_Head(w, rRing);
    16881688
    1689       const int  gen = p_GetComp(h, rRing); // 1 ...
     1689      const int  gen = __p_GetComp(h, rRing); // 1 ...
    16901690
    16911691      assume(gen > 0);
  • m4/options.m4

    r12de09 r3c03e6  
    282282
    283283AC_DEFUN([SING_CHECK_PYTHON_MODULE],
    284 [ 
     284[
    285285AC_ARG_ENABLE(python_module, AS_HELP_STRING([--enable-python_module], [Enable python_module.so]),
    286286[if test $enableval = yes; then
     
    324324  bi_bigintm=false
    325325  bi_Order=false
     326  bi_gitfan=false
    326327
    327328
     
    356357       bigintm ) bi_bigintm=true ;;
    357358       Order ) bi_Order=true ;;
     359       gitfan ) bi_gitfan=true ;;
    358360      esac
    359361
     
    392394 AM_CONDITIONAL([SI_BUILTIN_BIGINTM], [test x$bi_bigintm = xtrue])
    393395 AM_CONDITIONAL([SI_BUILTIN_ORDER], [test x$bi_Order = xtrue])
     396 AM_CONDITIONAL([SI_BUILTIN_GITFAN], [test x$bi_gitfan = xtrue])
    394397
    395398 AC_MSG_CHECKING([BUILTIN_LIBS...])
Note: See TracChangeset for help on using the changeset viewer.