Hi Jason, On Thu, 12 Nov 2009 12:30:11 -0600 Jason Grout <jason-s...@creativetrax.com> wrote:
> It would be nice if we could do something like: > > sage: f(x,0)=e^x > > sage: f(x,t)=x*t > > > or > > sage: f(0)=0 > sage: f(x)=sin(x)/x > > Is there an elegant way to have multiple definitions like this in > pynac, or definitions with specific conditions on the arguments? You can do this: sage: def eval_f(x): ....: if x.is_zero(): ....: return 0 ....: return sin(x)/x ....: sage: f = function('f',nargs=1, eval_func=eval_f) sage: f(0) 0 sage: f(x) sin(x)/x I like the fact that the conditions and comparison order is explicit. > This is one thing that is really nice about Mathematica: since things > work by pattern-matching, you can define a function different ways > based on all sorts of conditions on the inputs. Mathematica then > uses the most general definition it can when trying to evaluate the > function. There are subtle changes in pattern matching between different versions of MMA, and this leads to really (really, really!) hard to track bugs in code written this way. I've heard many people (not all from the same institute :) ) complain about this. Cheers, Burcin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---