Fibonacci numbers mod $p$

$p\equiv 1,4\pmod{5}$

$\newcommand{\phib}{\psi}$Let $\phi$ and $\phib$ be roots of $x^2-x-1$ in $\mathbb Z/p^2\mathbb Z,$ which exist by quadratic reciprocity. They satisfy $\phib=1-\phi$ and $\phi\phib=-1.$ Let $H(x)=\sum_{k=1}^{p-1}x^k/k$ and let $\delta(x)$ be the $p$-derivation $\frac{x-x^p}p,$ which is well-defined as a function from $\mathbb Z/p^2\mathbb Z$ to $\mathbb F_p.$ Then $H(x)=\delta(x) + \delta(1-x)$ - I learnt this from a blog post "Entropy Modulo a Prime (Continued)" but it is presumably classical. Note that the product rule for $p$-derivations becomes simply $\delta(ab)=a\delta(b)+\delta(a)b$ because $x^p=x$ in $\mathbb F_p.$ Note also $\delta(-x)=-\delta(x),$ and by the product rule for p-derivations $\delta(\phib)=(1/\phi^2)\delta(\phi).$ Using $F_n=(\phi^n-\phib^n)/(\phi-\phib),$ the sum in question can be written as $1/2(\phi-\phib)$ multiplied by

\begin{align*} &\phi(H(\phi)-H(-\phi))-\phib(H(\phib)-H(-\phib))\\ =&\phi(2\delta(\phi)+\delta(\phib)-\delta(\phi^2))-\phib(2\delta(\phib)+\delta(\phi)-\delta(\phib^2))\\ =&((\phi-3)-(\phib-3)/\phi^2)\delta(\phi)\\ =&((\phi-3)\phi^2-(\phib-3))\delta(\phi)/\phi^2\\ =&((-\phi-2)+(\phi+2))\delta(\phi)/\phi^2\\ =&0. \end{align*}

(Values inside $\delta(.)$ are in $\mathbb Z/p^2\mathbb Z,$ values outside are in $\mathbb F_p.$)

$p\equiv 2,3\pmod{5}$

This is similar, but using $\mathbb Z[\phi]/(p^2)\to\mathbb F_p[\phi]$ in place of $\mathbb Z/p^2\mathbb Z\to\mathbb F_p,$ and $\delta(x)=\frac{\sigma(x)-x^p}p$ where $\sigma$ is the map that swaps $\phi$ and $\phib$ (a lift of the Frobenius map from $\mathbb F_p[\phi]$ to $\mathbb Z[\phi]/(p^2)$). Note $H(x)=\delta(x)+\delta(1-x)$ still holds because $\sigma(x)+\sigma(1-x)=\sigma(1)=1.$ For values in $\mathbb F_p[\phi]$ we no longer have $x^p=x;$ in particular $\phi^p=\phib$ and $\phib^p=\phi.$ So instead of $\delta(ab)=a\delta(b)+\delta(a)b$ we have to be careful to use $\delta(ab)=a^p\delta(b)+\delta(a)b^p.$ This gives $\delta(\phib)=\phi^2\delta(\phi).$ We get \begin{align*} &\phi^{-1}(H(\phi)-H(-\phi))\\ =&(\phi-1)(2\delta(\phi)+\delta(\phib)-\delta(\phi^2))\\ =&(\phi-1)(2+\phi^2-2\phib)\delta(\phi)\\ =&(\phi+2)\delta(\phi). \end{align*}

By the automorphism $\sigma$ we also get $$\phib^{-1}(H(\phib)-H(-\phib))=(\phib+2)\delta(\phib)=\phi^2(3-\phi)\delta(\phi)=(\phi+2)\delta(\phi),$$

giving $\phi^{-1}(H(\phi)-H(-\phi))-\phib^{-1}(H(\phib)-H(-\phib))=0.$

Remark

