expressionrawdomain.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """Implementation of :class:`ExpressionRawDomain` class. """
  2. from sympy.core import Expr, S, sympify, Add
  3. from sympy.polys.domains.characteristiczero import CharacteristicZero
  4. from sympy.polys.domains.field import Field
  5. from sympy.polys.domains.simpledomain import SimpleDomain
  6. from sympy.polys.polyerrors import CoercionFailed
  7. from sympy.utilities import public
  8. @public
  9. class ExpressionRawDomain(Field, CharacteristicZero, SimpleDomain):
  10. """A class for arbitrary expressions but without automatic simplification. """
  11. is_SymbolicRawDomain = is_EXRAW = True
  12. dtype = Expr
  13. zero = S.Zero
  14. one = S.One
  15. rep = 'EXRAW'
  16. has_assoc_Ring = False
  17. has_assoc_Field = True
  18. def __init__(self):
  19. pass
  20. @classmethod
  21. def new(self, a):
  22. return sympify(a)
  23. def to_sympy(self, a):
  24. """Convert ``a`` to a SymPy object. """
  25. return a
  26. def from_sympy(self, a):
  27. """Convert SymPy's expression to ``dtype``. """
  28. if not isinstance(a, Expr):
  29. raise CoercionFailed(f"Expecting an Expr instance but found: {type(a).__name__}")
  30. return a
  31. def convert_from(self, a, K):
  32. """Convert a domain element from another domain to EXRAW"""
  33. return K.to_sympy(a)
  34. def get_field(self):
  35. """Returns a field associated with ``self``. """
  36. return self
  37. def sum(self, items):
  38. return Add(*items)
  39. EXRAW = ExpressionRawDomain()