exceptions.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """Special exception classes for numberfields. """
  2. class ClosureFailure(Exception):
  3. r"""
  4. Signals that a :py:class:`ModuleElement` which we tried to represent in a
  5. certain :py:class:`Module` cannot in fact be represented there.
  6. Examples
  7. ========
  8. >>> from sympy.polys import Poly, cyclotomic_poly, ZZ
  9. >>> from sympy.polys.matrices import DomainMatrix
  10. >>> from sympy.polys.numberfields.modules import PowerBasis, to_col
  11. >>> T = Poly(cyclotomic_poly(5))
  12. >>> A = PowerBasis(T)
  13. >>> B = A.submodule_from_matrix(2 * DomainMatrix.eye(4, ZZ))
  14. Because we are in a cyclotomic field, the power basis ``A`` is an integral
  15. basis, and the submodule ``B`` is just the ideal $(2)$. Therefore ``B`` can
  16. represent an element having all even coefficients over the power basis:
  17. >>> a1 = A(to_col([2, 4, 6, 8]))
  18. >>> print(B.represent(a1))
  19. DomainMatrix([[1], [2], [3], [4]], (4, 1), ZZ)
  20. but ``B`` cannot represent an element with an odd coefficient:
  21. >>> a2 = A(to_col([1, 2, 2, 2]))
  22. >>> B.represent(a2)
  23. Traceback (most recent call last):
  24. ...
  25. ClosureFailure: Element in QQ-span but not ZZ-span of this basis.
  26. """
  27. pass
  28. class StructureError(Exception):
  29. r"""
  30. Represents cases in which an algebraic structure was expected to have a
  31. certain property, or be of a certain type, but was not.
  32. """
  33. pass
  34. class MissingUnityError(StructureError):
  35. r"""Structure should contain a unity element but does not."""
  36. pass
  37. __all__ = [
  38. 'ClosureFailure', 'StructureError', 'MissingUnityError',
  39. ]