2009/6/20 Golam Mortuza Hossain <gmhoss...@gmail.com>: > > Hi, > > It seems that there is a major bug in new symbolics simplify() > method involving "D" and symbolic function (Sage-4.0.1). > > ----------- > sage: f(x) = function('f',x) > sage: f(-x).diff(x) > -D[0](f)(-x) > sage: f(-x).diff(x).simplify() > -D[0](f)(x) > ----------- > Notice that simplify() causes f(-x) to become f(x).
The bug isn't really in simplify so much as its in the Sage --> Maxima conversion function. The simplify function, whose existence I'm not even sure we should have, just converts an object to maxima, then converts it back. It shouldn't even be needed with the new pynac based symbolics. But anyway, in this case I'm happy it helped expose a bug. In particular: sage: g = -f(-x).diff(x); g D[0](f)(-x) sage: g._maxima_init_() "diff('f(x), x, 1)" Notice that the code that generates the maxima version of g above just forgets the minus! In fact, the _maxima_init_ function is really broken in this case: sage: h = g.subs(-x==sin(x^2));h D[0](f)(sin(x^2)) sage: h._maxima_init_() "diff('f(x), x, 1)" Even sin(x^2) gets replaced by x. The relevant broken wrong code is #================================================ File: /scratch/wstein/build/sage-4.0.2/local/lib/python2.5/site-packages/sage/symbolic/expression_conversions.py Definition: I.derivative(self, ex, operator) Source: def derivative(self, ex, operator): """ EXAMPLES:: sage: import operator sage: from sage.symbolic.expression_conversions import InterfaceInit sage: m = InterfaceInit(maxima) sage: a = function('f', x).diff(x); a D[0](f)(x) sage: print m.derivative(a, a.operator()) diff('f(x), x, 1) sage: b = function('f', x).diff(x).diff(x) sage: print m.derivative(b, b.operator()) diff('f(x), x, 2) """ #This code should probably be moved into the interface #object in a nice way. from sage.symbolic.ring import is_SymbolicVariable if self.name_init != "_maxima_init_": raise NotImplementedError args = ex.args() if (not all(is_SymbolicVariable(v) for v in args) or len(args) != len(set(args))): raise NotImplementedError, "arguments must be distinct variables" f = operator.function() params = operator.parameter_set() params = ["%s, %s"%(args[i], params.count(i)) for i in set(params)] return "diff('%s(%s), %s)"%(f.name(), ", ".join(map(repr, args)), ", ".join(params)) #================================================ and notice that sage: g.args() (x,) whereas .operands() would be the right thing to call. So indeed you were spot on right. However, note reading the code above that we're just going to get a NotImplementedError once this is fixed. Anyway, clearly this is a bug. I've made this trac #6376 http://trac.sagemath.org/sage_trac/ticket/6376 I've also cc'd Mike Hansen, since this bug is in his code, so maybe it will be easier for him to fix. William > > Also it seems that the order of operands is getting messed up > ------------ > sage: x,y = var('x,y') > sage: f(x,y) = function('f',x,y) > sage: f(-y,-x).diff(x) > -D[1](f)(-y, -x) > sage: f(-y,-x).diff(x).simplify() > -D[1](f)(x, y) > ------------ > > I suspect that somewhere ".arguments()" method is used > to evaluate the function rather than the ".operands()" method. > > Cheers, > Golam > > > > -- William Stein Associate Professor of Mathematics University of Washington http://wstein.org --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---