Primality of
n
∑
k=1
1+k
(-1)
k!
​​by Vitaliy Kaurov
In a thought-provoking LinkedIn group called Fermat’s Library I saw a post about primality of the following expression
In[]:=
Inactivate[Sum[
1+k
(-1)
k!,{k,1,n}],Sum]​​%//TeXForm
Out[]=
n
∑
k=1
1+k
(-1)
k!
Out[]//TeXForm=
\underset{k=1}{\overset{n}{\sum }}(-1)^{k+1} k!
But surprisingly they counted only up to 15. So lets generalize. Define a function
In[]:=
f[n_]:=Sum[
1+k
(-1)
k!,{k,1,n}];
After automatic symbolic simplification the closed form is expressed in special function and no explicit summation is required
In[]:=
f[n]//TraditionalForm
Out[]//TraditionalForm=
(-
n
(-1)
)
E
n+2
(1)Γ(n+2)+Ei(-1)+1
◼
  • E
    n+2
    (1)
    - exponential integral function
  • ◼
  • Ei(-1) - exponential integral function
  • ◼
  • Γ(n+2) - Euler gamma function
  • Out of first 1000 n
    In[]:=
    data=ParallelTable[{n,PrimeQ[#],#}&@f[n],{n,1,1000}];
    the following result into prime f[n]
    In[]:=
    Select[data,#[[2]]==True&][[All,1]]
    Out[]=
    {3,4,5,6,7,8,10,15,19,41,59,61,105,160,661}
    This is an OEIS number. Here is the table for all up to the n=41 (the two next ones after n=15):
    In[]:=
    TableForm[data[[;;41]],​​TableHeadings{None,{"n","Prime Test","f[n]"}}]
    Out[]//TableForm=
    n
    Prime Test
    f[n]
    1
    False
    1
    2
    False
    -1
    3
    True
    5
    4
    True
    -19
    5
    True
    101
    6
    True
    -619
    7
    True
    4421
    8
    True
    -35899
    9
    False
    326981
    10
    True
    -3301819
    11
    False
    36614981
    12
    False
    -442386619
    13
    False
    5784634181
    14
    False
    -81393657019
    15
    True
    1226280710981
    16
    False
    -19696509177019
    17
    False
    335990918918981
    18
    False
    -6066382786809019
    19
    True
    115578717622022981
    20
    False
    -2317323290554617019
    21
    False
    48773618881154822981
    22
    False
    -1075227108896452857019
    23
    False
    24776789629988523782981
    24
    False
    -595671612103250915577019
    25
    False
    14915538431227735068422981
    26
    False
    -388375922695377900515577019
    27
    False
    10500493527722974260252422981
    28
    False
    -294387851083990886241251577019
    29
    False
    8547374142655711068302364422981
    30
    False
    -256705485669535347568006115577019
    31
    False
    7966133168508387470157556764422981
    32
    False
    -255164703765185142697060455395577019
    33
    False
    8428152915046701352821133945884422981
    34
    False
    -286804646124557439494797475697635577019
    35
    False
    10046343320261587490171853861825564422981
    36
    False
    -361946983469639629977827594289009635577019
    37
    False
    13401806107756705416338151987291892764422981
    38
    False
    -509620811358844406343669072112782398435577019
    39
    False
    19888261269838598952296612667790114958364422981
    40
    False
    -796027021978059135393314656928325779313635577019
    41
    True
    32656499591185747972776747396512425885838364422981