Hi Luis,
Thank you for sharing your formula for possible primes:
p = n^8-1+n^4.
I decided to explore it a bit further :-)
First let’s find a value of integer n that yields a Fermat prime in the 1st 60 primes.
Mathematica will give us the kth prime number with the function Prime[].
We use Table:
Thank you for sharing your formula for possible primes:
p = n^8-1+n^4.
I decided to explore it a bit further :-)
First let’s find a value of integer n that yields a Fermat prime in the 1st 60 primes.
Mathematica will give us the kth prime number with the function Prime[].
We use Table:
In[]:=
FpTable=Table[Solve[-1Prime[k],n,PositiveIntegers],{k,1,60}]
n
2
Out[]=
{{},{{n2}},{},{{n3}},{},{},{},{},{},{},{{n5}},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{{n7}},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}}
or get the same result with Map:
In[]:=
FpTable=Solve[-1Prime[#],n,PositiveIntegers]&/@Range[1,60]
n
2
Out[]=
{{},{{n2}},{},{{n3}},{},{},{},{},{},{},{{n5}},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{{n7}},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}}
Either way, we found that for Format’s formula n 2, 3, 5, and 7 works!
And for the Luis formula:
And for the Luis formula:
In[]:=
LpTable=Table[Solve[-1+Prime[k],n,PositiveIntegers],{k,1,60}]
8
n
4
n
Out[]=
{{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{{n2}},{},{}}
We find n 2 works -- apparently your formula is a bit more sparse than Fermat’s in the lower range.
Now let’s clean the output from the Table.
First of all, those empty solutions are boring.
Here I’m using Map to eliminate them in an If[] statement:
Now let’s clean the output from the Table.
First of all, those empty solutions are boring.
Here I’m using Map to eliminate them in an If[] statement:
In[]:=
FpTable=If[#{},Nothing,#]&/@Table[Solve[-1Prime[k],n,PositiveIntegers],{k,1,60}]
n
2
Out[]=
{{{n2}},{{n3}},{{n5}},{{n7}}}
We’d like to know what k the n belongs to, so I’m inserting k in the Table definition.
See how I enclosed k with Solve using brackets?
But now the solution is in the 2nd part of each Table element, so the test in the If statement was updated to #[[2]].
You can read more about those brackets in the Mathematica documentation for Part.
See how I enclosed k with Solve using brackets?
But now the solution is in the 2nd part of each Table element, so the test in the If statement was updated to #[[2]].
You can read more about those brackets in the Mathematica documentation for Part.
In[]:=
FpTable=If[#[[2]]{},Nothing,#]&/@Table[{k,Solve[-1Prime[k],n,PositiveIntegers]},{k,1,60}]
n
2
Out[]=
{{2,{{n2}}},{4,{{n3}}},{11,{{n5}}},{31,{{n7}}}}
Well that’s better, but notice how Solve[] outputs solutions in a List; e.g. {{n2}} ?
We know that both the Luis and the Fermat formula are increasing, so let’s restrict to the first solution.
See how I was very specific about what I wanted at the end of the If statement?
We know that both the Luis and the Fermat formula are increasing, so let’s restrict to the first solution.
See how I was very specific about what I wanted at the end of the If statement?
In[]:=
FpTable=If[#[[2]]{},Nothing,{#[[1]],#[[2,1,1]]}]&/@Table[{k,Solve[-1Prime[k],n,PositiveIntegers]},{k,1,60}]
n
2
Out[]=
{{2,n2},{4,n3},{11,n5},{31,n7}}
and for the Luis formula:
In[]:=
LpTable=If[#[[2]]{},Nothing,{#[[1]],#[[2,1,1]]}]&/@Table[{k,Solve[-1+Prime[k],n,PositiveIntegers]},{k,1,60}]
8
n
4
n
Out[]=
{{58,n2}}
Well, the 1st 60 primes is interesting, but how about the 1st 10000?
Let’s time it.
Let’s time it.
In[]:=
time1=AbsoluteTime[];LpTable1000=If[#[[2]]{},Nothing,{#[[1]],#[[2,1,1]]}]&/@Table[{k,Solve[-1+Prime[k],n,PositiveIntegers]},{k,1,10000}];time2=AbsoluteTime[];Print[];Print["elapsed time = ",(time2-time1)/60.," minutes"];Print["LpTable = ",LpTable];
8
n
4
n
elapsed time = 0.34039 minutes
LpTable = {{58,n2}}
Whew!
Whew!