Feat(Core): add coefficients property to MOstr, MOstrPower, MOMonomial

This commit is contained in:
Bertrand Benjamin 2018-12-07 15:09:39 +01:00
parent bcf589c607
commit cad6cd7182
2 changed files with 38 additions and 0 deletions

View File

@ -255,6 +255,19 @@ class MOstr(MO):
def variable(self): def variable(self):
return self._variable return self._variable
@property
def coefficients(self):
""" Dictionnary of coefficients
:example:
>>> p = MOstr("x")
>>> p.coefficients
{1: <MOnumber 1>}
"""
return {1: MOnumber(1)}
# ----------------------------- # -----------------------------
# Reglages pour 'vim' # Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4: # vim:set autoindent expandtab tabstop=4 shiftwidth=4:

View File

@ -66,6 +66,19 @@ class MOstrPower(MO):
MO.__init__(self, _tree) MO.__init__(self, _tree)
@property
def coefficients(self):
""" Dictionnary of coefficients
:example:
>>> p = MOstrPower("x", 2)
>>> p.coefficients
{2: <MOnumber 1>}
"""
return {self.power.value: MOnumber(1)}
@property @property
def variable(self): def variable(self):
return self._variable return self._variable
@ -150,6 +163,18 @@ class MOMonomial(MO):
def coefficient(self): def coefficient(self):
return self._coefficient return self._coefficient
@property
def coefficients(self):
""" Dictionnary of coefficients
:example:
>>> p = MOMonomial(3, "x", 2)
>>> p.coefficients
{2: <MOnumber 3>}
"""
return {self.power.value: self._coefficient}
@property @property
def strpower(self): def strpower(self):
if self._power == 1: if self._power == 1: