From 2f7f20167ba6da5b6197b48333772d292662d2ef Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 3 Oct 2017 16:33:18 -0500 Subject: [PATCH] Help CSE by using UnevaluatedExpr --- sumpy/expansion/multipole.py | 4 ++-- sumpy/symbolic.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/sumpy/expansion/multipole.py b/sumpy/expansion/multipole.py index 4e226cd9..92ae80f3 100644 --- a/sumpy/expansion/multipole.py +++ b/sumpy/expansion/multipole.py @@ -178,11 +178,11 @@ class VolumeTaylorMultipoleExpansionBase(MultipoleExpansionBase): assert n >= k from sympy import binomial contrib *= (binomial(n, k) - * dvec[idim]**(n-k)) + * sym.UnevaluatedExpr(dvec[idim]/tgt_rscale)**(n-k)) result[i] += ( contrib - * (src_rscale**sum(src_mi) / tgt_rscale**sum(tgt_mi))) + * sym.UnevaluatedExpr(src_rscale/tgt_rscale)**sum(src_mi)) result[i] /= mi_factorial(tgt_mi) diff --git a/sumpy/symbolic.py b/sumpy/symbolic.py index c213f4b9..c7ed61e6 100644 --- a/sumpy/symbolic.py +++ b/sumpy/symbolic.py @@ -98,6 +98,19 @@ def _coeff_isneg(a): return a.is_Number and a.is_negative +have_unevaluated_expr = False +if not USE_SYMENGINE: + try: + from sympy import UnevaluatedExpr + have_unevaluated_expr = True + except ImportError: + pass + +if not have_unevaluated_expr: + def UnevaluatedExpr(x): # noqa + return x + + # {{{ debugging of sympy CSE via Maxima class _DerivativeKiller(IdentityMapperBase): -- GitLab