Volodymyr Mutel ([personal profile] muwlgr) wrote2025-01-02 12:21 pm

approximate Golden Ratio with Regular (5-smooth) Numbers

(code in Ruby)
First, let's get a 64-bit IEEE754 approximation of phi, and find a pair of Fibonacci numbers which approximate it well enough:
phi=(Math.sqrt(5)+1)/2
f1,f2=1,1
while f2.to_f/f1 != phi
 f1,f2=f2,f1+f2
end
p [f1,f2]
With Ruby's Floats, i.e. IEEE754 64-bit doubles, you should get [102334155, 165580141] as a result.
f1 and f2 will be the numerator and denominator in our search of reg.number ratios.
Next, generate regular (5-smooth) numbers, divide them by our phi approximation, and check if the quotient is also in the regular set:
require 'algorithms' # gem install algorithms
h=Containers::MinHeap.new([1]) # intermediate hash for reg.num.generation

require 'set'
s=Set.new() # set of generated reg.numbers

i=0 # to have this variable in the outer scope to while
while i<f2+f2 # choose your own upper limit
 i=h.pop # get minimal item from the heap
 s << i
 [2,3,5].each { |m| kk=i*m
                    h.push(kk) unless h.has_key?(kk) } # add its following reg.numbers to the heap
 j1=i*f1/f2 # truncated integer division
 j2=(i*f1+f2/2)/f2 # rounded, that is +1/2 then truncated
 Set[j1,j2].each { |k| p [i,k] if s.include?(k) and i.gcd(k) == 1 }
end
j1 and j2 could be identical, so we construct a Set[j1,j2] of their unique values
Also we use .gcd to drop non-unique representations of the ratio as (n*a)/(n*b)
This is the printout you should get as a result :

[1, 1]
[2, 1]
[3, 1]
[3, 2]
[5, 3]
[8, 5]
[9, 5]
[16, 9]
[27, 16]
[81, 50]
[16384, 10125]


So as you see, 214/34/53 would be a better approximation of phi than 34/2/52.
I would dream about a proof that there is no other regular numbers ratio even closer to phi, but my knowledge of the higher mathematics is only limited to my university diploma.
So you are on your own on what to do next with the reached conclusion :>