Changeset 20d9284 in git
- Timestamp:
- Mar 23, 2011, 6:10:41 PM (12 years ago)
- 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
- Location:
- libpolys/polys
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libpolys/polys/monomials/p_polys.h
r630ca9 r20d9284 36 36 #define p_GetCoeff(p,r) pGetCoeff(p) 37 37 #define p_SetCoeff0(p,n,r) pSetCoeff0(p,n) 38 // deletes old p->coef and sets new one39 static inline number p_SetCoeff(poly p, number n, ring r);40 41 // get Order42 static inline long p_GetOrder(poly p, ring r);43 44 // Component45 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 // Exponent50 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/Deletion63 * except for pHead, all polys must be != NULL64 *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 != NULL84 *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 weights89 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, otherwise102 static inline BOOLEAN p_ExpVectorEqual(poly p1, poly p2, ring r);103 /// compute the degree of the leading monomial of p104 /// with respect to weigths 1105 /// the ordering may not be compatible with degree so do not use p->Order106 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 111 38 112 39 /*************************************************************** … … 115 42 * 116 43 ***************************************************************/ 117 static inline int p_LmCmp(poly p, poly q, ring r);118 44 #define p_LmCmpAction(p, q, r, actionE, actionG, actionS) \ 119 45 _p_LmCmpAction(p, q, r, actionE, actionG, actionS) … … 122 48 #define p_LmEqual(p1, p2, r) p_ExpVectorEqual(p1, p2, r) 123 49 124 // pCmp: args may be NULL125 // 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 129 50 /*************************************************************** 130 51 * … … 133 54 * 134 55 ***************************************************************/ 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);138 56 unsigned 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 Lm150 *151 ***************************************************************/152 // test if the monomial is a constant as a vector component153 // i.e., test if all exponents are zero154 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, otherwise159 static inline BOOLEAN p_LmExpVectorAddIsOk(const poly p1, const poly p2, ring r);160 57 161 58 /*************************************************************** … … 164 61 * 165 62 ***************************************************************/ 166 // return the maximal exponent of p167 static inline unsigned long p_GetMaxExp(poly p, ring r);168 63 // return the maximal exponent of p in form of the maximal long var 169 64 unsigned long p_GetMaxExpL(poly p, const ring r, unsigned long l_max = 0); … … 172 67 poly p_GetMaxExpP(poly p, ring r); 173 68 174 // suppose that l is a long var in r, return maximal exponent of l175 static inline unsigned long p_GetMaxExp(const unsigned long l, const ring r);176 177 69 // return the TotalDegree of the long var l 178 70 static inline unsigned long p_GetTotalDegree(const unsigned long l, const ring r); … … 184 76 long p_DegW(poly p, const short *w, const ring R); 185 77 186 187 // like the respective p_LmIs* routines, except that p might be empty188 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 203 78 // return TRUE if all monoms have the same component 204 79 BOOLEAN p_OneComp(poly p, ring r); … … 225 100 * 226 101 ***************************************************************/ 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 240 103 // simply deletes monomials, does not free coeffs 241 104 void p_ShallowDelete(poly *p, const ring r); … … 253 116 * 254 117 ***************************************************************/ 255 // returns -p, p is destroyed256 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 p261 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 m265 static inline poly pp_Mult_mm(poly p, poly m, const ring r);266 // returns p*m, destroys p, const: m267 static inline poly p_Mult_mm(poly p, poly m, const ring r);268 269 /// returns p+q, destroys p and q270 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);273 118 274 119 poly p_Sub(poly a, poly b, const ring r); 275 276 // return p - m*q, destroys p; const: q,m277 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, m283 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, m286 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 q290 static inline poly p_Mult_q(poly p, poly q, const ring r);291 // returns p*q, does neither destroy p nor q292 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 pm295 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 pm298 // if lp is length of p on input then lp is length of returned poly on output299 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 equal302 static inline poly p_Merge_q(poly p, poly c, const ring r);303 // sorts p using bucket sort: returns sorted poly304 // assumes that monomials of p are all different305 // reverses it first, if revert == TRUE, use this if input p is "almost" sorted306 // correctly307 static inline poly p_SortMerge(poly p, const ring r, BOOLEAN revert = FALSE);308 // like SortMerge, except that p may have equal monimals309 static inline poly p_SortAdd(poly p, const ring r, BOOLEAN revert = FALSE);310 120 311 121 poly p_Power(poly p, int i, const ring r); … … 354 164 #define p_SetmComp p_Setm 355 165 166 // component 167 static 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 } 356 174 // sets component of poly a to i, returns length of p 357 175 static inline void p_SetCompP(poly p, int i, ring r) … … 454 272 * 455 273 ***************************************************************/ 456 static inline int pLength(poly a);457 274 static inline poly pLast(poly a, int &length); 458 275 inline poly pLast(poly a) { int l; return pLast(a, l);} 459 static inline poly pReverse(poly p); 276 static 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 } 460 293 void pEnlargeSet(poly**p, int length, int increment); 461 294 … … 603 436 } 604 437 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 613 439 static inline unsigned long p_AddComp(poly p, unsigned long v, ring r) 614 440 { … … 890 716 * 891 717 ***************************************************************/ 718 719 // pCmp: args may be NULL 720 // returns: (p2==NULL ? 1 : (p1 == NULL ? -1 : p_LmCmp(p1, p2))) 892 721 static inline int p_Cmp(poly p1, poly p2, ring r) 893 722 { … … 971 800 } 972 801 802 static 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 973 816 static inline poly p_Copy(poly p, const ring lmRing, const ring tailRing) 974 817 { … … 1010 853 } 1011 854 855 // copys monomials of p, allocates new monomials from bin, 856 // deletes monomoals of p 1012 857 static inline poly p_ShallowCopyDelete(poly p, const ring r, omBin bin) 1013 858 { … … 1024 869 } 1025 870 871 /// like p_Add_q, except that if lp == pLength(lp) lq == pLength(lq) then lp == pLength(p+q) 1026 872 static inline poly p_Add_q(poly p, poly q, int &lp, int lq, const ring r) 1027 873 { … … 1066 912 } 1067 913 914 // test if the monomial is a constant as a vector component 915 // i.e., test if all exponents are zero 916 static 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 933 static 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 1068 940 // returns Copy(p)*m, does neither destroy p nor m 1069 941 static inline poly pp_Mult_mm(poly p, poly m, const ring r) … … 1105 977 } 1106 978 979 // like p_Minus_mm_Mult_qq, except that if lp == pLength(lp) lq == pLength(lq) 980 // then lp == pLength(p -m*q) 1107 981 static inline poly p_Minus_mm_Mult_qq(poly p, poly m, poly q, int &lp, int lq, 1108 982 poly spNoether, const ring r) … … 1120 994 } 1121 995 996 // returns p*Coeff(m) for such monomials pm of p, for which m is divisble by pm 1122 997 static inline poly pp_Mult_Coeff_mm_DivSelect(poly p, const poly m, const ring r) 1123 998 { … … 1126 1001 } 1127 1002 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 1128 1005 static inline poly pp_Mult_Coeff_mm_DivSelect(poly p, int &lp, const poly m, const ring r) 1129 1006 { … … 1255 1132 } 1256 1133 1134 // returns merged p and q, assumes p and q have no monomials which are equal 1257 1135 static inline poly p_Merge_q(poly p, poly q, const ring r) 1258 1136 { … … 1260 1138 } 1261 1139 1262 static inline poly p_SortAdd(poly p, const ring r, BOOLEAN revert) 1140 // like p_SortMerge, except that p may have equal monimals 1141 static inline poly p_SortAdd(poly p, const ring r, BOOLEAN revert= FALSE) 1263 1142 { 1264 1143 if (revert) p = pReverse(p); … … 1266 1145 } 1267 1146 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 1151 static inline poly p_SortMerge(poly p, const ring r, BOOLEAN revert= FALSE) 1269 1152 { 1270 1153 if (revert) p = pReverse(p); … … 1420 1303 return p_LmInit(s_p, s_r, d_r, d_r->PolyBin); 1421 1304 } 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 1434 1306 // set all exponents l..k to 0, assume exp. k+1..n and 1..l-1 are in 1435 1307 // different blocks … … 1455 1327 } 1456 1328 1329 // simialar to p_ShallowCopyDelete but does it only for leading monomial 1457 1330 static inline poly p_LmShallowCopyDelete(poly p, const ring r, omBin bin) 1458 1331 { … … 1825 1698 * 1826 1699 ***************************************************************/ 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 1851 1701 1852 1702 // like the respective p_LmIs* routines, except that p might be empty … … 1861 1711 if (p == NULL) return TRUE; 1862 1712 return (pNext(p)==NULL) && p_LmIsConstant(p, r); 1713 } 1714 1715 static 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; 1863 1725 } 1864 1726 -
libpolys/polys/pInline0.h
r630ca9 r20d9284 26 26 * 27 27 ***************************************************************/ 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 do36 {37 qn = pNext(q);38 pNext(q) = p;39 p = q;40 q = qn;41 }42 while (qn != NULL);43 return p;44 }45 28 46 29
Note: See TracChangeset
for help on using the changeset viewer.