       Re: Re: Mathematica bug in handling trigonometric functions? (and more)

• To: mathgroup at smc.vnet.net
• Subject: [mg55797] Re: [mg55755] Re: Mathematica bug in handling trigonometric functions? (and more)
• From: Devendra Kapadia <dkapadia at wolfram.com>
• Date: Wed, 6 Apr 2005 03:11:49 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```On Tue, 5 Apr 2005, dh wrote:

> Hi APC,
> I tried to simplify the problem a bit. There is definitly a bug that
> Wolfram should take notice. It would be nice if WRI could give an answer .
>
> The folllowing is obviously correct:
> Sum[Sin[k]*Cos[k + 1], {k, 1, 1}]
> Out: Cos Sin
>
> When we do the same with indefinite summation:
> Sum[Sin[k]*Cos[k + 1], {k, 1, n}] /. n -> 1 // Simplify // Expand
> Out: Sin/2 + Cos Sin
>
> we get an additional term: Sin/2 !!!
>
> Sincerely, Daniel
>
> APC wrote:
> > a)"Sum"-Command
> >
> > mathematica 5.1:
> >
> > input:   Sum[Sin[k]*Cos[k + 1], {k, 1, n}]
> > output:  (1/4)*(Cos - Cos[2 + 2*n])*Csc
> >
> > which is obviously incorrect.
> >
> > with the more general Sum[Sin[a*k]*Cos[k + 1], {k, 1, n}] i get correct results, though.
> >
> > (mathematica 2.2's "SymbolicSum" command has no problems at all)
> >
> > another example:
> >
> > input:  Sum[Log[k]/Exp[k], {k, 1, Infinity}]
> > output:  (-(E*Derivative[1, 0][PolyLog][0, E^(-1)]) +
> >   Derivative[0, 1, 0][LerchPhi][E^(-1), 0, 1])/E
> >
> > which is incorrect. -Derivative[1, 0][PolyLog][0, E^(-1)]alone is the correct result, the LerchPhi term is identical so the output could be simplified to "0", which is wrong, of course. there seems to be a problem with "Sum" and derivatives of functions, as
> >
> > Sum[Log[k]^2/k^3, {k, 1, Infinity}]
> >
> > for example yields an incorrect result under similar circumstances.
> >
> > b)"Integrate" command
> >
> > input:  Integrate[Sqrt[Sin[x] + Cos[x]], x]
> > output:  (2*(Cos[x] + Sin[x] + Null*(1 + Sin[2*x])^(1/4)))/Sqrt[Cos[x] + Sin[x]]
> >
> > the output includes a "Null"-term.
> >
> > the result for the more general case
> >
> > input:  Integrate[Sqrt[a*Sin[x] + b*Cos[x]], x]
> >
> > is correct, though.
> >
> > apparently "Sum" and "Integrate" have problems handling special cases involving trigonometric functions.
> > please check for yourself. if i'm correct, i can no more trust any "Sum" or "Integrate" results without checking twice.
> >
>
Hello APC and Daniel,

Thank you for bringing these problematic Sum and Integrate
examples to our attention.

Here are some comments on the individual examples.

For the trigonometric Sum, using numerical upper and lower limits avoids
any appeal to symbolic summation and hence we get the correct answer. A
workaround for the case where the upper limit 'n' is symbolic is to apply
TrigReduce as shown in In below.

==========================================================================
In:= \$Version

Out= 5.1 for Linux (February 20, 2005)

In:=  s1 = Sum[Sin[k]*Cos[k + 1], {k, 1, 1}]

Out= Cos Sin

In:= (s2 = Expand[Simplify[Sum[Sin[k]*Cos[k + 1], {k, 1, n}] /.
n -> 1]])//InputForm

Out//InputForm= Sin/2 + Cos*Sin

In:= (s3 = Sum[TrigReduce[Sin[k]*Cos[k + 1]], {k, 1, n}] /. n ->
1)//InputForm

Out//InputForm= (-2*Sin + Csc*Sin^2)/2

In:= Simplify[s1 - s2]//InputForm

Out//InputForm= -Sin/2

In:= Simplify[s1 - s3]

Out= 0

=============================================================================

The LerchPhi term in the output for Sum[Log[k]/Exp[k], {k, 1, Infinity}]
is indeed incorrect. Here is an informal derivation of the answer which uses
the fact that the derivative of k^x with respect to x at x = 0 is Log[k].

============================================================================
In:= (Sum[k^x/Exp[k], {k, 1, Infinity}])//InputForm

Out//InputForm= PolyLog[-x, E^(-1)]

In:= (D[%, x])//InputForm

Out//InputForm= -Derivative[1, 0][PolyLog][-x, E^(-1)]

In:= (Series[%, {x, 0, 0}] // Normal) // InputForm

Out//InputForm= -Derivative[1, 0][PolyLog][0, E^(-1)]

In:= N[%]

Out= 0.192093

In:= NSum[Log[k]/Exp[k], {k, 1, Infinity}]

Out= 0.192093

===============================================================================

A similar derivation can be given for Sum[Log[k]^2/k^3, {k, 1, Infinity}],
as follows.

==============================================================================
In:= Sum[k^x/k^3, {k, 1, Infinity}]

Out= Zeta[3 - x]

In:= D[%, {x, 2}]

Out= Zeta''[3 - x]

In:= Series[%, {x, 0, 0}] // Normal

Out= Zeta''

In:= N[%]

Out= 0.239747

In:= NSum[Log[k]^2/k^3, {k, 1, Infinity}]

Out= 0.239747 + 0. I

================================================================================

Finally, one possible answer for Integrate[Sqrt[Sin[x] + Cos[x]], x]
(from a development version) is the following:

================================================================================
In:= ans = (-2*Sqrt*Sqrt[Cos[(Pi - 4*x)/4]]*EllipticE[(Pi - 4*x)/8, 2])/
Sqrt[Cos[x] + Sin[x]];

In:= D[ans, x]//FullSimplify

Out= Sqrt[Cos[x] + Sin[x]]

================================================================================

We apologize for any inconvenience caused by these problems, which have
been noted for fixing in a future release.

Regards,