Skip to content

Commit

Permalink
Add warning for taking commutator with SymPy objects
Browse files Browse the repository at this point in the history
All SymPy objects should be commutative in drudge, so taking commutator
with SymPy objects is highly likely to be caused by an error.
  • Loading branch information
tschijnmo committed Sep 16, 2017
1 parent 72b6960 commit c6dafe3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion drudge/drudge.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from IPython.display import Math, display
from pyspark import RDD, SparkContext
from sympy import IndexedBase, Symbol, Indexed, Wild, symbols, sympify
from sympy import IndexedBase, Symbol, Indexed, Wild, symbols, sympify, Expr

from .canonpy import Perm, Group
from .drs import compile_drs, DrsEnv, DrsSymbol
Expand Down Expand Up @@ -786,6 +786,13 @@ def __ror__(self, other):

def _comm(self, other, right=False):
"""Compute the commutator."""

if isinstance(other, Expr):
msg = 'Taking commutator with commutative expression `{}`'.format(
other
)
warnings.warn(msg)

prod, free_vars, expanded = self._cartesian_terms(other, right)

dumms = self._drudge.dumms
Expand Down

0 comments on commit c6dafe3

Please sign in to comment.