Feat(Core): Change default str function for MO

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

View File

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