diff --git a/mapytex/calculus/API/expression.py b/mapytex/calculus/API/expression.py index 231b253..36def04 100644 --- a/mapytex/calculus/API/expression.py +++ b/mapytex/calculus/API/expression.py @@ -174,6 +174,22 @@ class Expression(object): 10 + 1680 * 9 10 + 15120 15130 + >>> e = Expression.from_str("1+2/3/4/5") + >>> f = e.simplify() + >>> for s in f.explain(): + ... print(s) + 1 + 2 / 3 / 4 / 5 + 1 + (2 / 3 * 1 / 4) / 5 + 1 + (2 * 1) / (3 * 4) / 5 + 1 + 2 / 12 / 5 + 1 + 2 / 12 * 1 / 5 + 1 + (2 * 1) / (12 * 5) + 1 + 2 / 60 + 1 / 1 + 2 / 60 + (1 * 60) / (1 * 60) + 2 / 60 + 60 / 60 + 2 / 60 + (60 + 2) / 60 + 62 / 60 """ try: yield from self._ancestor.explain() diff --git a/mapytex/calculus/core/compute/divide.py b/mapytex/calculus/core/compute/divide.py index 7a81b44..197e3ae 100644 --- a/mapytex/calculus/core/compute/divide.py +++ b/mapytex/calculus/core/compute/divide.py @@ -70,7 +70,7 @@ def monumber_monumber(left, right): >>> a = MOnumber(4) >>> b = MOnumber(6.2) >>> monumber_monumber(a, b) - Decimal('0.6451612903225806266768278939') + >>> a = MOnumber(4) >>> b = MOnumber(6) >>> monumber_monumber(a, b) @@ -80,7 +80,7 @@ def monumber_monumber(left, right): """ if type(left.value) in [float, Decimal] or \ type(right.value) in [float, Decimal]: - return left / right + return MO.factory(left / right) else: raise NotImplementedError("Can't divide 2 int. Need to create a Fraction instead") @@ -126,7 +126,7 @@ def mofraction_monumber(left, right): | > 4 """ - right_fraction = MOFraction(1, right) + right_fraction = MOFraction(MOnumber(1), right) return Tree("*", left, right_fraction) @divide.register(MOFraction, MOFraction)