A recent question caused me to ponder Fibonacci sequences in $\mathbb{Z}_n$.
An immediate observation is that the sequence is determined by the current value and the previous. So, it could be considered as a finite state machine with $\mathbb{Z}_n^2$ as its state space. So, the period cannot be more than $n^2$. Actually, $n^2 - 1$ since $(0, 0)$ is an obvious fixed point. However, this only limits the period to a maximum of $n^2 - 1$.
Next, I realised that it was important to understand the prime cases and, in these cases, I am dealing with a field.
I'll say Fibonacci like sequence to mean a sequence which obeys the same recurrence relation but not necessarily the same initial values. These Fibonacci like sequences form a vector space of dimension $2$ over the field.
I can try to use Binet's formula. This seems to work well in most cases. Let's ignore some of the small ones at the moment so $\mathbb{Z}_p$ with $p \ge 7$. There are two cases;
The field contains a square root of $5$. In this case, Binet's formula gives us two linearly independent Fibonacci like sequences and hence they span the whole space. The multiplicative group of a finite field is cyclic so these solutions have a period which divides $p - 1$. This is a considerably tighter limitation than my observation from the finite state machine.
The field does not contain a square root of $5$. In this case, I can use a field extension of degree $2$. This is rather like the familiar case with $\mathbb{Z}$ or $\mathbb{Q}$. Again, I get two linearly independent solutions and hence they span the whole space. This time, I can only say that the period divides $p^2 -1$. This is still a tighter restriction.
Now the small cases. $\mathbb{Z}_2$ and $\mathbb{Z}_3$ feel a little odd since $5$ is not a canonical member of the field. Nonetheless, I can solve them in field extensions of degree $2$ and they are like case 2.
The most interesting case is $\mathbb{Z}_5$. Binet's formula works but only gives me only one solution which has period $4$. So, it does not span the space. Manual inspection shows that the period of the standard Fibonacci series is $20$. This does not contradict my initial observation that the period is $\le n^2 - 1$ but it does not fit cases 1 or 2 above. It is not a Binet like solution.
Finally my question: is there anything interesting going on here? Or, is it just that there is no guarantee that the Binet formula always gives us two independent solutions and we are just lucky that it does in most cases. When it does not then there may be another solution of a different form.