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.Thu, 02 Feb 2017 17:27:29 -0600symbolic integrationhttps://ask.sagemath.org/question/36408/symbolic-integration/ If you ask sage to symbolically integrate the following properly, the answer is wrong. Why?
cos(x)/(a*cos(x) + b*sin(x))
[Aside -- the captcha was invisible with firefox 50.1/linux, leading to much teeth-gnashing. Seems to work OK with Chrome. Not happy]Sat, 28 Jan 2017 22:44:30 -0600https://ask.sagemath.org/question/36408/symbolic-integration/Answer by eric_g for <p>If you ask sage to symbolically integrate the following properly, the answer is wrong. Why?</p>
<p>cos(x)/(a<em>cos(x) + b</em>sin(x))</p>
<p>[Aside -- the captcha was invisible with firefox 50.1/linux, leading to much teeth-gnashing. Seems to work OK with Chrome. Not happy]</p>
https://ask.sagemath.org/question/36408/symbolic-integration/?answer=36413#post-id-36413Can you be more specific? It seems OK to me, since with Sage 7.5.1, we have
sage: var('a b')
(a, b)
sage: f = cos(x)/(a*cos(x) + b*sin(x))
sage: F = integrate(f, x) ; F
2*a*arctan(sin(x)/(cos(x) + 1))/(a^2 + b^2) + b*log(-a - 2*b*sin(x)/(cos(x) + 1) + a*sin(x)^2/(cos(x) + 1)^2)/(a^2 + b^2) - b*log(sin(x)^2/(cos(x) + 1)^2 + 1)/(a^2 + b^2)
sage: DF = diff(F, x).simplify_full() ; DF
cos(x)/(a*cos(x) + b*sin(x))
sage: bool(DF == f)
True
EDIT (2 Feb 2017, after the answer/precisions posted by @bev):
To simplify further Sage's output, we may proceed as follows. First to simplify the arctan part, introduce the double-angle variable `u=2*x`:
sage: var('u')
u
sage: F1 = F.subs({x: 2*u}).simplify_full().trig_reduce(); F1
2*a*arctan(tan(u))/(a^2 + b^2) + b*log(-a*cos(2*u)*sec(u)^2 - b*sec(u)^2*sin(2*u))/(a^2 + b^2) - b*log(sec(u)^2)/(a^2 + b^2)
To go further, one has to assume that `u in (-pi/2, pi/2)`, so that `arctan(tan(u))` simplifies to `u`:
sage: assume(u>-pi/2, u<pi/2)
sage: F2 = F1.simplify_full().simplify_log().trig_reduce(); F2
2*a*u/(a^2 + b^2) + b*log(-a*cos(2*u) - b*sin(2*u))/(a^2 + b^2)
Then we can go back to the original variable and get the final result:
sage: F = F2.subs({u: x/2}).simplify_full(); F
(a*x + b*log(-a*cos(x) - b*sin(x)))/(a^2 + b^2)
which coincides with the Maple result that you've quoted, up to some sign in the log argument (which depends on the ranges of `a`, `b` and `x`). The obtained result is indeed correct:
sage: DF = diff(F, x).simplify_full() ; DF
cos(x)/(a*cos(x) + b*sin(x))
sage: bool(DF == f)
TrueMon, 30 Jan 2017 06:36:35 -0600https://ask.sagemath.org/question/36408/symbolic-integration/?answer=36413#post-id-36413Comment by bev for <p>Can you be more specific? It seems OK to me, since with Sage 7.5.1, we have</p>
<pre><code>sage: var('a b')
(a, b)
sage: f = cos(x)/(a*cos(x) + b*sin(x))
sage: F = integrate(f, x) ; F
2*a*arctan(sin(x)/(cos(x) + 1))/(a^2 + b^2) + b*log(-a - 2*b*sin(x)/(cos(x) + 1) + a*sin(x)^2/(cos(x) + 1)^2)/(a^2 + b^2) - b*log(sin(x)^2/(cos(x) + 1)^2 + 1)/(a^2 + b^2)
sage: DF = diff(F, x).simplify_full() ; DF
cos(x)/(a*cos(x) + b*sin(x))
sage: bool(DF == f)
True
</code></pre>
<p>EDIT (2 Feb 2017, after the answer/precisions posted by @bev):</p>
<p>To simplify further Sage's output, we may proceed as follows. First to simplify the arctan part, introduce the double-angle variable <code>u=2*x</code>:</p>
<pre><code>sage: var('u')
u
sage: F1 = F.subs({x: 2*u}).simplify_full().trig_reduce(); F1
2*a*arctan(tan(u))/(a^2 + b^2) + b*log(-a*cos(2*u)*sec(u)^2 - b*sec(u)^2*sin(2*u))/(a^2 + b^2) - b*log(sec(u)^2)/(a^2 + b^2)
</code></pre>
<p>To go further, one has to assume that <code>u in (-pi/2, pi/2)</code>, so that <code>arctan(tan(u))</code> simplifies to <code>u</code>:</p>
<pre><code>sage: assume(u>-pi/2, u<pi/2)
sage: F2 = F1.simplify_full().simplify_log().trig_reduce(); F2
2*a*u/(a^2 + b^2) + b*log(-a*cos(2*u) - b*sin(2*u))/(a^2 + b^2)
</code></pre>
<p>Then we can go back to the original variable and get the final result:</p>
<pre><code>sage: F = F2.subs({u: x/2}).simplify_full(); F
(a*x + b*log(-a*cos(x) - b*sin(x)))/(a^2 + b^2)
</code></pre>
<p>which coincides with the Maple result that you've quoted, up to some sign in the log argument (which depends on the ranges of <code>a</code>, <code>b</code> and <code>x</code>). The obtained result is indeed correct:</p>
<pre><code>sage: DF = diff(F, x).simplify_full() ; DF
cos(x)/(a*cos(x) + b*sin(x))
sage: bool(DF == f)
True
</code></pre>
https://ask.sagemath.org/question/36408/symbolic-integration/?comment=36446#post-id-36446Thank you for going to this much trouble to share my pain. I was also able to simplify the sage expression, but maple did it all by itself. I don't have maple myself, a [rich] friend did it for me. Thanks again.Thu, 02 Feb 2017 17:27:29 -0600https://ask.sagemath.org/question/36408/symbolic-integration/?comment=36446#post-id-36446Answer by bev for <p>If you ask sage to symbolically integrate the following properly, the answer is wrong. Why?</p>
<p>cos(x)/(a<em>cos(x) + b</em>sin(x))</p>
<p>[Aside -- the captcha was invisible with firefox 50.1/linux, leading to much teeth-gnashing. Seems to work OK with Chrome. Not happy]</p>
https://ask.sagemath.org/question/36408/symbolic-integration/?answer=36428#post-id-36428The latest linux (slackware) version I was able to find is 7.3, which I'm using. I'll try to find 7.5.1 and report back...
Maple gives a different answer for the integral, and maple has a simplify function which reduces the integral to (b*ln(a*cos(x)+b*sin(x))+ax)/(a^2+b^2).
I tried to use the simplify_full function for the sage integral, and it didn't change anything.
In order to get 7.5.1 I downloaded the source code, but it wouldn't compile -- it came up with an error about sem_open, which I traced back to a known error #3770 which I couldn't use to unravel the problem. Accordingly, I tossed the source and downloaded the binary (Ubuntu 64-bit.bz2) and the file terminated abruptly, so I went to MIT -- their download worked, I could unzip and run it. If you've read this far, I have one more request --
When I compare this version of sage to 7.3, this does funny things with colors as I type a line in console mode -- which is especially troubling since it changes open and closed parens to big white blocks. Is there a simple way I can turn that off?
Thanks for your help.Wed, 01 Feb 2017 14:53:13 -0600https://ask.sagemath.org/question/36408/symbolic-integration/?answer=36428#post-id-36428Comment by eric_g for <p>The latest linux (slackware) version I was able to find is 7.3, which I'm using. I'll try to find 7.5.1 and report back...</p>
<p>Maple gives a different answer for the integral, and maple has a simplify function which reduces the integral to (b<em>ln(a</em>cos(x)+b*sin(x))+ax)/(a^2+b^2).</p>
<p>I tried to use the simplify_full function for the sage integral, and it didn't change anything.</p>
<p>In order to get 7.5.1 I downloaded the source code, but it wouldn't compile -- it came up with an error about sem_open, which I traced back to a known error #3770 which I couldn't use to unravel the problem. Accordingly, I tossed the source and downloaded the binary (Ubuntu 64-bit.bz2) and the file terminated abruptly, so I went to MIT -- their download worked, I could unzip and run it. If you've read this far, I have one more request --</p>
<p>When I compare this version of sage to 7.3, this does funny things with colors as I type a line in console mode -- which is especially troubling since it changes open and closed parens to big white blocks. Is there a simple way I can turn that off?</p>
<p>Thanks for your help.</p>
https://ask.sagemath.org/question/36408/symbolic-integration/?comment=36440#post-id-36440I've edited my answer; as you can see, thanks to some assumptions on the range of `x`, it's possible to recover Maple's result.Thu, 02 Feb 2017 06:42:48 -0600https://ask.sagemath.org/question/36408/symbolic-integration/?comment=36440#post-id-36440