The problem is, that there is no "simple" way to do it with BuiltinFunction. The documentation of this class is currently in the SAGE_ROOT/devel/sage/symbolic/function.pxd itself. You can there see the Function base class from which BuiltinFunction is derived, there is also the __call__ method defined. There you will also find many helpful docstrings how these classes work. This was also the way how I started ^^ In fact the only thing you do is overload the right methods. _eval_ for the evaluation, _evalf_ for the .n() method, _derivative_ for derivative of the function and so on.
Normally if you derive BuiltinFunction (for user defined function you normally use symbolic function) you don't overload __call__. Only __eval__ should be overloaded (this is also mentioned in the functions.pxd). You would have to overload __call__ in your new class to handle the vectors (but lose the handling of other data types, but it could be a fast solution), or modify the current __call__ method in the Function class to work with that (there you find the coercion methods). I don't think it's complicated, you simply would have to add a statement that checks if one of the arguments is a vector and hand it over to the right method. But it would require some work, and is the reason why I said you would get credits for doing that =) You will find examples on the trac ticket I posted (here the latest version: http://trac.sagemath.org/sage_trac/attachment/ticket/9706/orthogonal_polys.9.py ). look for example at the OrthogonalPolynomials class (which is the base class) and the Chebyshev_T class: You define class functions and give it to the __eval__ (or define eval differently for each subclass)). Also you see how to define derivatives and so on. But as mentioned above: to understand BuiltinFunction, you should understand how the base class is working (at least the basics). regards, maldun On 18 Jan., 22:24, Chris Swierczewski <cswie...@gmail.com> wrote: > > Coercion is currently still a little problem, and I think you would > > earn some credits here if add this ability to the call method in > > BuiltinFunction. Have you ever looked into that class? Perhaps it > > helps you understanding the problem. > > So I've been looking at some of the trigonometric functions in > sage/functions/trig.pyx but I'm having trouble understanding what's going on. > There's not much going on in terms of documentation and __call__ isn't even > being overloaded in those examples. (See arccos or something similar.) > > Have you encountered any slight more elaborate examples? > > > If you need a quick solution, simply writing a small python class > > would do the trick. (similar as in the current ortho_polys version) > > I considered this at first but I wanted to see if there's a preexisting Sage > construct that could help me out. BuiltinFunction seems like a step in the > right direction if I can only find examples of its use. There's not a lot of > helpful documentation out there. I'm gonna have to make a blog post about it > once I figure it out. :) > > -- > Chris -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org