64

Can you provide a proof or a counterexample for the claim given below ?

Inspired by Agrawal's conjecture in this paper and by Theorem 4 in this paper I have formulated the following claim :

Let $n$ be a natural number greater than two . Let $r$ be the smallest odd prime number such that $r \nmid n$ and $n^2 \not\equiv 1 \pmod r$ . Let $T_n(x)$ be Chebyshev polynomial of the first kind , then $n$ is a prime number if and only if $T_n(x) \equiv x^n \pmod {x^r-1,n}$ .

You can run this test here .

I have tested this claim up to $5 \cdot 10^4$ and there were no counterexamples .

EDIT

Algorithm implementation in Sage without directly computing $T_n(x)$ .

Python script that implements this test can be found here.

The Android app that implements this test can be found on Google Play.

ADDED

I offer $100$ € for a proof of this claim. The proof must be published in one of the following journals: Journal of Number Theory , Algebra & Number Theory , Moscow Journal of Combinatorics and Number Theory .

Pedja
  • 2,673
  • I tried it with $n=311231$ and got this: PARI/GP interpreter crashed -- automatically restarting. *** at top-level: if(Mod((polchebyshev(n,1,x))%(x^r-1),n)-( *** ^-------------------- *** incorrect type in gtos [integer expected] (t_POL). – მამუკა ჯიბლაძე Nov 17 '17 at 14:57
  • 4
    @მამუკა ჯიბლაძე A stack overflow error has occurred . – Pedja Nov 17 '17 at 16:04
  • 4
    This is very cool, but, if true, can it be made into a useful algorithm? As stated it is about an $O(n^2)$ algorithm to determine primality of $n$ – Igor Rivin Nov 17 '17 at 17:07
  • @IgorRivin Please see analysis at the top of the page 8 . Since these two algorithms are similar their time complexities should be the same . – Pedja Nov 18 '17 at 08:01
  • 3
    @IgorRivin Seems that it depends on how fast one can find $T_n(x)\mod x^r-1$ (for very small $r$, about $\log n$) without computing $T_n(x)$ itself completely. The way it is implemented now, the whole $T_n(x)$ is found first, and I think it is worse than polynomial then. – მამუკა ჯიბლაძე Nov 21 '17 at 12:29
  • 3
  • 1
    @IgorRivin Thanks to the answer by Lucia to that question, I believe the answer to your question is more than positive - seems like this produces a logarithmically efficient primality test. I tried to demonstrate it in another answer below. – მამუკა ჯიბლაძე Nov 21 '17 at 18:53
  • 2
    @IgoRivin We tried implementing the algorithm in C++ here without directly computing T_n(x) https://github.com/dendisuhubdy/Chebyshev-primality-test/blob/master/src/chebyshev-primality-test.cpp. This is really cool! – Dendi Suhubdy Dec 07 '17 at 05:10
  • Generalization of this claim and an attempted proof of it can be found here. – Pedja Jul 06 '19 at 14:58
  • 2
    Since no one has said this explicitly yet: It is easy to see that, if $n$ is prime, then $T_n(x) \equiv x^n \bmod n$. Indeed, $T_n(x)$ is the unique polynomial such that $T_n(u+u^{-1}) = u^n + u^{-n}$ and, if $n$ is prime and we take coefficients modulo $n$, then $x^n$ has this property. – David E Speyer Nov 06 '19 at 16:21
  • 8
    Not that I think I am going to earn the reward, but could you please choose a non-Elsevier journal? Algebra and Number Theory is an open journal whose standards are at least as high. – David E Speyer Nov 06 '19 at 16:26
  • @DavidESpeyer Journal of Number Theory also allows authors to make their individual articles open. – Pedja Nov 07 '19 at 09:35
  • 1
    What was the conclusion on this new test? Did it turn out to be correct/faster/better? – Simd Jun 06 '20 at 04:46

3 Answers3

33

Wow. This deserves a separate answer.

As I mentioned in a comment, motivated by the question, in a previous comment, by Igor Rivin whether an efficient primality test can be made if the statement in the question is true, I asked a separate question about whether one could efficiently compute $T_n(x)$ modulo $x^r-1,n$. That question got a brilliant answer by Lucia, which enables to really demonstrate that if the statement in the question is true, one indeed obtains a very efficient primality test based on it.

I made this quick-and-dirty Mathematica code

polmul[f_, g_, r_, n_] := Mod[f.NestList[RotateRight, g, r - 1], n]

matmul[a_, b_, r_, n_] :=  Mod[
 {{polmul[a[[1, 1]], b[[1, 1]], r, n] + polmul[a[[1, 2]], b[[2, 1]], r, n], 
   polmul[a[[1, 1]], b[[1, 2]], r, n] + polmul[a[[1, 2]], b[[2, 2]], r, n]}, 
  {polmul[a[[2, 1]], b[[1, 1]], r, n] + polmul[a[[2, 2]], b[[2, 1]], r, n], 
   polmul[a[[2, 1]], b[[1, 2]], r, n] + polmul[a[[2, 2]], b[[2, 2]], r, n]}}, n]

matsq[a_, r_, n_] := matmul[a, a, r, n]

matpow[a_, k_, r_, n_] := If[k == 1, a,
 If[EvenQ[k],
  matpow[matsq[a, r, n], k/2, r, n], 
  matmul[a, matpow[matsq[a, r, n], (k - 1)/2, r, n], r, n]
 ]
]

xmat[r_, n_] :=
 {{PadRight[{0, 2}, r], PadRight[{n - 1}, r]},
  {PadRight[{1}, r], ConstantArray[0, r]}}

isprime[n_] := With[{r = smallestr[n]}, 
 If[r == 0, n == 2,
  With[{xp = matpow[xmat[r, n], n - 1, r, n]},
   Mod[RotateRight[xp[[1, 1]]] + xp[[1, 2]], n]
    === PadRight[Append[ConstantArray[0, Mod[n, r]], 1], r]
  ]
 ]
]

where smallestr is as in my other answer.

Running this on $n$ up to 100000 (all answers correct) gives the following timing:

enter image description here

Seems that it is of at worst logarithmic order (as that answer by Lucia suggests) - actually the graph of $\log(\operatorname{time}(n))/\log\log(n)$ looks almost like going to be bounded above:

enter image description here

Since the algorithm involves a recursive procedure for matrix powers, in principle one also has to check memory use. Here I must confess results are strange, maybe it is something hardware-specific. $$ \begin{array}{r|l} \text{amount of memory}&\text{number of cases (out of 100000)}\\ \hline 32&1407\\ 64&94408\\ 80&1\\ 288&1\\ 320&42\\ 352&3\\ 392&8\\ 424&2316\\ 456&1812\\ 3452552&1 \end{array} $$ This last amount 3452552 corresponds to $n=65969$, I have no idea why it needed so much memory. As I said this might be something machine specific - maybe some garbage collection occurred at that point or something like that. Anyway, as opposed to memory measurement timing data seem to be very accurate, I used the Mathematica command AbsoluteTiming and documentation says it gives actual processor time used for the calculation with quite high precision.

  • 3
    That IS amazing, thanks for investigating! – Igor Rivin Nov 21 '17 at 19:39
  • @IgorRivin Pleasure is mine indeed :) – მამუკა ჯიბლაძე Nov 21 '17 at 22:23
  • 1
    Looks like using the FFT method to multiply polynomials, and assuming r = O(log n), the whole algorithm takes O(log^3 n) time (times some polyloglogs, depending on your exact model of computation). – Ryan O'Donnell Nov 22 '17 at 03:24
  • 5
    @RyanO'Donnell Which is the same complexity as in the Agrawal et al. paper. I don't understand what, if anything, was gained by using Čebyšev's polynomials. – Vít Tuček Nov 22 '17 at 13:48
  • 2
    @VítTuček You are right, that one is in fact simpler: have to find $n-1$st power of $x+a$ modulo $x^r-1$ instead of $n-1$st power of a 2$\times$2 matrix. On the other hand, in their case $r$ is larger and one has to test for several $a$s. – მამუკა ჯიბლაძე Nov 23 '17 at 08:13
  • 4
    @მამუკაჯიბლაძე Look at their conjecture in section six -- the one mentioned by the OP. I mean, it's great that this conjecture seems plausible also for $T_n$ and not only for $(x-1)^n$. Maybe it could be worthwhile to to try to find some large class of polynomials with this property. – Vít Tuček Nov 23 '17 at 15:06
  • 1
    @VítTuček Acknowledged - after all this one is also a conjecture (so far). I don't think it will turn out easier to prove than theirs... – მამუკა ჯიბლაძე Nov 23 '17 at 17:44
  • 1
    @მამუკაჯიბლაძე Right. So far we have two families of polynomials. Maybe we can identify more and then try to find out what they have in common which could perhaps give us some information on why such a conjecture might be true. – Vít Tuček Nov 23 '17 at 18:28
  • 1
    @RyanO'Donnell While the algorithm is $\tilde{O}(\log^3 n)$ in the worst case, it is $\tilde{O}(\log^2 n)$ in the average case and in the average prime case, because $r$ may be taken to be $O_{\varepsilon}(1)$ except on a set of density $\varepsilon$ defined by congruence conditions. – Gene S. Kopp Nov 26 '17 at 02:39
  • 1
    https://www.wolframcloud.com/objects/princeps37/Published/Cheby.cdf – Pedja May 18 '19 at 19:02
8

Decided to make a cw answer with an illustration of time growth.

I've tried on Mathematica this:

isprime[n_] := 
 With[{r = smallestr[n]}, 
  If[r == 0, n == 2, 
   PolynomialMod[PolynomialRemainder[ChebyshevT[n, t] - t^n, t^r - 1, t], n] === 0
  ]
 ]

where

smallestr[n_] := Module[{r},
  If[n==1 \[Or] EvenQ[n], Return[0]];
  For[r = 3, MemberQ[{0, 1, r - 1}, Mod[n, r]], r = NextPrime[r + 1],
   If[r < n \[And] Mod[n, r] == 0, Return[0]]
  ];
  r
 ]

I've run it on $n$ up to about 31000 (all answers are correct); here is the graph of time needed as a function of $n$.

enter image description here

Growth looks like faster than polynomial - the graph of $\log(\text{time}(n))/\log(n)$ does not seem to stabilize:

enter image description here

On the other hand a rough upper bound on growth can be deduced from the fact that $\log(\text{time}(n))/(n\log(n))$ seems to go down:

enter image description here

Some additional remarks.

(0)

Datapoints are only for those $n$ which have positive value of smallestr, i. e. such that the corresponding $r$ is smaller than any nontrivial divisor of $n$. Understandably, for other $n$ calculation is qualitatively quicker.

(1)

Finding $r$ is very efficient: $$ \begin{array}{c|c} r&\text{smallest $n$ that requires this $r$}\\ \hline 11&29\\ 13&419\\ 19&1429\\ 23&315589\\ 29&734161\\ 31&1456729 \end{array} $$

(2)

Seems like $n$ is prime iff all coefficients of $T_n(x)-x^n$ are divisible by $n$. If true, this must be well known of course, but I don't know. Should be provable from the explicit form of coefficients of $T_n$.

(2')

Given (2), it is obvious that at prime $n$ the algorithm gives correct answer. To also prove that it detects composite $n$ one has to show the following. Denote by $a_0$, ..., $a_n$ the coefficients of $T_n(x)-x^n$. Then, if some of the $a_i$ is not divisible by $n$, then also one of the sums $s_j:=a_j+a_{j+r}+a_{j+2r}+...$, $j=0,...,r-1$ is not divisible by $n$. Seemingly if $a_j$ is not divisible by $n$ then $j$ is not coprime to $n$; maybe this can help.

  • It is clear that n is prime implies the desired mod n congruence. What results do you get for composite n? In particular, are there any composite n for which the mod n congruence hold and the x^r-1 congruence fails? Gerhard "Bidirectionals Are Not Always Symmetric" Paseman, 2017.11.19. – Gerhard Paseman Nov 20 '17 at 05:41
  • 1
    @GerhardPaseman Experimentally, the mod n congruence holds iff n is prime. I believe it is not difficult to show using explicit expressions for coefficients of $T_n$,$$a_{n-2k}=(-1)^k2^{n-2k}\frac n2\frac{(n-k-1)!}{k!(n-2k)!},$$$k=0,1,...$ (all others zero). – მამუკა ჯიბლაძე Nov 20 '17 at 05:49
  • But you probably wanted to ask the opposite, right? Because if the mod n congruence holds, it will also hold mod x^r-1. The nontrivial fact to prove is that if mod n fails then it will also fail mod x^r-1. – მამუკა ჯიბლაძე Nov 20 '17 at 06:03
  • I probably did mean the opposite. Yes, if n is composite, then both congruences should fail. Gerhard "Doesn't Work With Ideals Ideally" Paseman, 2017.11.19. – Gerhard Paseman Nov 20 '17 at 06:19
7

I do not share excitement about this test and believe it admits false positives (i.e., pseudoprimes). Here are some supporting arguments.

Assuming that $n\equiv 2\text{ or }3\pmod{5}$, we will have $r=5$. A square-free composite integer $n$ will pass the test for $r=5$ if $T_n(x)\equiv x^n\pmod{x^5-1,p}$ for every prime $p\mid n$. At the same time, it can be seen that \begin{split} T_n(x) \equiv x^n\pmod{x^5-1,\ 3}\quad&\Longleftrightarrow\quad n\equiv 3,\ 27,\ 38,\text{ or } 137\pmod{205}\\ T_n(x) \equiv x^n\pmod{x^5-1,\ 7}\quad&\Longleftrightarrow\quad n\equiv 7,\ 343,\ 858,\text{ or } 4797\pmod{6005}\\ T_n(x) \equiv x^n\pmod{x^5-1,\ 13}\quad&\Longleftrightarrow\quad n\equiv 13,\ 2197,\ 14268,\text{ or } 54927\pmod{71405} \end{split} and so on. In general, for a prime $p\equiv 2,3\pmod5$ $$T_n(x) \equiv x^n\pmod{x^5-1,\ p}\quad\Longleftrightarrow\quad n\equiv p,\ p^3,\ p^5,\text{ or } p^7\pmod{5q_p},$$ where $q_p$ is the period of $T_n(x)\pmod{x^5-1,\ p}$. (Similar congruences hold for $r=7$.)

It is not clear why certain $n$ cannot satisfy such congruences modulo every $p\mid n$. I do not say that it is easy to find such $n$, but its existence seems quite plausible.

P.S. Also, notice that in the AKS test the value of $r$ is taken satisfying $r>\log(n)^2$ (in fact, even the order $o_r(n)>\log(n)^2$), and this makes huge difference. Perhaps, the present test can be saved from pseudoprimes as well by requiring $r$ be of the magnitude of $\log(n)$ or so.

UPDATE (2021-10-02). Congruences above have been corrected. Here is a Sage code for computing $q_p$.

Max Alekseyev
  • 30,425