2
from sympy.multipledispatch import dispatch
4
__all__ = ["SingletonInt"]
7
class SingletonInt(sympy.AtomicExpr):
12
def __new__(cls, *args, coeff=None, **kwargs):
13
instance = super().__new__(cls, *args, **kwargs)
18
def __init__(self, val, *, coeff=1):
24
def _eval_Eq(self, other):
26
isinstance(other, SingletonInt)
27
and other._val == self._val
28
and self._coeff == other._coeff
37
def free_symbols(self):
40
def __mul__(self, other):
41
if isinstance(other, SingletonInt):
43
"SingletonInt cannot be multiplied by another SingletonInt"
45
return SingletonInt(self._val, coeff=self._coeff * other)
47
def __rmul__(self, other):
48
if isinstance(other, SingletonInt):
50
"SingletonInt cannot be multiplied by another SingletonInt"
52
return SingletonInt(self._val, coeff=self._coeff * other)
56
def __add__(self, other):
57
raise NotImplementedError("NYI")
59
def __sub__(self, other):
60
raise NotImplementedError("NYI")
62
def __truediv__(self, other):
63
raise NotImplementedError("NYI")
65
def __floordiv__(self, other):
66
raise NotImplementedError("NYI")
68
def __mod__(self, other):
69
raise NotImplementedError("NYI")
73
@dispatch(sympy.Integer, SingletonInt)
77
raise ValueError("Symbolic SingletonInt: Relation is indeterminate")
80
@dispatch(SingletonInt, sympy.Integer)
84
raise ValueError("Symbolic SingletonInt: Relation is indeterminate")
87
@dispatch(SingletonInt, SingletonInt)
90
if a._coeff >= b._coeff:
94
raise ValueError("Symbolic SingletonInt: Relation is indeterminate")