Changeset 69fb9d0 in git
- Timestamp:
- May 6, 2011, 4:06:31 PM (12 years ago)
- Branches:
- (u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
- Children:
- 3b0ba67abd225a2bb2c09c675cfe3085aaf67f12
- Parents:
- ba23594edc15991ab3d4bd71e011e4139bb72c92
- git-author:
- Frank Seelisch <seelisch@mathematik.uni-kl.de>2011-05-06 16:06:31+02:00
- git-committer:
- Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 12:31:38+01:00
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libpolys/polys/monomials/p_polys.cc
rba2359 r69fb9d0 1444 1444 one is only interested in the remainder of the division. In this 1445 1445 case, the method will be faster.) */ 1446 poly p_PolyDiv(poly * p, poly divisor, BOOLEAN needResult, ring r)1446 poly p_PolyDiv(poly * p, poly divisor, BOOLEAN needResult, ring r) 1447 1447 { 1448 1448 assume(divisor != NULL); 1449 1449 if (*p == NULL) return NULL; 1450 1450 1451 /* yet to be implemented by Frank S.; 1452 for the time being, this should at least compile */ 1453 return NULL; 1451 poly result = NULL; 1452 number divisorLT = p_GetCoeff(divisor, r); 1453 int divisorExp = p_GetExp(divisor, 1, r); 1454 while (p_Deg(*p, r) > p_Deg(divisor, r)) 1455 { 1456 /* determine t = LT(*p) / LT(divisor) */ 1457 poly t = p_ISet(1, r); 1458 number c = n_Div(p_GetCoeff(*p, r), divisorLT, r->cf); 1459 p_SetCoeff(t, c, r); 1460 int e = p_GetExp(*p, 1, r) - divisorExp; 1461 p_SetExp(t, 1, e, r); 1462 p_Setm(t, r); 1463 result = p_Add_q(result, p_Copy(t, r), r); 1464 *p = p_Add_q(*p, p_Neg(t, r), r); 1465 } 1466 n_Delete(&divisorLT, r->cf); 1467 return result; 1468 } 1469 1470 /* see p_Gcd; 1471 additional assumption: deg(*p) >= deg(*q); 1472 must destroy *p and *q (unless one of them is returned) */ 1473 poly p_GcdHelper(poly * p, poly * q, ring r) 1474 { 1475 if (q == NULL) return *p; 1476 else 1477 { 1478 p_PolyDiv(p, *q, FALSE, r); 1479 return p_GcdHelper(q, p, r); 1480 } 1454 1481 } 1455 1482 … … 1458 1485 assumes a global monomial ordering in r; 1459 1486 assumes that not both p and q are NULL; 1460 returns the gcd of p and q */ 1487 returns the gcd of p and q; 1488 leaves p and q unmodified */ 1461 1489 poly p_Gcd(poly p, poly q, ring r) 1462 1490 { 1463 1491 assume((p != NULL) || (q != NULL)); 1464 if (p == NULL) return q;1465 if (q == NULL) return p;1466 1492 1467 /* yet to be implemented by Frank S.; 1468 for the time being, this should at least compile */ 1469 return NULL; 1493 poly a = p; poly b = q; 1494 if (p_Deg(a, r) < p_Deg(b, r)) { a = q; b = p; } 1495 a = p_Copy(a, r); b = p_Copy(b, r); 1496 return p_GcdHelper(&a, &b, r); 1497 } 1498 1499 /* see p_ExtGcd; 1500 additional assumption: deg(*p) >= deg(*q); 1501 must destroy *p and *q (unless one of them is returned) */ 1502 poly p_ExtGcdHelper(poly * p, poly * pFactor, poly * q, poly * qFactor, 1503 ring r) 1504 { 1505 if (q == NULL) 1506 { 1507 *qFactor = NULL; *pFactor = p_ISet(1, r); return *p; 1508 } 1509 else 1510 { 1511 poly pDivQ = p_PolyDiv(p, *q, TRUE, r); 1512 poly * ppFactor; poly * qqFactor; 1513 poly theGcd = p_ExtGcdHelper(q, ppFactor, p, qqFactor, r); 1514 pFactor = qqFactor; 1515 *qFactor = p_Add_q(*ppFactor, 1516 p_Neg(p_Mult_q(fDivG, p_Copy(*qqFactor, r), r), r), 1517 r); 1518 return theGcd; 1519 } 1470 1520 } 1471 1521 … … 1476 1526 returns the gcd of p and q; 1477 1527 moreover, afterwards *pFactor and *qFactor contain appropriate 1478 factors such that gcd(p, q) = p * (*pFactor) + q * (*qFactor) */ 1479 poly p_ExtGcd(poly p, poly *pFactor, poly q, poly *qFactor, ring r) 1528 factors such that gcd(p, q) = p * (*pFactor) + q * (*qFactor); 1529 leaves p and q unmodified */ 1530 poly p_ExtGcd(poly p, poly * pFactor, poly q, poly * qFactor, ring r) 1480 1531 { 1481 1532 assume((p != NULL) || (q != NULL)); 1482 if (p == NULL) { *pFactor = NULL; *qFactor = p_ISet(1, r); return q; };1483 if (q == NULL) { *qFactor = NULL; *pFactor = p_ISet(1, r); return p; };1484 1533 1485 /* yet to be implemented by Frank S.; 1486 for the time being, this should at least compile */ 1487 return NULL; 1534 poly a = p; poly b = q; 1535 poly * aFactor = pFactor; poly * bFactor = qFactor; 1536 if (p_Deg(a, r) < p_Deg(b, r)) 1537 { a = q; b = p; aFactor = qFactor, bFactor = pFactor; } 1538 a = p_Copy(a, r); b = p_Copy(b, r); 1539 return p_ExtGcdHelper(&a, aFactor, &b, bFactor, r); 1488 1540 } 1489 1541
Note: See TracChangeset
for help on using the changeset viewer.