diff --git a/mapytex/calculus/core/compute/multiply.py b/mapytex/calculus/core/compute/multiply.py index 2fc572c..8ba3da4 100644 --- a/mapytex/calculus/core/compute/multiply.py +++ b/mapytex/calculus/core/compute/multiply.py @@ -15,6 +15,7 @@ from ..tree import Tree from ..MO.mo import MO, MOnumber, MOstr from ..MO.fraction import MOFraction from ..MO.monomial import MOstrPower, MOMonomial +from ..MO.polynomial import MOpolynomial from .filters import special_case multiply_doc = """ Multiply MOs @@ -419,6 +420,141 @@ def momonomial_momonomial(left, right): coefs = Tree("*", left.coefficient, right.coefficient) return Tree("*", coefs, monome) +@multiply.register((MOnumber, MOFraction, MOstr, MOstrPower, MOMonomial), \ + MOpolynomial) +@special_case(multiply_filter) +def moscalar_mopolynomial(left, right): + """ Multiply a scalar and a MOMonomial + + >>> a = MOnumber(2) + >>> b = MOpolynomial('x', [1, 2, 3]) + >>> print(multiply(a, b)) + + + > * + | > 2 + | > 1 + > + + | > * + | | > 2 + | | > * + | | | > 2 + | | | > x + | > * + | | > 2 + | | > * + | | | > 3 + | | | > ^ + | | | | > x + | | | | > 2 + >>> a = MOFraction(1, 5) + >>> b = MOpolynomial('x', [1, 2, 3]) + >>> print(multiply(a, b)) + + + > * + | > / + | | > 1 + | | > 5 + | > 1 + > + + | > * + | | > / + | | | > 1 + | | | > 5 + | | > * + | | | > 2 + | | | > x + | > * + | | > / + | | | > 1 + | | | > 5 + | | > * + | | | > 3 + | | | > ^ + | | | | > x + | | | | > 2 + >>> a = MOstr("x") + >>> b = MOpolynomial('x', [1, 2, 3]) + >>> print(multiply(a, b)) + + + > * + | > x + | > 1 + > + + | > * + | | > x + | | > * + | | | > 2 + | | | > x + | > * + | | > x + | | > * + | | | > 3 + | | | > ^ + | | | | > x + | | | | > 2 + >>> a = MOstrPower("x", 2) + >>> b = MOpolynomial('x', [1, 2, 3]) + >>> print(multiply(a, b)) + + + > * + | > ^ + | | > x + | | > 2 + | > 1 + > + + | > * + | | > ^ + | | | > x + | | | > 2 + | | > * + | | | > 2 + | | | > x + | > * + | | > ^ + | | | > x + | | | > 2 + | | > * + | | | > 3 + | | | > ^ + | | | | > x + | | | | > 2 + >>> a = MOMonomial(3, "x", 2) + >>> b = MOpolynomial('x', [1, 2, 3]) + >>> print(multiply(a, b)) + + + > * + | > * + | | > 3 + | | > ^ + | | | > x + | | | > 2 + | > 1 + > + + | > * + | | > * + | | | > 3 + | | | > ^ + | | | | > x + | | | | > 2 + | | > * + | | | > 2 + | | | > x + | > * + | | > * + | | | > 3 + | | | > ^ + | | | | > x + | | | | > 2 + | | > * + | | | > 3 + | | | > ^ + | | | | > x + | | | | > 2 + """ + coefs = [Tree("*", left, monom) for monom in right.monomials.values()] + return Tree.from_list("+", coefs) + + # ----------------------------- # Reglages pour 'vim' # vim:set autoindent expandtab tabstop=4 shiftwidth=4: