Why do very large Fibonacci numbers create an ellipse-type shape?
Asked Answered
B

4

6
in_range = int(input("range: "))

fibo_list = []

a = 0
b = 1
count = 0

if in_range < 0:
    print("faulty")
elif in_range == 0:
    print("faulty")
else:
    while count < in_range:
        c = a + b
        a = b
        b = c
        count += 1
        fibo_list.append(a)


print(fibo_list)

When inputting 1000 for the range of this code, many ellipse shapes are created, some of which are hard to see. This seems to only happen with the Fibonacci sequence and no other chains of long numbers. Why is this?Here is what the ellipses look like

Brotherson answered 3/12, 2019 at 2:4 Comment(5)
While interesting, I don't think explaining the phenomenon is really on topic here if this is related to a property of the sequence.Iy
Fascinating. This question might be better suited to math.stackexchange.comAggrade
All of the white space creates the same pattern here, it just doesn't look like a cohesive ellipse for the lines closer to the top and bottom of your image because the white spaces are spaced further apart from one another, and your brain doesn't recognize it as the perimeter of an ellipse.Glede
These should be more like parabolas than ellipses.Pteropod
I'm voting to close this question as off-topic because it has nothing to do with programming.Nurserymaid
H
6

The "shape" of the blank spaces between the numbers is just an artifact of aligning numbers with a width (or multiple of the width) close to the terminal width, while slowly increasing the number of digits. Fibonacci progression just happens to increase the number of digits at a rate that is roughly the right speed to see the "ellipse pattern" appear, but any pattern that grows in digit count at a similar rate will see such a pattern. Maybe not at the same places, maybe slightly gentler or steeper curves, but similar.

Just as a simple example, printing truncated powers of 1.5 from 300 to 600 produces a very similar pattern:

print([int(1.5 ** i) for i in range(300, 600)])

Power pattern

Hyaluronidase answered 3/12, 2019 at 2:13 Comment(3)
I think it's not a complete answer anyhow.Droopy
@WenchengLi: Can you explain what you feel is missing? I gave an example, with screenshot, to make it clear how arbitrary the pattern is; the ellipse curve becomes vertical at the moment some multiple of the number's width is equal to the terminal width, curving away from vertical when the multiple of the number's width is less than or greater than the terminal width. Fibonacci is nothing special, which answers the question "Why is Fibonacci special" with "It isn't".Hyaluronidase
This is just an observation and an indecent incomplete answer.Crenelation
P
1

This is more of a mathematical question than a programming one, but we can investigate it more easily with code.

The only relevant feature of the Fibonacci sequence here is the string lengths of the numbers, i.e. their number of digits. Since the Fibonacci sequence has exponential growth, the number of digits increases approximately linearly, because the base-10 logarithm function tells you how many digits it has, and a logarithm is the inverse of an exponential function.

So we can observe the same pattern with strings of linearly-increasing length:

>>> print(*( '8'*i for i in range(70, 89) ))
8888888888888888888888888888888888888888888888888888888888888888888888 888888888
88888888888888888888888888888888888888888888888888888888888888 88888888888888888
8888888888888888888888888888888888888888888888888888888 888888888888888888888888
8888888888888888888888888888888888888888888888888 888888888888888888888888888888
88888888888888888888888888888888888888888888 88888888888888888888888888888888888
8888888888888888888888888888888888888888 888888888888888888888888888888888888888
8888888888888888888888888888888888888 888888888888888888888888888888888888888888
88888888888888888888888888888888888 88888888888888888888888888888888888888888888
8888888888888888888888888888888888 888888888888888888888888888888888888888888888
8888888888888888888888888888888888 888888888888888888888888888888888888888888888
88888888888888888888888888888888888 88888888888888888888888888888888888888888888
8888888888888888888888888888888888888 888888888888888888888888888888888888888888
8888888888888888888888888888888888888888 888888888888888888888888888888888888888
88888888888888888888888888888888888888888888 88888888888888888888888888888888888
8888888888888888888888888888888888888888888888888 888888888888888888888888888888
8888888888888888888888888888888888888888888888888888888 888888888888888888888888
88888888888888888888888888888888888888888888888888888888888888 88888888888888888
8888888888888888888888888888888888888888888888888888888888888888888888 888888888
8888888888888888888888888888888888888888888888888888888888888888888888888888888

The question is then, why do strings of linearly increasing length make this shape?

