From 8f99d1e71e668b87e962ee4487328c6eaaef087a Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Fri, 23 Nov 2018 10:05:36 +0100 Subject: [PATCH] Feat(Core): Add signature to mos --- mapytex/calculus/core/MO/mo.py | 16 ++++++++++++++++ mapytex/calculus/core/MO/monomial.py | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/mapytex/calculus/core/MO/mo.py b/mapytex/calculus/core/MO/mo.py index 08340e9..ad3c9a1 100644 --- a/mapytex/calculus/core/MO/mo.py +++ b/mapytex/calculus/core/MO/mo.py @@ -46,6 +46,7 @@ class MO(object): :attr value: sympy compatible version of the MO :attr _tree: tree version of the MO + :attr _signature: Name to identify the MO in the API """ @@ -67,6 +68,7 @@ class MO(object): self._tree = value self.is_scalar = True + self._signature = None @classmethod def factory(cls, value): @@ -128,6 +130,18 @@ class MO(object): except AttributeError: return self._tree == other + @property + def signature(self): + """ Name of the mo in the API + + :example: + >>> MOnumber(3).signature + 'scalar' + >>> MOstr("x").signature + 'monome1' + """ + return self._signature + @total_ordering class MOnumber(MO): @@ -168,6 +182,7 @@ class MOnumber(MO): raise MOError("The value of an MOnumber need to be a int, a float or a Decimal") self.value = self._tree + self._signature = "scalar" @property def __txt__(self): @@ -234,6 +249,7 @@ class MOstr(MO): MO.__init__(self, val) self.is_scalar = False self._variable = val + self._signature = "monome1" @property def variable(self): diff --git a/mapytex/calculus/core/MO/monomial.py b/mapytex/calculus/core/MO/monomial.py index 2f00168..26b9836 100644 --- a/mapytex/calculus/core/MO/monomial.py +++ b/mapytex/calculus/core/MO/monomial.py @@ -74,6 +74,18 @@ class MOstrPower(MO): def power(self): return self._power + @property + def signature(self): + """ Name of the mo in the API + + :example: + >>> MOstrPower("x", 3).signature + 'monome3' + >>> MOstrPower("x", 2).signature + 'monome2' + """ + return f"monome{self.power}" + class MOMonomial(MO): """ Monomial math object""" @@ -151,6 +163,18 @@ class MOMonomial(MO): def power(self): return self._power + @property + def signature(self): + """ Name of the mo in the API + + :example: + >>> MOMonomial(2, "x").signature + 'monome1' + >>> MOMonomial(4, "x", 2).signature + 'monome2' + """ + return f"monome{self.power}" + # ----------------------------- # Reglages pour 'vim' # vim:set autoindent expandtab tabstop=4 shiftwidth=4: