MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

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[2] Sin[1]
> 
> When we do the same with indefinite summation:
> Sum[Sin[k]*Cos[k + 1], {k, 1, n}] /. n -> 1 // Simplify // Expand
> Out: Sin[1]/2 + Cos[2] Sin[1]
> 
> we get an additional term: Sin[1]/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[2] - Cos[2 + 2*n])*Csc[1]
> > 
> > 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[4] below.

==========================================================================
In[1]:= $Version

Out[1]= 5.1 for Linux (February 20, 2005)

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

Out[2]= Cos[2] Sin[1]

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

Out[3]//InputForm= Sin[1]/2 + Cos[2]*Sin[1]

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

Out[4]//InputForm= (-2*Sin[1] + Csc[1]*Sin[2]^2)/2

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

Out[5]//InputForm= -Sin[1]/2

In[6]:= Simplify[s1 - s3]

Out[6]= 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[7]:= (Sum[k^x/Exp[k], {k, 1, Infinity}])//InputForm

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

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

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

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

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

In[10]:= N[%]

Out[10]= 0.192093

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

Out[11]= 0.192093

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

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

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

Out[12]= Zeta[3 - x]

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

Out[13]= Zeta''[3 - x]

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

Out[14]= Zeta''[3]

In[15]:= N[%]

Out[15]= 0.239747

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

Out[16]= 0.239747 + 0. I

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

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

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

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

Out[3]= 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,

Devendra Kapadia.
Wolfram Research, Inc.




  • Prev by Date: Re: Recommendations for a programming book?
  • Next by Date: Re: Numerical accuracy of Hypergeometric2F1
  • Previous by thread: Re: Mathematica bug in handling trigonometric functions? (and more)
  • Next by thread: file corrupted