Feat(Core): Change default str function for MO

This commit is contained in:
Bertrand Benjamin 2018-12-21 12:20:13 +01:00
parent 092fd3c0a7
commit 9a68b826a3
10 changed files with 159 additions and 513 deletions

View File

@ -35,9 +35,7 @@ class MOFraction(Molecule):
>>> print(f.__tex__) >>> print(f.__tex__)
\\frac{2}{3} \\frac{2}{3}
>>> print(f) >>> print(f)
/ 2 / 3
> 2
> 3
>>> f = MOFraction(2, 3, negative = True) >>> f = MOFraction(2, 3, negative = True)
>>> f >>> f
<MOFraction - 2 / 3> <MOFraction - 2 / 3>

View File

@ -185,8 +185,7 @@ class Molecule(MO):
return self._tree return self._tree
def __str__(self): def __str__(self):
# TODO: à changer pour utiliser .__txt__ |ven. déc. 21 08:30:33 CET 2018 return str(self.__txt__)
return str(self.tree)
@property @property
def __txt__(self): def __txt__(self):

View File

@ -29,9 +29,7 @@ class MOstrPower(Molecule):
>>> s >>> s
<MOstrPower x^2> <MOstrPower x^2>
>>> print(s) >>> print(s)
^ x^2
> x
> 2
>>> print(s.__txt__) >>> print(s.__txt__)
x^2 x^2
>>> print(s.__tex__) >>> print(s.__tex__)
@ -133,9 +131,7 @@ class MOMonomial(Molecule):
>>> m >>> m
<MOMonomial 4x> <MOMonomial 4x>
>>> print(m) >>> print(m)
* 4x
> 4
> x
>>> print(m.__txt__) >>> print(m.__txt__)
4x 4x
>>> print(m.__tex__) >>> print(m.__tex__)
@ -147,9 +143,7 @@ class MOMonomial(Molecule):
>>> m >>> m
<MOMonomial 4x> <MOMonomial 4x>
>>> print(m) >>> print(m)
* 4x
> 4
> x
>>> print(m.__txt__) >>> print(m.__txt__)
4x 4x
>>> print(m.__tex__) >>> print(m.__tex__)

View File

@ -43,12 +43,8 @@ Abstracts tools for calculs manipulations
>>> tt = t.apply_on_last_level(typing) >>> tt = t.apply_on_last_level(typing)
>>> print(tt.apply_on_last_level(compute)) >>> print(tt.apply_on_last_level(compute))
+ +
> / > 2 / 1
| > 2 > 3 / 4
| > 1
> /
| > 3
| > 4
>>> type(t.right_value) >>> type(t.right_value)
<class 'mapytex.calculus.core.tree.Tree'> <class 'mapytex.calculus.core.tree.Tree'>
>>> type(tt.right_value) >>> type(tt.right_value)

View File

