ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 21 Oct 2015 20:20:59 +0200Integrating with constant integrandhttps://ask.sagemath.org/question/30185/integrating-with-constant-integrand/How can you specify an integral with a constant integrand? For example, I know that
f = x
f.integrate(x,0,1)
works fine, but
f = 1
f.integrate(x,0,1)
doesn't, since the Integer class has no integrate() method. (Should it?) I can get around this with something like
f = x-x+1
f.integrate(x,0,1)
but that seems awfully kludgey.Jeremy MartinWed, 21 Oct 2015 20:20:59 +0200https://ask.sagemath.org/question/30185/Variable type returned after integrating.https://ask.sagemath.org/question/8038/variable-type-returned-after-integrating/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'Ben ReynwarFri, 08 Apr 2011 00:17:29 +0200https://ask.sagemath.org/question/8038/