On Thursday, April 21, 2016 at 10:44:19 AM UTC-7, Francisco Pena wrote: > > Hi, > > I believe the solution of Nils using SR(0) is very elegant, but it cannot > be applied in every case. For example, when the piecewise is created by > another method (trapezoid): > > f = Piecewise([[(-1,1), sin(x^2)]]) >
To be sure of what sage is doing, this should be f = Piecewise([[(-1,1), sin(x^2).function(x)]]) > t = f.trapezoid(3) > > That's just a bug in the implementation of the trapezoid method. A lot of people have worked on symbolics in sage without realizing the difference between callable functions and expressions. It sort-of works because expressions used to be callable (but you wouldn't know which variable the value would be substituted in!), but as you can see, only with the number of variables that actually occur. f.trapezoid should be rewritten to include the appropriate `.function(x)` calls or make things into `lambda x:` expressions in the definition. > Here t has a constant part in (-1/3,1/3): > > Piecewise defined function with 3 parts, [[(-1, -1/3), -3/2*(x + 1)*(sin(1 > ) - sin(1/9)) + sin(1)], [(-1/3, 1/3), sin(1/9)], [(1/3, 1), 1/2*(3*x - 1 > )*(sin(1) - sin(1/9)) + sin(1/9)]] > > So t(0.1) gives the following error: > > ValueError: the number of arguments must be less than or equal to 0 > Nice example! -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