@ -81,12 +81,8 @@ def monumber_mofraction(left, right):
>>> b = MOFraction(6, 5) >>> b = MOFraction(6, 5)
>>> print(add(a, b)) >>> print(add(a, b))
+ +
> / > 4 / 1
| > 4 > 6 / 5
| > 1
> /
| > 6
| > 5
""" """
left_fraction = MOFraction(left, MOnumber(1)) left_fraction = MOFraction(left, MOnumber(1))
return Tree("+", left_fraction, right) return Tree("+", left_fraction, right)
@ -100,12 +96,9 @@ def mofraction_monumber(left, right):
>>> b = MOnumber(4) >>> b = MOnumber(4)
>>> print(add(a, b)) >>> print(add(a, b))
+ +
> / > 6 / 5
| > 6 > 4 / 1
| > 5
> /
| > 4
| > 1
""" """
right_fraction = MOFraction(right, MOnumber(1)) right_fraction = MOFraction(right, MOnumber(1))
return Tree("+", left, right_fraction) return Tree("+", left, right_fraction)
@ -159,9 +152,8 @@ def mofraction_mofraction(left, right):
| > * | > *
| | > 2 | | > 2
| | > 2 | | > 2
> / > 1 / 4
| > 1
| > 4
Denominators are coprime Denominators are coprime
@ -248,15 +240,9 @@ def moscalar_mopolynomial(left, right):
>>> b = MOpolynomial("x", [2, 3, 4]) >>> b = MOpolynomial("x", [2, 3, 4])
>>> print(add(a, b)) >>> print(add(a, b))
+ +
> * > 4x^2
| > 4
| > ^
| | > x
| | > 2
> + > +
| > * | > 3x
| | > 3
| | > x
| > + | > +
| | > 1 | | > 1
| | > 2 | | > 2
@ -280,15 +266,9 @@ def mopolynomial_moscalar(left, right):
>>> b = MOnumber(1) >>> b = MOnumber(1)
>>> print(add(a, b)) >>> print(add(a, b))
+ +
> * > 4x^2
| > 4
| > ^
| | > x
| | > 2
> + > +
| > * | > 3x
| | > 3
| | > x
| > + | > +
| | > 2 | | > 2
| | > 1 | | > 1
@ -312,18 +292,13 @@ def mostr_mopolynomial(left, right):
>>> b = MOpolynomial("x", [2, 3, 4]) >>> b = MOpolynomial("x", [2, 3, 4])
>>> print(add(a, b)) >>> print(add(a, b))
+ +
> * > 4x^2
| > 4
| > ^
| | > x
| | > 2
> + > +
| > + | > +
| | > x | | > x
| | > * | | > 3x
| | | > 3
| | | > x
| > 2 | > 2
""" """
if 1 not in right.coefficients.keys(): if 1 not in right.coefficients.keys():
raise NotImplementedError("Polynomial with no constant, no calculus to do") raise NotImplementedError("Polynomial with no constant, no calculus to do")
@ -348,18 +323,13 @@ def mopolynomial_mostr(left, right):
>>> b = MOstr("x") >>> b = MOstr("x")
>>> print(add(a, b)) >>> print(add(a, b))
+ +
> * > 4x^2
| > 4
| > ^
| | > x
| | > 2
> + > +
| > + | > +
| | > * | | > 3x
| | | > 3
| | | > x
| | > x | | > x
| > 2 | > 2
""" """
if 1 not in left.coefficients.keys(): if 1 not in left.coefficients.keys():
raise NotImplementedError("No degree in common") raise NotImplementedError("No degree in common")
@ -385,42 +355,24 @@ def mostrpower_mopolynomial(left, right):
>>> print(add(a, b)) >>> print(add(a, b))
+ +
> + > +
| > ^ | > x^2
| | > x | > 4x^2
| | > 2
| > *
| | > 4
| | > ^
| | | > x
| | | > 2
> + > +
| > * | > 3x
| | > 3
| | > x
| > 2 | > 2
>>> b = MOpolynomial("x", [2, 3, 4, 5]) >>> b = MOpolynomial("x", [2, 3, 4, 5])
>>> print(add(a, b)) >>> print(add(a, b))
+ +
> + > +
| > * | > 5x^3
| | > 5
| | > ^
| | | > x
| | | > 3
| > + | > +
| | > ^ | | > x^2
| | | > x | | > 4x^2
| | | > 2
| | > *
| | | > 4
| | | > ^
| | | | > x
| | | | > 2
> + > +
| > * | > 3x
| | > 3
| | > x
| > 2 | > 2
""" """
if left.power not in right.coefficients.keys(): if left.power not in right.coefficients.keys():
raise NotImplementedError("No degree in common") raise NotImplementedError("No degree in common")
@ -446,42 +398,25 @@ def mopolynomial_mostrpower(left, right):
>>> print(add(a, b)) >>> print(add(a, b))
+ +
> + > +
| > * | > 4x^2
| | > 4 | > x^2
| | > ^
| | | > x
| | | > 2
| > ^
| | > x
| | > 2
> + > +
| > * | > 3x
| | > 3
| | > x
| > 2 | > 2
>>> a = MOpolynomial("x", [2, 3, 4, 5]) >>> a = MOpolynomial("x", [2, 3, 4, 5])
>>> print(add(a, b)) >>> print(add(a, b))
+ +
> + > +
| > * | > 5x^3
| | > 5
| | > ^
| | | > x
| | | > 3
| > + | > +
| | > * | | > 4x^2
| | | > 4 | | > x^2
| | | > ^
| | | | > x
| | | | > 2
| | > ^
| | | > x
| | | > 2
> + > +
| > * | > 3x
| | > 3
| | > x
| > 2 | > 2
""" """
if right.power not in left.coefficients.keys(): if right.power not in left.coefficients.keys():
raise NotImplementedError("No degree in common") raise NotImplementedError("No degree in common")
@ -507,46 +442,24 @@ def momonomial_mopolynomial(left, right):
>>> print(add(a, b)) >>> print(add(a, b))
+ +
> + > +
| > * | > 10x^2
| | > 10 | > 4x^2
| | > ^
| | | > x
| | | > 2
| > *
| | > 4
| | > ^
| | | > x
| | | > 2
> + > +
| > * | > 3x
| | > 3
| | > x
| > 2 | > 2
>>> b = MOpolynomial("x", [2, 3, 4, 5]) >>> b = MOpolynomial("x", [2, 3, 4, 5])
>>> print(add(a, b)) >>> print(add(a, b))
+ +
> + > +
| > * | > 5x^3
| | > 5
| | > ^
| | | > x
| | | > 3
| > + | > +
| | > * | | > 10x^2
| | | > 10 | | > 4x^2
| | | > ^
| | | | > x
| | | | > 2
| | > *
| | | > 4
| | | > ^
| | | | > x
| | | | > 2
> + > +
| > * | > 3x
| | > 3
| | > x
| > 2 | > 2
""" """
if left.power not in right.coefficients.keys(): if left.power not in right.coefficients.keys():
raise NotImplementedError("No degree in common") raise NotImplementedError("No degree in common")
@ -572,46 +485,24 @@ def mopolynomial_momonomial(left, right):
>>> print(add(a, b)) >>> print(add(a, b))
+ +
> + > +
| > * | > 4x^2
| | > 4 | > 10x^2
| | > ^
| | | > x
| | | > 2
| > *
| | > 10
| | > ^
| | | > x
| | | > 2
> + > +
| > * | > 3x
| | > 3
| | > x
| > 2 | > 2
>>> a = MOpolynomial("x", [2, 3, 4, 5]) >>> a = MOpolynomial("x", [2, 3, 4, 5])
>>> print(add(a, b)) >>> print(add(a, b))
+ +
> + > +
| > * | > 5x^3
| | > 5
| | > ^
| | | > x
| | | > 3
| > + | > +
| | > * | | > 4x^2
| | | > 4 | | > 10x^2
| | | > ^
| | | | > x
| | | | > 2
| | > *
| | | > 10
| | | > ^
| | | | > x
| | | | > 2
> + > +
| > * | > 3x
| | > 3
| | > x
| > 2 | > 2
""" """
if right.power not in left.coefficients.keys(): if right.power not in left.coefficients.keys():
raise NotImplementedError("No degree in common") raise NotImplementedError("No degree in common")
@ -637,73 +528,40 @@ def mopolynomial_mopolynomial(left, right):
>>> print(add(a, b)) >>> print(add(a, b))
+ +
> + > +
| > * | > 4x^2
| | > 4 | > 7x^2
| | > ^
| | | > x
| | | > 2
| > *
| | > 7
| | > ^
| | | > x
| | | > 2
> + > +
| > + | > +
| | > * | | > 3x
| | | > 3 | | > 6x
| | | > x
| | > *
| | | > 6
| | | > x
| > + | > +
| | > 2 | | > 2
| | > 5 | | > 5
>>> b = MOpolynomial("x", [0, 3, 4]) >>> b = MOpolynomial("x", [0, 3, 4])
>>> print(add(a, b)) >>> print(add(a, b))
+ +
> + > +
| > * | > 4x^2
| | > 4 | > 4x^2
| | > ^
| | | > x
| | | > 2
| > *
| | > 4
| | > ^
| | | > x
| | | > 2
> + > +
| > + | > +
| | > * | | > 3x
| | | > 3 | | > 3x
| | | > x
| | > *
| | | > 3
| | | > x
| > 2 | > 2
>>> b = MOpolynomial("x", [0, 3, 0, 5]) >>> b = MOpolynomial("x", [0, 3, 0, 5])
>>> print(add(a, b)) >>> print(add(a, b))
+ +
> + > +
| > * | > 5x^3
| | > 5 | > 4x^2
| | > ^
| | | > x
| | | > 3
| > *
| | > 4
| | > ^
| | | > x
| | | > 2
> + > +
| > + | > +
| | > * | | > 3x
| | | > 3 | | > 3x
| | | > x
| | > *
| | | > 3
| | | > x
| > 2 | > 2
""" """
common_degree = set(left.monomials.keys()).intersection(right.monomials.keys()) common_degree = set(left.monomials.keys()).intersection(right.monomials.keys())
if not common_degree: if not common_degree:
@ -768,9 +626,7 @@ def mostrpower_momonomial(left, right):
> + > +
| > 1 | > 1
| > 3 | > 3
> ^ > x^2
| > x
| > 2
""" """
if right.power != left.power: if right.power != left.power:
raise NotImplementedError("MOs does not have same degree") raise NotImplementedError("MOs does not have same degree")
@ -790,9 +646,7 @@ def momonomial_mostrpower(left, right):
> + > +
| > 3 | > 3
| > 1 | > 1
> ^ > x^2
| > x
| > 2
""" """
if left.power != right.power: if left.power != right.power:
raise NotImplementedError("MOs does not have same degree") raise NotImplementedError("MOs does not have same degree")
@ -812,9 +666,8 @@ def momonomial_momonomial(left, right):
> + > +
| > 3 | > 3
| > 4 | > 4
> ^ > x^2
| > x
| > 2
""" """
if left.power != right.power: if left.power != right.power:
raise NotImplementedError("MOs does not have same degree") raise NotImplementedError("MOs does not have same degree")

