RFC on #30818 - new printing order

65 views
Skip to first unread message

Chris Smith

unread,
Oct 26, 2026, 8:47:25 PMOct 26
to sympy
In the PR I have attempted to remove evaluation from ordering of terms. Currently, every print operation runs through evaluation of every term in an expression to determine what order it should appear; it is recognized that this is a high cost to pay for obtaining an order.

With the changes I have made, a new method of ordering terms was built and I need feedback on it. I prefer to have the ordre of terms be the same with or without the O() operator, so `1+x+x**2`. I don't know how strong of a preference this is for others. And in any case, the order can still be explicitly requested using the order settings like 'grlex'.

Anyone who has an opinion is encouraged to express it here or on the PR:

Oscar Benjamin

unread,
Oct 27, 2026, 1:00:20 PMOct 27
to sy...@googlegroups.com
What do you mean by "evaluation of every term"?

Changing the printing based on having an O term is problematic but
really the problem is just representing series as an Add with an O
term. There should be a separate Series object rather than butchering
Expr to cope with big O terms.
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/sympy/a05de132-9a82-4138-bb9f-43d2f338342bn%40googlegroups.com.

Chris Smith

unread,
Oct 27, 2026, 1:44:23 PMOct 27
to sympy
In `as_terms`, every term has its extracted coefficient converted to a Python complex number (that is the easy part). In addition, every numerical factor remaining in the term is passed to `complex(factor)`, too. All of this happens before sorting, regardless of whether the numerical values are needed to distinguish the terms or not.

/c

Aaron Meurer

unread,
Oct 27, 2026, 6:02:09 PMOct 27
to sy...@googlegroups.com
I still need to look at the PR more closely, but I approve of a change
to make the printer not numerically evaluate expressions.

Aaron Meurer
> To view this discussion visit https://groups.google.com/d/msgid/sympy/37ad80d9-b8eb-487e-bb42-66ce885e6244n%40googlegroups.com.

Chris Smith

unread,
Nov 5, 2026, 3:22:10 PMNov 5
to sympy
This is a second request for anyone that has a preference for how sympy expressions are printed to look at the summary of changes and perhaps to check the diff for a module of  interested to see if there was any contrariwise change. In all I really like the modifications to print order. And of course anyone who has had an expression hang while trying to print it is going to be happy with the changes to as_terms, too.

/c
Reply all
Reply to author
Forward
0 new messages