Custom ordering in Sympy

22 views
Skip to first unread message

Paul Royik

unread,
Nov 29, 2014, 12:59:06 PM11/29/14
to sy...@googlegroups.com

I want to rewrite Integral of 10x^7-xy+y/x+2x^5 as sum of integrals. Something like

Int(10x^7-xy+y/x+2x^5) = Int(10x^7)-Int(xy)+Int(y/x)+Int(2x^5)

But sympy makes its own ordering and outputs

Int(10x^7-xy+y/x+2x^5) = Int(2x^5)+Int(10x^7)+Int(y/x)-Int(xy)

Where can I override this behaviour if Int is my own class?

Aaron Meurer

unread,
Nov 30, 2014, 10:58:37 PM11/30/14
to sy...@googlegroups.com
The order that an Add is printed in is determined by the printer. I
think the only way to override this is to subclass the printer you are
using and override _as_ordered_terms. See
http://docs.sympy.org/latest/modules/printing.html and
https://github.com/sympy/sympy/blob/e6fc53f27ee872b27bc79b96529fc4bf34d4f023/sympy/printing/printer.py#L264.

Aaron Meurer
> --
> 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 post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/ca91d6e0-54fb-416f-bdd5-4432a36ff976%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages