Might there be a way to do something that doesn't conflict with the builtin max function in the same way as the (nearly reviewed) #3587 seems to avoid conflict with the builtin sum function? This would be pretty useful, as currently:
sage: var('x,y') (x, y) sage: max(x,y) x sage: f(x)=1+x;g(x)=2-x sage: max(f,g) x |--> x + 1 which last result is... debatable. - kcrisman On Sep 16, 10:34 am, Burcin Erocal <bur...@erocal.org> wrote: > Hi Matt, > > On Mon, 14 Sep 2009 05:02:54 -0700 (PDT) > > Matt Rissler <discn...@gmail.com> wrote: > > Is it possible to have max behave as you would expect with a symbolic > > expression, i.e. wait until you evaluate it or restrict the domain to > > check what is the maximum of the two or more values. > > Below is a quick implementation of a symbolic max function. It seems > to work here: > > sage: max_symbolic = MaxSymbolic() > sage: max_symbolic(5,0) > 5 > sage: max_symbolic(x,0) > max(x, 0) > sage: max_symbolic(x,0).subs(x=5) > 5 > > Is this at all useful? Note that trying to evaluate this many times > might be very very slow. > > Cheers, > Burcin > > ---- > > from sage.symbolic.function import SFunction > > class MaxSymbolic(SFunction): > def __init__(self): > SFunction.__init__(self, 'max', eval_func=self._eval_) > > def _eval_(*args): > largs = len(args) > if largs == 0: > raise TypeError, "expected one or more arguments" > if largs == 1: > return args[0] > > res = 0 > for x in args: > try: > if hasattr(x, 'pyobject'): > pyobj = x.pyobject() > else: > pyobj = x > except TypeError: > return None > res = max(pyobj, res) > > return res --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---