-1

I was playing around with numbers the other day and realized that the first few values for $n(n - 1) + 1$ are prime. Now, I also quickly realized that not all values are prime ($n = 5$ results in 21, which is not prime), but I also noticed that all of the values for which the formula doesn't result in a prime are odd. I wrote up a quick python script, and since checking $n < 100,000,000$ hasn't provided an even counterexample, I was wondering if I could somehow prove or disprove the hypothesis that, for all even $n$, $n^2 - n + 1$ is prime.

I am aware of Goldbach's proof (mention of it) that for any polynomial, not all of its outputs can be prime, but I don't think that applies if the input is restricted to to just even integers.

Python 3.6.7 code I used:

from math import sqrt
from itertools import count, islice

n=0
m=100000000
q=0
p=1
j=0

for n in islice(count(1), m):
    if (n % 2):
        p = 0
    else:
        q = n * (n - 1) + 1
        p = n > 1 and all(n % j for j in islice(count(2), int(sqrt(n) + 1)))
    if (p): print(n, p)

Link to source of method of checking primality.

IronEagle
  • 272
  • 1
    $n=10?{{{{}}}}$ – Angina Seng May 13 '19 at 20:37
  • 1
    Goldbach's proof applies to $f(2n)$ too. – Bill Dubuque May 13 '19 at 20:40
  • 1
    Or $n=8$. $\quad $ – lulu May 13 '19 at 20:40
  • 1
    checking wether an integer is prime by using float point arithmetic is a bit risky – Adren May 13 '19 at 20:40
  • 2
    If $p(n)$ is a polynomial with prime values at all the even integers then $q(n)=p(2n)$ is prime for all integers. – lulu May 13 '19 at 20:42
  • $8^2-8+1=57=3\times19$ – Adren May 13 '19 at 20:42
  • It is known that none polynomial can give only primesand you r example is $x^2-x+1$ – Piquito May 13 '19 at 20:45
  • 1
    @Piquito No it's not that $f(x).,$ Rather it is $f(2x),$ as I remarked above. – Bill Dubuque May 13 '19 at 20:48
  • If $p$ is a polynomial and $|p(a)|>2$, then $p(a+kp(a))\equiv p(a)\equiv0\pmod(p(a))$, for all $k$. Since polynomials only have finitely many roots $p(a+kp(a))$ cannot be always equal to $\pm p(a)$. So, for infinitely many $k$ it is going to be a non-trivial factor of $p(a)$. – logarithm May 13 '19 at 20:50
  • Something is wrong with your code if $n=6k+2$ then $n^2-n+1=$ $(6k+2)^2-(6k+2)+1=$ $36k^2+24k+4-6k-2+1=$ $36k^2+18k+3=$ $3(12k^2+6k+1)$

    So if $n$ is of the form $6k+2$, then $n^2-n+1$ is divisible by three.

    – quantus14 May 13 '19 at 20:53
  • 1
    If $p(n)$ is your polynomial, then $q(n)=p(2n)$ is another polynomial, and Goldbach shows that $q(n)$ cannot always be prime. – Thomas Andrews May 13 '19 at 21:02
  • Thanks for all the comments, I wondered if something was wrong. Thanks also for explaining that $q(n)=p(2n)$, and thus Goldbach's proof still applies. – IronEagle May 14 '19 at 14:43
  • @Adren it would appear that that was my mistake. – IronEagle May 14 '19 at 14:44
  • +1. No idea why it was at -2. It's still a great question. I also noticed you followed my Materials Modeling proposal. We are now in the commitment stage and it would be very very helpful if you could click commit! https://area51.stackexchange.com/proposals/122958/materials-modeling?referrer=MGFkOGRlMTg1ODg2NTUxZDQ1MDVjZmQyOTg1ZDcxODQzMjc0OGIyMjBhZDM4ZDQ5MzM0MWE1YzZhNDBjMzhlYfHJBfp5EvPDPybryqjeDgXYucHU-wUv4jp4j6imjIfF0 Only 2.7% of the people fulfill commitment on new proposals anyway so it doesn't matter if you can't participate much, but it would be very very helpful if you can commit! – Nike Dattani Mar 13 '20 at 09:26

1 Answers1

2

This is not true. A simple search in Python gives counterexamples of $$n=8, 10, 12, 14, 20, 24, 26, 30, 32, 36, 38, 40, 44, 46, 48, 50, 52, 54, 56, 62, 64, 66, 68,\dots$$ which have corresponding composite values of $$n^2-n+1=3\cdot19, 7\cdot13, 7\cdot19, 3\cdot61, 3\cdot127, 7\cdot79, 3\cdot7\cdot31, 13\cdot67, 3\cdot331, 13\cdot97, \dots$$

Here is the code I used by the way:

#Returns a list of all primes less than or equal to Max
def ListPrimes(Max):
    if Max <= 1:
        return []
    Primes = [True for i in range(Max+1)] 

    for PrimeIndex in range(2, Max+1): 
        if (Primes[PrimeIndex] == True):
            Primes[PrimeIndex]=PrimeIndex
            PrimeIndex2 = PrimeIndex * 2
            while(PrimeIndex2 <= Max): 
                Primes[PrimeIndex2] = False
                PrimeIndex2 += PrimeIndex
    return [p for p in Primes if p!= False][2:]

print([i for i in range(2,100,2) if not ((i*i-i+1) in ListPrimes(10000))])
Peter Foreman
  • 19,947