I asked an LLM how I might use a list of prime numbers to compute an approximation to pi - there's surely a way - and indeed there is, it's called Euler's product formula which is an approximation to the zeta function. Just the ticket!
(I'm pretty sure there's a probabilistic way too, based on the chance of two numbers being coprime, but I'll leave that as an exercise.)
Here's a little code in owlet: I used one of the prime sieves developed in this thread:
Short and sweet prime numbers in Basic
(I'm pretty sure there's a probabilistic way too, based on the chance of two numbers being coprime, but I'll leave that as an exercise.)
Here's a little code in owlet:
Code:
L%=2000:Z%=SQR(L%):P=6*1/(1-1/2/2)DIM S% L%+2FORI%=1TOL%+1STEP4:S%!I%=TRUE:NEXTP%=2REPEAT FORI%=P%*P%TOL%STEPP%:S%?I%=0:NEXT REPEATP%=P%+1:UNTILS%?P%UNTIL P%>Z%FOR I%=3 TO L% STEP 2 IF S%?I% P=P*1/(1-1/I%/I%):PRINT I%;" ";SQR(P)NEXTPRINT"pi approximated using primes, per Euler"
Short and sweet prime numbers in Basic
Statistics: Posted by BigEd — Sun Aug 04, 2024 12:37 pm