Skip to content

Commit

Permalink
Improve the simplification of Neg further
Browse files Browse the repository at this point in the history
Ref. eng/recordflux/RecordFlux#1797
  • Loading branch information
andrestt committed Oct 28, 2024
1 parent 4e18a65 commit e2905c5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
7 changes: 1 addition & 6 deletions rflx/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/expr_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))),
Expand Down

0 comments on commit e2905c5

Please sign in to comment.