6
$\begingroup$

Here is the primality test I found for a number $n$ and the algorithm :

Step 1 : Let $n$ an odd number not divisible by $3$ or $5$ and greater than $5$.

Step 2 : Let $k$ an positive integer (here $k = 1$).

Step 3 : Let $a = (k-1)^2 + 3$.

Step 4 : Let $\left(\frac{n}{a}\right)$ denotes the Jacobi Symbol.

Step 5 : While $a = (k-1)^2 + 3$ is even or $\left(\frac{n}{a}\right)\neq1$ or $gcd(n,a+1) \neq 1$, add $1$ to $k$.

Step 6 : Let $B \equiv x^{n-1}$ mod $(n, f_a)$ where $f_a = x^2 - ax - a$

Step 7 : Let $T=x+n-a-1$ and $U=(n+1)/2 \cdot x + 2$

Step 8 : If $B \neq 1$ check if $B = T$ or $B = U$, if it is, return prime, if not, return composite

Step 9 : If $B = 1$ add $1$ to $k$ and redo step 3 to step 8.

Here is a PARI GP Code

k=1;
c(n,k) = {a=(k-1)^2+3;while(a%2!=1||kronecker(n,a)!=1||gcd(n,a+1)!=1,k++;a=(k-1)^2+3);
B=Mod(Mod(x,n),x^2-a*x-a)^(n-1);
T=x+n-a-1;U=((n+1)/2)*x + 2;
if(B!=1, if(B==T || B==U, print(n,",","probably prime"), 
print(n,",","composite"))); 
while(B==1, k++ && c(n,k))}


{for(n=1,10000,
if(n!=1&&n%2==1&&n%5!=0&&n%3!=0,c(n,k)))}

I have checked all primes and composites to $2^{31}$ and all pass the test.

I would like to know if this is only an coincidence or not. And if not, is there a way to prove it ?

$\endgroup$
9
  • 1
    $\begingroup$ Please make your PARI GP Code consistent with your steps. Why do you say $k=1$ in step 2 but assign $k=0$ in your PARI GP Code? Why do your introduce he variable $S=B$ in your PARI GP Code when there is no $S$ in your steps? Why is the variable $x$ in your steps and PARI GP Code never assigned a value? If the value of $x$ is unassigned, how can you assign a value to $\text{Mod}(x,n)$ for example? Have your also checked all primes to $10^9$? $\endgroup$ Commented Jun 3 at 15:53
  • 1
    $\begingroup$ Thanks. I'm not familiar with PARI GP Code. Is while(B==1, k++ && c(n,k)) the same thing as while(B==1, k++; c(n,k))? I'm used to using && as a logical and operation which doesn't seem to make sense to me in this statement. $\endgroup$ Commented Jun 3 at 17:47
  • 2
    $\begingroup$ Since you work modulo $n$, you can set $T=x-a-1$ and $U=x/2+2$. Also, $a$ is even when $k$ is even, so you can safely increase $k$ by 2 (instead of 1) to keep it odd. $\endgroup$ Commented Jun 3 at 18:14
  • 2
    $\begingroup$ In Step 5, what is the point of increasing $k$ when $\gcd(n,a+1)\ne1$? If $\gcd(n,a+1)\ne1$, you know $n$ is composite (assuming $a$ can’t get as high as $n$ itself?). $\endgroup$ Commented Jun 3 at 18:24
  • 2
    $\begingroup$ @Aurel-BG: Here is a cleaned version of your test, which for a given n returns 1 or 0 depending on its asserted primality: pastebin.com/DW9DHUGy $\endgroup$ Commented Jun 3 at 18:43

1 Answer 1

4
$\begingroup$

As for many other similar tests, it's relatively easy to see why the proposed test cannot fail on prime $n$, but it may be hard to (dis)prove that there are no pseudoprimes (composites determined by the test as "probably prime").

In case of prime $n$ and a particular choice of $a$, this tests will get $B=1$, $B=U$ or $B=T$ depending on Jacobi symbol $\left(\frac{a^2+4a}n\right)$ being $1$, $0$, or $-1$, respectively.

As Martin Seysen pointed out, the case $\left(\frac{a^2+4a}n\right)=-1$, meaning that $f_a(x)$ is irreducible modulo $n$, corresponds to Quadratic Frobenius test, which in the given settings will get $x^{n+1}\equiv a\pmod{n, f_a(x)}$, implying that $x^{n-1}\equiv T\pmod{n, f_a(x)}$.

The case $\left(\frac{a^2+4a}n\right)=0$ means $a\equiv -4\pmod n$ and thus $f_a(x)\equiv (x+2)^2\pmod{n}$. Then $x^n = (-2+(x+2))^n \equiv (-2)^n \equiv -2\pmod{n, (x+2)^2}$, and thus $x^{n-1} \equiv U\pmod{n, (x+2)^2}$.

Finally, when $\left(\frac{a^2+4a}n\right)=1$, we have $f_a(x) = (x-r_1)(x-r_2)$ for some residues $r_1\ne r_2$ modulo $n$. Then $x^{n-1} \equiv r_i^{n-1} \equiv 1\pmod{n, x-r_i}$ for $i\in\{1,2\}$, and thus $x^{n-1}\equiv 1\pmod{n,f_a(x)}$.

$\endgroup$
2
  • $\begingroup$ Thanks for you answer (and the pastebin) I noticed than the case $U = x/2 + 2$ seems only happens when the number $n$ is a prime of the form $x^2 + 7y^2$ by the way. $\endgroup$ Commented Jun 4 at 1:21
  • 2
    $\begingroup$ @Aurel-BG: If prime $n$ divides $a+4 = (k-1)^2 + 7$, it must be of the form $x^2+7y^2$. $\endgroup$ Commented Jun 4 at 2:16

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.