Changeset 20c540 in git
- Timestamp:
- Oct 4, 2012, 7:47:33 PM (10 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- Children:
- db347cb0bbec256ffb358817738b700f8da08253
- Parents:
- dc79bd7d1e331302a1fc20150a37e81890e6300a
- git-author:
- Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-10-04 19:47:33+02:00
- git-committer:
- Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-10-05 19:05:33+02:00
- Location:
- libpolys/polys
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
libpolys/polys/clapconv.cc
rdc79bd r20c540 290 290 if (a!=NULL) 291 291 { 292 if (r->cf->extRing->qideal->m[0]!=NULL) 293 { 294 poly l=r->cf->extRing->qideal->m[0]; 295 if (p_GetExp(a,1,r->cf->extRing) >= p_GetExp(l,1,r->cf->extRing)) 296 a = p_PolyDiv (a, l, FALSE, r->cf->extRing); 297 } 292 if( r->cf->extRing != NULL ) 293 if (r->cf->extRing->qideal->m[0]!=NULL) 294 { 295 poly l=r->cf->extRing->qideal->m[0]; 296 if (p_GetExp(a,1,r->cf->extRing) >= p_GetExp(l,1,r->cf->extRing)) 297 a = p_PolyDiv (a, l, FALSE, r->cf->extRing); // ??? 298 } 298 299 } 299 300 return a; -
libpolys/polys/ext_fields/algext.cc
rdc79bd r20c540 111 111 112 112 static BOOLEAN naCoeffIsEqual(const coeffs cf, n_coeffType n, void * param); 113 114 115 /// returns NULL if p == NULL, otherwise makes p monic by dividing 116 /// by its leading coefficient (only done if this is not already 1); 117 /// this assumes that we are over a ground field so that division 118 /// is well-defined; 119 /// modifies p 120 // void p_Monic(poly p, const ring r); 121 122 /// assumes that p and q are univariate polynomials in r, 123 /// mentioning the same variable; 124 /// assumes a global monomial ordering in r; 125 /// assumes that not both p and q are NULL; 126 /// returns the gcd of p and q; 127 /// leaves p and q unmodified 128 // poly p_Gcd(const poly p, const poly q, const ring r); 129 130 /* returns NULL if p == NULL, otherwise makes p monic by dividing 131 by its leading coefficient (only done if this is not already 1); 132 this assumes that we are over a ground field so that division 133 is well-defined; 134 modifies p */ 135 static inline void p_Monic(poly p, const ring r) 136 { 137 if (p == NULL) return; 138 number n = n_Init(1, r->cf); 139 if (p->next==NULL) { p_SetCoeff(p,n,r); return; } 140 poly pp = p; 141 number lc = p_GetCoeff(p, r); 142 if (n_IsOne(lc, r->cf)) return; 143 number lcInverse = n_Invers(lc, r->cf); 144 p_SetCoeff(p, n, r); // destroys old leading coefficient! 145 pIter(p); 146 while (p != NULL) 147 { 148 number n = n_Mult(p_GetCoeff(p, r), lcInverse, r->cf); 149 n_Normalize(n,r->cf); 150 p_SetCoeff(p, n, r); // destroys old leading coefficient! 151 pIter(p); 152 } 153 n_Delete(&lcInverse, r->cf); 154 p = pp; 155 } 156 157 /// see p_Gcd; 158 /// additional assumption: deg(p) >= deg(q); 159 /// must destroy p and q (unless one of them is returned) 160 static inline poly p_GcdHelper(poly &p, poly &q, const ring r) 161 { 162 while (q != NULL) 163 { 164 p_PolyDiv(p, q, FALSE, r); 165 // swap p and q: 166 poly& t = q; 167 q = p; 168 p = t; 169 170 } 171 return p; 172 } 173 174 /* assumes that p and q are univariate polynomials in r, 175 mentioning the same variable; 176 assumes a global monomial ordering in r; 177 assumes that not both p and q are NULL; 178 returns the gcd of p and q; 179 leaves p and q unmodified */ 180 static inline poly p_Gcd(const poly p, const poly q, const ring r) 181 { 182 assume((p != NULL) || (q != NULL)); 183 184 poly a = p; poly b = q; 185 if (p_Deg(a, r) < p_Deg(b, r)) { a = q; b = p; } 186 a = p_Copy(a, r); b = p_Copy(b, r); 187 188 /* We have to make p monic before we return it, so that if the 189 gcd is a unit in the ground field, we will actually return 1. */ 190 a = p_GcdHelper(a, b, r); 191 p_Monic(a, r); 192 return a; 193 } 194 195 /* see p_ExtGcd; 196 additional assumption: deg(p) >= deg(q); 197 must destroy p and q (unless one of them is returned) */ 198 static inline poly p_ExtGcdHelper(poly &p, poly &pFactor, poly &q, poly &qFactor, 199 ring r) 200 { 201 if (q == NULL) 202 { 203 qFactor = NULL; 204 pFactor = p_ISet(1, r); 205 p_SetCoeff(pFactor, n_Invers(p_GetCoeff(p, r), r->cf), r); 206 p_Monic(p, r); 207 return p; 208 } 209 else 210 { 211 poly pDivQ = p_PolyDiv(p, q, TRUE, r); 212 poly ppFactor = NULL; poly qqFactor = NULL; 213 poly theGcd = p_ExtGcdHelper(q, qqFactor, p, ppFactor, r); 214 pFactor = ppFactor; 215 qFactor = p_Add_q(qqFactor, 216 p_Neg(p_Mult_q(pDivQ, p_Copy(ppFactor, r), r), r), 217 r); 218 return theGcd; 219 } 220 } 221 222 /* assumes that p and q are univariate polynomials in r, 223 mentioning the same variable; 224 assumes a global monomial ordering in r; 225 assumes that not both p and q are NULL; 226 returns the gcd of p and q; 227 moreover, afterwards pFactor and qFactor contain appropriate 228 factors such that gcd(p, q) = p * pFactor + q * qFactor; 229 leaves p and q unmodified */ 230 poly p_ExtGcd(poly p, poly &pFactor, poly q, poly &qFactor, ring r) 231 { 232 assume((p != NULL) || (q != NULL)); 233 poly a = p; poly b = q; BOOLEAN aCorrespondsToP = TRUE; 234 if (p_Deg(a, r) < p_Deg(b, r)) 235 { a = q; b = p; aCorrespondsToP = FALSE; } 236 a = p_Copy(a, r); b = p_Copy(b, r); 237 poly aFactor = NULL; poly bFactor = NULL; 238 poly theGcd = p_ExtGcdHelper(a, aFactor, b, bFactor, r); 239 if (aCorrespondsToP) { pFactor = aFactor; qFactor = bFactor; } 240 else { pFactor = bFactor; qFactor = aFactor; } 241 return theGcd; 242 } 243 244 113 245 114 246 #ifdef LDEBUG -
libpolys/polys/ext_fields/algext.h
rdc79bd r20c540 49 49 int naIsParam(number, const coeffs); 50 50 51 struct spolyrec; 52 typedef struct spolyrec polyrec; 53 typedef polyrec * poly; 54 55 /// assumes that p and q are univariate polynomials in r, 56 /// mentioning the same variable; 57 /// assumes a global monomial ordering in r; 58 /// assumes that not both p and q are NULL; 59 /// returns the gcd of p and q; 60 /// moreover, afterwards pFactor and qFactor contain appropriate 61 /// factors such that gcd(p, q) = p * pFactor + q * qFactor; 62 /// leaves p and q unmodified 63 poly p_ExtGcd(poly p, poly &pFactor, poly q, poly &qFactor, ring r); 64 65 51 66 #endif 52 67 /* ALGEXT_H */ -
libpolys/polys/monomials/p_polys.cc
rdc79bd r20c540 1506 1506 case, the method will be slightly faster.) 1507 1507 leaves divisor unmodified */ 1508 poly p_PolyDiv(poly &p, poly divisor, BOOLEAN needResult,ring r)1508 poly p_PolyDiv(poly &p, const poly divisor, const BOOLEAN needResult, const ring r) 1509 1509 { 1510 1510 assume(divisor != NULL); … … 1527 1527 } 1528 1528 return result; 1529 }1530 1531 /* returns NULL if p == NULL, otherwise makes p monic by dividing1532 by its leading coefficient (only done if this is not already 1);1533 this assumes that we are over a ground field so that division1534 is well-defined;1535 modifies p */1536 void p_Monic(poly p, const ring r)1537 {1538 if (p == NULL) return;1539 number n = n_Init(1, r->cf);1540 if (p->next==NULL) { p_SetCoeff(p,n,r); return; }1541 poly pp = p;1542 number lc = p_GetCoeff(p, r);1543 if (n_IsOne(lc, r->cf)) return;1544 number lcInverse = n_Invers(lc, r->cf);1545 p_SetCoeff(p, n, r); // destroys old leading coefficient!1546 pIter(p);1547 while (p != NULL)1548 {1549 number n = n_Mult(p_GetCoeff(p, r), lcInverse, r->cf);1550 n_Normalize(n,r->cf);1551 p_SetCoeff(p, n, r); // destroys old leading coefficient!1552 pIter(p);1553 }1554 n_Delete(&lcInverse, r->cf);1555 p = pp;1556 }1557 1558 /* see p_Gcd;1559 additional assumption: deg(p) >= deg(q);1560 must destroy p and q (unless one of them is returned) */1561 poly p_GcdHelper(poly &p, poly &q, ring r)1562 {1563 if (q == NULL)1564 {1565 /* We have to make p monic before we return it, so that if the1566 gcd is a unit in the ground field, we will actually return 1. */1567 p_Monic(p, r);1568 return p;1569 }1570 else1571 {1572 p_PolyDiv(p, q, FALSE, r);1573 return p_GcdHelper(q, p, r);1574 }1575 }1576 1577 /* assumes that p and q are univariate polynomials in r,1578 mentioning the same variable;1579 assumes a global monomial ordering in r;1580 assumes that not both p and q are NULL;1581 returns the gcd of p and q;1582 leaves p and q unmodified */1583 poly p_Gcd(poly p, poly q, ring r)1584 {1585 assume((p != NULL) || (q != NULL));1586 1587 poly a = p; poly b = q;1588 if (p_Deg(a, r) < p_Deg(b, r)) { a = q; b = p; }1589 a = p_Copy(a, r); b = p_Copy(b, r);1590 return p_GcdHelper(a, b, r);1591 }1592 1593 /* see p_ExtGcd;1594 additional assumption: deg(p) >= deg(q);1595 must destroy p and q (unless one of them is returned) */1596 poly p_ExtGcdHelper(poly &p, poly &pFactor, poly &q, poly &qFactor,1597 ring r)1598 {1599 if (q == NULL)1600 {1601 qFactor = NULL;1602 pFactor = p_ISet(1, r);1603 p_SetCoeff(pFactor, n_Invers(p_GetCoeff(p, r), r->cf), r);1604 p_Monic(p, r);1605 return p;1606 }1607 else1608 {1609 poly pDivQ = p_PolyDiv(p, q, TRUE, r);1610 poly ppFactor = NULL; poly qqFactor = NULL;1611 poly theGcd = p_ExtGcdHelper(q, qqFactor, p, ppFactor, r);1612 pFactor = ppFactor;1613 qFactor = p_Add_q(qqFactor,1614 p_Neg(p_Mult_q(pDivQ, p_Copy(ppFactor, r), r), r),1615 r);1616 return theGcd;1617 }1618 }1619 1620 /* assumes that p and q are univariate polynomials in r,1621 mentioning the same variable;1622 assumes a global monomial ordering in r;1623 assumes that not both p and q are NULL;1624 returns the gcd of p and q;1625 moreover, afterwards pFactor and qFactor contain appropriate1626 factors such that gcd(p, q) = p * pFactor + q * qFactor;1627 leaves p and q unmodified */1628 poly p_ExtGcd(poly p, poly &pFactor, poly q, poly &qFactor, ring r)1629 {1630 assume((p != NULL) || (q != NULL));1631 poly a = p; poly b = q; BOOLEAN aCorrespondsToP = TRUE;1632 if (p_Deg(a, r) < p_Deg(b, r))1633 { a = q; b = p; aCorrespondsToP = FALSE; }1634 a = p_Copy(a, r); b = p_Copy(b, r);1635 poly aFactor = NULL; poly bFactor = NULL;1636 poly theGcd = p_ExtGcdHelper(a, aFactor, b, bFactor, r);1637 if (aCorrespondsToP) { pFactor = aFactor; qFactor = bFactor; }1638 else { pFactor = bFactor; qFactor = aFactor; }1639 return theGcd;1640 1529 } 1641 1530 -
libpolys/polys/monomials/p_polys.h
rdc79bd r20c540 1825 1825 int p_Weight(int c, const ring r); 1826 1826 1827 /* assumes that p and divisor are univariate polynomials in r, 1828 mentioning the same variable; 1829 assumes divisor != NULL; 1830 p may be NULL; 1831 assumes a global monomial ordering in r; 1832 performs polynomial division of p by divisor: 1833 - afterwards p contains the remainder of the division, i.e., 1834 p_before = result * divisor + p_afterwards; 1835 - if needResult == TRUE, then the method computes and returns 'result', 1836 otherwise NULL is returned (This parametrization can be used when 1837 one is only interested in the remainder of the division. In this 1838 case, the method will be slightly faster.) 1839 leaves divisor unmodified */ 1840 poly p_PolyDiv(poly &p, poly divisor, BOOLEAN needResult, ring r); 1841 1842 /* returns NULL if p == NULL, otherwise makes p monic by dividing 1843 by its leading coefficient (only done if this is not already 1); 1844 this assumes that we are over a ground field so that division 1845 is well-defined; 1846 modifies p */ 1847 void p_Monic(poly p, const 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 leaves p and q unmodified */ 1855 poly p_Gcd(poly p, poly q, ring r); 1856 1857 /* assumes that p and q are univariate polynomials in r, 1858 mentioning the same variable; 1859 assumes a global monomial ordering in r; 1860 assumes that not both p and q are NULL; 1861 returns the gcd of p and q; 1862 moreover, afterwards pFactor and qFactor contain appropriate 1863 factors such that gcd(p, q) = p * pFactor + q * qFactor; 1864 leaves p and q unmodified */ 1865 poly p_ExtGcd(poly p, poly &pFactor, poly q, poly &qFactor, ring r); 1827 /// assumes that p and divisor are univariate polynomials in r, 1828 /// mentioning the same variable; 1829 /// assumes divisor != NULL; 1830 /// p may be NULL; 1831 /// assumes a global monomial ordering in r; 1832 /// performs polynomial division of p by divisor: 1833 /// - afterwards p contains the remainder of the division, i.e., 1834 /// p_before = result * divisor + p_afterwards; 1835 /// - if needResult == TRUE, then the method computes and returns 'result', 1836 /// otherwise NULL is returned (This parametrization can be used when 1837 /// one is only interested in the remainder of the division. In this 1838 /// case, the method will be slightly faster.) 1839 /// leaves divisor unmodified 1840 poly p_PolyDiv(poly &p, const poly divisor, const BOOLEAN needResult, const ring r); 1866 1841 1867 1842 /* syszygy stuff */
Note: See TracChangeset
for help on using the changeset viewer.