On Jun 10, 2008, at 10:58 AM, Stan Schymanski wrote: > > Dear all > > I have been using the .subs(locals()) functionality extensively, but > now I found out that this does not work for piecewise defined > functions. > > Example: > > sage: var('x a b') > (x, a, b) > sage: f1=a*sin(x) > sage: f2=b*sin(x) > sage: f = Piecewise([[(0,pi/2),f1],[(pi/2,pi),f2]]) > sage: a=1 > sage: b=-1 > sage: f.subs(locals()) > ---------------------------------------------------------------------- > ----- > AttributeError Traceback (most recent call > last) > > ... > > AttributeError: PiecewisePolynomial instance has no attribute 'subs'
This is an (easily fixed) bug in PiecewisePolynomial. > The python function approach also fails in this case: > > sage: def g(x): > ....: return Piecewise([[(0,pi/2),f1],[(pi/2,pi),f2]]) > sage: a=1 > sage: b=-1 > sage: g(1) > Piecewise defined function with 2 parts, [[(0, pi/2), a*sin(x)], [(pi/ > 2, pi), b*sin(x)]] > > Am I doing something wrong? The python approach won't work recursively unless everything is a python function (which may have performance impacts). To better understand what's going on here, when you write "a=1" it does not mean "the symbolic variable a is now 1 in every expression it occurs" but rather "the global variable a is 1." In fact writing "var('a,b,c')" simply binds the symbolic expression "a" to the global variable "a." The difference is subtle but important. - Robert --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---