How should existing functions be overridden for new symbols?
22 views
Skip to first unread message
Michael O'Connor
unread,
Oct 30, 2015, 9:14:54 AM10/30/15
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
Hi,
I'm quite new to Sympy, so this is probably simple, but I couldn't find it in the documentation. The documentation does a good job of explaining how you can define a new function, and specify how it should reduce on certain arguments. But I couldn't see how to define new symbols and declare how they should act with respect to +, *, **, ...
For example, I was thinking of trying to implement ordinal arithmetic. In that case, I would have, for example, new symbols omega and epsilon0, and would like omega**epsilon0 to evaluate to epsilon0. Can that be accomplished?
Thanks!
Aaron Meurer
unread,
Oct 30, 2015, 11:55:03 AM10/30/15
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 sy...@googlegroups.com
You should subclass Expr and define certain methods. For **, you
should define _eval_power(self, expt) on the omega object.
For + and *, there are no direct ways to interface with Add and Mul,
but you can define __add__ and __mul__ to define the Python operators
directly.