Fix(API): organise import and clean API renders
This commit is contained in:
parent
a2c1174ff3
commit
092fd3c0a7
@ -93,6 +93,19 @@ x^7
|
|||||||
5 + 2x^2 + (3 + 5) * x
|
5 + 2x^2 + (3 + 5) * x
|
||||||
5 + 2x^2 + 8x
|
5 + 2x^2 + 8x
|
||||||
|
|
||||||
|
>>> e = Expression.from_str("(2x+3)^2")
|
||||||
|
>>> e_simplified = e.simplify()
|
||||||
|
>>> e_simplified
|
||||||
|
<Quadratic 12x + 4x^2 + 9>
|
||||||
|
>>> for s in e_simplified.explain():
|
||||||
|
... print(s)
|
||||||
|
(2x + 3)^2
|
||||||
|
(2x + 3)(2x + 3)
|
||||||
|
2x * 2x + 2x * 3 + 3 * 2x + 3 * 3
|
||||||
|
2 * 2 * x^(1 + 1) + 3 * 2 * x + 3 * 2 * x + 9
|
||||||
|
6x + 6x + 4x^2 + 9
|
||||||
|
(6 + 6) * x + 4x^2 + 9
|
||||||
|
12x + 4x^2 + 9
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -198,10 +198,10 @@ class Expression(object):
|
|||||||
|
|
||||||
:example:
|
:example:
|
||||||
>>> e = Expression.from_str("2x", typing=False)
|
>>> e = Expression.from_str("2x", typing=False)
|
||||||
>>> print(e._tree.map_on_leaf(type))
|
>>> print(e._tree.map_on_leaf(lambda x: type(x).__name__))
|
||||||
*
|
*
|
||||||
> <class 'mapytex.calculus.core.MO.mo.MOnumber'>
|
> MOnumber
|
||||||
> <class 'mapytex.calculus.core.MO.mo.MOstr'>
|
> MOstr
|
||||||
>>> typed_e = e._typing()
|
>>> typed_e = e._typing()
|
||||||
>>> print(type(typed_e._tree))
|
>>> print(type(typed_e._tree))
|
||||||
<class 'mapytex.calculus.core.MO.monomial.MOMonomial'>
|
<class 'mapytex.calculus.core.MO.monomial.MOMonomial'>
|
||||||
@ -210,21 +210,28 @@ class Expression(object):
|
|||||||
<class 'mapytex.calculus.core.MO.monomial.MOMonomial'>
|
<class 'mapytex.calculus.core.MO.monomial.MOMonomial'>
|
||||||
|
|
||||||
>>> e = Expression.from_str("2x+3+4/5", typing=False)
|
>>> e = Expression.from_str("2x+3+4/5", typing=False)
|
||||||
>>> print(e._tree.map_on_leaf(type))
|
>>> print(e._tree.map_on_leaf(lambda x: type(x).__name__))
|
||||||
+
|
+
|
||||||
> +
|
> +
|
||||||
| > *
|
| > *
|
||||||
| | > <class 'mapytex.calculus.core.MO.mo.MOnumber'>
|
| | > MOnumber
|
||||||
| | > <class 'mapytex.calculus.core.MO.mo.MOstr'>
|
| | > MOstr
|
||||||
| > <class 'mapytex.calculus.core.MO.mo.MOnumber'>
|
| > MOnumber
|
||||||
> /
|
> /
|
||||||
| > <class 'mapytex.calculus.core.MO.mo.MOnumber'>
|
| > MOnumber
|
||||||
| > <class 'mapytex.calculus.core.MO.mo.MOnumber'>
|
| > MOnumber
|
||||||
|
|
||||||
>>> typed_e = e._typing()
|
>>> typed_e = e._typing()
|
||||||
>>> print(typed_e._tree.map_on_leaf(type))
|
>>> print(e._tree.map_on_leaf(lambda x: type(x).__name__))
|
||||||
+
|
+
|
||||||
> <class 'mapytex.calculus.core.MO.polynomial.MOpolynomial'>
|
> +
|
||||||
> <class 'mapytex.calculus.core.MO.fraction.MOFraction'>
|
| > *
|
||||||
|
| | > MOnumber
|
||||||
|
| | > MOstr
|
||||||
|
| > MOnumber
|
||||||
|
> /
|
||||||
|
| > MOnumber
|
||||||
|
| > MOnumber
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return Expression(self._tree.apply(typing))
|
return Expression(self._tree.apply(typing))
|
||||||
|
@ -16,7 +16,7 @@ def _txt(mo_tree):
|
|||||||
""" txt render for MOs or Trees"""
|
""" txt render for MOs or Trees"""
|
||||||
try:
|
try:
|
||||||
return tree2txt(mo_tree)
|
return tree2txt(mo_tree)
|
||||||
except AttributeError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -28,7 +28,7 @@ def _tex(mo_tree):
|
|||||||
""" Tex render for MOs or Trees"""
|
""" Tex render for MOs or Trees"""
|
||||||
try:
|
try:
|
||||||
return tree2tex(mo_tree)
|
return tree2tex(mo_tree)
|
||||||
except AttributeError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
Tokens represents MathObject at API level
|
Tokens represents MathObject at API level
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from ...core.MO.mo import MO, MOnumber, MOstr
|
from ...core.MO import MO, MOnumber, MOstr
|
||||||
from ...core.MO.fraction import MOFraction
|
from ...core.MO.fraction import MOFraction
|
||||||
from ...core.MO.monomial import MOstrPower, MOMonomial
|
from ...core.MO.monomial import MOstrPower, MOMonomial
|
||||||
from ...core.MO.polynomial import MOpolynomial
|
from ...core.MO.polynomial import MOpolynomial
|
||||||
|
@ -11,8 +11,7 @@ Tokens representing interger and decimal
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from .token import Token
|
from .token import Token
|
||||||
from ...core.MO import MO
|
from ...core.MO import MO, MOnumber
|
||||||
from ...core.MO.mo import MOnumber
|
|
||||||
from ...core.MO.fraction import MOFraction
|
from ...core.MO.fraction import MOFraction
|
||||||
from decimal import Decimal as _Decimal
|
from decimal import Decimal as _Decimal
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user