On Monday, February 16, 2015 at 5:46:06 AM UTC-8, pdenapo 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 
>

Well ... it isn't the null function. You have to construct it as such. 
Similarly "x-1" isn't a function but an expression. Computer algebra 
systems tend to be a little finicky that way. In order to get a function, 
you can do

sage: (x-1).function(x)
x |--> x - 1

which tells sage to make a function that uses its first (and only) argument 
to substitute for x in x-1. This is required to resolve ambiguity if there 
are more variables:

sage: A=(x-y).function(x,y)
sage: B=(x-y).function(y,x)

sage: var('y')
y
sage: A=(x-y).function(x,y)
sage: B=(x-y).function(y,x)
sage: A(1,2)
-1
sage: B(1,2)
1

You see that A,B are distinct functions.
 

> Then, I've tried defining 
>
>  f1=Piecewise ([([0,1],ConstantFunction(0)),([1,2],x-1)]) 
>

Yes, it seems ConstantFunction is poorly integrated with SR. You could use 
SR(0).function(x) instead.
 

> 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 ?


f3=Piecewise([([0,1],SR(0).function(x)),([1,2],(1-x).function(x))])
 

> The behavior of Sage is annoying !  Any help is 
> welcome! 
>

The hard thing is probably to learn to distinguish between "functions" and 
"expressions". This distinction is important because from an expression you 
can't see which variables are supposed to be "parameters", and in which 
order they should be read off from a function call g(a,b,c,d).
 
On Monday, February 16, 2015 at 6:22:17 AM UTC-8, pdenapo wrote:Hi, 

> Another strange behavoir: 
> sage: f=Piecewise([[(1/3,1/2),x]]) 
> sage: f.extend_by_zero_to(0,1) 
> Piecewise defined function with 3 parts, [[(0, 1/3), 0], [(1/3, 1/2), x], 
[(1/2, 1), 0]] 
> sage: f.domain() 
> (1/3, 1/2) 
> extend_by_zero shouldn't have changed the domain to (0,1) ? 

no, it returned as its value a new function with the domain extended.

sage:  f=Piecewise([[(1/3,1/2),x.function(x)]]) 
sage: f
Piecewise defined function with 1 parts, [[(1/3, 1/2), x |--> x]]
sage: g=f.extend_by_zero_to(0,1)
sage: g
Piecewise defined function with 3 parts, [[(0, 1/3), 0], [(1/3, 1/2), x 
|--> x], [(1/2, 1), 0]]
sage: g.domain()
(0, 1)

> sage: f.derivative() 
> /media/sdb3/pablo.sdb3/sage/
>
> sage-6.3-x86_64-Linux/src/bin/sage-ipython:1: 
> DeprecationWarning: Substitution using function-call syntax and 
> unnamed arguments is deprecated and will be removed from a future 
> release of Sage; you can use named arguments instead, like EXPR(x=..., 
> y=...) 
> See http://trac.sagemath.org/5930 for details. 
>   #!/usr/bin/env python 
> Piecewise defined function with 1 parts, [[(1/3, 1/2), x |--> 1]] 
> A bit annoying message, not? 


That message is mainly annoying because sage didn't give you an outright 
error before, when defining a piecewise function with invalid input (with 
an expression instead of a function). As it's saying, it's deprecation 
warning. It will turn into an outright error any day now (and Piecewise 
should probably have thrown an error at you earlier). 

-- 
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.

Reply via email to