Changeset f0b01f in git


Ignore:
Timestamp:
May 19, 2011, 10:30:09 AM (13 years ago)
Author:
Frank Seelisch <seelisch@…>
Branches:
(u'spielwiese', '2a584933abf2a2d3082034c7586d38bb6de1a30a')
Children:
c28ecf1b368527a9ec9e39a3db43a7b75040f036
Parents:
c5484888248231a7dfff33b9693cdd46980c1448
git-author:
Frank Seelisch <seelisch@mathematik.uni-kl.de>2011-05-19 10:30:09+02:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 12:36:12+01:00
Message:
alg ext fields: further development
Location:
libpolys/polys
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libpolys/polys/ext_fields/algext.cc

    rc54848 rf0b01f  
    7474{
    7575  assume(getCoeffType(cf) == naID);
    76   #ifdef LDEBUG
    77   omCheckAddr(&a);
    78   #endif
     76  if (a == NULL) return TRUE;
     77  p_Test((poly)a, naRing); // cannot use omCheckAddrSize(a, sizeof(*a)) here
    7978  assume(p_Deg((poly)a, naRing) <= p_Deg(naMinpoly, naRing));
    8079  return TRUE;
     
    430429  omCheckAddr(p); omCheckAddr(reducer);
    431430  #endif
    432   p_PolyDiv(&p, reducer, FALSE, naRing);
     431  p_PolyDiv(p, reducer, FALSE, naRing);
    433432}
    434433
     
    444443  naTest(a);
    445444  if (a == NULL) WerrorS(nDivBy0);
    446   poly *aFactor; poly *mFactor;
     445  poly aFactor; poly mFactor;
    447446  poly theGcd = p_ExtGcd((poly)a, aFactor, naMinpoly, mFactor, naRing);
    448447  /* the gcd must be one since naMinpoly is irreducible and a != NULL: */
    449448  assume(naIsOne((number)theGcd, cf));     
    450449  p_Delete(&theGcd, naRing);
    451   p_Delete(mFactor, naRing);
    452   return (number)(*aFactor);
     450  p_Delete(&mFactor, naRing);
     451  return (number)(aFactor);
    453452}
    454453
  • libpolys/polys/monomials/p_polys.cc

    rc54848 rf0b01f  
    14301430}
    14311431
    1432 /* assumes that *p and divisor are univariate polynomials in r,
     1432/* assumes that p and divisor are univariate polynomials in r,
    14331433   mentioning the same variable;
    14341434   assumes divisor != NULL;
    1435    *p may be NULL;
     1435   p may be NULL;
    14361436   assumes a global monomial ordering in r;
    1437    performs polynomial division of *p by divisor:
    1438      - afterwards *p contains the remainder of the division, i.e.,
    1439        *p_before = result * divisor + *p_afterwards;
     1437   performs polynomial division of p by divisor:
     1438     - afterwards p contains the remainder of the division, i.e.,
     1439       p_before = result * divisor + p_afterwards;
    14401440     - if needResult == TRUE, then the method computes and returns 'result',
    14411441       otherwise NULL is returned (This parametrization can be used when
    14421442       one is only interested in the remainder of the division. In this
    1443        case, the method will be faster.) */
    1444 poly p_PolyDiv(poly * p, poly divisor, BOOLEAN needResult, ring r)
    1445 {
     1443       case, the method will be slightly faster.)
     1444   leaves divisor unmodified */
     1445poly p_PolyDiv(poly &p, poly divisor, BOOLEAN needResult, ring r)
     1446{
     1447//printf("p_PolyDiv:\n");
    14461448  assume(divisor != NULL);
    1447   if (*p == NULL) return NULL;
     1449  if (p == NULL) return NULL;
    14481450 
    14491451  poly result = NULL;
    1450   number divisorLT = p_GetCoeff(divisor, r);
    1451   int divisorExp = p_GetExp(divisor, 1, r);
    1452   while (p_Deg(*p, r) > p_Deg(divisor, r))
    1453   {
    1454     /* determine t = LT(*p) / LT(divisor) */
     1452  number divisorLC = p_GetCoeff(divisor, r);
     1453  int divisorLE = p_GetExp(divisor, 1, r);
     1454//p_Write(p, r); p_Write(divisor, r);
     1455  while ((p != NULL) && (p_Deg(p, r) > p_Deg(divisor, r)))
     1456  {
     1457    /* determine t = LT(p) / LT(divisor) */
    14551458    poly t = p_ISet(1, r);
    1456     number c = n_Div(p_GetCoeff(*p, r), divisorLT, r->cf);
     1459    number c = n_Div(p_GetCoeff(p, r), divisorLC, r->cf);
    14571460    p_SetCoeff(t, c, r);
    1458     int e = p_GetExp(*p, 1, r) - divisorExp;
     1461    int e = p_GetExp(p, 1, r) - divisorLE;
    14591462    p_SetExp(t, 1, e, r);
    14601463    p_Setm(t, r);
    1461     result = p_Add_q(result, p_Copy(t, r), r);
    1462     *p = p_Add_q(*p, p_Neg(t, r), r);
    1463   }
    1464   n_Delete(&divisorLT, r->cf);
     1464//printf("t\n"); p_Write(t, r);
     1465    if (needResult) result = p_Add_q(result, p_Copy(t, r), r);
     1466//t = p_Mult_q(t, p_Copy(divisor, r), r); p_Write(t, r);
     1467//t = p_Neg(t, r); p_Write(t, r);
     1468//printf("p\n"); p_Write(p, r);
     1469//t = p_Add_q(p, t, r); p_Write(t, r);
     1470//p = t;
     1471    p = p_Add_q(p, p_Neg(p_Mult_q(t, p_Copy(divisor, r), r), r), r);
     1472//printf("EXECUTION STOPPED\n"); while (1) { };
     1473  }
     1474  n_Delete(&divisorLC, r->cf);
    14651475  return result;
    14661476}
    14671477
    14681478/* see p_Gcd;
    1469    additional assumption: deg(*p) >= deg(*q);
    1470    must destroy *p and *q (unless one of them is returned) */
    1471 poly p_GcdHelper(poly * p, poly * q, ring r)
    1472 {
    1473   if (q == NULL) return *p;
     1479   additional assumption: deg(p) >= deg(q);
     1480   must destroy p and q (unless one of them is returned) */
     1481poly p_GcdHelper(poly &p, poly &q, ring r)
     1482{
     1483  if (q == NULL) return p;
    14741484  else
    14751485  {
    1476     p_PolyDiv(p, *q, FALSE, r);
     1486    p_PolyDiv(p, q, FALSE, r);
    14771487    return p_GcdHelper(q, p, r);
    14781488  }
     
    14921502  if (p_Deg(a, r) < p_Deg(b, r)) { a = q; b = p; }
    14931503  a = p_Copy(a, r); b = p_Copy(b, r);
    1494   return p_GcdHelper(&a, &b, r);
     1504  return p_GcdHelper(a, b, r);
    14951505}
    14961506
    14971507/* see p_ExtGcd;
    1498    additional assumption: deg(*p) >= deg(*q);
    1499    must destroy *p and *q (unless one of them is returned) */
    1500 poly p_ExtGcdHelper(poly * p, poly * pFactor, poly * q, poly * qFactor,
     1508   additional assumption: deg(p) >= deg(q);
     1509   must destroy p and q (unless one of them is returned) */
     1510poly p_ExtGcdHelper(poly &p, poly &pFactor, poly &q, poly &qFactor,
    15011511                    ring r)
    15021512{
     1513//printf("p_ExtGcdHelper:\n");
    15031514  if (q == NULL)
    15041515  {
    1505     *qFactor = NULL; *pFactor = p_ISet(1, r); return *p;
     1516    qFactor = NULL; pFactor = p_ISet(1, r); return p;
    15061517  }
    15071518  else
    15081519  {
    1509     poly pDivQ = p_PolyDiv(p, *q, TRUE, r);
    1510     poly * ppFactor; poly * qqFactor;
     1520//p_Write(p, r); p_Write(q, r);
     1521    poly pDivQ = p_PolyDiv(p, q, TRUE, r);
     1522    poly ppFactor; poly qqFactor;
    15111523    poly theGcd = p_ExtGcdHelper(q, ppFactor, p, qqFactor, r);
    15121524    pFactor = qqFactor;
    1513     *qFactor = p_Add_q(*ppFactor,
    1514                        p_Neg(p_Mult_q(pDivQ, p_Copy(*qqFactor, r), r), r),
    1515                        r);
     1525    qFactor = p_Add_q(ppFactor,
     1526                      p_Neg(p_Mult_q(pDivQ, p_Copy(qqFactor, r), r), r),
     1527                      r);
    15161528    return theGcd;
    15171529  }
     
    15231535   assumes that not both p and q are NULL;
    15241536   returns the gcd of p and q;
    1525    moreover, afterwards *pFactor and *qFactor contain appropriate
    1526    factors such that gcd(p, q) = p * (*pFactor) + q * (*qFactor);
     1537   moreover, afterwards pFactor and qFactor contain appropriate
     1538   factors such that gcd(p, q) = p * pFactor + q * qFactor;
    15271539   leaves p and q unmodified */
    1528 poly p_ExtGcd(poly p, poly * pFactor, poly q, poly * qFactor, ring r)
    1529 {
    1530   assume((p != NULL) || (q != NULL));
    1531  
     1540poly p_ExtGcd(poly p, poly &pFactor, poly q, poly &qFactor, ring r)
     1541{
     1542//printf("p_ExtGcd:\n");
     1543//p_Write(p, r); p_Write(q, r);
     1544  assume((p != NULL) || (q != NULL)); 
    15321545  poly a = p; poly b = q;
    1533   poly * aFactor = pFactor; poly * bFactor = qFactor;
     1546  poly aFactor = pFactor; poly bFactor = qFactor;
    15341547  if (p_Deg(a, r) < p_Deg(b, r))
    15351548  { a = q; b = p; aFactor = qFactor, bFactor = pFactor; }
    15361549  a = p_Copy(a, r); b = p_Copy(b, r);
    1537   return p_ExtGcdHelper(&a, aFactor, &b, bFactor, r);
     1550  return p_ExtGcdHelper(a, aFactor, b, bFactor, r);
    15381551}
    15391552
  • libpolys/polys/monomials/p_polys.h

    rc54848 rf0b01f  
    18241824int       p_Weight(int c, const ring r);
    18251825
    1826 /* assumes that *p and divisor are univariate polynomials in r,
     1826/* assumes that p and divisor are univariate polynomials in r,
    18271827   mentioning the same variable;
    18281828   assumes divisor != NULL;
    1829    *p may be NULL;
     1829   p may be NULL;
    18301830   assumes a global monomial ordering in r;
    1831    performs polynomial division of *p by divisor:
    1832      - afterwards *p contains the remainder of the division, i.e.,
    1833        *p_before = result * divisor + *p_afterwards;
     1831   performs polynomial division of p by divisor:
     1832     - afterwards p contains the remainder of the division, i.e.,
     1833       p_before = result * divisor + p_afterwards;
    18341834     - if needResult == TRUE, then the method computes and returns 'result',
    18351835       otherwise NULL is returned (This parametrization can be used when
    18361836       one is only interested in the remainder of the division. In this
    1837        case, the method will be faster.) */
    1838 poly      p_PolyDiv(poly *p, poly divisor, BOOLEAN needResult, ring r);
    1839 
    1840 /* assumes that p and q are univariate polynomials in r,
    1841    mentioning the same variable;
    1842    assumes a global monomial ordering in r;
    1843    assumes that not both p and q are NULL;
    1844    returns the gcd of p and q */
    1845 poly      p_Gcd(poly p, poly q, ring r);
     1837       case, the method will be slightly faster.)
     1838   leaves divisor unmodified */
     1839poly      p_PolyDiv(poly &p, poly divisor, BOOLEAN needResult, ring r);
    18461840
    18471841/* assumes that p and q are univariate polynomials in r,
     
    18501844   assumes that not both p and q are NULL;
    18511845   returns the gcd of p and q;
    1852    moreover, afterwards *pFactor and *qFactor contain appropriate
    1853    factors such that gcd(p, q) = p * (*pFactor) + q * (*qFactor) */
    1854 poly      p_ExtGcd(poly p, poly *pFactor, poly q, poly *qFactor, ring r);
     1846   leaves p and q unmodified */
     1847poly      p_Gcd(poly p, poly q, ring r);
     1848
     1849/* assumes that p and q are univariate polynomials in r,
     1850   mentioning the same variable;
     1851   assumes a global monomial ordering in r;
     1852   assumes that not both p and q are NULL;
     1853   returns the gcd of p and q;
     1854   moreover, afterwards pFactor and qFactor contain appropriate
     1855   factors such that gcd(p, q) = p * pFactor + q * qFactor;
     1856   leaves p and q unmodified */
     1857poly      p_ExtGcd(poly p, poly &pFactor, poly q, poly &qFactor, ring r);
    18551858
    18561859/* syszygy stuff */
Note: See TracChangeset for help on using the changeset viewer.