From 0faaf481ca8a1ac8a958aa7576e6eaf69d27d62e Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Mon, 15 Jul 2019 09:57:19 +0200 Subject: [PATCH] Feat: start working on eval for polynoms --- mapytex/calculus/API/tokens/polynomial.py | 27 +++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/mapytex/calculus/API/tokens/polynomial.py b/mapytex/calculus/API/tokens/polynomial.py index 72070f1..4252e7e 100644 --- a/mapytex/calculus/API/tokens/polynomial.py +++ b/mapytex/calculus/API/tokens/polynomial.py @@ -18,7 +18,13 @@ __all__ = ["Polynomial", "Quadratic", "Linear"] class Polynomial(Token): - """ Token representing a polynomial """ + """ Token representing a polynomial + + :examples: + >>> from ...core.MO.polynomial import MOpolynomial + >>> P = Polynomial(MOpolynomial('x', [1, 2, 3])) + >>> P + """ def __init__(self, a, name="", ancestor=None): if not isinstance(a, MO): @@ -50,7 +56,13 @@ class Polynomial(Token): pass def __call__(self, value): - """ Call a Polynomial to evaluate itself on value """ + """ Call a Polynomial to evaluate itself on value + + :examples: + >>> from ...core.MO.polynomial import MOpolynomial + >>> P = Polynomial(MOpolynomial('x', [1, 2, 3])) + >>> P(2) + """ pass @@ -82,6 +94,17 @@ class Quadratic(Polynomial): raise NotImplemented +def extract_variable(leaf): + try: + return leaf.variable + except AttributeError: + return None + +def replace(leaf, origin, dest): + # map_on_leaf sur leaf? + if leaf == origin: + return dest + return leaf # ----------------------------- # Reglages pour 'vim' # vim:set autoindent expandtab tabstop=4 shiftwidth=4: