1

The law of quadratic reciprocity for Jacobi symbols says if m and n are positive coprimes intergers then:

$\left(\frac{m}{n}\right)\left(\frac{n}{m}\right) = (-1)^{\tfrac{m-1}{2}\cdot\tfrac{n-1}{2}} = \begin{cases} 1 & \text{if } n \equiv 1 \pmod 4 \text{ or } m \equiv 1 \pmod 4,\\ -1 & \text{if } n\equiv m \equiv 3 \pmod 4 \end{cases}$

In all implementations of calculating the Jacobi symbol I've seen, they just seems to ignore this coprime requirement and just turn flip the symbol.

Some examples that show this:

Why can this coprime requirement be ignored?

When implementing this, checking that the gcd would clearly slow it down.

  • If $\gcd(m,n)>1$ then $\left(\frac mn\right)=0$. – Angina Seng Jul 25 '18 at 08:37
  • In an actual implementation, you can check after the loop has finished whether the final n is 1. Then the computed result is valid, otherwise the Jacobi symbol is zero. – gammatester Jul 25 '18 at 09:09
  • So are you saying that since the case that gcd > 1, it's not valid anyway, and the result will still say it's invalid? – Kurt Roeckx Jul 25 '18 at 12:35
  • A Jacobi algorithm switches the intermediate result between +1 and -1. When it has finished and and $\gcd > 1$ the intermediate result is invalid and the final result is zero. See e.g. Cohen, A Course in Computational Number Theory, Algorithms 1.4.10 or 1.4.11. – gammatester Jul 25 '18 at 15:06

0 Answers0