Changeset 7f5789 in git for Singular


Ignore:
Timestamp:
Jan 18, 2020, 10:59:58 PM (4 years ago)
Author:
Karim Abou Zeid <karim23697@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
c417af59af93bdad5278db69f84585a318ee2ba5
Parents:
da6d43a81ee1ba91b8ecae7bb3a89f608e66b354
git-author:
Karim Abou Zeid <karim23697@gmail.com>2020-01-18 22:59:58+01:00
git-committer:
Karim Abou Zeid <karim23697@gmail.com>2020-01-18 23:05:58+01:00
Message:
Fix fpaprops for ncgen and add tests
Location:
Singular
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/fpaprops.lib

    rda6d43a r7f5789  
    2828  lpGlDimBound(<GB>);     compute an upper bound for the global dimension of A/<GB>
    2929  lpSubstitute();         substitute a variable with polynomials (ring homomorphism)
    30   lpUfGraph(<GB>);        constructs the Ufnarovskij graph for <LM(GB)>
    3130  lpCalcSubstDegBound(); utility for lpSubstitute
    3231";
     
    4443    example lpGlDimBound;
    4544    example lpSubstitute;
    46     example lpUfGraph;
    4745    example lpCalcSubstDegBound;
    4846};
     
    9088  if (l == 1) {
    9189    int n = lpVarBlockSize(basering); // variable count
     90    int ncgenCount = lpNcgenCount(basering);
    9291    int k = size(G);
    93     if (k == n) { // only the field left
     92    if (k == n - ncgenCount) { // only the field left
    9493      return(3); // every field is noetherian
    9594    }
    96     if (k == n-1) { // V = {1} with loop
     95    if (k == n - ncgenCount - 1) { // V = {1} with loop
    9796      return(3);
    9897    }
    99     if (k <= n-2) { // V = {1} with more than one loop
     98    if (k <= n ncgenCount - 2) { // V = {1} with more than one loop
    10099      return(0);
    101100    }
    102101  }
    103102
    104   intmat UG = lpUfGraph(G);
     103  intmat UG = lpUfGraph(G)[1];
    105104
    106105  // check special case 2
     
    311310  }
    312311
    313   list VUG = lpUfGraph(G, 1);
     312  list VUG = lpUfGraph(G);
    314313  intmat UG = VUG[1]; // the Ufnarovskij graph
    315314  ideal V = VUG[2]; // the vertices of UG (standard words with length = l-1)
     
    419418  }
    420419
    421   list VUG = lpUfGraph(G, 1);
     420  list VUG = lpUfGraph(G);
    422421  intmat UG = VUG[1]; // the Ufnarovskij graph
    423422  ideal V = VUG[2]; // the vertices of UG (standard words with length = l-1)
     
    726725}
    727726
    728 proc lpUfGraph(ideal G, list #)
    729 "USAGE: lpUfGraph(G); G a set of monomials in a letterplace ring.
    730 RETURN: intmat or list
    731 NOTE: lpUfGraph(G); returns intmat. lpUfGraph(G,1); returns list L with L[1] an intmat and L[2] an ideal.
    732       The intmat is the Ufnarovskij Graph and the ideal contains the vertices.
    733 PURPOSE: Constructs the Ufnarovskij graph induced by G
    734       the adjacency matrix of the Ufnarovskij graph induced by G
    735 ASSUME: - basering is a Letterplace ring
    736       - G are the leading monomials of a Groebner basis
    737 "
    738 {
    739   dbprint("computing maxDeg");
    740   int l = maxDeg(G);
    741   if (l - 1 == 0) {
    742     // TODO: how should the graph look like when l - 1 = 0 ?
    743     ERROR("Ufnarovskij graph not implemented for l = 1");
    744   }
    745   int lV = lpVarBlockSize(basering);
    746   // TODO: what if l <= 0?
    747   dbprint("computing standard words");
    748   ideal SW = lpStandardWords(G, l - 1); // vertices
    749   int n = ncols(SW);
    750   dbprint("n = " + string(n));
    751   intmat UG[n][n]; // Ufnarovskij graph
    752   for (int i = 1; i <= n; i++) {
    753     for (int j = 1; j <= n; j++) {
    754       dbprint("Ufnarovskii graph: " + string((i-1)*n + j) + "/" + string(n*n) + " entries");
    755       // [Studzinski page 76]
    756       poly v = SW[i];
    757       poly w = SW[j];
    758       intvec v_overlap;
    759       intvec w_overlap;
    760       if (l - 1 > 1) {
    761         v_overlap = leadexp(v);
    762         w_overlap = leadexp(w);
    763         v_overlap = v_overlap[(lV+1) .. (l-1)*lV];
    764         w_overlap = w_overlap[1 .. (l-2)*lV];
    765       }
    766       if (v_overlap == w_overlap && !lpLmDivides(G, v * lpVarAt(w, l - 1))) {
    767         UG[i,j] = 1;
    768       }
    769       kill v; kill w; kill v_overlap; kill w_overlap;
    770     } kill j;
    771   } kill i;
    772   if (size(#) > 0) {
    773     if (typeof(#[1]) == "int") {
    774       if (#[1] != 0) {
    775         list ret = UG;
    776         ret[2] = SW; // the vertices
    777         return (ret);
    778       }
    779     }
    780   }
    781   return (UG);
    782 }
    783 example
    784 {
    785   "EXAMPLE:"; echo = 2;
    786   ring r = 0,(x,y,z),dp;
    787   def R = freeAlgebra(r, 5); // constructs a Letterplace ring
    788   setring R; // sets basering to Letterplace ring
    789   ideal I = x*y, x*z, z*y, z*z;
    790   lpUfGraph(I);
    791   lpUfGraph(I,1);
    792 }
     727// Ufnarovskii graph is now implemented in the dynamic module (freeAlgebra.cc)
     728/* proc lpUfGraph(ideal G, list #) */
     729/* "USAGE: lpUfGraph(G); G a set of monomials in a letterplace ring. */
     730/* RETURN: intmat or list */
     731/* NOTE: lpUfGraph(G); returns intmat. lpUfGraph(G,1); returns list L with L[1] an intmat and L[2] an ideal. */
     732/*       The intmat is the Ufnarovskij Graph and the ideal contains the vertices. */
     733/* PURPOSE: Constructs the Ufnarovskij graph induced by G */
     734/*       the adjacency matrix of the Ufnarovskij graph induced by G */
     735/* ASSUME: - basering is a Letterplace ring */
     736/*       - G are the leading monomials of a Groebner basis */
     737/* " */
     738/* { */
     739/*   dbprint("computing maxDeg"); */
     740/*   int l = maxDeg(G); */
     741/*   if (l - 1 == 0) { */
     742/*     // TODO: how should the graph look like when l - 1 = 0 ? */
     743/*     ERROR("Ufnarovskij graph not implemented for l = 1"); */
     744/*   } */
     745/*   int lV = lpVarBlockSize(basering); */
     746/*   // TODO: what if l <= 0? */
     747/*   dbprint("computing standard words"); */
     748/*   ideal SW = lpStandardWords(G, l - 1); // vertices */
     749/*   int n = ncols(SW); */
     750/*   dbprint("n = " + string(n)); */
     751/*   intmat UG[n][n]; // Ufnarovskij graph */
     752/*   for (int i = 1; i <= n; i++) { */
     753/*     for (int j = 1; j <= n; j++) { */
     754/*       dbprint("Ufnarovskii graph: " + string((i-1)*n + j) + "/" + string(n*n) + " entries"); */
     755/*       // [Studzinski page 76] */
     756/*       poly v = SW[i]; */
     757/*       poly w = SW[j]; */
     758/*       intvec v_overlap; */
     759/*       intvec w_overlap; */
     760/*       if (l - 1 > 1) { */
     761/*         v_overlap = leadexp(v); */
     762/*         w_overlap = leadexp(w); */
     763/*         v_overlap = v_overlap[(lV+1) .. (l-1)*lV]; */
     764/*         w_overlap = w_overlap[1 .. (l-2)*lV]; */
     765/*       } */
     766/*       if (v_overlap == w_overlap && !lpLmDivides(G, v * lpVarAt(w, l - 1))) { */
     767/*         UG[i,j] = 1; */
     768/*       } */
     769/*       kill v; kill w; kill v_overlap; kill w_overlap; */
     770/*     } kill j; */
     771/*   } kill i; */
     772/*   if (size(#) > 0) { */
     773/*     if (typeof(#[1]) == "int") { */
     774/*       if (#[1] != 0) { */
     775/*         list ret = UG; */
     776/*         ret[2] = SW; // the vertices */
     777/*         return (ret); */
     778/*       } */
     779/*     } */
     780/*   } */
     781/*   return (UG); */
     782/* } */
     783/* example */
     784/* { */
     785/*   "EXAMPLE:"; echo = 2; */
     786/*   ring r = 0,(x,y,z),dp; */
     787/*   def R = freeAlgebra(r, 5); // constructs a Letterplace ring */
     788/*   setring R; // sets basering to Letterplace ring */
     789/*   ideal I = x*y, x*z, z*y, z*z; */
     790/*   lpUfGraph(I); */
     791/*   lpUfGraph(I,1); */
     792/* } */
    793793
    794794static proc maxDeg(ideal G)
     
    833833    return (words); // no standard words
    834834  }
    835   int lV = lpVarBlockSize(basering); // variable count
     835  int nVars = lpVarBlockSize(basering) - lpNcgenCount(basering); // variable count
    836836  list prevWords = ivStandardWords(G, length - 1);
    837837  list words;
    838   for (int i = 1; i <= lV; i++) {
     838  for (int i = 1; i <= nVars; i++) {
    839839    for (int j = 1; j <= size(prevWords); j++) {
    840840      intvec word = prevWords[j];
     
    919919
    920920/*   dbprint("computing Ufnarovskii graph"); */
    921 /*   intmat UG = lpUfGraph(G); */
     921/*   intmat UG = lpUfGraph(G)[1]; */
    922922/*   if (printlevel >= voice + 1) { */
    923923/*     UG; */
     
    10021002  if (size(G1) > 0) {
    10031003    while (size(G1) > 0) {
    1004       if (lpVarBlockSize(R) > 1) {
     1004      if (lpVarBlockSize(R) - lpNcgenCount(R) > 1) {
    10051005        def @R = R - string(G1[1]);
    10061006        R = @R;
  • Singular/LIB/freegb.lib

    rda6d43a r7f5789  
    2626lpDegBound(R);                   returns the degree bound of a letterplace ring
    2727lpVarBlockSize(R);               returns the size of the letterplace blocks
     28lpNcgenCount(R);                 returns the number of ncgen variables
    2829lpDivision(f,I);                 two-sided division with remainder
    2930lpGBPres2Poly(L,I);              reconstructs a polynomial from the output of lpDivision
     
    10041005  def R = freeAlgebra(r, 7);
    10051006  isFreeAlgebra(R);
     1007}
     1008
     1009proc lpNcgenCount(def R)
     1010"USAGE:  lpNcgenCount(R); R a letterplace ring
     1011RETURN:  int
     1012PURPOSE: returns the number of ncgen variables in the letterplace ring.
     1013EXAMPLE: example ncgenCount; shows examples
     1014"
     1015{
     1016  return(attrib(R, "ncgenCount"));
     1017}
     1018example
     1019{
     1020  "EXAMPLE:"; echo = 2;
     1021  ring r = 0,(x,y,z),dp;
     1022  def R = freeAlgebra(r, 7, 10);
     1023  lpNcgenCount(R); // should be 10
    10061024}
    10071025
  • Singular/attrib.cc

    rda6d43a r7f5789  
    259259      #ifdef HAVE_SHIFTBBA
    260260      PrintS("attr:isLetterplaceRing, type int\n");
     261      PrintS("attr:ncgenCount, type int\n");
    261262      #endif
    262263
     
    331332    res->data=(void *)(long)(((ring)v->Data())->isLPring);
    332333  }
     334  else if ((strcmp(name,"ncgenCount")==0)
     335  &&(/*v->Typ()*/t==RING_CMD))
     336  {
     337    res->rtyp=INT_CMD;
     338    res->data=(void *)(long)(((ring)v->Data())->LPncGenCount);
     339  }
    333340#endif
    334341  else
     
    436443    }
    437444  }
     445  else if ((strcmp(name,"ncgenCount")==0)
     446  &&(/*v->Typ()*/t==RING_CMD))
     447  {
     448    if (c->Typ()==INT_CMD)
     449      ((ring)v->Data())->LPncGenCount=(int)(long)c->Data();
     450    else
     451    {
     452      WerrorS("attribute `ncgenCount` must be int");
     453      return TRUE;
     454    }
     455  }
    438456#endif
    439457  else
  • Singular/dyn_modules/freealgebra/freealgebra.cc

    rda6d43a r7f5789  
    191191
    192192// NULL if graph is undefined
    193 static intvec* ufnarovskiGraph(ideal G)
     193static intvec* ufnarovskiGraph(ideal G, ideal &standardWords)
    194194{
    195195  long l = 0;
     
    204204  int lV = currRing->isLPring;
    205205
    206   ideal standardWords = computeStandardWords(l, G);
     206  standardWords = computeStandardWords(l, G);
    207207
    208208  int n = IDELEMS(standardWords);
     
    251251}
    252252
     253static BOOLEAN lpUfGraph(leftv res, leftv h)
     254{
     255  const short t[]={1,IDEAL_CMD};
     256  if (iiCheckTypes(h,t,1))
     257  {
     258    ideal I = (ideal) h->Data();
     259    res->rtyp = LIST_CMD;
     260
     261    ideal standardWords;
     262    intvec* graph = ufnarovskiGraph(I, standardWords);
     263
     264    lists li=(lists)omAllocBin(slists_bin);
     265    li->Init(2);
     266    li->m[0].rtyp=INTMAT_CMD;
     267    li->m[1].rtyp=IDEAL_CMD;
     268    li->m[0].data=graph;
     269    li->m[1].data=standardWords;
     270
     271    res->data = li;
     272
     273    if (errorreported) return TRUE;
     274    return FALSE;
     275  }
     276  else return TRUE;
     277}
     278
    253279static std::vector<int> countCycles(const intvec* _G, int v, std::vector<int> path, std::vector<BOOLEAN> visited, std::vector<BOOLEAN> cyclic, std::vector<int> cache)
    254280{
     
    392418  }
    393419
    394   intvec* UG = ufnarovskiGraph(G);
     420  ideal standardWords;
     421  intvec* UG = ufnarovskiGraph(G, standardWords);
    395422  if (errorreported || UG == NULL) return -2;
    396423  return graphGrowth(UG);
     
    423450  p->iiAddCproc("freealgebra.so","lpVarAt",FALSE,lpVarAt);
    424451  p->iiAddCproc("freealgebra.so","lpGkDim",FALSE,lpGkDim);
     452  p->iiAddCproc("freealgebra.so","lpUfGraph",FALSE,lpUfGraph);
    425453
    426454  p->iiAddCproc("freealgebra.so","stest",TRUE,stest);
Note: See TracChangeset for help on using the changeset viewer.