Ask Your Question
0

Variable type returned after integrating.

asked 2011-04-07 17:17:29 -0500

Ben Reynwar gravatar image

If I have an expression and I integrate it, the type of object that is returned is not constant.

> x = var('x')
> type((x**2).integral(x))
<type 'sage.symbolic.expression.Expression'>
> type((0*x).integral(x))
<type 'sage.rings.integer.Integer'>

This makes it quite hard to write functions that do things with Expressions. Is there some trick I'm missing to get around this?

An example of where this causes a problem:

> ff = Piecewise([[(-Infinity, -1), 0*x], [(-1, 1), x**0], [(1, Infinity), 0*x]], x)
> ff.integral(x, -1.0, 1.0)         
Traceback (click to the left of this block for traceback)
...
AttributeError: 'sage.rings.integer.Integer' object has no attribute 'function'
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2011-04-07 20:01:53 -0500

DSM gravatar image

updated 2011-04-07 20:02:31 -0500

The problem with the Piecewise functions was reported in trac #10841 and a fix has been accepted and is pending for sage 4.7. It basically only adds four characters to cast the integrand to an Expression. If there are other functions which don't behave, could you report them to trac?

Integration does gives different type results depending on the ranges (e.g. for definite integrals you can easily get Integers, Rationals, RealDoubleElements, and so on.) You can work around this easily enough on the "outside" in your own code by explicitly casting to SR, but I admit it's sometimes hard to work around problems on the "inside", i.e. in built-in functions.

edit flag offensive delete link more

Comments

And if you report it to Trac, could you also cc: kcrisman on this? It's sometimes hard to track down all cases where this should be done. (Of course, then hoping that we don't break something because it doesn't return something in ZZ which requires a ZZ method!)

kcrisman gravatar imagekcrisman ( 2011-04-08 02:56:37 -0500 )edit

That makes sense. Thank you.

Ben Reynwar gravatar imageBen Reynwar ( 2011-04-08 05:06:36 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-04-07 17:17:29 -0500

Seen: 268 times

Last updated: Apr 07 '11