Changeset 340ab8 in git for kernel


Ignore:
Timestamp:
Oct 5, 2016, 7:44:03 PM (8 years ago)
Author:
Sharwan Tiwari <stiwari@…>
Branches:
(u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
Children:
7e48fd30f913149068233c11121d6395b3cf6fa6
Parents:
637aa3957f20a1c1863a9ca0de302c346df62fd7
git-author:
Sharwan Tiwari <stiwari@gmail.com>2016-10-05 19:44:03+02:00
git-committer:
Sharwan Tiwari <stiwari@gmail.com>2016-10-11 17:40:28+02:00
Message:
nchilb
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/combinatorics/hilb.cc

    r637aa3 r340ab8  
    14011401
    14021402
    1403 static void idInsertMonPos_nchilb(ideal I, poly p, int pos)
    1404 {  
     1403static void idInsertMonomials(ideal I, poly p)
     1404{
    14051405  /*
    1406    * poly p != null, and there is no null poly in I
    1407    * adds p at the position 'pos' in I
    1408    * without making  copy of it
    1409    */
    1410      
    1411   pEnlargeSet(&(I->m), IDELEMS(I), IDELEMS(I)+1);
    1412   IDELEMS(I) += 1;
    1413   for(int i = IDELEMS(I) - 1; i > pos; i--)
    1414   {
    1415     I->m[i] = I->m[i-1];
    1416   }
    1417   I->m[pos] = p;
    1418 }
    1419 
    1420 static void idInsertMonAtEnd_nchilb(ideal I, poly p)
    1421 
    1422   /*
    1423    * poly p !=null, and there is no null poly in I
     1406   * adds monomial in I and if required,
     1407   * enlarges the size of poly-set by 16
     1408   * does not make copy of  p
    14241409   */
    14251410   
    1426   pEnlargeSet(&(I->m), IDELEMS(I), IDELEMS(I)+1);
    1427   IDELEMS(I) += 1;
    1428   I->m[IDELEMS(I)-1] = p;
    1429 }
    1430 
    1431 static void idInsertMonomials(ideal h1, poly h2)
    1432 {
    1433   /*
    1434    * adds monomial in h1 and if required,
    1435    * enlarges the size of poly-set by 16
    1436    * does not make copy of  h2
    1437    */
    1438    
    1439   if(h2 == NULL)
     1411  if(I == NULL)
    14401412  {
    14411413    return;
    14421414  }
    14431415
    1444   int j = IDELEMS(h1) - 1;
    1445   while ((j >= 0) && (h1->m[j] == NULL))
     1416  int j = IDELEMS(I) - 1;
     1417  while ((j >= 0) && (I->m[j] == NULL))
    14461418  {
    14471419    j--;
    14481420  }
    14491421  j++;
    1450   if (j == IDELEMS(h1))
    1451   {
    1452     pEnlargeSet(&(h1->m), IDELEMS(h1), 16);
    1453     IDELEMS(h1) +=16;
    1454   }
    1455   h1->m[j] = h2;
     1422  if (j == IDELEMS(I))
     1423  {
     1424    pEnlargeSet(&(I->m), IDELEMS(I), 16);
     1425    IDELEMS(I) +=16;
     1426  }
     1427  I->m[j] = p;
    14561428}
    14571429
     
    14701442*/
    14711443
    1472 static ideal PlacePolyInSortedMonoIdeal_TotalDegOrder(ideal I, poly p)
    1473 {
    1474   /*
    1475    * order of the currRing should be a total degree
    1476    * poly p != null
    1477    * inserts poly p in the I, s.t.
    1478    * the polys of I are in ascending order
    1479    * does not make copy of p2
    1480    */
    1481   int i;
    1482   if((I == NULL) || (idIs0(I)))
    1483   {
    1484     ideal res = idInit(1,1);
    1485     res->m[0] = p;
    1486     return(res);
    1487   }
    1488   idSkipZeroes(I);
    1489 
    1490   for(i = 0; (i<IDELEMS(I)) && (p_Totaldegree(I->m[i], currRing) <= p_Totaldegree(p, currRing)); i++)
    1491   {
    1492     if(p_DivisibleBy(I->m[i], p, currRing))
    1493     {
    1494       pDelete(&p);//this poly is not required anymore
    1495       return(I);
    1496     }
    1497   }
    1498   for(i = IDELEMS(I)-1; (i>=0) && (p_Totaldegree(I->m[i],currRing) >= p_Totaldegree(p,currRing)); i--)
    1499   {
    1500     if(p_DivisibleBy(p, I->m[i], currRing))
    1501     {
    1502       I->m[i] = NULL;
    1503     }
    1504   }
    1505   if(idIs0(I))
    1506   {
    1507     I->m[0] = p;
    1508     return(I);
    1509   }
    1510 
    1511   idSkipZeroes(I);
    1512   //when all polynomials of I have same degree
    1513   if(p_Totaldegree(I->m[0], currRing) == p_Totaldegree(I->m[IDELEMS(I)-1], currRing))
    1514   {
    1515     if(p_Totaldegree(p, currRing) < p_Totaldegree(I->m[0], currRing))
    1516     {
    1517       idInsertMonPos_nchilb(I, p, 0);
    1518       return(I);
    1519     }
    1520     if(p_Totaldegree(p, currRing) >= p_Totaldegree(I->m[IDELEMS(I)-1], currRing))
    1521     {
    1522 
    1523       for(i = IDELEMS(I)-1; i>=0; i--)
    1524       {
    1525         if(p_LmCmp(I->m[i], p, currRing) == 1)
    1526         {       
    1527           if(i==0)
    1528           {
    1529             idInsertMonPos_nchilb(I, p, 0);
    1530             return(I);
    1531           }
    1532         }
    1533         else
    1534         {
    1535           if(i == (IDELEMS(I)-1))
    1536           {
    1537            idInsertMonAtEnd_nchilb(I, p);
    1538             return(I);
    1539           }
    1540           idInsertMonPos_nchilb(I, p, i+1);
    1541           return(I);
    1542         }
    1543       }
    1544     }
    1545   }
    1546   if(p_Totaldegree(p, currRing) <= p_Totaldegree(I->m[0], currRing))
    1547   {
    1548    
    1549     for(i = 0; i < IDELEMS(I); i++)
    1550     {
    1551       if(p_LmCmp(I->m[i], p, currRing) == 1)
    1552       {
    1553         idInsertMonPos_nchilb(I, p, i);
    1554         return(I);
    1555       }
    1556     }
    1557     idInsertMonAtEnd_nchilb(I, p);
    1558     return(I);
    1559   }
    1560   if(p_Totaldegree(p, currRing) >= p_Totaldegree(I->m[IDELEMS(I)-1], currRing))
    1561   {
    1562     for(i = IDELEMS(I)-1; i >= 0; i--)
    1563     {
    1564       if(p_LmCmp(I->m[i], p, currRing) != 1)
    1565       {
    1566         if(i == IDELEMS(I)-1)
    1567         {
    1568           idInsertMonAtEnd_nchilb(I, p);
    1569           return(I);
    1570         }
    1571         else
    1572         {
    1573           idInsertMonPos_nchilb(I, p, i+1);
    1574           return(I);
    1575         }
    1576 
    1577       }
    1578     }
    1579 
    1580   }
    1581  
    1582   for(i = IDELEMS(I)-2; ;)
    1583   {
    1584     if(p_Totaldegree(p, currRing) == p_Totaldegree(I->m[i], currRing))
    1585     {
    1586       for(int j = i; j >= 0; j--)
    1587       {
    1588         if(p_LmCmp(I->m[j], p, currRing) != 1)
    1589         {
    1590           idInsertMonPos_nchilb(I, p, j+1);
    1591           return(I);
    1592         }
    1593       }
    1594     }
    1595     if(p_Totaldegree(p, currRing) > p_Totaldegree(I->m[i], currRing))
    1596     {
    1597       idInsertMonPos_nchilb(I, p, i+1);
    1598       return(I);
    1599     }
    1600     i--;
    1601   }
    1602 }
    1603 
    1604 static ideal SortMonoId_TotalDegOrder(ideal I)
    1605 {
    1606   /*
    1607    * sorts the ideal in ascending order
    1608    * order must be a total degree
    1609    */
    1610   if(idIs0(I))
    1611   {
    1612     return(I);
    1613   }
    1614   int i;
    1615   ideal result;
    1616   idSkipZeroes(I);
    1617   result = idInit(1, 1);
    1618   for(i = 0; i <= IDELEMS(I)-1; i++)
    1619   {
    1620      result = PlacePolyInSortedMonoIdeal_TotalDegOrder(result, I->m[i]);
    1621   }
    1622   idSkipZeroes(result);
    1623   return(result);
    1624 }
    1625 
    16261444static int isMonoIdBasesSame(ideal J, ideal Ob)
    16271445{
     
    16321450   */
    16331451  int i, j, s, cnt;
    1634   s=1;
     1452  s = 1;
    16351453  int JCount = IDELEMS(J);
    16361454  int ObCount = IDELEMS(Ob);
     
    16691487  }
    16701488 
    1671   int count=0;
     1489  int count = 0;
    16721490  for(int i = 0; i < IDELEMS(I); i++)
    16731491  {
     
    16761494      return (count);
    16771495    }
    1678     count=count+1;
     1496    count = count + 1;
    16791497  }
    16801498 
     
    18261644}
    18271645
    1828 static ideal  MinimalMonomialBasis(ideal I)
     1646static int monCompare(const void  *m, const void *n)
     1647{
     1648  /* compares monomials */
     1649
     1650  return (p_Compare(*(poly*)m, *(poly*)n, currRing));
     1651}
     1652
     1653static void sortMonoIdeal_totalDegOrder(ideal I)
     1654{
     1655  /*
     1656   * sorts the monomial ideal in ascending order
     1657   * order must be a total degree
     1658   */
     1659
     1660  qsort(I->m, IDELEMS(I), sizeof(poly), monCompare);
     1661
     1662}
     1663
     1664
     1665
     1666static ideal  minimalMonomialsGenSet(ideal I)
    18291667{
    18301668  /*
     
    18321670   * can be generated by others in I
    18331671   */
    1834   I = SortMonoId_TotalDegOrder(I);
     1672  //first sort monomials of the ideal
     1673 
     1674  idSkipZeroes(I);
     1675
     1676  sortMonoIdeal_totalDegOrder(I);
     1677 
    18351678  ideal J = idInit(1, 1);
    18361679  int i, k;
    18371680  int count = 0;
    18381681  int ICount = IDELEMS(I);
    1839  
    1840   std::vector<BOOLEAN> checks(ICount, TRUE);
    1841   for(k = 0; k < ICount; k++)
    1842   {
    1843     if(checks[k])
    1844     {
    1845       idInsertMonomials(J, I->m[k]);
    1846       count++;
    1847       for(i = count; i < ICount; i++)
    1848       {
    1849         if(checks[i])
    1850         {
    1851           if( pLmDivisibleByNoComp(J->m[count-1], I->m[i]))
    1852           {
    1853             checks[i]=FALSE;
    1854             pDelete(&(I->m[i]));
    1855           }
    1856         }
     1682
     1683  for(k = ICount - 1; k >=1; k--)
     1684  {
     1685    for(i = 0; i < k; i++)
     1686    {
     1687 
     1688      if(p_LmDivisibleBy(I->m[i], I->m[k], currRing))
     1689      {
     1690        pDelete(&(I->m[k]));//this is not req.
     1691        break;
    18571692      }
    18581693    }
    18591694  }
    1860   idSkipZeroes(J);
    1861   return(J);
     1695 
     1696  idSkipZeroes(I);
     1697  return(I);
    18621698}
    18631699
     
    18841720    }
    18851721  }
    1886   p_SetExpV(smon, s, r);
     1722 
     1723  p_SetExpV(smon, s, currRing);
    18871724  omFree(e);
    18881725  omFree(s);
    1889   p_SetComp(smon, p_GetComp(p, r), r);
     1726 
     1727  p_SetComp(smon, p_GetComp(p, currRing), currRing);
     1728  p_Setm(smon, currRing);
     1729 
    18901730  return(smon);
    18911731}
     
    19141754    s[j] = e[j];
    19151755  }
    1916   p_SetExpV(dw, s, r);//new exponents
     1756 
     1757  p_SetExpV(dw, s, currRing);//new exponents
    19171758  omFree(e);
    19181759  omFree(s);
    1919   p_SetComp(dw, p_GetComp(w, r), r);
     1760 
     1761  p_SetComp(dw, p_GetComp(w, currRing), currRing);
     1762  p_Setm(dw, currRing);
     1763 
    19201764  return(dw);
    19211765}
     
    19331777   */
    19341778  int i;
    1935   //ring r=currRing;
    19361779  poly smon, dw;
    19371780  poly qmonp = NULL;
    19381781  bool del;
     1782 
    19391783  for(i = 0;i <= d - 1; i++)
    19401784  {
     
    19421786    smon = shiftInMon(p, i, lV, currRing);
    19431787    del = TRUE;
    1944     if(pLmDivisibleByNoComp(smon, w))
     1788   
     1789    if(pLmDivisibleBy(smon, w))
    19451790    {
    19461791      flag = TRUE;
     
    19501795      pDelete(&smon);
    19511796     
    1952       //make Jwi =1;
     1797      //delete all monomials of Jwi
     1798      //and make Jwi =1
     1799     
    19531800      for(int j = 0;j < IDELEMS(Jwi); j++)
    19541801      {
    19551802        pDelete(&Jwi->m[j]);
    19561803      }
    1957      
    1958       pEnlargeSet(&(Jwi->m), IDELEMS(Jwi), -IDELEMS(Jwi)+1);
    1959       IDELEMS(Jwi)=1;
    1960       Jwi->m[0]=p_One(currRing);
     1804
     1805      idInsertMonomials(Jwi, p_One(currRing));
    19611806      break;
    19621807    }
    19631808
    1964     if(pLmDivisibleByNoComp(dw, smon))
     1809    if(pLmDivisibleBy(dw, smon))
    19651810    {
    19661811      del = FALSE;
    19671812      qmonp = p_Divide(smon, dw, currRing);
    1968 
    1969       pEnlargeSet(&(Jwi->m), IDELEMS(Jwi), 1);
    1970       IDELEMS(Jwi) += 1;
    1971       Jwi->m[IDELEMS(Jwi)-1] = shiftInMon(qmonp, -d, lV, currRing);
     1813      idInsertMonomials(Jwi, shiftInMon(qmonp, -d, lV, currRing));
    19721814     
    1973       pDelete(&qmonp);//shiftInMon(qmonp, -d, lV, currRing):returns a new poly,
    1974                      // qmonp remains unchanged
     1815      //shiftInMon(qmonp, -d, lV, currRing):returns a new poly,
     1816      //qmonp remains unchanged, delete it
     1817      pDelete(&qmonp);
    19751818      pDelete(&dw);
    19761819      pDelete(&smon);
    19771820    }
    1978     //in case both if were false, delete dw and smon
     1821    //in case both if are false, delete dw and smon
    19791822    if(del)
    19801823    {
     
    20121855    }
    20131856  }
    2014   Jwi = MinimalMonomialBasis(Jwi);
     1857 
     1858  Jwi = minimalMonomialsGenSet(Jwi);
    20151859  return(Jwi);
    20161860}
     1861
    20171862
    20181863void HilbertSeries_OrbitData(ideal S, int lV, bool IG_CASE )
     
    20291874
    20301875  int trInd;
    2031   S = SortMonoId_TotalDegOrder(S);
    2032 
    2033 
     1876  S = minimalMonomialsGenSet(S);
     1877 
    20341878  int (*POS)(ideal, poly, std::vector<ideal>, std::vector<poly>, int);
    20351879  if(IG_CASE)
     
    20561900
    20571901  std::vector<int> C;
    2058 
    2059   ring r = currRing;
    20601902
    20611903  int ds, is, ps, sz;
     
    20941936
    20951937      wi = pCopy(w);
    2096       p_SetExp(wi, (ds*lV)+is, 1, r);
    2097       p_Setm(wi, r);
     1938      p_SetExp(wi, (ds*lV)+is, 1, currRing);
     1939      p_Setm(wi, currRing);
    20981940
    20991941      Jwi = NULL;
     
    21551997  //printf("\nlength of the Orbit==%ld\n", C.size());
    21561998#endif
    2157 
     1999  ring r = currRing;
    21582000  char** tt=(char**)omalloc(sizeof(char*));
    21592001  tt[0] = omStrDup("t");
     
    21792021      if(mat[rowCount][colCount] != 0)
    21802022      {
    2181         mR->m[lO*rowCount + colCount] = p_ISet(mat[rowCount][colCount], R);
    2182         p_SetCoeff(mR->m[lO*rowCount+colCount], n_Mult(pGetCoeff(mR->m[lO*rowCount+colCount]),n_Param(1, R->cf), R->cf), R);
     2023       MATELEM(mR, rowCount + 1, colCount + 1) = p_ISet(mat[rowCount][colCount], R);
     2024        p_SetCoeff(MATELEM(mR, rowCount + 1, colCount + 1), n_Mult(pGetCoeff(mR->m[lO*rowCount+colCount]),n_Param(1, R->cf), R->cf), R);
    21832025      }
    21842026    }
     
    22192061  omFree(xx[0]);
    22202062  omFree(xx);
     2063  rKill(R);
    22212064  rChangeCurrRing(r);
    22222065}
Note: See TracChangeset for help on using the changeset viewer.