View File

@ -91,21 +91,15 @@ def monumber_mofraction(left, right):
>>> a = MOnumber(4) >>> a = MOnumber(4)
>>> b = MOFraction(6, 5) >>> b = MOFraction(6, 5)
>>> print(monumber_mofraction(a, b)) >>> print(divide(a, b))
* *
> 4 > 4
> / > 5 / 6
| > 5
| > 6
>>> b = MOFraction(6, 5, True) >>> b = MOFraction(6, 5, True)
>>> print(monumber_mofraction(a, b)) >>> print(divide(a, b))
* *
> 4 > 4
> - > - 5 / 6
| > None
| > /
| | > 5
| | > 6
""" """
return Tree("*", left, right.inverse()) return Tree("*", left, right.inverse())
@ -118,12 +112,8 @@ def mofraction_monumber(left, right):
>>> b = MOnumber(4) >>> b = MOnumber(4)
>>> print(mofraction_monumber(a, b)) >>> print(mofraction_monumber(a, b))
* *
> / > 6 / 5
| > 6 > 1 / 4
| > 5
> /
| > 1
| > 4
""" """
right_fraction = MOFraction(MOnumber(1), right) right_fraction = MOFraction(MOnumber(1), right)
@ -138,12 +128,8 @@ def mofraction_mofraction(left, right):
>>> b = MOFraction(4, 5) >>> b = MOFraction(4, 5)
>>> print(mofraction_mofraction(a, b)) >>> print(mofraction_mofraction(a, b))
* *
> / > 1 / 5
| > 1 > 5 / 4
| > 5
> /
| > 5
| > 4
""" """
return Tree("*", left, right.inverse()) return Tree("*", left, right.inverse())

