Reputation: 117
It's not clear from the documentation how one might easily define a function, based on existing SymPy functions, and alias it to a particular symbol for printing.
For example, I have defined the rectangular function as follows.
import sympy as sp
def rect(t):
return (sp.Heaviside(t + 1/2) - sp.Heaviside(t - 1/2))
While this is useful for the algebra side of things, preventing me from having to define a new Function subclass with derivatives and so forth, it would be nice if I could associate it with uppercase Pi (Π) so that expressions using it would print that instead of a series of Heaviside symbols.
Upvotes: 0
Views: 800
Reputation: 19057
Your rect
would have to be a class rect(Function)
instead of a function and it would need a custom printer. Note, too, that if you define the eval
method as above (in terms of Heaviside) then your expression will no longer be the rect
class...it will be an Add.
Another way to handle this would be to just use Function('\Pi')(t)
in your expressions and when you are ready to do something with them, replace those instances with your definition. But what sorts of things do you want to do with the rect
? Could you use a Piecewise instead?
Upvotes: 1