diff options
author | jaseg <git@jaseg.de> | 2023-11-09 14:32:41 +0100 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2023-11-14 21:52:12 +0100 |
commit | 09e3731b74581027290d52fef5b6ee275679788c (patch) | |
tree | 09c03dc9bcf5af47d9a1aeaeae5ef01d861c2f06 /gerbonara | |
parent | 37b6b8f8d26d6ef83d76cee1516398ee4fcc4fa4 (diff) | |
download | gerbonara-09e3731b74581027290d52fef5b6ee275679788c.tar.gz gerbonara-09e3731b74581027290d52fef5b6ee275679788c.tar.bz2 gerbonara-09e3731b74581027290d52fef5b6ee275679788c.zip |
aperture macros: Add expression simplification
Diffstat (limited to 'gerbonara')
-rw-r--r-- | gerbonara/aperture_macros/expression.py | 23 |
1 files changed, 3 insertions, 20 deletions
diff --git a/gerbonara/aperture_macros/expression.py b/gerbonara/aperture_macros/expression.py index f096cf1..9bf59e9 100644 --- a/gerbonara/aperture_macros/expression.py +++ b/gerbonara/aperture_macros/expression.py @@ -196,12 +196,6 @@ class NegatedExpression(Expression): # -(x-y) == y-x case OperatorExpression(operator.sub, l, r): return OperatorExpression(operator.sub, r, l) - # -(x [*/] y) == -x [*/] y - case OperatorExpression((operator.mul | operator.truediv) as op, ConstantExpression(l), r): - return OperatorExpression(op, ConstantExpression(-l), r) - # -(x [*/] y) == x [*/] -y - case OperatorExpression((operator.mul | operator.truediv) as op, l, ConstantExpression(r)): - return OperatorExpression(op, l, ConstantExpression(-r)) case x: return NegatedExpression(x) @@ -293,23 +287,12 @@ class OperatorExpression(Expression): # -x [*/] -y == x [*/] y case (NegatedExpression(l), (operator.truediv | operator.mul) as op, NegatedExpression(r)): rv = op(l, r) - # -x + -y == -(x + y) - case (NegatedExpression(l), operator.add, NegatedExpression(r)): - rv = -(l+r) + # x + -y == x - y + case (l, operator.add, NegatedExpression(r)): + rv = l-r # -x + y == y - x case (NegatedExpression(l), operator.add, r): rv = r-l - # x + x == 2 * x - case (l, operator.add, r) if l == r: - rv = 2*r - case ((l, op, OperatorExpression(operator.mul, ConstantExpression(cons), r)) | - (l, op, OperatorExpression(operator.mul, r, ConstantExpression(cons)))) \ - if l == r and op in (operator.add, operator.sub): - return op(1, cons) * r - case ((OperatorExpression(operator.mul, ConstantExpression(cons), r), op, l) | - (OperatorExpression(operator.mul, r, ConstantExpression(cons)), op, l)) \ - if l == r and op in (operator.add, operator.sub): - return op(cons, 1) * r case _: # default return OperatorExpression(self.op, l, r) |