View File

@ -47,35 +47,25 @@ def mofraction(_, right):
>>> a = MOFraction(6, 5) >>> a = MOFraction(6, 5)
>>> print(minus(None, a)) >>> print(minus(None, a))
- - 6 / 5
> None
> /
| > 6
| > 5
The fraction is negative The fraction is negative
>>> a = MOFraction(6, 5, True) >>> a = MOFraction(6, 5, True)
>>> print(minus(None, a)) >>> print(minus(None, a))
/ 6 / 5
> 6
> 5
Numerator is negative Numerator is negative
>>> a = MOFraction(-6, 5) >>> a = MOFraction(-6, 5)
>>> print(minus(None, a)) >>> print(minus(None, a))
/ 6 / 5
> 6
> 5
Denominators is negative Denominators is negative
>>> a = MOFraction(6, -5) >>> a = MOFraction(6, -5)
>>> print(minus(None, a)) >>> print(minus(None, a))
/ 6 / 5
> 6
> 5
""" """
if right.negative: if right.negative:
return MOFraction(right._numerator, right._denominator) return MOFraction(right._numerator, right._denominator)
@ -101,9 +91,7 @@ def mostr(_, right):
:example: :example:
>>> x = MOstr("x") >>> x = MOstr("x")
>>> print(minus(None, x)) >>> print(minus(None, x))
* - x
> -1
> x
""" """
return MOMonomial(-1, right) return MOMonomial(-1, right)
@ -114,11 +102,7 @@ def mostrpower(_, right):
:example: :example:
>>> x2 = MOstrPower("x", 2) >>> x2 = MOstrPower("x", 2)
>>> print(minus(None, x2)) >>> print(minus(None, x2))
* - x^2
> -1
> ^
| > x
| > 2
""" """
return MOMonomial(-1, right.variable, right.power) return MOMonomial(-1, right.variable, right.power)
@ -129,11 +113,7 @@ def momonomial(_, right):
:example: :example:
>>> tx2 = MOMonomial(3, "x", 2) >>> tx2 = MOMonomial(3, "x", 2)
>>> print(minus(None, tx2)) >>> print(minus(None, tx2))
* - 3x^2
> -3
> ^
| > x
| > 2
""" """
try: try:
return MOMonomial(-right.coefficient.value, right.variable, right.power) return MOMonomial(-right.coefficient.value, right.variable, right.power)
@ -148,17 +128,7 @@ def mopolynomial(_, right):
:example: :example:
>>> P = MOpolynomial('x', [1, -2, 3]) >>> P = MOpolynomial('x', [1, -2, 3])
>>> print(minus(None, P)) >>> print(minus(None, P))
+ - 3x^2 + 2x - 1
> *
| > -3
| > ^
| | > x
| | > 2
> +
| > *
| | > 2
| | > x
| > -1
""" """
neg_coefs = {p: -c.value for (p, c) in right.coefficients.items()} neg_coefs = {p: -c.value for (p, c) in right.coefficients.items()}
return MOpolynomial(right.variable, neg_coefs) return MOpolynomial(right.variable, neg_coefs)

