Changeset 152e71c in git for libpolys


Ignore:
Timestamp:
Feb 28, 2014, 5:23:48 PM (10 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'spielwiese', '2a584933abf2a2d3082034c7586d38bb6de1a30a')
Children:
546e3e4eb7aba52cab2eb659c027866693024f3c
Parents:
c2b10fe022a6d9764f0efba82bd5909bf1739ee0
Message:
Fixed ratGB compilation&linkage (if HAVE_RATGRING)
Location:
libpolys/polys/monomials
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libpolys/polys/monomials/p_polys.cc

    rc2b10f r152e71c  
    15891589  /* Don't do a pSetm here, otherwise hres/lres chockes */
    15901590}
     1591
     1592
     1593
     1594#ifdef HAVE_RATGRING
     1595/*2
     1596* returns the rational LCM of the head terms of a and b
     1597* without coefficient!!!
     1598*/
     1599poly p_LcmRat(const poly a, const poly b, const long lCompM, const ring r)
     1600{
     1601  poly m = // p_One( r);
     1602          p_Init(r);
     1603
     1604//  const int (currRing->N) = r->N;
     1605
     1606  //  for (int i = (currRing->N); i>=r->real_var_start; i--)
     1607  for (int i = r->real_var_end; i>=r->real_var_start; i--)
     1608  {
     1609    const int lExpA = p_GetExp (a, i, r);
     1610    const int lExpB = p_GetExp (b, i, r);
     1611
     1612    p_SetExp (m, i, si_max(lExpA, lExpB), r);
     1613  }
     1614
     1615  p_SetComp (m, lCompM, r);
     1616  p_Setm(m,r);
     1617  n_New(&(p_GetCoeff(m, r)), r);
     1618
     1619  return(m);
     1620};
     1621
     1622void p_LmDeleteAndNextRat(poly *p, int ishift, ring r)
     1623{
     1624  /* modifies p*/
     1625  //  Print("start: "); Print(" "); p_wrp(*p,r);
     1626  p_LmCheckPolyRing2(*p, r);
     1627  poly q = p_Head(*p,r);
     1628  const long cmp = p_GetComp(*p, r);
     1629  while ( ( (*p)!=NULL ) && ( p_Comp_k_n(*p, q, ishift+1, r) ) && (p_GetComp(*p, r) == cmp) )
     1630  {
     1631    p_LmDelete(p,r);
     1632    //    Print("while: ");p_wrp(*p,r);Print(" ");
     1633  }
     1634  //  p_wrp(*p,r);Print(" ");
     1635  //  PrintS("end\n");
     1636  p_LmDelete(&q,r);
     1637}
     1638
     1639
     1640/* returns x-coeff of p, i.e. a poly in x, s.t. corresponding xd-monomials
     1641have the same D-part and the component 0
     1642does not destroy p
     1643*/
     1644poly p_GetCoeffRat(poly p, int ishift, ring r)
     1645{
     1646  poly q   = pNext(p);
     1647  poly res; // = p_Head(p,r);
     1648  res = p_GetExp_k_n(p, ishift+1, r->N, r); // does pSetm internally
     1649  p_SetCoeff(res,n_Copy(p_GetCoeff(p,r),r),r);
     1650  poly s;
     1651  long cmp = p_GetComp(p, r);
     1652  while ( (q!= NULL) && (p_Comp_k_n(p, q, ishift+1, r)) && (p_GetComp(q, r) == cmp) )
     1653  {
     1654    s   = p_GetExp_k_n(q, ishift+1, r->N, r);
     1655    p_SetCoeff(s,n_Copy(p_GetCoeff(q,r),r),r);
     1656    res = p_Add_q(res,s,r);
     1657    q   = pNext(q);
     1658  }
     1659  cmp = 0;
     1660  p_SetCompP(res,cmp,r);
     1661  return res;
     1662}
     1663
     1664
     1665
     1666void p_ContentRat(poly &ph, const ring r)
     1667// changes ph
     1668// for rat coefficients in K(x1,..xN)
     1669{
     1670  // init array of RatLeadCoeffs
     1671  //  poly p_GetCoeffRat(poly p, int ishift, ring r);
     1672
     1673  int len=pLength(ph);
     1674  poly *C = (poly *)omAlloc0((len+1)*sizeof(poly));  //rat coeffs
     1675  poly *LM = (poly *)omAlloc0((len+1)*sizeof(poly));  // rat lead terms
     1676  int *D = (int *)omAlloc0((len+1)*sizeof(int));  //degrees of coeffs
     1677  int *L = (int *)omAlloc0((len+1)*sizeof(int));  //lengths of coeffs
     1678  int k = 0;
     1679  poly p = p_Copy(ph, r); // ph will be needed below
     1680  int mintdeg = p_Totaldegree(p, r);
     1681  int minlen = len;
     1682  int dd = 0; int i;
     1683  int HasConstantCoef = 0;
     1684  int is = r->real_var_start - 1;
     1685  while (p!=NULL)
     1686  {
     1687    LM[k] = p_GetExp_k_n(p,1,is, r); // need LmRat istead of  p_HeadRat(p, is, currRing); !
     1688    C[k] = p_GetCoeffRat(p, is, r);
     1689    D[k] =  p_Totaldegree(C[k], r);
     1690    mintdeg = si_min(mintdeg,D[k]);
     1691    L[k] = pLength(C[k]);
     1692    minlen = si_min(minlen,L[k]);
     1693    if (p_IsConstant(C[k], r))
     1694    {
     1695      // C[k] = const, so the content will be numerical
     1696      HasConstantCoef = 1;
     1697      // smth like goto cleanup and return(pContent(p));
     1698    }
     1699    p_LmDeleteAndNextRat(&p, is, r);
     1700    k++;
     1701  }
     1702
     1703  // look for 1 element of minimal degree and of minimal length
     1704  k--;
     1705  poly d;
     1706  int mindeglen = len;
     1707  if (k<=0) // this poly is not a ratgring poly -> pContent
     1708  {
     1709    p_Delete(&C[0], r);
     1710    p_Delete(&LM[0], r);
     1711    p_Content(ph, r);
     1712    goto cleanup;
     1713  }
     1714
     1715  int pmindeglen;
     1716  for(i=0; i<=k; i++)
     1717  {
     1718    if (D[i] == mintdeg)
     1719    {
     1720      if (L[i] < mindeglen)
     1721      {
     1722        mindeglen=L[i];
     1723        pmindeglen = i;
     1724      }
     1725    }
     1726  }
     1727  d = p_Copy(C[pmindeglen], r);
     1728  // there are dd>=1 mindeg elements
     1729  // and pmideglen is the coordinate of one of the smallest among them
     1730
     1731  //  poly g = singclap_gcd(p_Copy(p,r),p_Copy(q,r));
     1732  //  return naGcd(d,d2,currRing);
     1733
     1734  // adjoin pContentRat here?
     1735  for(i=0; i<=k; i++)
     1736  {
     1737    d=singclap_gcd(d,p_Copy(C[i], r), r);
     1738    if (p_Totaldegree(d, r)==0)
     1739    {
     1740      // cleanup, pContent, return
     1741      p_Delete(&d, r);
     1742      for(;k>=0;k--)
     1743      {
     1744        p_Delete(&C[k], r);
     1745        p_Delete(&LM[k], r);
     1746      }
     1747      p_Content(ph, r);
     1748      goto cleanup;
     1749    }
     1750  }
     1751  for(i=0; i<=k; i++)
     1752  {
     1753    poly h=singclap_pdivide(C[i],d, r);
     1754    p_Delete(&C[i], r);
     1755    C[i]=h;
     1756  }
     1757
     1758  // zusammensetzen,
     1759  p=NULL; // just to be sure
     1760  for(i=0; i<=k; i++)
     1761  {
     1762    p = p_Add_q(p, p_Mult_q(C[i],LM[i], r), r);
     1763    C[i]=NULL; LM[i]=NULL;
     1764  }
     1765  p_Delete(&ph, r); // do not need it anymore
     1766  ph = p;
     1767  // aufraeumen, return
     1768cleanup:
     1769  omFree(C);
     1770  omFree(LM);
     1771  omFree(D);
     1772  omFree(L);
     1773}
     1774
     1775
     1776#endif
     1777
    15911778
    15921779/* assumes that p and divisor are univariate polynomials in r,
     
    26142801    {
    26152802      /* quick unit detection in the rational case is done in gr_nc_bba */
    2616       pContentRat(p);
     2803      p_ContentRat(p, r);
    26172804      start=p;
    26182805    }
  • libpolys/polys/monomials/p_polys.h

    rc2b10f r152e71c  
    15771577  }
    15781578#ifdef HAVE_RINGS
    1579   pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == nDivBy(p_GetCoeff(b, r), p_GetCoeff(a, r)));
     1579  pDivAssume(p_DebugLmDivisibleByNoComp(a, b, r) == n_DivBy(p_GetCoeff(b, r), p_GetCoeff(a, r), r->cf));
    15801580  return (!rField_is_Ring(r)) || n_DivBy(p_GetCoeff(b, r), p_GetCoeff(a, r), r->cf);
    15811581#else
     
    16181618  while (i>=start);
    16191619#ifdef HAVE_RINGS
    1620   return nDivBy(p_GetCoeff(b, r), p_GetCoeff(a, r));
     1620  return n_DivBy(p_GetCoeff(b, r_b), p_GetCoeff(a, r_a), r_a->cf);
    16211621#else
    16221622  return TRUE;
     
    18371837// returns the LCM of the head terms of a and b in *m
    18381838void p_Lcm(const poly a, const poly b, poly m, const ring r);
     1839
     1840#ifdef HAVE_RATGRING
     1841poly p_LcmRat(const poly a, const poly b, const long lCompM, const ring r);
     1842poly p_GetCoeffRat(poly p, int ishift, ring r);
     1843void p_LmDeleteAndNextRat(poly *p, int ishift, ring r);
     1844void p_ContentRat(poly &ph, const ring r);
     1845#endif /* ifdef HAVE_RATGRING */
     1846
    18391847
    18401848poly      p_Diff(poly a, int k, const ring r);
Note: See TracChangeset for help on using the changeset viewer.