I've purposely selected the lengths from 70 to 89 because the terminal width is 80, so this puts one "gap" on each line, simplifying the analysis considerably.

  • When a string of length 75 runs over the line break, the gap on the next line is 5 spaces further left than the gap on the line above, because 75 is 5 less than 80.
  • The next string has length 76, so the gap is 4 spaces further left.
  • The next string length is 77, so the gap is 3 spaces further left.
  • The next string length is 78, so the gap is 2 spaces further left.
  • The next string length is 79, so the gap is 1 space further left.
  • The next string length is 80, so the gap is directly underneath the gap on the line above - 0 spaces further left.
  • The next string length is 81, so the gap is 1 space further right.
  • The next string length is 82, so the gap is 2 spaces further right.
  • ...and so on.

Notice the simple pattern: because the string gets longer by 1 each time, the relative offset of the gap changes by 1 on each line. This is a bit like a differential equation: d(gap position) / d(line number) is a linear function of the line number, so we can find the absolute offset of the gap by integrating: gap position is a quadratic function of the line number. That means the shape is a parabola (not an ellipse).

A mildly amusing consequence is that if you tune the string width to be near the terminal width, you can draw an integral of any function you like. Here's the integral of the sign function, which looks like abs(x) as expected:

>>> def sign(x):
...     return -1 if x < 0 else 1 if x > 0 else 0
...
>>> print(*( '8'*(79 + 5*sign(i)) for i in range(-10, 10) ))
88888888888888888888888888888888888888888888888888888888888888888888888888 88888
888888888888888888888888888888888888888888888888888888888888888888888 8888888888
8888888888888888888888888888888888888888888888888888888888888888 888888888888888
88888888888888888888888888888888888888888888888888888888888 88888888888888888888
888888888888888888888888888888888888888888888888888888 8888888888888888888888888
8888888888888888888888888888888888888888888888888 888888888888888888888888888888
88888888888888888888888888888888888888888888 88888888888888888888888888888888888
888888888888888888888888888888888888888 8888888888888888888888888888888888888888
8888888888888888888888888888888888 888888888888888888888888888888888888888888888
88888888888888888888888888888 88888888888888888888888888888888888888888888888888
88888888888888888888888888888 88888888888888888888888888888888888888888888888888
8888888888888888888888888888888888 888888888888888888888888888888888888888888888
888888888888888888888888888888888888888 8888888888888888888888888888888888888888
88888888888888888888888888888888888888888888 88888888888888888888888888888888888
8888888888888888888888888888888888888888888888888 888888888888888888888888888888
888888888888888888888888888888888888888888888888888888 8888888888888888888888888
88888888888888888888888888888888888888888888888888888888888 88888888888888888888
8888888888888888888888888888888888888888888888888888888888888888 888888888888888
888888888888888888888888888888888888888888888888888888888888888888888 8888888888
88888888888888888888888888888888888888888888888888888888888888888888888888
Pteropod answered 3/12, 2019 at 19:29 Comment(0)
F
0

This is just a coincidence. The eclipse is formed by the separaters ", " which means the position is ultimately dependent on the length of the number and the width of your display. As the numbers' length is growing 0-1 each time, the position shift between lines depends on how many numbers you can fit on each line. You may find this pattern disappear or the radious of the eclipse changes if you try to print 10000 :p

Fayalite answered 3/12, 2019 at 2:13 Comment(0)
C
-1

You observed:

This seems to only happen with the Fibonacci sequence

Some patterns can appear with any sequences, but with the Fibonnacci suite it goes stable to the infinite, with even more precision. You are seeing some curve of a bigger spiral.

Taking two consecutives numbers in the sequences of Fibonnacci, example:

144 / 89 = 1.6179..

89 / 144 = 0.618..

Two consecutives numbers in the suite are always returning the same ratio.

This (1 + squareRoot(5)) / 2) = 1.618...

And (1 - squareRoot(5)) / 2) = 0.618...

This the golden ratio, a lot to say, this goes way beyond programming:

https://en.wikipedia.org/wiki/Golden_ratio

About programming, the golden ratio is the best trick to avoid loops interlacing. It's a lot in use in synthetizer. Just as we see, it apply with the time. Using many loops, it's still very pleasant. To go deeper, I recommend to see how it apply to the music theory, and to financial technical analysis.

Those patterns are very common in the nature, your text is forming those sequences:

enter image description here enter image description hereenter image description here

Crenelation answered 3/12, 2019 at 2:50 Comment(1)
It is not a spiral pattern; they are parabolas. It has nothing to do with the Fibonacci spiral.Pteropod

© 2022 - 2024 — McMap. All rights reserved.