diff --git a/devito/symbolics/unevaluation.py b/devito/symbolics/unevaluation.py index 44a3273e54..38b0621d13 100644 --- a/devito/symbolics/unevaluation.py +++ b/devito/symbolics/unevaluation.py @@ -18,4 +18,13 @@ class Mul(sympy.Mul, UnevaluableMixin): class Pow(sympy.Pow, UnevaluableMixin): - __new__ = UnevaluableMixin.__new__ + + def __new__(cls, base, exp, evaluate=None, **kwargs): + if base == 1: + # Otherwise we might get trapped within vicious recursion inside + # SymPy each time it tries to perform a simplification via + # `as_numer_denom`, since the `denom` turns into a Pow itself + # such as `1**c` + return sympy.S.One + else: + return cls.__base__.__new__(cls, base, exp, evaluate=False, **kwargs)