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