Baking-Pi Challenge - Understanding & Improving

后端 未结 1 1476
孤城傲影
孤城傲影 2021-01-07 02:32

I spent some time yesterday writing the solution for this challenge published on Reddit, and was able to get through it without cheating, but I was left with a couple of que

相关标签:
1条回答
  • 2021-01-07 03:25
    1. if you want more bits computed per bpp call

      then you have to change your equation from 1/(16^k) base to bigger one. You can do it by summing 2 iterations (k and k+1) so you have something like

      (...)/16^k  + (...)/16^(k+1)
      (...)/256^k
      

      but in this case you need more precise int operations. It is usually faster to use the less precise iterations

    2. if you look at the basic equation then you see you do not need bigint for computation at all

      that is why this iterations are used but the output number is bigint of course. So you do not need to compute modular arithmetics on bigint.

      I do not know how optimized are the one you used ... but here are mine:

      • Modular arithmetics and finite field NTT optimizations
    3. if you want just speed and not infinite precision then use other PSLQ equations

      My understanding of PSLQ is that it is algorithm to find relation between real number and integer iterations.

    here is my favorite up to 800 digits of Pi algorithm and here is extracted code from it in case the link broke down:

    //The following 160 character C program, written by Dik T. Winter at CWI, computes pi  to 800 decimal digits. 
    int a=10000,b,c=2800,d,e,f[2801],g;main(){for(;b-c;)f[b++]=a/5;
    for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);}
    
    0 讨论(0)
提交回复
热议问题