Calculating Pi in Hopscotch

math
helpwithcode

#43

@BuildASnowman

I researched this topic a little and believe that you're spot on with the use of a Spigot algorithm. Due to the limited precision available to use on Hopscotch, a spigot algorithm may be the only way to accomplish this.

I've a few ideas on how to implement the code. Would you like input on what you've done so far, or would you like me to just give it a go?


#44

I have a few things that may of be of use. First off, here is a base 10 spigot algorithm that is in O(n^2) time.


Where v(p,k) is the multiplicity of the prime p in k (the exponent of p in the multiplicative decomposition of k in prime powers, another name is "p-adic valuation").
Example : v(3,18)=2 since 18=2⋅32

I tried and failed to implement this awhile back, but now that there is modulo and floor, it will be much easier.
Another base 10 algorithm is described here:
http://numbers.computation.free.fr/Constants/Algorithms/nthdecimaldigit.pdf

The hardest part will be summing binomial coefficients, but it also should be pretty simple to implement.

But I really haven't made much progress. Go ahead and give it a shot, and show me what you are doing along the way :smiley:


#45

Revive!


#46

I'm interested in seeing if this will legitimately work in Hopscotch. Have you attempted coding the Spigot algorithm in-app?


#47

Yeah, but it's close to impossible. Especially calculating the exponent of a certain number in the prime factorization of n, and using lists. If anyone can do it, I'll be thoroughly impressed. Although I doubt that will happen, so I'll offer my account pass as a prize to whoever can do it.


#48

lol.

Would be very interesting to see. Wish there were lists/arrays in Hopscotch.


#49

uh. only to ur hs account. thx.


#50

I'm not good at math, can't do this sorry


#51

Revive

@BuildASnowman, @Gilbert189, et al
It’s almost Pi Day. Anyone still interested interested in this?

Turns out that implementing a base 10 Rabinowitz and Wagon spigot alogorithm in Hopscotch is actually relatively easy in Hopscotch…


#52

I was thinking of using clones to make a binary calculator which would convert into base 10.

The clones would display the numbers so that high precision calculations would be possible.


Speaking of pi day
Maybe there should be an app with different formulas to calculate pi, and you could watch the process of the formulas run as they diverge to pi.


#53

Those are good ideas. Although the spigot algorithm doesn’t produce a number that converges. It sequentially yields the digits of pi, one at a time. But using clones, the algorithm can calculate 1 digit per frame. And using a Gosper series instead of Euler’s, we only need Log13(10^n) clones to calculate n digits.


#54

With the new (at least, past my time) math functions in Hopscotch, implementing a spigot algorithm should be much simpler. Sadly, I no longer have an IPad :slight_smile: Theoretically, I could use my Hopscotch scripting language thing to make a json file that someone else could upload but I have a feeling this project would be sufficiently complicated as to require some manual error correction in the json, and knowledge of Hopscotch’s json structure has also left my mind.

But I implore any of you that want to try - please do. 2 Pi-days later, we could finally finish this challenge.


#55

This is very interesting and well thought out. I was thinking maybe something to do with sine and cosine and then somehow calculating a diameter.


#56

Actually, the only math functions that are required are +, -, *, /

The Rabinowitz and Wagon algorithm doesn’t even require floating point arithmetic.

Although, it does use modulo but modulo could be coded using other math functions that have always been there.


#57

Here’s screenshots of the calculation (this is the Rabinowitz and Wagon algorithm except using Gosper’s series)


#58

I wish Hopscotch would display the full equations :pensive:

The most significant language aspect that wasn’t available originally are the object variables (with self references).


#59

To calculate a precise amount of digits you also need the floor function, but yeah. When I tried implementing it a while back it just got too complicated because I tried doing modulo and floor with a helper object so I wouldn’t have to re-code it every time I need it, but for reasons I don’t remember (probably timing) it just got waay overcomplicated. Plus the fact that at that time all clone variables were held in speed and rotation.

So, just to clarify, the code above works and produces the right digits?


#60

Here’s a preview. I’m going to limit the calculation to about 4400 digits or else I’ll have to slow down the max calculation speed. If anyone wants to check the project for correctness before 3/14, just let me know :wink:


#61

Well, looks like you’ve done it. After 2 years.

GG.


#62

Tomorrow is Pi Day!!