From e2905c581dd82a9cbafcfa0603e9e93ee5c6972e Mon Sep 17 00:00:00 2001 From: Andres Toom Date: Thu, 19 Sep 2024 00:32:03 +0300 Subject: [PATCH] Improve the simplification of Neg further Ref. eng/recordflux/RecordFlux#1797 --- rflx/expr.py | 7 +------ tests/unit/expr_test.py | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/rflx/expr.py b/rflx/expr.py index ce4e79e92..453f84df9 100644 --- a/rflx/expr.py +++ b/rflx/expr.py @@ -726,12 +726,7 @@ def substituted( return expr def simplified(self) -> Expr: - simple_expr = self.expr.simplified() - if isinstance(simple_expr, Neg): - return simple_expr.expr - if isinstance(simple_expr, Number): - return -simple_expr - return self.__class__(simple_expr, self.location) + return -self.expr.simplified() class MathAssExpr(AssExpr): diff --git a/tests/unit/expr_test.py b/tests/unit/expr_test.py index 2bff5bb27..a0a38187f 100644 --- a/tests/unit/expr_test.py +++ b/tests/unit/expr_test.py @@ -702,7 +702,7 @@ def test_neg_substituted() -> None: # Argument simplifies to some other expression ( Neg(Mul(Variable("X"), Add(Number(2), Number(3)))), - Neg(Mul(Variable("X"), Number(5))), + Mul(Variable("X"), Number(-5)), ), # Argument cannot be simplified (Neg(Variable("X")), Neg(Variable("X"))),