From a298bfd2c121f87d71fee2363fde2a6ae280e94b Mon Sep 17 00:00:00 2001 From: Ayush Date: Sat, 20 Apr 2019 20:52:44 +0530 Subject: [PATCH 1/3] simplified expression --- visma/functions/structure.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/visma/functions/structure.py b/visma/functions/structure.py index f7206ad..172c2d6 100644 --- a/visma/functions/structure.py +++ b/visma/functions/structure.py @@ -178,6 +178,7 @@ def __init__(self, tokens=None, coefficient=None, power=None): self.tokens = [] if tokens is not None: self.tokens.extend(tokens) + self.get_reduced() self.type = 'Expression' def __str__(self): @@ -194,6 +195,14 @@ def __str__(self): represent += "{(" + str(self.operand) + ")}" return represent + def get_reduced(self): + '''Simpilifies the expression + ''' + from visma.simplify.simplify import simplify + self.tokens, _, _, _, _ = simplify(self.tokens) + if(self.__class__ == Expression): + self.reduced = True + class Equation(Expression): """Class for equation type From 9994565be409d0bef18c59df6e30445826c08b11 Mon Sep 17 00:00:00 2001 From: Ayush Date: Sat, 20 Apr 2019 20:59:57 +0530 Subject: [PATCH 2/3] corrections --- visma/functions/structure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/visma/functions/structure.py b/visma/functions/structure.py index 172c2d6..cd48cb2 100644 --- a/visma/functions/structure.py +++ b/visma/functions/structure.py @@ -196,7 +196,7 @@ def __str__(self): return represent def get_reduced(self): - '''Simpilifies the expression + '''Simpilifies the expression ''' from visma.simplify.simplify import simplify self.tokens, _, _, _, _ = simplify(self.tokens) From 43ca0d088ba6a2c4780edcbb0a2cb21977426775 Mon Sep 17 00:00:00 2001 From: Ayush Date: Fri, 26 Apr 2019 02:30:56 +0530 Subject: [PATCH 3/3] tests added --- tests/test_functions.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_functions.py b/tests/test_functions.py index ce580f8..782fea8 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -1,5 +1,6 @@ from visma.functions.constant import Constant from visma.functions.variable import Variable +from tests.tester import getTokens ###################### @@ -39,3 +40,21 @@ def test_Variable(): assert isinstance(variable2, Expression) assert variable2.__str__() == '{3log{x}}' ''' + + +####################### +# functions.structure # +####################### + + +def test_reduce(): + + expr = getTokens("(2x+x)") + assert str(expr) == "3.0{x}" + assert expr.type == "Variable" + + expr = getTokens("(3x+4*(x+(2x))+2y)") + assert str(expr) == "{(15.0{x}+2.0{y})}" + + expr = getTokens("((2x+4x)+(2y+4y))") + assert str(expr) == "{(6.0{x}+6.0{y})}"