domainelement.py 860 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. __slots__ = ()
  11. def parent(self):
  12. """Get the domain associated with ``self``
  13. Examples
  14. ========
  15. >>> from sympy import ZZ, symbols
  16. >>> x, y = symbols('x, y')
  17. >>> K = ZZ[x,y]
  18. >>> p = K(x)**2 + K(y)**2
  19. >>> p
  20. x**2 + y**2
  21. >>> p.parent()
  22. ZZ[x,y]
  23. Notes
  24. =====
  25. This is used by :py:meth:`~.Domain.convert` to identify the domain
  26. associated with a domain element.
  27. """
  28. raise NotImplementedError("abstract method")