<commit_before>""" Defines default methods for unary and binary operations.
"""

from basic import Basic, S
from sympify import sympify, SympifyError, _sympifyit
#from add import Add    /cyclic/
#from mul import Mul    /cyclic/
#from pow import Pow    /cyclic/
#from relational import Equality, Unequality, Inequality, StrictInequality /cyclic/
#from sympy.functions.elementary.complexes import abs as abs_   /cyclic/

def _no_unary_operation(op, obj):
    return 'unary operation `%s` not defined for %s' % (op, obj.__class__.__name__)
def _no_binary_operation(op, obj1, obj2):
    return 'binary operation `%s` not defined between %s and %s' \
           % (op, obj1.__class__.__name__, obj2.__class__.__name__)

class ArithMeths(object):

    def __pos__(self):
        return self
    def __neg__(self):
        return S.NegativeOne * self
    def __abs__(self):
        return abs_(self)

    @_sympifyit('other', NotImplemented)
    def __add__(self, other):
        return Add(self, other)
    @_sympifyit('other', NotImplemented)
    def __radd__(self, other):
        return Add(other, self)

    @_sympifyit('other', NotImplemented)
    def __sub__(self, other):
        return Add(self, -other)
    @_sympifyit('other', NotImplemented)
    def __rsub__(self, other):
        return Add(other, -self)

    @_sympifyit('other', NotImplemented)
    def __mul__(self, other):
        # FIXME this is a dirty hack. matrix should be ordinary SymPy object
        from sympy.matrices import Matrix
        if isinstance(other, Matrix): return NotImplemented
        return Mul(self, other)
    @_sympifyit('other', NotImplemented)
    def __rmul__(self, other):
        return Mul(other, self)

    @_sympifyit('other', NotImplemented)
    def __pow__(self, other):
        return Pow(self, other)
    @_sympifyit('other', NotImplemented)
    def __rpow__(self, other):
        return Pow(other, self)

    @_sympifyit('other', NotImplemented)
    def __div__(self, other):
        return self * (other ** S.NegativeOne)
    @_sympifyit('other', NotImplemented)
    def __rdiv__(self, other):
        return other * (self ** S.NegativeOne)

    __truediv__ = __div__
    __rtruediv__ = __rdiv__

class NoArithMeths(object):
    
    def __pos__(self):
        raise TypeError, _no_unary_operation('+', self)
    def __neg__(self):
        raise TypeError, _no_unary_operation('-', self)
    def __add__(self, other):
        raise TypeError, _no_binary_operation('+', self, other)
    def __radd__(self, other):
        raise TypeError, _no_binary_operation('+', other, self)
    def __sub__(self, other):
        raise TypeError, _no_binary_operation('-', self, other)
    def __rsub__(self, other):
        raise TypeError, _no_binary_operation('-', other, self)
    def __mul__(self, other):
        raise TypeError, _no_binary_operation('*', self, other)
    def __rmul__(self, other):
        raise TypeError, _no_binary_operation('*', other, self)
    def __div__(self, other):
        raise TypeError, _no_binary_operation('/', self, other)
    def __rdiv__(self, other):
        raise TypeError, _no_binary_operation('/', other, self)
    def __pow__(self, other):
        raise TypeError, _no_binary_operation('**', self, other)
    def __rpow__(self, other):
        raise TypeError, _no_binary_operation('**', other, self)
    def _eval_power(self, other):
        return None

class RelMeths(object):
    
    def __eq__(self, other):
        try:
            other = sympify(other)
        except ValueError:
            return False
        return Equality(self, other)
    def __ne__(self, other):
        try:
            other = sympify(other)
        except ValueError:
            return True
        return Unequality(self, other)
    def __lt__(self, other):
        #return sympify(other) > self
        return StrictInequality(self, other)
    def __gt__(self, other):
        return StrictInequality(other, self)
        #return sympify(other) < self
    def __le__(self, other):
        return Inequality(self, other)
    def __ge__(self, other):
        return sympify(other) <= self

class NoRelMeths(object):

    def __eq__(self, other):
        return Equality(self, other)
    def __ne__(self, other):
        return Unequality(self, other)
    def __lt__(self, other):
        return hash(self) < hash(other)
        raise TypeError, _no_binary_operation('<', self, other)
    def __gt__(self, other):
        return hash(self) > hash(other)
        raise TypeError, _no_binary_operation('>', self, other)
    def __le__(self, other):
        raise TypeError, _no_binary_operation('<=', self, other)
    def __ge__(self, other):
        raise TypeError, _no_binary_operation('>=', self, other)<commit_msg>[4/7] _sympifyit -- fast decorator to _sympify(arg)<commit_after>""" Defines default methods for unary and binary operations.
"""

