7/5/2023 0 Comments Calculate pi programPrint("Last 5 digits d wrong should be d" % (last_five_digits, check_digits)) Print("Last 5 digits d OK" % last_five_digits) Print("chudnovsky_gmpy_mpz_bs: digits",digits,"time",time()-start) # The last 5 digits or pi for various numbers of digits # Recursively calculate P(a,m), Q(a,m) and T(a,m) # Recursively compute P(a,b), Q(a,b) and T(a,b) This is done using Chudnovsky's series with BINARY splittingĬomputes the terms for binary splitting the Chudnovsky infinite series Python3 program to calculate Pi using python long integers, BINARY I think the most efficient method is the Chudnovsky algoritm (100 million digits of Pi, in under 10 minutes!) Now, if you're actually into this kind of discussion, think about what kind of architecture you actually try to optimize for: A single threaded computer with uniform multiply, add, memory address loading and storage costs has never really existed the norm today are hyperthreaded multicore processors with a limited number of SIMD registers and multilevel caches, which can make algorithms which "look good on paper" perform terribly because they just misuse the capabilities of the architecture, whilst stupid implementation might work exceptionally well because of possible compile- and execution-time optimization. You could specify things like "minimum number of multiplications plus additions", but you'd totally neglect possibly different cost for these operations, and, much worse, memory movement complexity etc. If your measurement is "how long does it take to have N significant digits", most probably even the most naive C implementation would beat the hell out of your Python program - just because python is such a capable scripting language, which requires a lot of indirection.
0 Comments
Leave a Reply. |