ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 18 Mar 2011 15:09:53 -0500integral of 1/x, tan xhttps://ask.sagemath.org/question/8004/integral-of-1x-tan-x/why integral ($ $$1/x$, $x$) returns $log(x)$? Shouldn't it return $log(|x|)$. Similarly,
integral$(tan(x),x)$ returns $log(sec(x))$ shouldn't it return $log(|sec(x)|)$.
Can anyone explain?
After previous post, I dig a little bit and find:
sage: equation=integral(1/x+x,x).real()
sage: equation
1/2*real_part(x)^2 - 1/2*imag_part(x)^2 + log(abs(x))
sage:
Now, anyway to set real_part(x)=x and imag_part(x)=0 in "eq" and get the resultant "eq"?
More>>
sage: integral(1/(x^3-1),x).real()
-1/3*sqrt(3)*real_part(arctan(1/3*(2*x + 1)*sqrt(3))) + 1/3*log(abs(x - 1)) - 1/6*log(abs(x^2 + x + 1))
Everything is fine in the above computation except the word "real_part". Anyway to get rid of that?Wed, 16 Mar 2011 05:13:20 -0500https://ask.sagemath.org/question/8004/integral-of-1x-tan-x/Answer by benjaminfjones for <p>why integral ($ $$1/x$, $x$) returns $log(x)$? Shouldn't it return $log(|x|)$. Similarly,
integral$(tan(x),x)$ returns $log(sec(x))$ shouldn't it return $log(|sec(x)|)$.
Can anyone explain?</p>
<p>After previous post, I dig a little bit and find:</p>
<pre><code> sage: equation=integral(1/x+x,x).real()
sage: equation
1/2*real_part(x)^2 - 1/2*imag_part(x)^2 + log(abs(x))
sage:
</code></pre>
<p>Now, anyway to set real_part(x)=x and imag_part(x)=0 in "eq" and get the resultant "eq"?</p>
<p>More>></p>
<pre><code>sage: integral(1/(x^3-1),x).real()
-1/3*sqrt(3)*real_part(arctan(1/3*(2*x + 1)*sqrt(3))) + 1/3*log(abs(x - 1)) - 1/6*log(abs(x^2 + x + 1))
</code></pre>
<p>Everything is fine in the above computation except the word "real_part". Anyway to get rid of that?</p>
https://ask.sagemath.org/question/8004/integral-of-1x-tan-x/?answer=12195#post-id-12195The default backend for symbolic integration is Maxima. You can find out more about the Maxima interface here: http://www.sagemath.org/doc/reference/sage/interfaces/maxima.html
In Maxima, there is a global flag called `logabs` which changes the default behavior when integrating functions like `1/x` or `tan(x)`. Here is how you can get Maxima (via Sage) to return the anti-derivative of `1/x` on its full natural domain:
sage: x=var('x')
sage: maxima.eval('logabs:true')
sage: maxima.integrate(1/x,x)
log(abs(x))
sage: maxima.integrate(tan(x),x)
log(sec(x))
I don't know if there is currently a way to accomplish this through the Sage `integrate` function directly. I do know that for definite integrals, `log(abs(x))` is used as an anti-derivative of `1/x`:
sage: integrate(1/x, x)
log(x)
sage: integrate(1/x, x, -2, -1)
-log(2)
which is correct.
Wed, 16 Mar 2011 09:34:05 -0500https://ask.sagemath.org/question/8004/integral-of-1x-tan-x/?answer=12195#post-id-12195Comment by kcrisman for <p>The default backend for symbolic integration is Maxima. You can find out more about the Maxima interface here: <a href="http://www.sagemath.org/doc/reference/sage/interfaces/maxima.html">http://www.sagemath.org/doc/reference...</a></p>
<p>In Maxima, there is a global flag called <code>logabs</code> which changes the default behavior when integrating functions like <code>1/x</code> or <code>tan(x)</code>. Here is how you can get Maxima (via Sage) to return the anti-derivative of <code>1/x</code> on its full natural domain:</p>
<pre><code>sage: x=var('x')
sage: maxima.eval('logabs:true')
sage: maxima.integrate(1/x,x)
log(abs(x))
sage: maxima.integrate(tan(x),x)
log(sec(x))
</code></pre>
<p>I don't know if there is currently a way to accomplish this through the Sage <code>integrate</code> function directly. I do know that for definite integrals, <code>log(abs(x))</code> is used as an anti-derivative of <code>1/x</code>:</p>
<pre><code>sage: integrate(1/x, x)
log(x)
sage: integrate(1/x, x, -2, -1)
-log(2)
</code></pre>
<p>which is correct.</p>
https://ask.sagemath.org/question/8004/integral-of-1x-tan-x/?comment=21964#post-id-21964Ordinarily we try to stay away from that sort of thing unless absolutely (hee-hee) necessary, but this has come up before. See http://maxima.sourceforge.net/docs/manual/en/maxima_14.html - I don't see any obvious negative side effects. At the same time, this has been the behavior for a LONG time, and it would be worth bringing up on sage-devel if you want to do it. Fri, 18 Mar 2011 15:09:53 -0500https://ask.sagemath.org/question/8004/integral-of-1x-tan-x/?comment=21964#post-id-21964Comment by niles for <p>The default backend for symbolic integration is Maxima. You can find out more about the Maxima interface here: <a href="http://www.sagemath.org/doc/reference/sage/interfaces/maxima.html">http://www.sagemath.org/doc/reference...</a></p>
<p>In Maxima, there is a global flag called <code>logabs</code> which changes the default behavior when integrating functions like <code>1/x</code> or <code>tan(x)</code>. Here is how you can get Maxima (via Sage) to return the anti-derivative of <code>1/x</code> on its full natural domain:</p>
<pre><code>sage: x=var('x')
sage: maxima.eval('logabs:true')
sage: maxima.integrate(1/x,x)
log(abs(x))
sage: maxima.integrate(tan(x),x)
log(sec(x))
</code></pre>
<p>I don't know if there is currently a way to accomplish this through the Sage <code>integrate</code> function directly. I do know that for definite integrals, <code>log(abs(x))</code> is used as an anti-derivative of <code>1/x</code>:</p>
<pre><code>sage: integrate(1/x, x)
log(x)
sage: integrate(1/x, x, -2, -1)
-log(2)
</code></pre>
<p>which is correct.</p>
https://ask.sagemath.org/question/8004/integral-of-1x-tan-x/?comment=21977#post-id-21977maybe 'logabs:true' should be set by default in Sage's maxima environment -- what do you think? On the other hand, if setting such global flags is an important part of working with maxima, maybe Sage should add functionality for setting and using them natively, rather than trying to find a default setting everyone will likeWed, 16 Mar 2011 10:36:24 -0500https://ask.sagemath.org/question/8004/integral-of-1x-tan-x/?comment=21977#post-id-21977