Skip to content

Instantly share code, notes, and snippets.

@asmeurer
Created September 10, 2011 20:57
Show Gist options
  • Save asmeurer/1208773 to your computer and use it in GitHub Desktop.
Save asmeurer/1208773 to your computer and use it in GitHub Desktop.
cmp_to_key fix
diff --git a/sympy/core/expr.py b/sympy/core/expr.py
index 88713b6..44eda0c 100644
--- a/sympy/core/expr.py
+++ b/sympy/core/expr.py
@@ -1825,7 +1825,7 @@ def as_coeff_exponent(self, x):
""" c*x**e -> c,e where x can be any symbolic expression.
"""
x = sympify(x)
- wc = Wild('wc')
+ wc = Wild('wc', exclude=[x])
we = Wild('we')
p = wc*x**we
from sympy import collect
diff --git a/sympy/core/mul.py b/sympy/core/mul.py
index d544ca4..ef27545 100644
--- a/sympy/core/mul.py
+++ b/sympy/core/mul.py
@@ -3,7 +3,8 @@
from operations import AssocOp
from cache import cacheit
from logic import fuzzy_not
-from compatibility import cmp_to_key
+
+from sympy.utilities.misc import default_sort_key
# internal marker to indicate:
# "there are still non-commutative objects -- don't forget to process them"
@@ -452,7 +453,7 @@ def flatten(cls, seq):
return [coeff], [], order_symbols
# order commutative part canonically
- c_part.sort(key=cmp_to_key(Basic.compare))
+ c_part.sort(key=default_sort_key)
# current code expects coeff to be always in slot-0
if coeff is not S.One:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment