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

1"""Implementation of :class:`ExpressionRawDomain` class. """ 

2 

3 

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 

10 

11 

12@public 

13class ExpressionRawDomain(Field, CharacteristicZero, SimpleDomain): 

14 """A class for arbitrary expressions but without automatic simplification. """ 

15 

16 is_SymbolicRawDomain = is_EXRAW = True 

17 

18 dtype = Expr 

19 

20 zero = S.Zero 

21 one = S.One 

22 

23 rep = 'EXRAW' 

24 

25 has_assoc_Ring = False 

26 has_assoc_Field = True 

27 

28 def __init__(self): 

29 pass 

30 

31 @classmethod 

32 def new(self, a): 

33 return sympify(a) 

34 

35 def to_sympy(self, a): 

36 """Convert ``a`` to a SymPy object. """ 

37 return a 

38 

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 

44 

45 def convert_from(self, a, K): 

46 """Convert a domain element from another domain to EXRAW""" 

47 return K.to_sympy(a) 

48 

49 def get_field(self): 

50 """Returns a field associated with ``self``. """ 

51 return self 

52 

53 def sum(self, items): 

54 return Add(*items) 

55 

56 

57EXRAW = ExpressionRawDomain()