View File

@ -158,9 +158,7 @@ def moscalar_monomonial(left, right):
> * > *
| > 4 | > 4
| > 5 | > 5
> ^ > x^4
| > x
| > 4
""" """
coefficient = Tree('*', left, right.coefficient) coefficient = Tree('*', left, right.coefficient)
@ -179,9 +177,7 @@ def monomonial_moscalar(left, right):
> * > *
| > 4 | > 4
| > 5 | > 5
> ^ > x^4
| > x
| > 4
""" """
coefficient = Tree('*', right, left.coefficient) coefficient = Tree('*', right, left.coefficient)
@ -279,7 +275,7 @@ def mostr_mostrpower(left, right):
@multiply.register(MOstrPower, MOMonomial) @multiply.register(MOstrPower, MOMonomial)
@special_case(multiply_filter) @special_case(multiply_filter)
def mostr_momonomial(left, right): def mostrpower_momonomial(left, right):
""" Multiply a MOstrPower and a MOMonomial """ Multiply a MOstrPower and a MOMonomial
>>> a = MOstrPower('x', 2) >>> a = MOstrPower('x', 2)
@ -344,11 +340,7 @@ def mostr_momonomial(left, right):
>>> a = MOstr('x') >>> a = MOstr('x')
>>> b = MOMonomial(2, 'x', 4) >>> b = MOMonomial(2, 'x', 4)
>>> print(multiply(a, b)) >>> print(multiply(a, b))
* 2x^5
> 2
> ^
| > x
| > 5
>>> a = MOstr('x') >>> a = MOstr('x')
>>> b = MOMonomial(2, 'y', 4) >>> b = MOMonomial(2, 'y', 4)
>>> multiply(a, b) >>> multiply(a, b)
@ -369,11 +361,7 @@ def momonomial_mostr(left, right):
>>> a = MOMonomial(2, 'x', 4) >>> a = MOMonomial(2, 'x', 4)
>>> b = MOstr('x') >>> b = MOstr('x')
>>> print(multiply(a, b)) >>> print(multiply(a, b))
* 2x^5
> 2
> ^
| > x
| > 5
>>> a = MOMonomial(2, 'y', 4) >>> a = MOMonomial(2, 'y', 4)
>>> b = MOstr('x') >>> b = MOstr('x')
>>> multiply(a, b) >>> multiply(a, b)
@ -432,17 +420,11 @@ def lotsmo_mopolynomial(left, right):
+ +
> * > *
| > 2 | > 2
| > * | > 3x^2
| | > 3
| | > ^
| | | > x
| | | > 2
> + > +
| > * | > *
| | > 2 | | > 2
| | > * | | > 2x
| | | > 2
| | | > x
| > * | > *
| | > 2 | | > 2
| | > 1 | | > 1
@ -452,74 +434,45 @@ def lotsmo_mopolynomial(left, right):
>>> print(multiply(a, b)) >>> print(multiply(a, b))
+ +
> * > *
| > / | > 1 / 5
| | > 1 | > 3x^2
| | > 5
| > *
| | > 3
| | > ^
| | | > x
| | | > 2
> + > +
| > * | > *
| | > / | | > 1 / 5
| | | > 1 | | > 2x
| | | > 5
| | > *
| | | > 2
| | | > x
| > * | > *
| | > / | | > 1 / 5
| | | > 1
| | | > 5
| | > 1 | | > 1
>>> a = MOstr("x") >>> a = MOstr("x")
>>> b = MOpolynomial('x', [1, 2, 3]) >>> b = MOpolynomial('x', [1, 2, 3])
>>> print(multiply(a, b)) >>> print(multiply(a, b))
+ +
> * > *
| > x | > x
| > * | > 3x^2
| | > 3
| | > ^
| | | > x
| | | > 2
> + > +
| > * | > *
| | > x | | > x
| | > * | | > 2x
| | | > 2
| | | > x
| > * | > *
| | > x | | > x
| | > 1 | | > 1
>>> a = MOstrPower("x", 2) >>> a = MOstrPower("x", 2)
>>> b = MOpolynomial('x', [1, 2, 3]) >>> b = MOpolynomial('x', [1, 2, 3])
>>> print(multiply(a, b)) >>> print(multiply(a, b))
+ +
> * > *
| > ^ | > x^2
| | > x | > 3x^2
| | > 2
| > *
| | > 3
| | > ^
| | | > x
| | | > 2
> + > +
| > * | > *
| | > ^ | | > x^2
| | | > x | | > 2x
| | | > 2
| | > *
| | | > 2
| | | > x
| > * | > *
| | > ^ | | > x^2
| | | > x
| | | > 2
| | > 1 | | > 1
>>> a = MOMonomial(3, "x", 2) >>> a = MOMonomial(3, "x", 2)
@ -527,32 +480,14 @@ def lotsmo_mopolynomial(left, right):
>>> print(multiply(a, b)) >>> print(multiply(a, b))
+ +
> * > *
| > * | > 3x^2
| | > 3 | > 3x^2
| | > ^
| | | > x
| | | > 2
| > *
| | > 3
| | > ^
| | | > x
| | | > 2
> + > +
| > * | > *
| | > * | | > 3x^2
| | | > 3 | | > 2x
| | | > ^
| | | | > x
| | | | > 2
| | > *
| | | > 2
| | | > x
| > * | > *
| | > * | | > 3x^2
| | | > 3
| | | > ^
| | | | > x
| | | | > 2
| | > 1 | | > 1
@ -573,17 +508,11 @@ def mopolynomial_lotsmo(left, right):
>>> print(multiply(a, b)) >>> print(multiply(a, b))
+ +
> * > *
| > * | > 3x^2
| | > 3
| | > ^
| | | > x
| | | > 2
| > 2 | > 2
> + > +
| > * | > *
| | > * | | > 2x
| | | > 2
| | | > x
| | > 2 | | > 2
| > * | > *
| | > 1 | | > 1
@ -594,44 +523,27 @@ def mopolynomial_lotsmo(left, right):
>>> print(multiply(a, b)) >>> print(multiply(a, b))
+ +
> * > *
| > * | > 3x^2
| | > 3 | > 1 / 5
| | > ^
| | | > x
| | | > 2
| > /
| | > 1
| | > 5
> + > +
| > * | > *
| | > * | | > 2x
| | | > 2 | | > 1 / 5
| | | > x
| | > /
| | | > 1
| | | > 5
| > * | > *
| | > 1 | | > 1
| | > / | | > 1 / 5
| | | > 1
| | | > 5
>>> a = MOpolynomial('x', [1, 2, 3]) >>> a = MOpolynomial('x', [1, 2, 3])
>>> b = MOstr("x") >>> b = MOstr("x")
>>> print(multiply(a, b)) >>> print(multiply(a, b))
+ +
> * > *
| > * | > 3x^2
| | > 3
| | > ^
| | | > x
| | | > 2
| > x | > x
> + > +
| > * | > *
| | > * | | > 2x
| | | > 2
| | | > x
| | > x | | > x
| > * | > *
| | > 1 | | > 1
@ -642,60 +554,31 @@ def mopolynomial_lotsmo(left, right):
>>> print(multiply(a, b)) >>> print(multiply(a, b))
+ +
> * > *
| > * | > 3x^2
| | > 3 | > x^2
| | > ^
| | | > x
| | | > 2
| > ^
| | > x
| | > 2
> + > +
| > * | > *
| | > * | | > 2x
| | | > 2 | | > x^2
| | | > x
| | > ^
| | | > x
| | | > 2
| > * | > *
| | > 1 | | > 1
| | > ^ | | > x^2
| | | > x
| | | > 2
>>> a = MOpolynomial('x', [1, 2, 3]) >>> a = MOpolynomial('x', [1, 2, 3])
>>> b = MOMonomial(3, "x", 2) >>> b = MOMonomial(3, "x", 2)
>>> print(multiply(a, b)) >>> print(multiply(a, b))
+ +
> * > *
| > * | > 3x^2
| | > 3 | > 3x^2
| | > ^
| | | > x
| | | > 2
| > *
| | > 3
| | > ^
| | | > x
| | | > 2
> + > +
| > * | > *
| | > * | | > 2x
| | | > 2 | | > 3x^2
| | | > x
| | > *
| | | > 3
| | | > ^
| | | | > x
| | | | > 2
| > * | > *
| | > 1 | | > 1
| | > * | | > 3x^2
| | | > 3
| | | > ^
| | | | > x
| | | | > 2
""" """
coefs = [Tree("*", monom, right) \ coefs = [Tree("*", monom, right) \
@ -714,41 +597,23 @@ def mopolynomial_mopolynomial(left, right):
+ +
> + > +
| > * | > *
| | > * | | > 3x^2
| | | > 3 | | > 5x
| | | > ^
| | | | > x
| | | | > 2
| | > *
| | | > 5
| | | > x
| > + | > +
| | > * | | > *
| | | > * | | | > 3x^2
| | | | > 3
| | | | > ^
| | | | | > x
| | | | | > 2
| | | > 4 | | | > 4
| | > * | | > *
| | | > * | | | > 2x
| | | | > 2 | | | > 5x
| | | | > x
| | | > *
| | | | > 5
| | | | > x
> + > +
| > * | > *
| | > * | | > 2x
| | | > 2
| | | > x
| | > 4 | | > 4
| > + | > +
| | > * | | > *
| | | > 1 | | | > 1
| | | > * | | | > 5x
| | | | > 5
| | | | > x
| | > * | | > *
| | | > 1 | | | > 1
| | | > 4 | | | > 4

View File

@ -142,28 +142,8 @@ def mopolynomial_monumber(left, right):
>>> a = MOnumber(2) >>> a = MOnumber(2)
>>> print(power(P, a)) >>> print(power(P, a))
* *
> + > 3x^2 - 2x + 1
| > * > 3x^2 - 2x + 1
| | > 3
| | > ^
| | | > x
| | | > 2
| > +
| | > *
| | | > -2
| | | > x
| | > 1
> +
| > *
| | > 3
| | > ^
| | | > x
| | | > 2
| > +
| | > *
| | | > -2
| | | > x
| | > 1
""" """
return Tree.from_list("*", [left]*right.value) return Tree.from_list("*", [left]*right.value)

View File

@ -84,6 +84,8 @@ def mul2txt(left, right):
>>> a = MO.factory('x') >>> a = MO.factory('x')
>>> mul2txt(MO.factory(3), a) >>> mul2txt(MO.factory(3), a)
'3x' '3x'
>>> mul2txt(MO.factory(-3), a)
'- 3x'
>>> mul2txt(a, a) >>> mul2txt(a, a)
'x * x' 'x * x'
""" """
@ -92,8 +94,11 @@ def mul2txt(left, right):
left_ = render_with_parenthesis(left, "*") left_ = render_with_parenthesis(left, "*")
right_ = render_with_parenthesis(right, "*") right_ = render_with_parenthesis(right, "*")
if (right_[0].isalpha() and (left_.isnumeric() or left_.isdecimal())) or \ if right_[0].isalpha():
right_[0] == '(': # TODO: C'est bien beurk en dessous... |ven. déc. 21 12:03:07 CET 2018
if type(left).__name__ == 'MOnumber':
display_time = False
elif right_[0] == '(':
display_time = False display_time = False
if display_time: if display_time: