Révision 307 pobysoPythonSage/src/pobyso.py
pobyso.py (revision 307) | ||
---|---|---|
1453 | 1453 |
def pobyso_is_poly_sa_sa(objectSa): |
1454 | 1454 |
""" |
1455 | 1455 |
Check if an object is a polynomial. |
1456 |
We consider 3 kinds of polynomials: |
|
1457 |
- symbolicExpressions that are polynomials; |
|
1458 |
- callable symbolicExpression that are polynomials; |
|
1459 |
- polynomials over a ring. |
|
1456 | 1460 |
""" |
1461 |
# We consider a constant as a polynomial. All 3 kinds of polynomials |
|
1462 |
# have the is_constant() method. |
|
1457 | 1463 |
try: |
1458 |
coefficientsListSa = objectSa |
|
1459 |
if len(objectSa.coefficients()) < 0: |
|
1464 |
if objectSa.is_constant(): |
|
1465 |
return True |
|
1466 |
except AttributeError: |
|
1467 |
return False |
|
1468 |
# All 3 kinds of polynomials have the args() method. |
|
1469 |
# A polynomial has at least one argument. |
|
1470 |
# We catch the TypeError in case the return value of args() has |
|
1471 |
# no __getitem__ method. |
|
1472 |
try: |
|
1473 |
argument = objectSa.args()[0] |
|
1474 |
except (AttributeError, TypeError): |
|
1475 |
return False |
|
1476 |
# The 2 first kinds have a is_polynomial() method that returns True |
|
1477 |
try: |
|
1478 |
if not objectSa.is_polynomial(argument): |
|
1460 | 1479 |
return False |
1461 | 1480 |
except AttributeError: |
1462 |
return False |
|
1481 |
try: |
|
1482 |
objectSa.polynomial(argument) |
|
1483 |
except AttributeError: |
|
1484 |
return False |
|
1463 | 1485 |
return True |
1464 | 1486 |
# End pobyso_is_poly_sa_sa |
1465 | 1487 |
|
Formats disponibles : Unified diff