On Mon, Feb 16, 2015 at 8:46 AM, Pablo De Napoli <pden...@gmail.com> wrote: > Hi, > > I'm having trouble with some piecewise constant functions. > > Suppose that I define > > f=Piecewise ([([0,1],0),([1,2],x-1)]) > > Then f.integral() works as expected, but f.derivative() will fail with > > TypeError: 'sage.rings.integer.Integer' object is not callable > > It seems that Sage does not understand that 0 is the null function, > and treat it as an integer for with a derivative is not meaningful > > Then, I've tried defining > > f1=Piecewise ([([0,1],ConstantFunction(0)),([1,2],x-1)]) > > f1.derivative() now works and one would expect, but > f1.integral() fails with a TypeError > > My last try was to cast 0 to the symbolic ring > > f2=Piecewise ([([0,1],SR(0)),([1,2],x-1)]) > > Now f2.integral() works, but f2.derivative() fails with the error message > > ValueError: the number of arguments must be less than or equal to 0 > > Whats the right way to define my function so that both integral and > derivative work ? The behavior of Sage is annoying ! Any help is > welcome! >
Sorry, but I missed this message earlier. Try instead: sage: PR.<x> = PolynomialRing(RR, "x") sage: f = Piecewise([([0,1],0*x),([1,2],x-1)]) sage: f.derivative() Piecewise defined function with 2 parts, [[(0, 1), x |--> 0], [(1, 2), x |--> 1]] sage: f.integral() Piecewise defined function with 2 parts, [[(0, 1), x |--> 0], [(1, 2), x |--> 1/2*x^2 - 1.0*x + 0.5]] > best regards > Pablo > > -- > 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 sage-devel+unsubscr...@googlegroups.com. > To post to this group, send email to sage-devel@googlegroups.com. > Visit this group at http://groups.google.com/group/sage-devel. > For more options, visit https://groups.google.com/d/optout. -- 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 sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.