Feat: dirty sub (repeatition in explain)
This commit is contained in:
parent
510f6a1fa2
commit
1dccaabd86
@ -97,6 +97,10 @@ class Token(object):
|
||||
_other = factory(Expression(moify(other)))
|
||||
else:
|
||||
_other = other
|
||||
|
||||
if operation == '-':
|
||||
tree = Tree("+", self._mo, Tree("-", None, _other._mo))
|
||||
else:
|
||||
tree = Tree(operation, self._mo, _other._mo)
|
||||
return Expression(tree).simplify()
|
||||
|
||||
@ -143,6 +147,32 @@ class Token(object):
|
||||
"""
|
||||
return self._operate(other, "+")
|
||||
|
||||
def __sub__(self, other):
|
||||
""" Subing 2 Tokens or a Token and a Expression
|
||||
|
||||
:example:
|
||||
>>> from .number import Integer
|
||||
>>> a = Integer(3)
|
||||
>>> b = Integer(7)
|
||||
>>> c = a - b
|
||||
>>> c
|
||||
<Integer - 4>
|
||||
>>> for i in c.explain():
|
||||
... print(i)
|
||||
3 - 7
|
||||
3 - 7
|
||||
- 4
|
||||
>>> a = Integer(3)
|
||||
>>> c = a - 7
|
||||
>>> c
|
||||
<Integer - 4>
|
||||
>>> a = Integer(3)
|
||||
>>> c = a - "x"
|
||||
>>> c
|
||||
<Linear 3 - x>
|
||||
"""
|
||||
return self._operate(other, "-")
|
||||
|
||||
def __mul__(self, other):
|
||||
""" Multiply 2 Tokens or a Token and a Expression
|
||||
|
||||
@ -222,6 +252,9 @@ class Token(object):
|
||||
_other = factory(Expression(moify(other)))
|
||||
else:
|
||||
_other = other
|
||||
if operation == '-':
|
||||
tree = Tree("+", _other._mo, Tree("-", None, self._mo))
|
||||
else:
|
||||
tree = Tree(operation, _other._mo, self._mo)
|
||||
return Expression(tree).simplify()
|
||||
|
||||
@ -240,6 +273,21 @@ class Token(object):
|
||||
"""
|
||||
return self._roperate(other, "+")
|
||||
|
||||
def __rsub__(self, other):
|
||||
""" Subing 2 Tokens or a Token and a Expression
|
||||
|
||||
:example:
|
||||
>>> from .number import Integer
|
||||
>>> a = Integer(3)
|
||||
>>> c = 7 - a
|
||||
>>> c
|
||||
<Integer 4>
|
||||
>>> a = Integer(3)
|
||||
>>> c = "x" - a
|
||||
>>> c
|
||||
<Linear x - 3>
|
||||
"""
|
||||
return self._roperate(other, "-")
|
||||
def __rmul__(self, other):
|
||||
""" Multiply 2 Tokens or a Token and a Expression
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user