File size: 1,448 Bytes
6a86ad5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Implementation of :class:`ExpressionRawDomain` class. """


from sympy.core import Expr, S, sympify, Add
from sympy.polys.domains.characteristiczero import CharacteristicZero
from sympy.polys.domains.field import Field
from sympy.polys.domains.simpledomain import SimpleDomain
from sympy.polys.polyerrors import CoercionFailed
from sympy.utilities import public


@public
class ExpressionRawDomain(Field, CharacteristicZero, SimpleDomain):
    """A class for arbitrary expressions but without automatic simplification. """

    is_SymbolicRawDomain = is_EXRAW = True

    dtype = Expr

    zero = S.Zero
    one = S.One

    rep = 'EXRAW'

    has_assoc_Ring = False
    has_assoc_Field = True

    def __init__(self):
        pass

    @classmethod
    def new(self, a):
        return sympify(a)

    def to_sympy(self, a):
        """Convert ``a`` to a SymPy object. """
        return a

    def from_sympy(self, a):
        """Convert SymPy's expression to ``dtype``. """
        if not isinstance(a, Expr):
            raise CoercionFailed(f"Expecting an Expr instance but found: {type(a).__name__}")
        return a

    def convert_from(self, a, K):
        """Convert a domain element from another domain to EXRAW"""
        return K.to_sympy(a)

    def get_field(self):
        """Returns a field associated with ``self``. """
        return self

    def sum(self, items):
        return Add(*items)


EXRAW = ExpressionRawDomain()