Feat(Core): Multiply 2 MOpolynomial together

This commit is contained in:
Bertrand Benjamin 2018-11-23 11:59:07 +01:00
parent 55c0830671
commit 9e4edc09e3

View File

@ -423,7 +423,7 @@ def momonomial_momonomial(left, right):
@multiply.register((MOnumber, MOFraction, MOstr, MOstrPower, MOMonomial), \ @multiply.register((MOnumber, MOFraction, MOstr, MOstrPower, MOMonomial), \
MOpolynomial) MOpolynomial)
@special_case(multiply_filter) @special_case(multiply_filter)
def moscalar_mopolynomial(left, right): def lotsmo_mopolynomial(left, right):
""" Multiply a scalar and a MOMonomial """ Multiply a scalar and a MOMonomial
>>> a = MOnumber(2) >>> a = MOnumber(2)
@ -554,6 +554,62 @@ def moscalar_mopolynomial(left, right):
coefs = [Tree("*", left, monom) for monom in right.monomials.values()] coefs = [Tree("*", left, monom) for monom in right.monomials.values()]
return Tree.from_list("+", coefs) return Tree.from_list("+", coefs)
@multiply.register(MOpolynomial, MOpolynomial)
@special_case(multiply_filter)
def mopolynomial_mopolynomial(left, right):
""" Multiply 2 MOpolynomial
>>> a = MOpolynomial('x', [1, 2, 3])
>>> b = MOpolynomial('x', [4, 5])
>>> print(multiply(a, b))
+
> +
| > *
| | > 1
| | > 4
| > +
| | > *
| | | > 1
| | | > *
| | | | > 5
| | | | > x
| | > *
| | | > *
| | | | > 2
| | | | > x
| | | > 4
> +
| > *
| | > *
| | | > 2
| | | > x
| | > *
| | | > 5
| | | > x
| > +
| | > *
| | | > *
| | | | > 3
| | | | > ^
| | | | | > x
| | | | | > 2
| | | > 4
| | > *
| | | > *
| | | | > 3
| | | | > ^
| | | | | > x
| | | | | > 2
| | | > *
| | | | > 5
| | | | > x
"""
coefs = [Tree("*", l_monom, r_monom) \
for l_monom in left.monomials.values() \
for r_monom in right.monomials.values()]
return Tree.from_list("+", coefs)
# ----------------------------- # -----------------------------
# Reglages pour 'vim' # Reglages pour 'vim'