I am trying to learn about the Langlands program and was watching this video by Edward Frenkel where he explains how to count integer solutions to $y^2+y=x^3-x^2$
If I understood correctly one can count those solutions with this program:
"Mathematica start"
nn = 60;
Table[(Prime[n] -
Count[Flatten[
Table[Table[
Mod[y^2 + y - (x^3 - x^2), Prime[n]], {y, 1, Prime[n]}], {x, 1,
Prime[n]}]], 0]), {n, 1, nn}]
"Mathematica end"
giving the last column of the table in the picture above:
{-2, -1, 1, -2, 1, 4,...
The equation I am interested is:
$$\left(\left(2 y^2+y\right)-\left(x^2+x+1\right)\right) \bmod p_n = 0$$
which I computed with a similar program:
"Mathematica start Counting solutions to Mod[y + 2 y^2 - (1 + x + x^2), Prime[n]]"
nn = 42;
Table[(-1)^((Prime[n]^2 - 1)/24) - (Prime[n] -
Count[Flatten[
Table[Table[
Mod[(y + 2 y^2) - (1 + x + x^2), Prime[n]], {y, 1,
Prime[n]}], {x, 1, Prime[n]}]], 0]), {n, 1, nn}]
"Mathematica end"
and after which I did a OEIS search.
Question:
Is it true that for $n>4$ the solution count is:
$$a(p_n)=p_n-\text{#} = (-1)^{\frac{1}{24} \left((p_n){}^2-1\right)}$$
where the differences $(-1)^{\frac{1}{24} \left((p_n){}^2-1\right)}-(p_n-\text{#})$ start:
{(-1)^(1/8), 1 + (-1)^(1/3), 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,...
I don't know how to tag this question.
As a sidenote, if one changes the minus sign in the equation to plus:
$$\left(\left(2 y^2+y\right)+\left(x^2+x+1\right)\right) \bmod p_n = 0$$
"Mathematica start Counting solutions to Mod[y + 2 y^2 - (1 + x + \
x^2), Prime[n]]"
nn = 42;
Table[(-1)^((Prime[n]^2 - 1)/24) - (Prime[n] -
Count[Flatten[
Table[Table[
Mod[(y + 2 y^2) + (1 + x + x^2), Prime[n]], {y, 1,
Prime[n]}], {x, 1, Prime[n]}]], 0]), {n, 1, nn}]/2
"Mathematica end"
one gets a match with:
Second least-significant bit in the binary expansion of the n-th prime.

Let $p \nmid 14$ be a prime.
The equation $2y^2+y=x^2+x+1$ over $\mathbb{F}_p$ can be rewritten as $(x+1/2)^2-2(y+1/4)^2=-7/8$.
So the number of solutions of this equation is the same as the number of solutions of the equation $x^2-2y^2=-7/8$. Let $v \in \mathbb{F}_p^{\times}$ be given by $-7/8$.
If $2=u^2$ in $\mathbb{F}_p$, then this equation is $(x-uy)(x+uy)=v$. Every value of $x-uy \in \mathbb{F}_p^{\times}$ defines a unique solution, so there are $p-1$ solutions.
If $2$ is not a square in $\mathbb{F}_p$, then this equation is equivalent to $N_{\mathbb{F}_{p^2}/\mathbb{F}_p}(z)=v$, where $z \in \mathbb{F}_{p^2}$ and $z=x+\sqrt{2}y$. It’s then classical (considering the surjective norm homomorphism $\mathbb{F}_{p^2}^{\times} \rightarrow \mathbb{F}_p^{\times}$) that such an equation has $p+1$ solutions.
Thus the original equation has $p-\left(\frac{2}{p}\right)=p-(-1)^{(p^2-1)/8}$ solutions, the relationship that you had observed.
Note 1: if you flip the sign, then the same reasoning works, but the case study is about $\left(\frac{-2}{p}\right)$, hence your observation.
Note 2: the equation $2y^2+y=x^2+x+1$ defines a conic, so the point counting is easy to make explicit. But the equation in the video is a cubic, where it gets rather trickier.