Phase 1: Fibonacci Sequence modulo m

Before applying the 24:17:13:7:3 sequence of the previous post, I though, that I could check all Fibonacci sequences modulo 2 to 12 (period(12)=24) and see if some are interesting for my goal.

The period of a Fibonacci sequence is called Pisano period and —to my knowledge— there is not a formula with ()+-*/^ that could give them as a function of the modulo m. Thus I wrote a small Python script that does this:

def my_zeros(n):
        result = []
        for i in range(n):
                result.append(0)
        return result

for modulo in range(2,13):
        print "modulo =",modulo
        max = modulo**2
        fibonacci = my_zeros(max)
        fibonacci[0] = 0
        fibonacci[1] = 1
        j = 2
        for j in range(2, max):
                fibonacci[j] = (fibonacci[j-1] + fibonacci[j-2]) % modulo
		# the 2 last numbers x=F_(n-1) y=F_n of the period
		# must satisfy the following (for modulo m):
		# x + y = 0 mod m
		# y + 0 = 1 mod m
		# because 0 and 1 should be the next numbers.
		# Thus (x,y) = (m-1, 1).
                if fibonacci[j] == 1:
                        if fibonacci[j-1] == modulo - 1:
                                per = j + 1
                                break
        print fibonacci[0:per]
        print "period =", per
        print

The output is very interesting:

modulo = 2
[0, 1, 1]
period = 3

modulo = 3
[0, 1, 1, 2, 0, 2, 2, 1]
period = 8

modulo = 4
[0, 1, 1, 2, 3, 1]
period = 6

modulo = 5
[0, 1, 1, 2, 3, 0, 3, 3, 1, 4, 0, 4, 4, 3, 2, 0, 2, 2, 4, 1]
period = 20

modulo = 6
[0, 1, 1, 2, 3, 5, 2, 1, 3, 4, 1, 5, 0, 5, 5, 4, 3, 1, 4, 5, 3, 2, 5, 1]
period = 24

modulo = 7
[0, 1, 1, 2, 3, 5, 1, 6, 0, 6, 6, 5, 4, 2, 6, 1]
period = 16

modulo = 8
[0, 1, 1, 2, 3, 5, 0, 5, 5, 2, 7, 1]
period = 12

modulo = 9
[0, 1, 1, 2, 3, 5, 8, 4, 3, 7, 1, 8, 0, 8, 8, 7, 6, 4, 1, 5, 6, 2, 8, 1]
period = 24

modulo = 10
[0, 1, 1, 2, 3, 5, 8, 3, 1, 4, 5, 9, 4, 3, 7, 0, 7, 7, 4, 1, 5, 6, 1, 7, 8, 5,
3, 8, 1, 9, 0, 9, 9, 8, 7, 5, 2, 7, 9, 6, 5, 1, 6, 7, 3, 0, 3, 3, 6, 9, 5, 4,
9, 3, 2, 5, 7, 2, 9, 1]
period = 60

modulo = 11
[0, 1, 1, 2, 3, 5, 8, 2, 10, 1]
period = 10

modulo = 12
[0, 1, 1, 2, 3, 5, 8, 1, 9, 10, 7, 5, 0, 5, 5, 10, 3, 1, 4, 5, 9, 2, 11, 1]
period = 24

Now the idea is the following: let all sequences represent divisions of the octave by the respective modulo (e.g. m=12: semitones, m=11: 1/11 of the octave etc) and stretch them equidistant in order to fill the same duration. Then select the ones that are going to sound at the given position (filtering). Allow rhythmical and pitch deviations. The whole piece is in forte.

About the words: I decided not to use a poem. I think 2 arts at the same time is a bit too much for my taste. Music alone should suffice.

4 Responses to “Phase 1: Fibonacci Sequence modulo m”

  1. fixpoint says:

    Hello,

    if I may, I’d like to suggest an improvement to the python code. It removes the my_zeros function and therefore the list is not traversed twice. I hope the code doesn’t get mangled in the comment..
    Have a nice day!

    for modulo in range(2,13):
            print "modulo =",modulo
            max = modulo**2
            fibonacci = []
            fibonacci.append(0)
            fibonacci.append(1)
            j = 2
            for j in range(2, max):
                    fibonacci.append( (fibonacci[j-1] + fibonacci[j-2]) % modulo )
                    if fibonacci[j] == 1:
                            if fibonacci[j-1] == modulo - 1:
                                    per = j + 1
                                    break
            print fibonacci[0:per]
            print "period =", per
            print
    
  2. admin says:

    Hello!

    [I never edit comments, but the indentation in your code was destroyed in the display, so I corrected it with a pre/pre. I hope you don’t mind].

    Thank you very much for your improvement! Actually, to be honest, I had thought of that solution, but I thought falsely that 3 “append” would make the code less clear. Obviously I was wrong! 😉

  3. fixpoint says:

    Sure, thanks for for fixing the indentation. What are the tags exactly to do this?
    Have fun with python!

  4. admin says:

    You are welcome!

    The tags are
    <pre>
    here comes the PREedited code
    </pre>

    Python is great!