Function Repository Resource:

CRVZSum

Source Notebook

Evaluate an alternating sum using the Cohen-Rodriguez Villegas-Zagier method

Contributed by: Jan Mangaldan

ResourceFunction["CRVZSum"][f,{i,imin,}]

numerically evaluates the sum using the CRVZ algorithm.

Details and Options

The Cohen-Rodriguez Villegas-Zagier (CRVZ) algorithm is an acceleration technique intended for infinite alternating sums.
The following options can be given:
"ExtraTerms"15number of terms to use in the CRVZ method
"Terms”15number of terms to sum directly
WorkingPrecisionMachinePrecisionthe precision used in internal computations
Given sufficiently pathological summands, ResourceFunction["CRVZSum"] can give wrong answers. Generally one can test the answer by looking at its sensitivity to changes in the setting of options for ResourceFunction["CRVZSum"].
ResourceFunction["CRVZSum"] has the attribute HoldAll and effectively uses Block to localize variables.

Examples

Basic Examples (2) 

Evaluate the alternating harmonic series:

In[1]:=
ResourceFunction["CRVZSum"][(-1)^(j - 1)/j, {j, 1, \[Infinity]}]
Out[1]=

Compare with the closed form:

In[2]:=
% - Log[2]
Out[2]=

Options (5) 

ExtraTerms (2) 

Use 25 terms for the CRVZ extrapolation:

In[3]:=
ResourceFunction["CRVZSum"][(-1)^k/(2 k + 1), {k, 0, \[Infinity]}, "ExtraTerms" -> 25, WorkingPrecision -> 25]
Out[3]=

Compare with the exact result:

In[4]:=
% - \[Pi]/4
Out[4]=

Set "Terms" to 0 so that all terms are used in extrapolation:

In[5]:=
ResourceFunction["CRVZSum"][(-1)^k/(2 k + 1), {k, 0, \[Infinity]}, "ExtraTerms" -> 25, "Terms" -> 0, WorkingPrecision -> 35]
Out[5]=

Compare with the exact result:

In[6]:=
% - \[Pi]/4
Out[6]=

Terms (2) 

Directly sum the first 25 terms before applying CRVZ extrapolation:

In[7]:=
ResourceFunction["CRVZSum"][(-1)^k/(2 k + 1), {k, 0, \[Infinity]}, "Terms" -> 25, WorkingPrecision -> 25]
Out[7]=

Compare with the exact result:

In[8]:=
% - \[Pi]/4
Out[8]=

WorkingPrecision (1) 

Use a higher setting of WorkingPrecision:

In[9]:=
ResourceFunction["CRVZSum"][(-1)^k/(2 k + 1), {k, 0, \[Infinity]}, WorkingPrecision -> 25]
Out[9]=
In[10]:=
% - \[Pi]/4
Out[10]=

Applications (2) 

Use CRVZSum to evaluate the Dirichlet eta function:

In[11]:=
eta[z_?NumericQ] := ResourceFunction["CRVZSum"][(-1)^(j - 1)/j^z, {j, 1, \[Infinity]}]

Compare with the built-in DirichletEta:

In[12]:=
Plot[{DirichletEta[z], eta[z]}, {z, -3, 3}, PlotStyle -> {Thick, Dashed}]
Out[12]=

Plot the relative error:

In[13]:=
Plot[Abs[DirichletEta[z] - eta[z]]/Abs[DirichletEta[z]], {z, -3, 3}, PlotRange -> All]
Out[13]=

Use CRVZSum with NIntegrate to numerically evaluate an oscillatory integral:

In[14]:=
ResourceFunction["CRVZSum"][
 NIntegrate[Sinc[x], {x, j \[Pi], (j + 1) \[Pi]}, WorkingPrecision -> 25], {j, 0, \[Infinity]}, WorkingPrecision -> 25]
Out[14]=

Compare with the exact result:

In[15]:=
% - \[Pi]/2
Out[15]=

Properties and Relations (2) 

Directly summing the first few terms of an alternating series usually does not give sufficient accuracy:

In[16]:=
Sum[N[(-1)^k/(2 k + 1), 35], {k, 0, 19}]
Out[16]=
In[17]:=
% - \[Pi]/4
Out[17]=

Using the CRVZ method on an alternating series often gives better results:

In[18]:=
ResourceFunction["CRVZSum"][(-1)^k/(2 k + 1), {k, 0, \[Infinity]}, "ExtraTerms" -> 20, "Terms" -> 0, WorkingPrecision -> 35]
Out[18]=
In[19]:=
% - \[Pi]/4
Out[19]=

Possible Issues (2) 

CRVZSum usually gives poor results for non-alternating series:

In[20]:=
ResourceFunction["CRVZSum"][1/j^2, {j, 1, \[Infinity]}]
Out[20]=

CRVZSum may give results for formally divergent series:

In[21]:=
ResourceFunction["CRVZSum"][(-1)^j j, {j, 0, \[Infinity]}]
Out[21]=

Compare with the Borel sum:

In[22]:=
Sum[(-1)^j j, {j, 0, \[Infinity]}, Regularization -> "Borel"]
Out[22]=

Version History

  • 1.0.0 – 29 March 2021

Source Metadata

Related Resources

License Information