diff --git a/src/pystencils/fast_approximation.py b/src/pystencils/fast_approximation.py index 7e678da412f1e99a00c55384f95fc13e491948a2..0caba4d91a12158639d3559abbba4fcd1ef940e6 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