From ddf15e42769cee4cf3303ee1ffc29ca088ad811d Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Wed, 10 Oct 2018 10:13:58 +0200 Subject: [PATCH] Feat(compute): Write powers of fraction --- mapytex/calculus/API/__init__.py | 9 +++++++++ mapytex/calculus/core/compute/power.py | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/mapytex/calculus/API/__init__.py b/mapytex/calculus/API/__init__.py index 5092337..999ed70 100644 --- a/mapytex/calculus/API/__init__.py +++ b/mapytex/calculus/API/__init__.py @@ -32,6 +32,15 @@ Generate and compute like a student! 4 / 2 + 3 / 2 (4 + 3) / 2 7 / 2 +>>> e = Expression.from_str("(2/3)^4") +>>> e_simplified = e.simplify() +>>> print(e_simplified) +16 / 81 +>>> for s in e_simplified.explain(): +... print(s) +(2 / 3)^4 +2^4 / 3^4 +16 / 81 """ diff --git a/mapytex/calculus/core/compute/power.py b/mapytex/calculus/core/compute/power.py index 89522ef..7e4f4ae 100644 --- a/mapytex/calculus/core/compute/power.py +++ b/mapytex/calculus/core/compute/power.py @@ -80,8 +80,17 @@ def mofraction_monumber(left, right): >>> a = MOFraction(3, 2) >>> b = MOnumber(2) >>> print(power(a, b)) + / + > ^ + | > 3 + | > 2 + > ^ + | > 2 + | > 2 """ - raise NotImplementedError + num = Tree("^", left.numerator, right) + denom = Tree("^", left.denominator, right) + return Tree("/", num, denom)