On Fri, 13 Nov 2009 11:50:10 +0100 Burcin Erocal <bur...@erocal.org> wrote:
> > 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. You can also use this http://peak.telecommunity.com/DevCenter/RulesReadme to define the evaf_f() above. I still prefer being explicit though. 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 -~----------~----~----~----~------~----~------~--~---