Skip to content

Commit

Permalink
Don't use ordering_of_classes for comparison of classes
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Dec 26, 2015
1 parent b0a218c commit 73027a6
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 87 deletions.
3 changes: 2 additions & 1 deletion sympy/core/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,8 @@ def _preorder_traversal(self, node, keys):
yield subtree

def skip(self):
"""Skip yielding current node's (last yielded node's) subtrees.
"""
Skip yielding current node's (last yielded node's) subtrees.
Examples
========
Expand Down
76 changes: 4 additions & 72 deletions sympy/core/core.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,5 @@
""" The core's core. """

# used for canonical ordering of symbolic sequences
# via __cmp__ method:
# FIXME this is *so* irrelevant and outdated!
ordering_of_classes = [
# singleton numbers
'Zero', 'One', 'Half', 'Infinity', 'NaN', 'NegativeOne', 'NegativeInfinity',
# numbers
'Integer', 'Rational', 'Float',
# singleton symbols
'Exp1', 'Pi', 'ImaginaryUnit',
# symbols
'Symbol', 'Wild', 'Temporary',
# arithmetic operations
'Pow', 'Mul', 'Add',
# function values
'Derivative', 'Integral',
# defined singleton functions
'Abs', 'Sign', 'Sqrt',
'Floor', 'Ceiling',
'Re', 'Im', 'Arg',
'Conjugate',
'Exp', 'Log',
'Sin', 'Cos', 'Tan', 'Cot', 'ASin', 'ACos', 'ATan', 'ACot',
'Sinh', 'Cosh', 'Tanh', 'Coth', 'ASinh', 'ACosh', 'ATanh', 'ACoth',
'RisingFactorial', 'FallingFactorial',
'factorial', 'binomial',
'Gamma', 'LowerGamma', 'UpperGamma', 'PolyGamma',
'Erf',
# special polynomials
'Chebyshev', 'Chebyshev2',
# undefined functions
'Function', 'WildFunction',
# anonymous functions
'Lambda',
# Landau O symbol
'Order',
# relational operations
'Equality', 'Unequality', 'StrictGreaterThan', 'StrictLessThan',
'GreaterThan', 'LessThan',
]


class Registry(object):
"""
Expand All @@ -65,39 +24,12 @@ def __delattr__(self, name):


class BasicMeta(type):

def __init__(cls, *args, **kws):
def __init__(cls, *args, **kwargs):
all_classes.add(cls)

def __cmp__(cls, other):
# If the other object is not a Basic subclass, then we are not equal to
# it.
if not isinstance(other, BasicMeta):
return -1
n1 = cls.__name__
n2 = other.__name__
if n1 == n2:
return 0

UNKNOWN = len(ordering_of_classes) + 1
try:
i1 = ordering_of_classes.index(n1)
except ValueError:
i1 = UNKNOWN
try:
i2 = ordering_of_classes.index(n2)
except ValueError:
i2 = UNKNOWN
if i1 == UNKNOWN and i2 == UNKNOWN:
return (n1 > n2) - (n1 < n2)
return (i1 > i2) - (i1 < i2)

def __lt__(cls, other):
if cls.__cmp__(other) == -1:
return True
return False
return cls.__name__ < other.__name__


def __gt__(cls, other):
if cls.__cmp__(other) == 1:
return True
return False
return cls.__name__ > other.__name__
4 changes: 0 additions & 4 deletions sympy/interactive/printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def init_printing(pretty_print=True, order=None, use_unicode=None,
lex (default), which is lexographic order;
grlex, which is graded lexographic order;
grevlex, which is reversed graded lexographic order;
old, which is used for compatibility reasons and for long expressions;
None, which sets it to lex.
use_unicode: boolean or None
If True, use unicode characters;
Expand Down Expand Up @@ -216,9 +215,6 @@ def init_printing(pretty_print=True, order=None, use_unicode=None,
>>> init_printing(order='grevlex') # doctest: +SKIP
>>> str(y * x**2 + x * y**2) # doctest: +SKIP
x**2*y + x*y**2
>>> init_printing(order='old') # doctest: +SKIP
>>> str(x**2 + y**2 + x + y) # doctest: +SKIP
x**2 + x + y**2 + y
>>> init_printing(num_columns=10) # doctest: +SKIP
>>> x**2 + x + y**2 + y # doctest: +SKIP
x + y +
Expand Down
3 changes: 0 additions & 3 deletions sympy/interactive/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,6 @@ def init_session(ipython=None, pretty_print=True, order=None,
>>> init_session(order='grevlex') #doctest: +SKIP
>>> y * x**2 + x * y**2 #doctest: +SKIP
x**2*y + x*y**2
>>> init_session(order='old') #doctest: +SKIP
>>> x**2 + y**2 + x + y #doctest: +SKIP
x + y + x**2 + y**2
>>> theta = Symbol('theta') #doctest: +SKIP
>>> theta #doctest: +SKIP
theta
Expand Down
6 changes: 1 addition & 5 deletions sympy/printing/repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,7 @@ def _print_NaN(self, expr):

def _print_Mul(self, expr, order=None):
terms = expr.args
if self.order != 'old':
args = expr._new_rawargs(*terms).as_ordered_factors()
else:
args = terms

args = expr._new_rawargs(*terms).as_ordered_factors()
args = map(self._print, args)
return "Mul(%s)" % ", ".join(args)

Expand Down
2 changes: 0 additions & 2 deletions sympy/printing/tests/test_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def _sympyrepr(self, printer):
def test_Add():
sT(x + y, "Add(Symbol('x'), Symbol('y'))")
assert srepr(x**2 + 1, order='lex') == "Add(Pow(Symbol('x'), Integer(2)), Integer(1))"
assert srepr(x**2 + 1, order='old') == "Add(Integer(1), Pow(Symbol('x'), Integer(2)))"


def test_Function():
Expand Down Expand Up @@ -165,7 +164,6 @@ def test_settins():

def test_Mul():
sT(3*x**3*y, "Mul(Integer(3), Pow(Symbol('x'), Integer(3)), Symbol('y'))")
assert srepr(3*x**3*y, order='old') == "Mul(Integer(3), Symbol('y'), Pow(Symbol('x'), Integer(3)))"


def test_PolyRing():
Expand Down

0 comments on commit 73027a6

Please sign in to comment.