Feat(Compute): Compute with monomials is done
This commit is contained in:
parent
b23d83b9da
commit
a79ffb0cf9
@ -717,6 +717,113 @@ def mopolynomial_mopolynomial(left, right):
|
|||||||
|
|
||||||
return Tree.from_list("+", list(merge_monomials.values())[::-1])
|
return Tree.from_list("+", list(merge_monomials.values())[::-1])
|
||||||
|
|
||||||
|
@add.register(MOstr, MOMonomial)
|
||||||
|
@special_case(add_filter)
|
||||||
|
def mostr_momonomial(left, right):
|
||||||
|
""" Add a str to a Monomial
|
||||||
|
|
||||||
|
:example:
|
||||||
|
>>> a = MOstr("x")
|
||||||
|
>>> b = MOMonomial(2, "x")
|
||||||
|
>>> print(add(a, b))
|
||||||
|
*
|
||||||
|
> +
|
||||||
|
| > 1
|
||||||
|
| > 2
|
||||||
|
> x
|
||||||
|
"""
|
||||||
|
if right.power != 1:
|
||||||
|
raise NotImplementedError("Monomial is more than deg 1")
|
||||||
|
add_scal = Tree("+", 1, right.coefficient)
|
||||||
|
return Tree("*", add_scal, left)
|
||||||
|
|
||||||
|
@add.register(MOMonomial, MOstr)
|
||||||
|
@special_case(add_filter)
|
||||||
|
def momonomial_mostr(left, right):
|
||||||
|
""" Add a str to a Monomial
|
||||||
|
|
||||||
|
:example:
|
||||||
|
>>> a = MOMonomial(2, "x")
|
||||||
|
>>> b = MOstr("x")
|
||||||
|
>>> print(add(a, b))
|
||||||
|
*
|
||||||
|
> +
|
||||||
|
| > 2
|
||||||
|
| > 1
|
||||||
|
> x
|
||||||
|
"""
|
||||||
|
if left.power != 1:
|
||||||
|
raise NotImplementedError("Monomial is more than deg 1")
|
||||||
|
add_scal = Tree("+", left.coefficient, 1)
|
||||||
|
return Tree("*", add_scal, right)
|
||||||
|
|
||||||
|
@add.register(MOstrPower, MOMonomial)
|
||||||
|
@special_case(add_filter)
|
||||||
|
def mostrpower_momonomial(left, right):
|
||||||
|
""" Add a strpower to a Monomial
|
||||||
|
|
||||||
|
:example:
|
||||||
|
>>> a = MOstrPower("x", 2)
|
||||||
|
>>> b = MOMonomial(3, "x", 2)
|
||||||
|
>>> print(add(a, b))
|
||||||
|
*
|
||||||
|
> +
|
||||||
|
| > 1
|
||||||
|
| > 3
|
||||||
|
> ^
|
||||||
|
| > x
|
||||||
|
| > 2
|
||||||
|
"""
|
||||||
|
if right.power != left.power:
|
||||||
|
raise NotImplementedError("MOs does not have same degree")
|
||||||
|
add_scal = Tree("+", 1, right.coefficient)
|
||||||
|
return Tree("*", add_scal, left)
|
||||||
|
|
||||||
|
@add.register(MOMonomial, MOstrPower)
|
||||||
|
@special_case(add_filter)
|
||||||
|
def momonomial_mostrpower(left, right):
|
||||||
|
""" Add a strpower to a Monomial
|
||||||
|
|
||||||
|
:example:
|
||||||
|
>>> a = MOMonomial(3, "x", 2)
|
||||||
|
>>> b = MOstrPower("x", 2)
|
||||||
|
>>> print(add(a, b))
|
||||||
|
*
|
||||||
|
> +
|
||||||
|
| > 3
|
||||||
|
| > 1
|
||||||
|
> ^
|
||||||
|
| > x
|
||||||
|
| > 2
|
||||||
|
"""
|
||||||
|
if left.power != right.power:
|
||||||
|
raise NotImplementedError("MOs does not have same degree")
|
||||||
|
add_scal = Tree("+", left.coefficient, 1)
|
||||||
|
return Tree("*", add_scal, right)
|
||||||
|
|
||||||
|
@add.register(MOMonomial, MOMonomial)
|
||||||
|
@special_case(add_filter)
|
||||||
|
def momonomial_momonomial(left, right):
|
||||||
|
""" Add a Monomial to a Monomial
|
||||||
|
|
||||||
|
:example:
|
||||||
|
>>> a = MOMonomial(3, "x", 2)
|
||||||
|
>>> b = MOMonomial(4, "x", 2)
|
||||||
|
>>> print(add(a, b))
|
||||||
|
*
|
||||||
|
> +
|
||||||
|
| > 3
|
||||||
|
| > 4
|
||||||
|
> ^
|
||||||
|
| > x
|
||||||
|
| > 2
|
||||||
|
"""
|
||||||
|
if left.power != right.power:
|
||||||
|
raise NotImplementedError("MOs does not have same degree")
|
||||||
|
add_scal = Tree("+", left.coefficient, right.coefficient)
|
||||||
|
return Tree("*", add_scal, right.strpower)
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
# Reglages pour 'vim'
|
# Reglages pour 'vim'
|
||||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||||
|
Loading…
Reference in New Issue
Block a user