Ignore:
Timestamp:
Jul 3, 2013, 12:04:32 PM (11 years ago)
Author:
Yue Ren <ren@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
f80a5305e1e0960855d4bd8702e48d1c2bbf8710
Parents:
a667138296109b29e11fe1654025d4581abfc50a
git-author:
Yue Ren <ren@mathematik.uni-kl.de>2013-07-03 12:04:32+02:00
git-committer:
Yue Ren <ren@mathematik.uni-kl.de>2013-07-18 14:56:50+02:00
Message:
fix: missed assume for allowing empty bigintmats
File:
1 edited

Legend:

Unmodified
Added
Removed
  • dyn_modules/callgfanlib/bbcone.cc

    ra667138 re44b149  
    111111  bigintmat* bim = zMatrixToBigintmat(zm);
    112112  char* s = bim->StringAsPrinted();
     113  if (s==NULL)
     114    s = (char*) omAlloc0(sizeof(char));
    113115  delete bim;
    114116  return s;
     
    127129    s<<"INEQUALITIES"<<std::endl;
    128130  s<<toString(i)<<std::endl;
     131  // std::cout << toString(i) << std::endl;
    129132  if (c->areImpliedEquationsKnown())
    130133    s<<"LINEAR_SPAN"<<std::endl;
     
    132135    s<<"EQUATIONS"<<std::endl;
    133136  s<<toString(e)<<std::endl;
     137  // std::cout << toString(e) << std::endl;
    134138  return s.str();
    135139}
     
    15591563  return TRUE;
    15601564}
     1565
     1566gfan::ZVector intStar2ZVector(const int d, const int* i)
     1567{
     1568  gfan::ZVector zv(d);
     1569  for(int j=0; j<d; j++)
     1570    zv[j]=i[j+1];
     1571  return zv;
     1572}
     1573
     1574BOOLEAN maximalGroebnerCone(leftv res, leftv args)
     1575{
     1576  leftv u = args;
     1577  if ((u != NULL) && (u->Typ() == IDEAL_CMD))
     1578  {
     1579    leftv v = u->next;
     1580    if (v == NULL)
     1581    {
     1582      int n = currRing->N;
     1583      ideal I = (ideal) u->Data();
     1584      poly g = NULL;
     1585      int* leadexpv = (int*) omAlloc((n+1)*sizeof(int));
     1586      int* tailexpv = (int*) omAlloc((n+1)*sizeof(int));
     1587      gfan::ZVector leadexpw = gfan::ZVector(n);
     1588      gfan::ZVector tailexpw = gfan::ZVector(n);
     1589      gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
     1590      for (int i=0; i<IDELEMS(I); i++)
     1591      {
     1592        g = (poly) I->m[i]; pGetExpV(g,leadexpv);
     1593        leadexpw = intStar2ZVector(n, leadexpv);
     1594        pIter(g);
     1595        while (g != NULL)
     1596        {
     1597          pGetExpV(g,tailexpv);
     1598          tailexpw = intStar2ZVector(n, tailexpv);
     1599          inequalities.appendRow(leadexpw-tailexpw);
     1600          pIter(g);
     1601        }
     1602      }
     1603      gfan::ZCone* gCone = new gfan::ZCone(inequalities,gfan::ZMatrix(0, inequalities.getWidth()));
     1604      omFreeSize(leadexpv,(n+1)*sizeof(int));
     1605      omFreeSize(tailexpv,(n+1)*sizeof(int));
     1606
     1607      res->rtyp = coneID;
     1608      res->data = (void*) gCone;
     1609      return FALSE;
     1610    }
     1611  }
     1612  WerrorS("maximalGroebnerCone: unexpected parameters");
     1613  return TRUE;
     1614}
     1615
     1616
     1617poly initial(poly p)
     1618{
     1619  poly g = p;
     1620  poly h = p_Head(g,currRing);
     1621  poly f = h;
     1622  long d = p_Deg(g,currRing);
     1623  pIter(g);
     1624  while ((g != NULL) && (p_Deg(g,currRing) == d))
     1625  {
     1626    pNext(h) = p_Head(g,currRing);
     1627    pIter(h);
     1628    pIter(g);
     1629  }
     1630  return(f);
     1631}
     1632
     1633
     1634BOOLEAN initial(leftv res, leftv args)
     1635{
     1636  leftv u = args;
     1637  if ((u != NULL) && (u->Typ() == POLY_CMD))
     1638  {
     1639    leftv v = u->next;
     1640    if (v == NULL)
     1641    {
     1642      poly p = (poly) u->Data();
     1643      res->rtyp = POLY_CMD;
     1644      res->data = (void*) initial(p);
     1645      return FALSE;
     1646    }
     1647  }
     1648  if ((u != NULL) && (u->Typ() == IDEAL_CMD))
     1649  {
     1650    leftv v = u->next;
     1651    if (v == NULL)
     1652    {
     1653      ideal I = (ideal) u->Data();
     1654      ideal inI = idInit(IDELEMS(I));
     1655      poly g; poly h; long d;
     1656      for (int i=0; i<IDELEMS(I); i++)
     1657      {
     1658        g = (poly) I->m[i];
     1659        inI->m[i]=initial(g);
     1660      }
     1661      res->rtyp = IDEAL_CMD;
     1662      res->data = (void*) inI;
     1663      return FALSE;
     1664    }
     1665  }
     1666  WerrorS("initial: unexpected parameters");
     1667  return TRUE;
     1668}
     1669
     1670
     1671BOOLEAN homogeneitySpace(leftv res, leftv args)
     1672{
     1673  leftv u = args;
     1674  if ((u != NULL) && (u->Typ() == IDEAL_CMD))
     1675  {
     1676    leftv v = u->next;
     1677    if (v == NULL)
     1678    {
     1679      int n = currRing->N;
     1680      ideal I = (ideal) u->Data();
     1681      poly g;
     1682      int* leadexpv = (int*) omAlloc((n+1)*sizeof(int));
     1683      int* tailexpv = (int*) omAlloc((n+1)*sizeof(int));
     1684      gfan::ZVector leadexpw = gfan::ZVector(n);
     1685      gfan::ZVector tailexpw = gfan::ZVector(n);
     1686      gfan::ZMatrix equations = gfan::ZMatrix(0,n);
     1687      for (int i=0; i<IDELEMS(I); i++)
     1688      {
     1689        g = (poly) I->m[i]; pGetExpV(g,leadexpv);
     1690        leadexpw = intStar2ZVector(n, leadexpv);
     1691        pIter(g);
     1692        while (g != NULL)
     1693        {
     1694          pGetExpV(g,tailexpv);
     1695          tailexpw = intStar2ZVector(n, tailexpv);
     1696          equations.appendRow(leadexpw-tailexpw);
     1697          pIter(g);
     1698        }
     1699      }
     1700      gfan::ZCone* gCone = new gfan::ZCone(gfan::ZMatrix(0, equations.getWidth()),equations);
     1701      omFreeSize(leadexpv,(n+1)*sizeof(int));
     1702      omFreeSize(tailexpv,(n+1)*sizeof(int));
     1703
     1704      res->rtyp = coneID;
     1705      res->data = (void*) gCone;
     1706      return FALSE;
     1707    }
     1708  }
     1709  WerrorS("homogeneitySpace: unexpected parameters");
     1710  return TRUE;
     1711}
     1712
     1713
     1714BOOLEAN groebnerCone(leftv res, leftv args)
     1715{
     1716  leftv u = args;
     1717  if ((u != NULL) && (u->Typ() == IDEAL_CMD))
     1718  {
     1719    leftv v = u->next;
     1720    if (v == NULL)
     1721    {
     1722      int n = currRing->N;
     1723      ideal I = (ideal) u->Data();
     1724      poly g = NULL;
     1725      int* leadexpv = (int*) omAlloc((n+1)*sizeof(int));
     1726      int* tailexpv = (int*) omAlloc((n+1)*sizeof(int));
     1727      gfan::ZVector leadexpw = gfan::ZVector(n);
     1728      gfan::ZVector tailexpw = gfan::ZVector(n);
     1729      gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
     1730      gfan::ZMatrix equations = gfan::ZMatrix(0,n);
     1731      long d;
     1732      for (int i=0; i<IDELEMS(I); i++)
     1733      {
     1734        g = (poly) I->m[i]; pGetExpV(g,leadexpv);
     1735        leadexpw = intStar2ZVector(n, leadexpv);
     1736        pIter(g);
     1737        d = p_Deg(g,currRing);
     1738        while ((g != NULL) && (p_Deg(g,currRing) == d))
     1739        {
     1740          pGetExpV(g,tailexpv);
     1741          tailexpw = intStar2ZVector(n, tailexpv);
     1742          equations.appendRow(leadexpw-tailexpw);
     1743          pIter(g);
     1744        }
     1745
     1746        if (g != NULL)
     1747        {
     1748          while (g != NULL)
     1749          {
     1750            pGetExpV(g,tailexpv);
     1751            tailexpw = intStar2ZVector(n, tailexpv);
     1752            inequalities.appendRow(leadexpw-tailexpw);
     1753            pIter(g);
     1754          }
     1755        }
     1756      }
     1757      gfan::ZCone* gCone = new gfan::ZCone(inequalities,equations);
     1758      omFreeSize(leadexpv,(n+1)*sizeof(int));
     1759      omFreeSize(tailexpv,(n+1)*sizeof(int));
     1760
     1761      res->rtyp = coneID;
     1762      res->data = (void*) gCone;
     1763      return FALSE;
     1764    }
     1765  }
     1766  WerrorS("groebnerCone: unexpected parameters");
     1767  return TRUE;
     1768}
     1769
     1770/***
     1771 * Given a cone and a point in its boundary,
     1772 * returns the inner normal vector of a facet
     1773 * containing the point.
     1774 * In case no facet contains the point,
     1775 * then 0 is returned.
     1776 **/
     1777gfan::ZVector* facetContaining(gfan::ZCone* zc, gfan::ZVector* zv)
     1778{
     1779  gfan::ZMatrix facets = zc->getFacets();
     1780  for (int i=0; i<facets.getHeight(); i++)
     1781  {
     1782    gfan::ZVector facet = facets[i];
     1783    if (dot(facet,*zv) == (long) 0)
     1784      return new gfan::ZVector(facet);
     1785  }
     1786  return new gfan::ZVector(zc->ambientDimension());
     1787}
     1788
     1789
     1790BOOLEAN facetContaining(leftv res, leftv args)
     1791{
     1792  leftv u = args;
     1793  if ((u != NULL) && (u->Typ() == coneID))
     1794  {
     1795    leftv v = u->next;
     1796    if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
     1797    {
     1798      gfan::ZCone* zc = (gfan::ZCone*) u->Data();
     1799
     1800      bigintmat* point1;
     1801      if (v->Typ() == INTVEC_CMD)
     1802      {
     1803        intvec* point0 = (intvec*) v->Data();
     1804        point1 = iv2bim(point0,coeffs_BIGINT)->transpose();
     1805      }
     1806      else
     1807        point1 = (bigintmat*) v->Data();
     1808
     1809      gfan::ZVector* point = bigintmatToZVector(*point1);
     1810      gfan::ZVector* facet = facetContaining(zc, point);
     1811
     1812      res->rtyp = BIGINTMAT_CMD;
     1813      res->data = (void*) zVectorToBigintmat(*facet);
     1814
     1815      delete facet;
     1816      delete point;
     1817      if (v->Typ() == INTVEC_CMD)
     1818        delete point1;
     1819      return FALSE;
     1820    }
     1821  }
     1822  WerrorS("facetContaining: unexpected parameters");
     1823  return TRUE;
     1824}
     1825
    15611826
    15621827void bbcone_setup(SModulFunctions* p)
     
    16121877  p->iiAddCproc("","uniquePoint",FALSE,uniquePoint);
    16131878  p->iiAddCproc("","listContainsCone",FALSE,containsCone);
     1879  p->iiAddCproc("","maximalGroebnerCone",FALSE,maximalGroebnerCone);
     1880  p->iiAddCproc("","groebnerCone",FALSE,groebnerCone);
     1881  p->iiAddCproc("","initial",FALSE,initial);
     1882  p->iiAddCproc("","homogeneitySpace",FALSE,homogeneitySpace);
     1883  p->iiAddCproc("","facetContaining",FALSE,facetContaining);
    16141884  coneID=setBlackboxStuff(b,"cone");
    16151885}
Note: See TracChangeset for help on using the changeset viewer.