Skip to content

Commit

Permalink
Implement __neg__, __sub__, __rsub__, __isub__, __pos__
Browse files Browse the repository at this point in the history
  • Loading branch information
yalishanda42 committed Mar 18, 2020
1 parent 6fb3e3e commit e178371
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions polynomial/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,29 @@ def __imul__(self, other):
self._vector = result._vector
return self

def __pos__(self):
"""Return +self."""
return self

def __neg__(self):
"""Return -self."""
result_vector = list(map(lambda k: -k, self._vector))
return Polynomial(result_vector[::-1])

def __sub__(self, other):
"""Return self - other."""
return self + (-other)

def __rsub__(self, other):
"""Return other - self."""
return other + (-self)

def __isub__(self, other):
"""Implement self -= other."""
result = self - other
self._vector = result._vector
return self


class Monomial(Polynomial):
"""Implements a single-variable monomial. A single-term polynomial."""
Expand Down

0 comments on commit e178371

Please sign in to comment.