integrate tan(x) for real argument

78 views
Skip to first unread message

Carsten Knoll

unread,
Feb 19, 2016, 8:07:27 AM2/19/16
to sy...@googlegroups.com
I want to calculate the antiderivative for tan(x)

In [4]: x = sp.Symbol('x', real=True)

In [5]: sp.integrate(sp.tan(x), x)
Out[5]: -log(sin(x)**2 - 1)/2


This result is technically correct, but I would (for didactic purposes)
prefer something like

-log(cos(x)).

How can I achieve this?

Thanks.
Carsten.

Aaron Meurer

unread,
Feb 19, 2016, 10:46:17 AM2/19/16
to sy...@googlegroups.com
trigsimp() will convert the sin to cos. To remove the negative and
square, you'll have to use expand_log(force=True), which gives a
complex constant (which can be ignored, since this is an integral).

It would definitely be better if integrate at least gave log(1 -
sin(x)**2) so that the result is real.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/56C71381.4090204%40gmx.de.
> For more options, visit https://groups.google.com/d/optout.

Ondřej Čertík

unread,
Feb 19, 2016, 2:21:17 PM2/19/16
to sympy
On Fri, Feb 19, 2016 at 8:45 AM, Aaron Meurer <asme...@gmail.com> wrote:
> trigsimp() will convert the sin to cos. To remove the negative and
> square, you'll have to use expand_log(force=True), which gives a
> complex constant (which can be ignored, since this is an integral).
>
> It would definitely be better if integrate at least gave log(1 -
> sin(x)**2) so that the result is real.

Here is a code that does this:

In [1]: expand_log(integrate(tan(x), x).trigsimp(), force=True)
Out[1]: -log(cos(x)) - I*pi/2

Ondrej

>
> Aaron Meurer
>
> On Fri, Feb 19, 2016 at 8:07 AM, Carsten Knoll <Carste...@gmx.de> wrote:
>> I want to calculate the antiderivative for tan(x)
>>
>> In [4]: x = sp.Symbol('x', real=True)
>>
>> In [5]: sp.integrate(sp.tan(x), x)
>> Out[5]: -log(sin(x)**2 - 1)/2
>>
>>
>> This result is technically correct, but I would (for didactic purposes)
>> prefer something like
>>
>> -log(cos(x)).
>>
>> How can I achieve this?
>>
>> Thanks.
>> Carsten.
>>
>> --
>> You received this message because you are subscribed to the Google Groups "sympy" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
>> To post to this group, send email to sy...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/sympy.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/56C71381.4090204%40gmx.de.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6JnGtQ2-40XA2kSyD%3D7J%3D1futiJx2z7ocr53T0UrW%3DpLw%40mail.gmail.com.

Aaron Meurer

unread,
Feb 19, 2016, 2:23:49 PM2/19/16
to sy...@googlegroups.com
It looks like the meijerg algorithm gives the better form:

In [33]: integrate(tan(x), x, meijerg=True)
Out[33]: -log(cos(x))

Aaron Meurer
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CADDwiVA%3DK7zMNjEYizfFDzqgf_2J6OjcHBC8wJ8amBcDr%2BKcVw%40mail.gmail.com.

Carsten Knoll

unread,
Feb 22, 2016, 8:42:34 AM2/22/16
to sy...@googlegroups.com
Thanks. Both variants are helpful!

Carsten
Reply all
Reply to author
Forward
0 new messages