2
$\begingroup$

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}, " "]]
$\endgroup$
8
  • $\begingroup$ 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. $\endgroup$
    – Greg Hurst
    Jul 21, 2014 at 19:58
  • $\begingroup$ 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. $\endgroup$
    – martin
    Jul 21, 2014 at 20:00
  • 2
    $\begingroup$ 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 $\endgroup$
    – george2079
    Jul 21, 2014 at 20:01
  • 1
    $\begingroup$ ..you can make this work nice, forgoing the adaptive evaluation, by using MaxRecursion -> 0, PlotPoints -> 200 $\endgroup$
    – george2079
    Jul 21, 2014 at 20:16
  • 1
    $\begingroup$ @martin yes, no problem. Monitor[Sum[Pause[0.1]; x, {x, 1, 100}], Row[{ProgressIndicator[x, {1, 100}], x}, " "]] $\endgroup$ Jul 21, 2014 at 20:20

2 Answers 2

2
$\begingroup$

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

$\endgroup$
5
  • $\begingroup$ ... actually MaxRecursion -> 0, PlotPoints -> 200 is really what I was after $\endgroup$
    – martin
    Jul 21, 2014 at 20:39
  • $\begingroup$ 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? $\endgroup$
    – martin
    Jul 21, 2014 at 20:43
  • $\begingroup$ ... only achieving (a) would be great ... $\endgroup$
    – martin
    Jul 21, 2014 at 20:45
  • $\begingroup$ that is just plotting all the points. It gets a bit hairy if you want to show only the points in the current recursion. $\endgroup$
    – george2079
    Jul 21, 2014 at 21:17
  • $\begingroup$ Hmmmm, ok - maybe this will be a separate question at some point then ... $\endgroup$
    – martin
    Jul 21, 2014 at 21:19
0
$\begingroup$

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

$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$ Jul 21, 2014 at 20:11
  • $\begingroup$ @Chip Hurst, sorry, should have made this clearer $\endgroup$
    – martin
    Jul 21, 2014 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.