From 6e3a147cab03d30ee6e168b5e67c14e20e660259 Mon Sep 17 00:00:00 2001
From: Michael Kuron <m.kuron@gmx.de>
Date: Sun, 8 Sep 2024 14:56:45 +0200
Subject: [PATCH] don't convert plain negation into fused-multiple add

---
 src/pystencils/fast_approximation.py | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/pystencils/fast_approximation.py b/src/pystencils/fast_approximation.py
index 7e678da41..0caba4d91 100644
--- a/src/pystencils/fast_approximation.py
+++ b/src/pystencils/fast_approximation.py
@@ -220,13 +220,14 @@ def insert_fma(term, operators):
         # Find Mul with three factors, one of them -1, which can be fused
         elif expr.func == sp.Mul and -1 in expr.args:
             expr = flatten(expr)
-            factors = list(expr.args)
-            factors.remove(-1)
-            factors = [visit(f) for f in factors]
-            if '-*+' in operators:
-                return fnmadd(factors[0], sp.Mul(*factors[1:]), 0)
-            elif '-*-' in operators:
-                return fnmsub(factors[0], sp.Mul(*factors[1:]), 0)
+            if len(expr.args) > 2:
+                factors = list(expr.args)
+                factors.remove(-1)
+                factors = [visit(f) for f in factors]
+                if '-*+' in operators:
+                    return fnmadd(factors[0], sp.Mul(*factors[1:]), 0)
+                elif '-*-' in operators:
+                    return fnmsub(factors[0], sp.Mul(*factors[1:]), 0)
         new_args = [visit(a) for a in expr.args]
         return expr.func(*new_args) if new_args else expr
 
-- 
GitLab