Changeset 20d9284 in git


Ignore:
Timestamp:
Mar 23, 2011, 6:10:41 PM (12 years ago)
Author:
Martin Lee <martinlee84@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
Children:
c45b2dc39dc745a56b92c3c59742e2fbe4f23e07
Parents:
630ca96539668c0d4cc157cc95f84f9a08e7d663
git-author:
Martin Lee <martinlee84@web.de>2011-03-23 18:10:41+01:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 12:04:12+01:00
Message:
deleted unneccessary forward declarations in p_polys.h
and moved pReverse from pInline0.h to p_polys.h
Location:
libpolys/polys
Files:
2 edited

Legend:

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

    r630ca9 r20d9284  
    3636#define p_GetCoeff(p,r)     pGetCoeff(p)
    3737#define p_SetCoeff0(p,n,r)  pSetCoeff0(p,n)
    38 // deletes old p->coef and sets new one
    39 static inline number p_SetCoeff(poly p, number n, ring r);
    40 
    41 // get Order
    42 static inline long p_GetOrder(poly p, ring r);
    43 
    44 // Component
    45 static inline unsigned long p_SetComp(poly p, unsigned long c, ring r);
    46 static inline unsigned long p_AddComp(poly p, unsigned long v, ring r);
    47 static inline unsigned long p_SubComp(poly p, unsigned long v, ring r);
    48 
    49 // Exponent
    50 static inline long p_GetExp(poly p, int v, ring r);
    51 static inline long p_SetExp(poly p, int v, long e, ring r);
    52 static inline long p_IncrExp(poly p, int v, ring r);
    53 static inline long p_DecrExp(poly p, int v, ring r);
    54 static inline long p_AddExp(poly p, int v, long ee, ring r);
    55 static inline long p_SubExp(poly p, int v, long ee, ring r);
    56 static inline long p_MultExp(poly p, int v, long ee, ring r);
    57 static inline long p_GetExpSum(poly p1, poly p2, int i, ring r);
    58 static inline long p_GetExpDiff(poly p1, poly p2, int i, ring r);
    59 
    60 /***************************************************************
    61  *
    62  * Allocation/Initalization/Deletion
    63  * except for pHead, all polys must be != NULL
    64  *
    65  ***************************************************************/
    66 static inline poly p_New(ring r);
    67 static inline poly p_New(ring r, omBin bin);
    68 static inline poly p_Init(ring r);
    69 static inline poly p_Init(ring r, omBin bin);
    70 static inline poly p_LmInit(poly p, ring r);
    71 static inline poly p_LmInit(poly s_p, ring s_r, ring d_p);
    72 static inline poly p_LmInit(poly s_p, ring s_r, ring d_p, omBin d_bin);
    73 static inline poly p_Head(poly p, ring r);
    74 static inline void p_LmFree(poly p, ring r);
    75 static inline void p_LmFree(poly *p, ring r);
    76 static inline poly p_LmFreeAndNext(poly p, ring r);
    77 static inline void p_LmDelete(poly p, ring r);
    78 static inline void p_LmDelete(poly *p, ring r);
    79 static inline poly p_LmDeleteAndNext(poly p, ring r);
    80 
    81 /***************************************************************
    82  *
    83  * Operation on ExpVectors: assumes polys != NULL
    84  *
    85  ***************************************************************/
    86 // ExpVextor(d_p) = ExpVector(s_p)
    87 static inline void p_ExpVectorCopy(poly d_p, poly s_p, ring r);
    88 // adjustments for negative weights
    89 static inline void p_MemAdd_NegWeightAdjust(poly p, ring r);
    90 static inline void p_MemSub_NegWeightAdjust(poly p, ring r);
    91 // ExpVector(p1) += ExpVector(p2)
    92 static inline void p_ExpVectorAdd(poly p1, poly p2, ring r);
    93 // ExpVector(p1) -= ExpVector(p2)
    94 static inline void p_ExpVectorSub(poly p1, poly p2, ring r);
    95 // ExpVector(p1) += ExpVector(p2) - ExpVector(p3)
    96 static inline void p_ExpVectorAddSub(poly p1, poly p2, poly p3, ring r);
    97 // ExpVector(pr) = ExpVector(p1) + ExpVector(p2)
    98 static inline void p_ExpVectorSum(poly pr, poly p1, poly p2, ring r);
    99 /// ExpVector(pr) = ExpVector(p1) + ExpVector(p2)
    100 static inline void p_ExpVectorDiff(poly pr, poly p1, poly p2, ring r);
    101 /// returns TRUE if ExpVector(p1) == ExpVector(p2), FALSE, otherwise
    102 static inline BOOLEAN p_ExpVectorEqual(poly p1, poly p2, ring r);
    103 /// compute the degree of the leading monomial of p
    104 /// with respect to weigths 1
    105 /// the ordering may not be compatible with degree so do not use p->Order
    106 static inline long p_Totaldegree(poly p, ring r);
    107 
    108 static inline void p_GetExpV(poly p, int *ev, ring r);
    109 static inline void p_SetExpV(poly p, int *ev, ring r);
    110 
    11138
    11239/***************************************************************
     
    11542 *
    11643 ***************************************************************/
    117 static inline int p_LmCmp(poly p, poly q, ring r);
    11844#define p_LmCmpAction(p, q, r, actionE, actionG, actionS) \
    11945  _p_LmCmpAction(p, q, r, actionE, actionG, actionS)
     
    12248#define p_LmEqual(p1, p2, r) p_ExpVectorEqual(p1, p2, r)
    12349
    124 // pCmp: args may be NULL
    125 // returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2)))
    126 static inline int p_Cmp(poly p1, poly p2, ring r);
    127 
    128 
    12950/***************************************************************
    13051 *
     
    13354 *
    13455 ***************************************************************/
    135 static inline BOOLEAN p_DivisibleBy(poly a, poly b, ring r);
    136 static inline BOOLEAN p_LmDivisibleBy(poly a, poly b, ring r);
    137 static inline BOOLEAN p_LmDivisibleByNoComp(poly a, poly b, ring r);
    13856unsigned long p_GetShortExpVector(poly a, ring r);
    139 static inline BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a,
    140                                       poly b, unsigned long not_sev_b, ring r);
    141 
    142 static inline BOOLEAN p_DivisibleBy(poly a, ring r_a, poly b, ring r_b);
    143 static inline BOOLEAN p_LmDivisibleBy(poly a, ring r_a, poly b, ring r_b);
    144 static inline BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, ring r_a,
    145                                       poly b, unsigned long not_sev_b, ring r_b);
    146 
    147 /***************************************************************
    148  *
    149  * Misc things on Lm
    150  *
    151  ***************************************************************/
    152 // test if the monomial is a constant as a vector component
    153 // i.e., test if all exponents are zero
    154 static inline BOOLEAN p_LmIsConstantComp(const poly p, const ring r);
    155 static inline BOOLEAN p_LmIsConstant(const poly p, const ring r);
    156 
    157 // return TRUE, if p_LmExpVectorAdd stays within ExpBound of ring r,
    158 //       FALSE, otherwise
    159 static inline BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2, ring r);
    16057
    16158/***************************************************************
     
    16461 *
    16562 ***************************************************************/
    166 // return the maximal exponent of p
    167 static inline unsigned long p_GetMaxExp(poly p, ring r);
    16863// return the maximal exponent of p in form of the maximal long var
    16964unsigned long p_GetMaxExpL(poly p, const ring r, unsigned long l_max = 0);
     
    17267poly p_GetMaxExpP(poly p, ring r);
    17368
    174 // suppose that l is a long var in r, return maximal exponent of l
    175 static inline unsigned long p_GetMaxExp(const unsigned long l, const ring r);
    176 
    17769// return the TotalDegree of the long var l
    17870static inline unsigned long p_GetTotalDegree(const unsigned long l, const ring r);
     
    18476long p_DegW(poly p, const short *w, const ring R);
    18577
    186 
    187 // like the respective p_LmIs* routines, except that p might be empty
    188 static inline BOOLEAN p_IsConstantComp(const poly p, const ring r);
    189 static inline BOOLEAN p_IsConstant(const poly p, const ring r);
    190 static inline BOOLEAN p_IsConstantPoly(const poly p, const ring r)
    191 {
    192   poly pp=p;
    193   while(pp!=NULL)
    194   {
    195     if (! p_LmIsConstantComp(pp, r))
    196       return FALSE;
    197     pIter(pp);
    198   }
    199   return TRUE;
    200 }
    201 
    202 
    20378// return TRUE if all monoms have the same component
    20479BOOLEAN   p_OneComp(poly p, ring r);
     
    225100 *
    226101 ***************************************************************/
    227 // returns a copy of p
    228 static inline poly p_Copy(poly p, const ring r);
    229 // returns a copy of p with Lm(p) from lmRing and Tail(p) from tailRing
    230 static inline poly p_Copy(poly p, const ring lmRing, const ring tailRing);
    231 // deletes *p, and sets *p to NULL
    232 static inline void p_Delete(poly *p, const ring r);
    233 static inline void p_Delete(poly *p, const ring lmRing, const ring tailRing);
    234 
    235 // copys monomials of p, allocates new monomials from bin,
    236 // deletes monomoals of p
    237 static inline poly p_ShallowCopyDelete(poly p, const ring r, omBin bin);
    238 // simial but does it only for leading monomial
    239 static inline poly p_LmShallowCopyDelete(poly p, const ring r, omBin bin);
     102
    240103// simply deletes monomials, does not free coeffs
    241104void p_ShallowDelete(poly *p, const ring r);
     
    253116 *
    254117 ***************************************************************/
    255 // returns -p, p is destroyed
    256 static inline poly p_Neg(poly p, const ring r);
    257 
    258 // returns p*n, p is const (i.e. copied)
    259 static inline poly pp_Mult_nn(poly p, number n, const ring r);
    260 // returns p*n, destroys p
    261 static inline poly p_Mult_nn(poly p, number n, const ring r);
    262 static inline poly p_Mult_nn(poly p, number n, const ring lmRing, const ring tailRing);
    263 
    264 // returns p*m, does neither destroy p nor m
    265 static inline poly pp_Mult_mm(poly p, poly m, const ring r);
    266 // returns p*m, destroys p, const: m
    267 static inline poly p_Mult_mm(poly p, poly m, const ring r);
    268 
    269 /// returns p+q, destroys p and q
    270 static inline poly p_Add_q(poly p, poly q, const ring r);
    271 /// like p_Add_q, except that if lp == pLength(lp) lq == pLength(lq) then lp == pLength(p+q)
    272 static inline poly p_Add_q(poly p, poly q, int &lp, int lq, const ring r);
    273118
    274119poly      p_Sub(poly a, poly b, const ring r);
    275 
    276 // return p - m*q, destroys p; const: q,m
    277 static inline poly p_Minus_mm_Mult_qq(poly p, poly m, poly q, const ring r);
    278 // like p_Minus_mm_Mult_qq, except that if lp == pLength(lp) lq == pLength(lq)
    279 // then lp == pLength(p -m*q)
    280 static inline poly p_Minus_mm_Mult_qq(poly p, poly m, poly q, int &lp, int lq,
    281                                  poly spNoether, const ring r);
    282 // returns p + m*q destroys p, const: q, m
    283 static inline poly p_Plus_mm_Mult_qq(poly p, poly m, poly q, const ring r);
    284 
    285 // returns p + m*q destroys p, const: q, m
    286 static inline poly p_Plus_mm_Mult_qq(poly p, poly m, poly q, int &lp, int lq,
    287                                 const ring r);
    288 
    289 // returns p*q, destroys p and q
    290 static inline poly p_Mult_q(poly p, poly q, const ring r);
    291 // returns p*q, does neither destroy p nor q
    292 static inline poly pp_Mult_qq(poly p, poly q, const ring r);
    293 
    294 // returns p*Coeff(m) for such monomials pm of p, for which m is divisble by pm
    295 static inline poly pp_Mult_Coeff_mm_DivSelect(poly p, const poly m, const ring r);
    296 
    297 // returns p*Coeff(m) for such monomials pm of p, for which m is divisble by pm
    298 // if lp is length of p on input then lp is length of returned poly on output
    299 static inline poly pp_Mult_Coeff_mm_DivSelect(poly p, int &lp, const poly m, const ring r);
    300 
    301 // returns merged p and q, assumes p and q have no monomials which are equal
    302 static inline poly p_Merge_q(poly p, poly c, const ring r);
    303 // sorts p using bucket sort: returns sorted poly
    304 // assumes that monomials of p are all different
    305 // reverses it first, if revert == TRUE, use this if input p is "almost" sorted
    306 // correctly
    307 static inline poly p_SortMerge(poly p, const ring r, BOOLEAN revert = FALSE);
    308 // like SortMerge, except that p may have equal monimals
    309 static inline poly p_SortAdd(poly p, const ring r, BOOLEAN revert = FALSE);
    310120
    311121poly      p_Power(poly p, int i, const ring r);
     
    354164#define p_SetmComp  p_Setm
    355165
     166// component
     167static inline  unsigned long p_SetComp(poly p, unsigned long c, ring r)
     168{
     169  p_LmCheckPolyRing2(p, r);
     170  pAssume2(rRing_has_Comp(r));
     171  __p_GetComp(p,r) = c;
     172  return c;
     173}
    356174// sets component of poly a to i, returns length of p
    357175static inline   void p_SetCompP(poly p, int i, ring r)
     
    454272 *
    455273 ***************************************************************/
    456 static inline int       pLength(poly a);
    457274static inline poly      pLast(poly a, int &length);
    458275inline   poly      pLast(poly a) { int l; return pLast(a, l);}
    459 static inline poly pReverse(poly p);
     276static inline poly pReverse(poly p)
     277{
     278  if (p == NULL || pNext(p) == NULL) return p;
     279
     280  poly q = pNext(p), // == pNext(p)
     281    qn;
     282  pNext(p) = NULL;
     283  do
     284  {
     285    qn = pNext(q);
     286    pNext(q) = p;
     287    p = q;
     288    q = qn;
     289  }
     290  while (qn != NULL);
     291  return p;
     292}
    460293void      pEnlargeSet(poly**p, int length, int increment);
    461294
     
    603436}
    604437
    605 // component
    606 static inline  unsigned long p_SetComp(poly p, unsigned long c, ring r)
    607 {
    608   p_LmCheckPolyRing2(p, r);
    609   pAssume2(rRing_has_Comp(r));
    610   __p_GetComp(p,r) = c;
    611   return c;
    612 }
     438
    613439static inline unsigned long p_AddComp(poly p, unsigned long v, ring r)
    614440{
     
    890716 *
    891717 ***************************************************************/
     718
     719// pCmp: args may be NULL
     720// returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2)))
    892721static inline int p_Cmp(poly p1, poly p2, ring r)
    893722{
     
    971800}
    972801
     802static inline poly p_Head(poly p, const ring r)
     803{
     804  if (p == NULL) return NULL;
     805  p_LmCheckPolyRing1(p, r);
     806  poly np;
     807  omTypeAllocBin(poly, np, r->PolyBin);
     808  p_SetRingOfLm(np, r);
     809  p_MemCopy_LengthGeneral(np->exp, p->exp, r->ExpL_Size);
     810  pNext(np) = NULL;
     811  pSetCoeff0(np, n_Copy(pGetCoeff(p), r->cf));
     812  return np;
     813}
     814
     815// returns a copy of p with Lm(p) from lmRing and Tail(p) from tailRing
    973816static inline poly p_Copy(poly p, const ring lmRing, const ring tailRing)
    974817{
     
    1010853}
    1011854
     855// copys monomials of p, allocates new monomials from bin,
     856// deletes monomoals of p
    1012857static inline poly p_ShallowCopyDelete(poly p, const ring r, omBin bin)
    1013858{
     
    1024869}
    1025870
     871/// like p_Add_q, except that if lp == pLength(lp) lq == pLength(lq) then lp == pLength(p+q)
    1026872static inline poly p_Add_q(poly p, poly q, int &lp, int lq, const ring r)
    1027873{
     
    1066912}
    1067913
     914// test if the monomial is a constant as a vector component
     915// i.e., test if all exponents are zero
     916static inline BOOLEAN p_LmIsConstantComp(const poly p, const ring r)
     917{
     918  //p_LmCheckPolyRing(p, r);
     919  int i = r->VarL_Size - 1;
     920
     921  do
     922  {
     923    if (p->exp[r->VarL_Offset[i]] != 0)
     924      return FALSE;
     925    i--;
     926  }
     927  while (i >= 0);
     928  return TRUE;
     929}
     930
     931// test if monomial is a constant, i.e. if all exponents and the component
     932// is zero
     933static inline BOOLEAN p_LmIsConstant(const poly p, const ring r)
     934{
     935  if (p_LmIsConstantComp(p, r))
     936    return (p_GetComp(p, r) == 0);
     937  return FALSE;
     938}
     939
    1068940// returns Copy(p)*m, does neither destroy p nor m
    1069941static inline poly pp_Mult_mm(poly p, poly m, const ring r)
     
    1105977}
    1106978
     979// like p_Minus_mm_Mult_qq, except that if lp == pLength(lp) lq == pLength(lq)
     980// then lp == pLength(p -m*q)
    1107981static inline poly p_Minus_mm_Mult_qq(poly p, poly m, poly q, int &lp, int lq,
    1108982                                 poly spNoether, const ring r)
     
    1120994}
    1121995
     996// returns p*Coeff(m) for such monomials pm of p, for which m is divisble by pm
    1122997static inline poly pp_Mult_Coeff_mm_DivSelect(poly p, const poly m, const ring r)
    1123998{
     
    11261001}
    11271002
     1003// returns p*Coeff(m) for such monomials pm of p, for which m is divisble by pm
     1004// if lp is length of p on input then lp is length of returned poly on output
    11281005static inline poly pp_Mult_Coeff_mm_DivSelect(poly p, int &lp, const poly m, const ring r)
    11291006{
     
    12551132}
    12561133
     1134// returns merged p and q, assumes p and q have no monomials which are equal
    12571135static inline poly p_Merge_q(poly p, poly q, const ring r)
    12581136{
     
    12601138}
    12611139
    1262 static inline poly p_SortAdd(poly p, const ring r, BOOLEAN revert)
     1140// like p_SortMerge, except that p may have equal monimals
     1141static inline poly p_SortAdd(poly p, const ring r, BOOLEAN revert= FALSE)
    12631142{
    12641143  if (revert) p = pReverse(p);
     
    12661145}
    12671146
    1268 static inline poly p_SortMerge(poly p, const ring r, BOOLEAN revert)
     1147// sorts p using bucket sort: returns sorted poly
     1148// assumes that monomials of p are all different
     1149// reverses it first, if revert == TRUE, use this if input p is "almost" sorted
     1150// correctly
     1151static inline poly p_SortMerge(poly p, const ring r, BOOLEAN revert= FALSE)
    12691152{
    12701153  if (revert) p = pReverse(p);
     
    14201303  return p_LmInit(s_p, s_r, d_r, d_r->PolyBin);
    14211304}
    1422 static inline poly p_Head(poly p, const ring r)
    1423 {
    1424   if (p == NULL) return NULL;
    1425   p_LmCheckPolyRing1(p, r);
    1426   poly np;
    1427   omTypeAllocBin(poly, np, r->PolyBin);
    1428   p_SetRingOfLm(np, r);
    1429   p_MemCopy_LengthGeneral(np->exp, p->exp, r->ExpL_Size);
    1430   pNext(np) = NULL;
    1431   pSetCoeff0(np, n_Copy(pGetCoeff(p), r->cf));
    1432   return np;
    1433 }
     1305
    14341306// set all exponents l..k to 0, assume exp. k+1..n and 1..l-1 are in
    14351307// different blocks
     
    14551327}
    14561328
     1329// simialar to p_ShallowCopyDelete but does it only for leading monomial
    14571330static inline poly p_LmShallowCopyDelete(poly p, const ring r, omBin bin)
    14581331{
     
    18251698 *
    18261699 ***************************************************************/
    1827 // test if the monomial is a constant as a vector component
    1828 // i.e., test if all exponents are zero
    1829 static inline BOOLEAN p_LmIsConstantComp(const poly p, const ring r)
    1830 {
    1831   //p_LmCheckPolyRing(p, r);
    1832   int i = r->VarL_Size - 1;
    1833 
    1834   do
    1835   {
    1836     if (p->exp[r->VarL_Offset[i]] != 0)
    1837       return FALSE;
    1838     i--;
    1839   }
    1840   while (i >= 0);
    1841   return TRUE;
    1842 }
    1843 // test if monomial is a constant, i.e. if all exponents and the component
    1844 // is zero
    1845 static inline BOOLEAN p_LmIsConstant(const poly p, const ring r)
    1846 {
    1847   if (p_LmIsConstantComp(p, r))
    1848     return (p_GetComp(p, r) == 0);
    1849   return FALSE;
    1850 }
     1700
    18511701
    18521702// like the respective p_LmIs* routines, except that p might be empty
     
    18611711  if (p == NULL) return TRUE;
    18621712  return (pNext(p)==NULL) && p_LmIsConstant(p, r);
     1713}
     1714
     1715static inline BOOLEAN p_IsConstantPoly(const poly p, const ring r)
     1716{
     1717  poly pp=p;
     1718  while(pp!=NULL)
     1719  {
     1720    if (! p_LmIsConstantComp(pp, r))
     1721      return FALSE;
     1722    pIter(pp);
     1723  }
     1724  return TRUE;
    18631725}
    18641726
  • libpolys/polys/pInline0.h

    r630ca9 r20d9284  
    2626 *
    2727 ***************************************************************/
    28 PINLINE0 poly pReverse(poly p)
    29 {
    30   if (p == NULL || pNext(p) == NULL) return p;
    31 
    32   poly q = pNext(p), // == pNext(p)
    33     qn;
    34   pNext(p) = NULL;
    35   do
    36   {
    37     qn = pNext(q);
    38     pNext(q) = p;
    39     p = q;
    40     q = qn;
    41   }
    42   while (qn != NULL);
    43   return p;
    44 }
    4528
    4629
Note: See TracChangeset for help on using the changeset viewer.