Join GitHub today
Remove args sorting from And and Or? #17087
As you can see from #17066 (comment), the sorting in the And and Or constructor (from LatticeOp) can take up a significant amount of time when using large logic expressions.
We should see if we can remove it. The
An important warning here, currently
This is related to #5954, but I think removing the ordering from Add/Mul will be much harder, as they are used everywhere. We should try doing it with the logic classes first, to see what are the issues that come up.
The expectation would be implicit. The issue is that the same object could appear twice with different arg orderings.
Here's a test failure from making the change
I haven't digged into it, but somehow simplify() isn't handling the different arg ordering correctly.
This is the test change (the real change should probably set
diff --git a/sympy/core/operations.py b/sympy/core/operations.py index 4c37663f4..2d10678f5 100644 --- a/sympy/core/operations.py +++ b/sympy/core/operations.py @@ -452,9 +452,8 @@ def make_args(cls, expr): return frozenset([sympify(expr)]) @property - @cacheit def args(self): - return tuple(ordered(self._argset)) + return tuple(self._argset) @staticmethod def _compare_pretty(a, b):
Yes, I'd like to try this first with the logic classes. If we can get it working, we can attempt to do it in the core (#5954). But that will be much harder.
In both instances the sorting is the cause of a significant amount of the time SymPy spends doing various things. Removing the sorting should provide a speed boost everywhere. For the logic classes, it should speed up anything using the new assumptions.