From 5df17b4779b1d6bf552a67a7e76899fe8bfadcdf Mon Sep 17 00:00:00 2001 From: Lafrite Date: Fri, 19 Dec 2014 15:40:35 +0100 Subject: [PATCH] dd simplified method for Expression --- pymath/expression.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pymath/expression.py b/pymath/expression.py index 1a5dc10..17029aa 100644 --- a/pymath/expression.py +++ b/pymath/expression.py @@ -72,6 +72,12 @@ class Expression(object): for s in self.child.simplify(): if old_s != s: yield s + def simplified(self): + """ Get the simplified version of the expression """ + if not self.can_go_further(): + return self.postfix_tokens[0] + else: + return self.child.simplified() def can_go_further(self): """Check whether it's a last step or not. If not create self.child the next expression. @@ -197,6 +203,8 @@ def test(exp): for i in a.simplify(): print(i) + print(type(a.simplified()), ":", a.simplified()) + print("\n") if __name__ == '__main__':