Coverage for /usr/lib/python3/dist-packages/sympy/polys/domains/expressionrawdomain.py: 76%
33 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
1"""Implementation of :class:`ExpressionRawDomain` class. """
4from sympy.core import Expr, S, sympify, Add
5from sympy.polys.domains.characteristiczero import CharacteristicZero
6from sympy.polys.domains.field import Field
7from sympy.polys.domains.simpledomain import SimpleDomain
8from sympy.polys.polyerrors import CoercionFailed
9from sympy.utilities import public
12@public
13class ExpressionRawDomain(Field, CharacteristicZero, SimpleDomain):
14 """A class for arbitrary expressions but without automatic simplification. """
16 is_SymbolicRawDomain = is_EXRAW = True
18 dtype = Expr
20 zero = S.Zero
21 one = S.One
23 rep = 'EXRAW'
25 has_assoc_Ring = False
26 has_assoc_Field = True
28 def __init__(self):
29 pass
31 @classmethod
32 def new(self, a):
33 return sympify(a)
35 def to_sympy(self, a):
36 """Convert ``a`` to a SymPy object. """
37 return a
39 def from_sympy(self, a):
40 """Convert SymPy's expression to ``dtype``. """
41 if not isinstance(a, Expr):
42 raise CoercionFailed(f"Expecting an Expr instance but found: {type(a).__name__}")
43 return a
45 def convert_from(self, a, K):
46 """Convert a domain element from another domain to EXRAW"""
47 return K.to_sympy(a)
49 def get_field(self):
50 """Returns a field associated with ``self``. """
51 return self
53 def sum(self, items):
54 return Add(*items)
57EXRAW = ExpressionRawDomain()