Practical use of the fibonacci sequence

[)roi(]

Executive Member
Joined
Apr 15, 2005
Messages
6,282
Conversions between imperial and metric has never been easy to remember.

For example:
  • According to Google; To convert miles to kilometres, we have to multiply by 1.60934 (yip, not so easy to remember)
So how do we make this easier? Apparently the fibonacci sequence can help us with this?

To test that theory I wrote some Swift code to convert miles to kilometres, using the fibonacci sequence as the input for miles:
Code:
import Foundation

struct Fibonacci: IteratorProtocol
{
  var previous: Int = 1
  var value: Int = 2
  
  mutating func next() -> Int?
  {
    (self.value, self.previous) = (self.value + previous, self.value)
    return value
  }
}

let line = String(repeating: Character("-"), count: 19)
let title = String(format: "| %@ | %@ |", "miles ", "  km  ")

var fibonacci = Fibonacci()
print("\(line)\n\(title)\n\(line)")
for i in 1...10
{
  let miles = fibonacci.next() ?? 0
  let km = Int(round(Double(miles) * 1.60934))
  let text = String(format: "| %6d | %6d |", miles, km)
  print(text)
}
print(line)
Here's the result, the equivalent km values have been rounded up to the nearest integer value.
Code:
-------------------
| miles  |   km   |
-------------------
|      3 |      5 |
|      5 |      8 |
|      8 |     13 |
|     13 |     21 |
|     21 |     34 |
|     34 |     55 |
|     55 |     89 |
|     89 |    143 |
|    144 |    232 |
|    233 |    375 |
-------------------
Surprising isn't it.

Note:
The above calculation loses a bit of precision after the 10 values, but it's accuracy it still fairly good, e.g. 40th fibonnaci number is 433494437 (miles) vs 431165193 (km). The loss of precision is definitely down to the use of 1.60934 -- if I use 1.6180339887 then the precision tracks perfectly through to 40th fibonacci number.

Code:
---------------------------
|   miles    |     km     |
---------------------------
|          3 |          5 |
|          5 |          8 |
|          8 |         13 |
|         13 |         21 |
|         21 |         34 |
|         34 |         55 |
|         55 |         89 |
|         89 |        144 |
|        144 |        233 |
|        233 |        377 |
|        377 |        610 |
|        610 |        987 |
|        987 |       1597 |
|       1597 |       2584 |
|       2584 |       4181 |
|       4181 |       6765 |
|       6765 |      10946 |
|      10946 |      17711 |
|      17711 |      28657 |
|      28657 |      46368 |
|      46368 |      75025 |
|      75025 |     121393 |
|     121393 |     196418 |
|     196418 |     317811 |
|     317811 |     514229 |
|     514229 |     832040 |
|     832040 |    1346269 |
|    1346269 |    2178309 |
|    2178309 |    3524578 |
|    3524578 |    5702887 |
|    5702887 |    9227465 |
|    9227465 |   14930352 |
|   14930352 |   24157817 |
|   24157817 |   39088169 |
|   39088169 |   63245986 |
|   63245986 |  102334155 |
|  102334155 |  165580141 |
|  165580141 |  267914296 |
|  267914296 |  433494437 |
|  433494437 |  701408733 |
---------------------------

Makes me wonder if there is some back story to this relationship, and whether the correct multiple should be based on the ratio between fibonacci numbers i.e. and not the 1.60934 Google suggests?
 
Last edited:

[)roi(]

Executive Member
Joined
Apr 15, 2005
Messages
6,282
Interesting.
Even more interesting, is that without realising it, I (re)discovered the Golden Ratio, dividing the 40th Fibonacci number by the 39th, gave me 1.6180339887 -- the golden ratio. So now even more so I'm intrigued to know whether the original authors of the mile and kilometre got the conversion wrong (simply because they didn't have a computer)
 

cguy

Executive Member
Joined
Jan 2, 2013
Messages
8,527
[)roi(];17913401 said:
Even more interesting, is that without realising it, I (re)discovered the Golden Ratio, dividing the 40th Fibonacci number by the 39th, gave me 1.6180339887 -- the golden ratio. So now even more so I'm intrigued to know whether the original authors of the mile and kilometre got the conversion wrong (simply because they didn't have a computer)

I think it is just a coincidence - there are a lot of interesting constants in maths, so it's not surprising that some match up to random things for the first few digits. I believe that the mile and kilometer were based on entirely unrelated things (Roman paces and circumference of the earth respectively).
 

cguy

Executive Member
Joined
Jan 2, 2013
Messages
8,527
BTW, the Fibonacci sequence has been used for Fibonacci Heaps (theoretically more efficient heap) and Fibonacci Hashing (good hash quality for it's simplicity).
 

Beachless

Executive Member
Joined
Oct 6, 2010
Messages
6,003
I already have numbers like 1.6 , 2.54 , 3.14 burned into my brain. But thanks for the alternative.
 

[)roi(]

Executive Member
Joined
Apr 15, 2005
Messages
6,282
I think it is just a coincidence - there are a lot of interesting constants in maths, so it's not surprising that some match up to random things for the first few digits. I believe that the mile and kilometer were based on entirely unrelated things (Roman paces and circumference of the earth respectively).
Most things are rooted to elements: nature and celestial; meaning I'm little less inclined to dismiss this as simple coincidence. The golden ratio is after all present in everything around us, and within us. In any case TIL
 

Indigogirl

Expert Member
Joined
Oct 2, 2010
Messages
3,386
Very interesting - love numerical sequences and patterns.

[)roi(];17913401 said:
Even more interesting, is that without realising it, I (re)discovered the Golden Ratio, dividing the 40th Fibonacci number by the 39th, gave me 1.6180339887 -- the golden ratio. So now even more so I'm intrigued to know whether the original authors of the mile and kilometre got the conversion wrong (simply because they didn't have a computer)
Tell that to light...

The metre is defined as the distance travelled by light in a specific fraction (1/299 792 458) of a second.

But it does raise a number of interesting things to ponder! Not the least of which is the original determination of the mile as a unit of length - over 400 years back. Maybe run a few of the variations on the 'historical miles' and see whether any of them provide a closer correlation?
 
Last edited:

[)roi(]

Executive Member
Joined
Apr 15, 2005
Messages
6,282
Very interesting - love numerical sequences and patterns.


Tell that to light...

The metre is defined as the distance travelled by light in a specific fraction (1/299 792 458) of a second.

But it does raise a number of interesting things to ponder! Not the least of which is the original determination of the mile as a unit of length - over 400 years back. Maybe run a few of the variations on the 'historical miles' and see whether any of them provide a closer correlation?
Metric is very much rooted in science... imperial not so. Still the history of all of this is certainly something I'd like to explore (added to reading stack); even if it's just coincidence it's certainly a very intriguing one.
 

xumwun

Expert Member
Joined
Jul 30, 2006
Messages
3,151
Very interesting - love numerical sequences and patterns.


Tell that to light...

The metre is defined as the distance travelled by light in a specific fraction (1/299 792 458) of a second.

But it does raise a number of interesting things to ponder! Not the least of which is the original determination of the mile as a unit of length - over 400 years back. Maybe run a few of the variations on the 'historical miles' and see whether any of them provide a closer correlation?

That's not the original definition of the metre.
 
Top