Changeset c8fd40 in git


Ignore:
Timestamp:
Nov 9, 2018, 4:09:43 PM (6 years ago)
Author:
Karim Abou Zeid <karim23697@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'd08f5f0bb3329b8ca19f23b74cb1473686415c3a')
Children:
6fac22d0e553731fefbeacc9e5e1cc9683b38ec2
Parents:
4aa50a694d58bf7ccd9553bb5644b3297c61b608
git-author:
Karim Abou Zeid <karim23697@gmail.com>2018-11-09 16:09:43+01:00
git-committer:
Karim Abou Zeid <karim23697@gmail.com>2018-11-14 16:38:23+01:00
Message:
Kernel stuff for uf graph
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/fpaprops.lib

    r4aa50a rc8fd40  
    622622  // iterate through all vertices
    623623
    624   intvec visited;
    625   visited[n] = 0;
    626 
    627   intvec cyclic;
    628   cyclic[n] = 0;
     624  intvec visited = 0:n;
     625  intvec cyclic = 0:n;
     626  intvec countedCycles = -2:n;
    629627
    630628  int maxCycleCount = 0;
    631629  for (int v = 1; v <= n; v++) {
    632     int cycleCount = countCycles(UG, v, visited, cyclic, 0);
    633     if (cycleCount == -1) {
     630    countedCycles = countCycles(UG, v, visited, cyclic, 0, countedCycles);
     631    dbprint("counted: " + string(v) + "/" + string(n));
     632    if (countedCycles[v] == -1) {
    634633      return(-1);
    635634    }
    636     if (cycleCount > maxCycleCount) {
    637       maxCycleCount = cycleCount;
    638     }
    639     kill cycleCount;
     635    if (countedCycles[v] > maxCycleCount) {
     636      maxCycleCount = countedCycles[v];
     637    }
    640638  } kill v;
    641   return(maxCycleCount);
    642 }
    643 
    644 static proc countCycles(intmat G, int v, intvec visited, intvec cyclic, intvec path)
     639  return (maxCycleCount);
     640}
     641
     642static proc countCycles(intmat G, int v, intvec visited, intvec cyclic, intvec path, intvec countedCycles)
    645643"USAGE: countCycles(G, v, visited, cyclic, path); G a Graph, v the vertex to
    646644start. The parameter visited, cyclic and path should be 0.
     
    651649"
    652650{
     651  if (countedCycles[v] > -2) {
     652    return (countedCycles);
     653  }
    653654  // Mark the current vertex as visited
    654655  visited[v] = 1;
     
    669670          if(cyclic[path[j]] == 1) {
    670671            // 1.1 if yes, return -1
    671             return (-1);
     672            countedCycles[v] = -1;
     673            return (countedCycles);
    672674          }
    673675          if (path[j] == w) {
     
    694696        int maxCycleCount = 0;
    695697        for (int j = size(path); j >= 1; j--) {
    696           int cycleCount = countCycles(G, path[j], visited, cyclic, path);
    697           if(cycleCount == -1) {
    698             return (-1);
     698          countedCycles = countCycles(G, path[j], visited, cyclic, path, countedCycles);
     699          if(countedCycles[path[j]] == -1) {
     700            countedCycles[v] = -1;
     701            return (countedCycles);
    699702          }
    700           if (cycleCount > maxCycleCount) {
    701             maxCycleCount = cycleCount;
     703          if (countedCycles[path[j]] > maxCycleCount) {
     704            maxCycleCount = countedCycles[path[j]];
    702705          }
    703           kill cycleCount;
    704706          if (path[j] == w) {
    705707            break;
     
    711713        kill maxCycleCount;
    712714      } else {
    713         int cycleCount = countCycles(G, w, visited, cyclic, path);
    714         if (cycleCount == -1) {
    715           return(-1);
    716         }
    717         if (cycleCount > cycles) {
    718           cycles = cycleCount;
    719         }
    720         kill cycleCount;
     715        countedCycles = countCycles(G, w, visited, cyclic, path, countedCycles);
     716        if (countedCycles[w] == -1) {
     717          countedCycles[v] = -1;
     718          return (countedCycles);
     719        }
     720        if (countedCycles[w] > cycles) {
     721          cycles = countedCycles[w];
     722        }
    721723      }
    722724    }
    723725  } kill w;
    724726  // printf("Path: %s countCycles: %s", path, cycles); // DEBUG
    725   return(cycles);
     727  countedCycles[v] = cycles;
     728  return (countedCycles);
    726729}
    727730
     
    738741"
    739742{
     743  dbprint("computing maxDeg");
    740744  int l = maxDeg(G);
    741   list LG = lpId2ivLi(G);
    742   list SW = ivStandardWords(LG, l - 1); // vertices
    743   int n = size(SW);
     745  if (l - 1 == 0) {
     746    // TODO: how should the graph look like when l - 1 = 0 ?
     747    ERROR("Ufnarovskij graph not implemented for l = 1");
     748  }
     749  int lV = attrib(basering, "isLetterplaceRing");
     750  // TODO: what if l <= 0?
     751  dbprint("computing standard words");
     752  ideal SW = lpStandardWords(G, l - 1); // vertices
     753  int n = ncols(SW);
     754  dbprint("n = " + string(n));
    744755  intmat UG[n][n]; // Ufnarovskij graph
    745756  for (int i = 1; i <= n; i++) {
    746757    for (int j = 1; j <= n; j++) {
     758      dbprint("Ufnarovskii graph: " + string((i-1)*n + j) + "/" + string(n*n) + " entries");
    747759      // [Studzinski page 76]
    748       intvec v = SW[i];
    749       intvec w = SW[j];
     760      poly v = SW[i];
     761      poly w = SW[j];
    750762      intvec v_overlap;
    751763      intvec w_overlap;
    752       //TODO how should the graph look like when l - 1 = 0 ?
    753       if (l - 1 == 0) {
    754         ERROR("Ufnarovskij graph not implemented for l = 1");
    755       }
    756764      if (l - 1 > 1) {
    757         v_overlap = v[2 .. l-1];
    758         w_overlap = w[1 .. l-2];
    759       }
    760       intvec vw = v;
    761       vw[l] = w[l-1];
    762       if (v_overlap == w_overlap && !ivdivides(LG, vw)) {
     765        v_overlap = leadexp(v);
     766        w_overlap = leadexp(w);
     767        v_overlap = v_overlap[(lV+1) .. (l-1)*lV];
     768        w_overlap = w_overlap[1 .. (l-2)*lV];
     769      }
     770      if (v_overlap == w_overlap && !lpdivides(G, v * lpVarAt(w, l - 1))) {
    763771        UG[i,j] = 1;
    764772      }
    765       kill v; kill w; kill v_overlap; kill w_overlap; kill vw;
     773      kill v; kill w; kill v_overlap; kill w_overlap;
    766774    } kill j;
    767775  } kill i;
     
    799807  } kill i;
    800808  return (l);
     809}
     810
     811static proc lpVarAt(poly p, int pos) {
     812  return (system("lpVarAt", p, pos));
     813}
     814
     815static proc lpStandardWords(ideal G, int length)
     816"ASSUME: G is simplified
     817"
     818{
     819  if (length < 0) {
     820    return (delete(ideal(0), 1)); // no standard words
     821  }
     822
     823  ideal words = maxideal(length);
     824  for (int i = ncols(words); i >= 1; i--) {
     825    if (lpdivides(G, words[i])) {
     826      words = delete(words, i);
     827    }
     828  } kill i;
     829  return (words);
    801830}
    802831
     
    841870}
    842871
     872proc lpdivides(ideal I, poly p) {
     873  for (int i = 1; i <= ncols(I); i++) {
     874    if (system("lpdivides", I[i], p)) {
     875      return (1);
     876    }
     877  } kill i;
     878  return (0);
     879}
     880
    843881static proc ivdivides(list G, intvec iv) {
    844882  for (int k = 1; k <= size(G); k++) {
     
    858896RETURN: int
    859897PURPOSE: Determines the Gelfand Kirillov dimension of A/<G>
    860 @*       -1 means it is positive infinite
     898@*       -1 means positive infinite
    861899ASSUME: - basering is a Letterplace ring
    862900@*      - G is a Groebner basis
     
    877915    // also if G is the whole ring return minus infinity
    878916    if (leadmonom(G[i]) == 1) {
    879       ERROR("Gk-Dim not defined for 0-ring")
     917      ERROR("GK-Dim not defined for 0-ring")
    880918    }
    881919    kill d;
     
    896934  }
    897935
     936  dbprint("computing Ufnarovskii graph");
    898937  intmat UG = lpUfGraph(G);
     938  dbprint("Ufnarovskii graph: ", string(UG));
    899939
    900940  // check special case 2
     
    905945
    906946  // check special case 3
     947  dbprint("topological sorting of Ufnarovskii graph");
    907948  UG = topologicalSort(UG);
    908949
     950  dbprint("check if Ufnarovskii graph is DAG");
    909951  if (imIsUpRightTriangle(UG)) {
    910952    UG = eliminateZerosUpTriangle(UG);
     
    912954      return (0)
    913955    }
     956    dbprint("DAG detected, using URTNZD growth alg");
    914957    return(UfGraphURTNZDGrowth(UG));
    915958  }
    916959
    917960  // otherwise count cycles in the Ufnarovskij Graph
     961  dbprint("not a DAG, using regular growth alg");
    918962  return(UfGraphGrowth(UG));
    919963}
  • Singular/extra.cc

    r4aa50a rc8fd40  
    12091209    else
    12101210  #endif
     1211  /*==================== divide-test for freeGB  =================*/
     1212  #ifdef HAVE_SHIFTBBA
     1213    if (strcmp(sys_cmd, "lpdivides") == 0)
     1214    {
     1215      const short t[]={2,POLY_CMD,POLY_CMD};
     1216      if (iiCheckTypes(h,t,1))
     1217      {
     1218        poly p=(poly)h->CopyD();
     1219        poly q=(poly)h->next->CopyD();
     1220        res->rtyp = INT_CMD;
     1221        res->data = (void*)(long)p_LPDivisibleBy(p, q, currRing);
     1222        return FALSE;
     1223      }
     1224      else return TRUE;
     1225    }
     1226    else
     1227  #endif
     1228  /*==================== get var for freeGB  ====================*/
     1229  #ifdef HAVE_SHIFTBBA
     1230    if (strcmp(sys_cmd, "lpVarAt") == 0)
     1231    {
     1232      const short t[]={2,POLY_CMD,INT_CMD};
     1233      if (iiCheckTypes(h,t,1))
     1234      {
     1235        poly p=(poly)h->CopyD();
     1236        int pos=(int)((long)(h->next->Data()));
     1237        res->rtyp = POLY_CMD;
     1238        res->data = p_LPVarAt(p, pos, currRing);
     1239        return FALSE;
     1240      }
     1241      else return TRUE;
     1242    }
     1243    else
     1244  #endif
    12111245  /*==================== pcv ==================================*/
    12121246  #ifdef HAVE_PCV
  • libpolys/polys/shiftop.cc

    r4aa50a rc8fd40  
    659659  omFreeSize((ADDRESS) B, (b+1)*sizeof(int));
    660660  return(1);
     661}
     662
     663BOOLEAN p_LPDivisibleBy(poly a, poly b, const ring r)
     664{
     665  pIfThen1(b!=NULL, p_LmCheckPolyRing1(b, r));
     666  pIfThen1(a!=NULL, p_LmCheckPolyRing1(a, r));
     667
     668  if (b == NULL) return TRUE;
     669  if (a != NULL && (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r)))
     670      return _p_LPLmDivisibleByNoComp(a,b,r);
     671  return FALSE;
     672}
     673
     674BOOLEAN p_LPLmDivisibleBy(poly a, poly b, const ring r)
     675{
     676  p_LmCheckPolyRing1(b, r);
     677  pIfThen1(a != NULL, p_LmCheckPolyRing1(b, r));
     678  if (p_GetComp(a, r) == 0 || p_GetComp(a,r) == p_GetComp(b,r))
     679    return _p_LPLmDivisibleByNoComp(a, b, r);
     680  return FALSE;
     681}
     682
     683BOOLEAN _p_LPLmDivisibleByNoComp(poly a, poly b, const ring r)
     684{
     685  if(p_LmIsConstantComp(a, r))
     686    return TRUE;
     687#ifdef SHIFT_MULT_COMPAT_MODE
     688  a = p_Head(a, r);
     689  p_mLPunshift(a, r);
     690  b = p_Head(b, r);
     691  p_mLPunshift(b, r);
     692#endif
     693  int i = (r->N / r->isLPring) - p_LastVblock(a, r);
     694  do {
     695    int j = r->N - (i * r->isLPring);
     696    bool divisible = true;
     697    do
     698    {
     699      if (p_GetExp(a, j, r) > p_GetExp(b, j + (i * r->isLPring), r))
     700      {
     701        divisible = false;
     702        break;
     703      }
     704      j--;
     705    }
     706    while (j);
     707    if (divisible) return TRUE;
     708    i--;
     709  }
     710  while (i > -1);
     711#ifdef SHIFT_MULT_COMPAT_MODE
     712  p_Delete(&a, r);
     713  p_Delete(&b, r);
     714#endif
     715  return FALSE;
     716}
     717
     718poly p_LPVarAt(poly p, int pos, const ring r)
     719{
     720  if (p == NULL || pos < 1 || pos > (r->N / r->isLPring)) return NULL;
     721  poly v = p_One(r);
     722  for (int i = (pos-1) * r->isLPring + 1; i <= pos * r->isLPring; i++) {
     723    if (p_GetExp(p, i, r)) {
     724      p_SetExp(v, i - (pos-1) * r->isLPring, 1, r);
     725      return v;
     726    }
     727  }
     728  return v;
    661729}
    662730
  • libpolys/polys/shiftop.h

    r4aa50a rc8fd40  
    4848#define pmIsInV(p) p_mIsInV(p, currRing)
    4949
     50BOOLEAN p_LPDivisibleBy(poly a, poly b, const ring r);
     51BOOLEAN p_LPLmDivisibleBy(poly a, poly b, const ring r);
     52BOOLEAN _p_LPLmDivisibleByNoComp(poly a, poly b, const ring r);
     53
     54poly p_LPVarAt(poly p, int pos, const ring r);
     55
    5056ring freeAlgebra(ring r, int d);
    5157#endif
Note: See TracChangeset for help on using the changeset viewer.