As in barto's answer, we could use the ring $\mathbb Z_{p}[\phi]/(\phi^2-\phi-1),$ where $\mathbb Z_p$ is the ring of $p$-adic integers, instead of $\mathbb Z/p^2\mathbb Z$ and $\mathbb Z[\phi]/(p^2).$ In the $p\equiv 1,4\pmod{5}$ case this is not an integral domain - $\phi$ acts as a generic root of a polynomial that already has roots in $\mathbb Z_{p}.$ I've left this argument in terms of finite rings since I think it is logically correct and I don't like to overpolish.


Partial answer: the calculation in the end turns out to be less trivial than expected, but it does given an equivalent form in terms of a congruence of three Fibonacci numbers mod $p^2$.

Idea: $F_n$ is a linear combination of geometric progressions, and by a classical trick (writing as an integral and making a change of variables) we have: $$\sum_{k=1}^n\frac{x^k}k = \sum_{k=1}^n\binom nk\frac{(x-1)^k-(-1)^k}k$$ Taking $n=p$ the binomial coefficient almost disappears and we obtain $$H(x)=\sum_{k=1}^{p-1}\frac{x^k}k \equiv\frac{(x-1)^p+1-x^p}p\pmod p$$ (for all $x\in \mathbb Z$, or as polynomials in $x$) for $p$ odd.

To filter out even or odd terms, take $H(x)\pm H(-x)$.

Back to the problem: We have $F_n = C \cdot (\phi^n-(\phi')^{n})$ for some constant $C=1/(\phi-\phi')$. Here $\phi'=-\phi^{-1}$.

Some details to make everything legal: to make sure we don't divide by $0$ and all congruences make sense, from now on we work in the ring $A=\mathbb Z_{(p)}[(\sqrt 5)^{-1}]\subset\mathbb Q(\sqrt5)$, where $1,2, \ldots,p-1,\sqrt5=1/C,\phi$ are invertible. Choosing a maximal ideal $\mathfrak m$ containing $p$ gives a morphism of $\mathbb Z$-algebras to either $\mathbb F_p$ or $\mathbb F_{p^2}$, which sends Fibonacci numbers in $\mathbb Z$ to Fibonacci numbers mod $p$. An integer is in $\mathfrak m^k$ iff it is divisible by $p^k$, since $p\neq5$ is unramified.

Applying the above over $A$, we only have to calculate $$\phi (H(\phi)-H(-\phi))\\ - \phi'( H(\phi')- H(-\phi'))$$ resp. $$\phi' (H(\phi)-H(-\phi))\\ - \phi( H(\phi')- H(-\phi'))$$

modulo $p$, for which we now have closed forms. Equivalently, we can get rid of the denominator $p$ and prove that $p$ times that is $0$ mod $p^2$.


It is actually not obvious that it is $0\pmod {p^2}$. For the first one, writing everything in terms of $\pm$ powers of $\phi$ (using $-\phi'-1=-\phi^2$ etc), we get $$[-p+1]-[p+1]+[2p+1]-[p+1]\\ -[p-1]+[-p-1]+[-2p-1]+[-p-1]$$ where $[n]$ denotes $\phi^n$. Using $[n]=\phi F_n+F_{n-1}$ and $F_{-n}=(-1)^nF_n$ this is: $$(2\phi-1)(F_{2p+1}-2F_{p+1}-F_{p-1})$$ so it is equivalent to show $$\bbox[5px,border:2px solid red]{F_{2p+1}-2F_{p+1}-F_{p-1} \equiv0\pmod{p^2}}\qquad p\equiv\pm1\pmod5$$

Likewise, for the second: $$[-p-1]-[p-1]+[2p-1]-[p-1]\\ -[p+1]+[-p+1]+[-2p+1]+[-p+1]$$ which gives the equivalent (times $2\phi-1$) $$\bbox[5px,border:2px solid red]{F_{2p-1}-2F_{p-1}-F_{p+1} \equiv0\pmod{p^2}}\qquad p\equiv\pm2\pmod5$$