2

I found out yesterday that there is a conjecture that the following function generates an addition chain: $f(n)=\pi({n(n+1)\over 2}+1)$ for and integer $n\ge 1$. $\pi(x)$ is the prime counting function. So the addition chain part requires:

$f(x) =\begin{cases}1 & \text{if }x=1\\f(y)+f(z) & 1\le y,z<x\end{cases}$

Slide 27 in https://static.uni-graz.at/fileadmin/veranstaltungen/additive2016/Talks/sun_zw_slides.pdf

says that this has been verified for $f(n), n\le 10^5$

I put together some code to map a file and verify the addition chain conditions. After some minor playing I got this running very fast. This is a strange addition chain in that it doesn't grow very fast unlike the normal chains I deal with. So you get extreme non-star steps (these are steps were $f(n)\ne f(n-1)+f(m)$ for any $m<n$. For example $f(877591)=f(693121)+f(518832)$.

The rate determining step then is outputting the PrimePi values. I am just looping over increasing $n$ writing to a binary file for each result.

I have done so far $n\le 1813748$ running overnight. Reading PrimePi doc I don't see anything on performance. I see different algorithms but nothing on what works best for repeated calls. Maybe one call with a very large value primes the pump etc? PrimePi is using all 64 cores completely. Can I get these values faster some way?

Neill Clift
  • 153
  • 6
  • Can you get away with a good approximation using RiemannR? See: Approximation to the prime counting function – MarcoB Jan 25 '24 at 20:59
  • 1
    According to the package's author, under the hood PrimePi uses primecount, a highly optimized routine for the prime counting function. You may be able to squeeze some more performance by using the utility directly and making your own lookup table. Maybe. – MarcoB Jan 25 '24 at 21:08
  • @MarcoB I coded up against primecount on Windows. I had to use openmp with a large array of numbers to keep the processors busy. This was much faster. I don't know why Mathematica was slower. I extended to $n \le 2^{24}$. Thanks. – Neill Clift Jan 29 '24 at 18:01
  • That's great to hear! Would you write a self-answer with the details of your solution, even if it does not entirely rely on MMA code? It would likely be useful to other MMA users as well. – MarcoB Jan 29 '24 at 19:50

0 Answers0