Groups
Groups
Sign in
Groups
Groups
sympy
Conversations
About
Send feedback
Help
Ordered terms of a new Expression
43 views
Skip to first unread message
Paul Royik
unread,
Mar 25, 2021, 10:06:42 AM
3/25/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sympy
I want to create a class that makes expression colored.
class Colored(Expr):
pass
How do I make Colored behave exactly as its arg, when I sort args?
(x+Colored(2)).as_ordered_terms() should give the same as (x+2).as_ordered_terms()
(x*Colored(y)).as_ordered_factors() should give the same as (x*y).as_ordered_factors()
Do I need to override some methods?
Paul Royik
unread,
Mar 25, 2021, 11:43:14 AM
3/25/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sympy
Also, what is the best way to set a color? Setting color in args is not a very good idea, as color is a string.
Aaron Meurer
unread,
Mar 26, 2021, 4:54:02 PM
3/26/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sympy
I didn't test it extensively, but I think it should be enough to
override the sort_key method
class Colored(Expr):
def sort_key(self, order=None):
return self.args[0].sort_key(order=order)
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 view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/62a9ddd1-b7be-4821-94f7-37103518355en%40googlegroups.com
.
Paul Royik
unread,
Mar 28, 2021, 8:33:15 AM
3/28/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sympy
Thank you!
Reply all
Reply to author
Forward
0 new messages