Render momonial and multiply with scalar

This commit is contained in:
2018-03-17 08:45:23 +03:00
parent b0ff919693
commit 0cef131c41
2 changed files with 80 additions and 1 deletions

View File

@@ -9,6 +9,7 @@
from mapytex.calculus.core.tree import Tree
from .mo import MO, MOnumber, MOstr
from .exceptions import MOError
from ..renders import tree2txt, tree2tex
__all__ = ["MOMonomial"]
@@ -27,6 +28,10 @@ class MOMonomial(MO):
<MOMonomial 4x^2>
>>> MOMonomial(4, "x", 1)
<MOMonomial 4x>
>>> MOMonomial(1, "x", 2)
<MOMonomial x^2>
>>> MOMonomial(1, "x", 1)
<MOMonomial x>
>>> MOMonomial(4, 3, 1)
Traceback (most recent call last):
...
@@ -79,6 +84,39 @@ class MOMonomial(MO):
self._variable,
)
@property
def __txt__(self):
try:
if self._coefficient == 1:
try:
return tree2txt(self.value.right_value)
except AttributeError:
return str(self.value.right_value)
except TypeError:
pass
try:
return tree2txt(self.value)
except AttributeError:
return str(self.value)
@property
def __tex__(self):
try:
if self._coefficient == 1:
try:
return tree2tex(self.value.right_value)
except AttributeError:
return str(self.value.right_value)
except TypeError:
pass
try:
return tree2tex(self.value)
except AttributeError:
return str(self.value)
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4: