2

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}, " "]]
martin
  • 8,678
  • 4
  • 23
  • 70
  • 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. – Greg Hurst Jul 21 '14 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. – martin Jul 21 '14 at 20:00
  • 2
    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 – george2079 Jul 21 '14 at 20:01
  • Your assumption that Plot goes from 2 to 1000 in small steps is incorrect.The plot process is recursive, with places that bend too much being refined in later stages. – Sjoerd C. de Vries Jul 21 '14 at 20:03
  • 1
    ..you can make this work nice, forgoing the adaptive evaluation, by using MaxRecursion -> 0, PlotPoints -> 200 – george2079 Jul 21 '14 at 20:16
  • @Sjoerd C. de Vries, is it possible to make any Sum work with ProgressIndicator? – martin Jul 21 '14 at 20:18
  • 1
    @martin yes, no problem. Monitor[Sum[Pause[0.1]; x, {x, 1, 100}], Row[{ProgressIndicator[x, {1, 100}], x}, " "]] – Sjoerd C. de Vries Jul 21 '14 at 20:20
  • @Sjoerd C. de Vries, great - thanks – martin Jul 21 '14 at 20:24

2 Answers2

2

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}}]]

enter image description here

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.. )

george2079
  • 38,913
  • 1
  • 43
  • 110
0

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}, " "]
]

enter image description here

Here's the progress bar in action:

enter image description here

Greg Hurst
  • 35,921
  • 1
  • 90
  • 136
  • 1
    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. – Sjoerd C. de Vries Jul 21 '14 at 20:11
  • @Chip Hurst, sorry, should have made this clearer – martin Jul 21 '14 at 20:32