domainelement.py 840 B

123456789101112131415161718192021222324252627282930313233343536
  1. """Trait for implementing domain elements. """
  2. from sympy.utilities import public
  3. @public
  4. class DomainElement:
  5. """
  6. Represents an element of a domain.
  7. Mix in this trait into a class whose instances should be recognized as
  8. elements of a domain. Method ``parent()`` gives that domain.
  9. """
  10. def parent(self):
  11. """Get the domain associated with ``self``
  12. Examples
  13. ========
  14. >>> from sympy import ZZ, symbols
  15. >>> x, y = symbols('x, y')
  16. >>> K = ZZ[x,y]
  17. >>> p = K(x)**2 + K(y)**2
  18. >>> p
  19. x**2 + y**2
  20. >>> p.parent()
  21. ZZ[x,y]
  22. Notes
  23. =====
  24. This is used by :py:meth:`~.Domain.convert` to identify the domain
  25. associated with a domain element.
  26. """
  27. raise NotImplementedError("abstract method")