diff --git a/pymath/calculus/explicable.py b/pymath/calculus/explicable.py index 3bb69af..1c87b1c 100644 --- a/pymath/calculus/explicable.py +++ b/pymath/calculus/explicable.py @@ -3,6 +3,7 @@ from .render import Renderable from decimal import Decimal +from .generic import transpose_fill class Explicable(Renderable): @@ -88,6 +89,40 @@ class Explicable(Renderable): """ self.steps = steps + self.steps + @staticmethod + def merge_history(expl1, expl2, operation): + """ Take two Explicable objects, explain where they are from and merge their history + + /!\ Using this method make the two objects amnesiac + + :param expl1: fist explicable + :param expl2: second explicable + :param operation: the operation that link them + :returns: the list of steps + + >>> from .expression import Expression + >>> from .operator import op + >>> action1 = Explicable() + >>> action1.postfix_tokens = Expression('42') + >>> action1.this_append_before([Expression('2+10*4'), Expression('2+40')]) + >>> action2 = Explicable() + >>> action2.postfix_tokens = Expression('24') + >>> action2.this_append_before([Expression('2*12')]) + >>> m_history = Explicable().merge_history(action1, action2, op.add) + >>> m_history + + >>> for i in m_history: + ... print(i) + ['2 + 10 \\times 4', '2 \\times 12', +] + ['2 + 40', '24', +] + ['42', '24', +] + + """ + steps1 = list(expl1.explain()) + steps2 = list(expl2.explain()) + + return transpose_fill([steps1, steps2, [operation]]) + class Explicable_int(int, Explicable):