from basic import Basic, S
from sympify import sympify, SympifyError, _sympifyit
#from add import Add    /cyclic/
#from mul import Mul    /cyclic/
#from pow import Pow    /cyclic/
#from relational import Equality, Unequality, Inequality, StrictInequality /cyclic/
#from sympy.functions.elementary.complexes import abs as abs_   /cyclic/

def _no_unary_operation(op, obj):
    return 'unary operation `%s` not defined for %s' % (op, obj.__class__.__name__)
def _no_binary_operation(op, obj1, obj2):
    return 'binary operation `%s` not defined between %s and %s' \
           % (op, obj1.__class__.__name__, obj2.__class__.__name__)

class ArithMeths(object):

    def __pos__(self):
        return self
    def __neg__(self):
        return S.NegativeOne * self
    def __abs__(self):
        return abs_(self)

    @_sympifyit('other', NotImplemented)
    def __add__(self, other):
        return Add(self, other)
    @_sympifyit('other', NotImplemented)
    def __radd__(self, other):
        return Add(other, self)

    @_sympifyit('other', NotImplemented)
    def __sub__(self, other):
        return Add(self, -other)
    @_sympifyit('other', NotImplemented)
    def __rsub__(self, other):
        return Add(other, -self)

    @_sympifyit('other', NotImplemented)
    def __mul__(self, other):
        # FIXME this is a dirty hack. matrix should be ordinary SymPy object
        from sympy.matrices import Matrix
        if isinstance(other, Matrix): return NotImplemented
        return Mul(self, other)
    @_sympifyit('other', NotImplemented)
    def __rmul__(self, other):
        return Mul(other, self)

    @_sympifyit('other', NotImplemented)
    def __pow__(self, other):
        return Pow(self, other)
    @_sympifyit('other', NotImplemented)
    def __rpow__(self, other):
        return Pow(other, self)

    @_sympifyit('other', NotImplemented)
    def __div__(self, other):
        return self * (other ** S.NegativeOne)
    @_sympifyit('other', NotImplemented)
    def __rdiv__(self, other):
        return other * (self ** S.NegativeOne)

    __truediv__ = __div__
    __rtruediv__ = __rdiv__

class NoArithMeths(object):
    
    def __pos__(self):
        raise TypeError, _no_unary_operation('+', self)
    def __neg__(self):
        raise TypeError, _no_unary_operation('-', self)
    def __add__(self, other):
        raise TypeError, _no_binary_operation('+', self, other)
    def __radd__(self, other):
        raise TypeError, _no_binary_operation('+', other, self)
    def __sub__(self, other):
        raise TypeError, _no_binary_operation('-', self, other)
    def __rsub__(self, other):
        raise TypeError, _no_binary_operation('-', other, self)
    def __mul__(self, other):
        raise TypeError, _no_binary_operation('*', self, other)
    def __rmul__(self, other):
        raise TypeError, _no_binary_operation('*', other, self)
    def __div__(self, other):
        raise TypeError, _no_binary_operation('/', self, other)
    def __rdiv__(self, other):
        raise TypeError, _no_binary_operation('/', other, self)
    def __pow__(self, other):
        raise TypeError, _no_binary_operation('**', self, other)
    def __rpow__(self, other):
        raise TypeError, _no_binary_operation('**', other, self)
    def _eval_power(self, other):
        return None

class RelMeths(object):
    
    # TODO rewrte to directly return True/False

    @_sympifyit('other', False) # sympy != other
    def __eq__(self, other):
        return Equality(self, other)

    @_sympifyit('other', True)  # sympy != other
    def __ne__(self, other):
        return Unequality(self, other)

    @_sympifyit('other', False) # sympy >  other
    def __lt__(self, other):
        #return sympify(other) > self
        return StrictInequality(self, other)

    @_sympifyit('other', True)  # sympy >  other
    def __gt__(self, other):
        return StrictInequality(other, self)
        #return sympify(other) < self

    @_sympifyit('other', False) # sympy >  other
    def __le__(self, other):
        return Inequality(self, other)

    @_sympifyit('other', True)  # sympy >  other
    def __ge__(self, other):
        return sympify(other) <= self

class NoRelMeths(object):

    def __eq__(self, other):
        return Equality(self, other)
    def __ne__(self, other):
        return Unequality(self, other)
    def __lt__(self, other):
        return hash(self) < hash(other)
        raise TypeError, _no_binary_operation('<', self, other)
    def __gt__(self, other):
        return hash(self) > hash(other)
        raise TypeError, _no_binary_operation('>', self, other)
    def __le__(self, other):
        raise TypeError, _no_binary_operation('<=', self, other)
    def __ge__(self, other):
        raise TypeError, _no_binary_operation('>=', self, other)
{'fraction_non_alphanumeric': 0.11366221946426724, 'fraction_numerical': 0.001034233116144379, 'mean_word_length': 3.1843357853742966, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4972817', 'n_tokens_mistral': 3094, 'n_tokens_neox': 3046, 'n_words': 842}