# Progress Indicator & sums

Having looked here, what should I do differently to get the progress indicator working properly?

Monitor[Plot[{Pause[0.1];
LogIntegral[x] - Sum[2 N[Re[ExpIntegralEi[ZetaZero[n] Log[x]]]], {n, 1, 500}] - Log[2],
Sum[PrimePi[x^(1/n)]/n, {n, 1, Floor[Log[x]]}]},
{x, 2, 1000}], Row[{ProgressIndicator[x, {2, 1000}], x}, " "]]

• I'm still exploring but I think the problem is with the speed of Sum[2 N[Re[ExpIntegralEi[ZetaZero[n] Log[x]]]]. If you remove that, things work fine. Jul 21, 2014 at 19:58
• This is just an example - what I am most concerned about is that ProgressIndicator seems to go through each sum, rather than indicate the progress of the entire calculation. Jul 21, 2014 at 20:00
• Plot adaptively evaluates x in a non sequential order. Without knowing a priori how many evaluations will be needed I see no sensible way to make the progress indicator work Jul 21, 2014 at 20:01
• ..you can make this work nice, forgoing the adaptive evaluation, by using MaxRecursion -> 0, PlotPoints -> 200 Jul 21, 2014 at 20:16
• @martin yes, no problem. Monitor[Sum[Pause[0.1]; x, {x, 1, 100}], Row[{ProgressIndicator[x, {1, 100}], x}, " "]] Jul 21, 2014 at 20:20

This is a quick and dirty way to watch whats going on..

 Monitor[list = {{0, 0}};
Plot[{y = LogIntegral[x] -
Sum[2 N[Re[ExpIntegralEi[ZetaZero[n] Log[x]]]], {n, 1, 500}] - Log[2],
Sum[PrimePi[x^(1/n)]/n, {n, 1, Floor[Log[x]]}]}, {x, 2, 1000},
EvaluationMonitor :> AppendTo[list, {x, y}] ],
ListPlot[list, Epilog -> {PointSize[.05], Red, Point[list[[-1]]]},
PlotRange -> {{0, 1000}, {0, 200}}]]


What you see is the function globally smooth but locally jagged so the recursion keeps going and going. ( you likely want to set MaxRecursion to something reasonable.. )

• ... actually MaxRecursion -> 0, PlotPoints -> 200 is really what I was after Jul 21, 2014 at 20:39
• Having replaced ListPlot with ListLinePlot, is there any way to (a) stop the tracing from max back to zero (b) replace each subsequent tracing with the new one? Jul 21, 2014 at 20:43
• ... only achieving (a) would be great ... Jul 21, 2014 at 20:45
• that is just plotting all the points. It gets a bit hairy if you want to show only the points in the current recursion. Jul 21, 2014 at 21:17
• Hmmmm, ok - maybe this will be a separate question at some point then ... Jul 21, 2014 at 21:19

The problem is with the speed of your first sum. I did the following and things worked fine.

(zzero[#] = N@ZetaZero[#]) & /@ Range[600];

sum[x_?NumericQ] := Sum[2 Re[ExpIntegralEi[zzero[n] Log[x]]], {n, 1, 500}]

Monitor[Plot[{
LogIntegral[x] - sum[x] - Log[2],
Sum[PrimePi[x^(1/n)]/n, {n, 1, Floor[Log[x]]}]}, {x, 2, 1000}
],
Row[{ProgressIndicator[x, {2, 1000}], x}, " "]
]


Here's the progress bar in action:

• I don't think this is the issue the OP is referring to. It's not the slowness (the OP added a Pause for a purpose), but the fact that the progress indicator starts anew multiple times. Jul 21, 2014 at 20:11
• @Chip Hurst, sorry, should have made this clearer Jul 21, 2014 at 20:32