# question on integration of piecewise related function

24 views

### linouc

Aug 15, 2011, 9:56:48 AM8/15/11
to sage-support
Hello, Sage groups, I have a problem, please see the example below, I
wonder anyone can help me solve this problem:

f = Piecewise([[(0,pi/2),-1],[(pi/2,pi),2]])
a=pi*integrate(f,x,0,pi)
a.show()
b=pi*integrate(sin(x),x,0,pi)
b.show()
integrate(f*sin(x),x,0,pi)

-----------------------------------------------
The first two integrations are right, but for the last one, I got the
following error message:

Traceback (click to the left of this block for traceback)
...
AttributeError: 'sage.symbolic.expression.Expression' object has no
attribute 'domain'

### David Joyner

Aug 15, 2011, 10:00:52 AM8/15/11
On Mon, Aug 15, 2011 at 9:56 AM, linouc <linzhe...@gmail.com> wrote:
> Hello, Sage groups, I have a problem, please see the example below, I
> wonder anyone can help me solve this problem:
>
> f = Piecewise([[(0,pi/2),-1],[(pi/2,pi),2]])
> a=pi*integrate(f,x,0,pi)
> a.show()
> b=pi*integrate(sin(x),x,0,pi)
> b.show()
> integrate(f*sin(x),x,0,pi)
>

I'm guessing that your error means that
multiplication of a piecewise times a symbolic function
has not been implemented:

sage: f = Piecewise([[(0,pi/2),-1],[(pi/2,pi),2]])
sage: f*sin(x)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)

> -----------------------------------------------
> The first two integrations are right, but for the last one, I got the
> following error message:
>
>
> Traceback (click to the left of this block for traceback)
> ...
> AttributeError: 'sage.symbolic.expression.Expression' object has no
> attribute 'domain'
>

> --
> To post to this group, send email to sage-s...@googlegroups.com
> To unsubscribe from this group, send email to sage-support...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org
>

### kcrisman

Aug 15, 2011, 10:21:10 AM8/15/11
to sage-support

On Aug 15, 10:00 am, David Joyner <wdjoy...@gmail.com> wrote:
> On Mon, Aug 15, 2011 at 9:56 AM, linouc <linzhenhua...@gmail.com> wrote:
> > Hello, Sage groups, I have a problem, please see the example below, I
> > wonder anyone can help me solve this problem:
>
> > f = Piecewise([[(0,pi/2),-1],[(pi/2,pi),2]])
> > a=pi*integrate(f,x,0,pi)
> > a.show()
> > b=pi*integrate(sin(x),x,0,pi)
> > b.show()
> > integrate(f*sin(x),x,0,pi)
>
> I'm guessing that your error means that
> multiplication of a piecewise times a symbolic function
> has not been implemented:
>
> sage: f = Piecewise([[(0,pi/2),-1],[(pi/2,pi),2]])
> sage: f*sin(x)

> > AttributeError: 'sage.symbolic.expression.Expression' object has no
> > attribute 'domain'

David is correct. This is only a symptom of the real problem, which
is an outdated (though still quite functional and useful for its
purposes) piecewise class. Using piecewise functions by themselves
is pretty coherent, but the rest of Sage has made a lot of progress
since then.

Unfortunately, we haven't had any developer with all three of the
time, motivation, and expertise to do this. We would welcome any
contributions to improve this!

- kcrisman