Prime Sums

Author

Eric W. Weisstein
August 22, 2021

This notebook downloaded from http://mathworld.wolfram.com/notebooks/PrimeNumbers/PrimeSums.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/PrimeSums.html.

©2021 Wolfram Research, Inc. except for portions noted otherwise

Sigma

<<Utilities`Plot`
<<Utilities`Typesetting`

PrimeSums[n_]:=Rest[FoldList[Plus,0,Prime[Range[n]]]]

PrimeSums[10]

{l=Flatten[Position[p=PrimeSums[100],_?PrimeQ]],p[[l]]}

Plot

Show[Block[{$DisplayFunction=Identity},
{
Plot[(1/2)(n^2)Log[n],{n,1,75},PlotStyle->Blue],
IntegerListPlot[PrimeSum[75],AxesLabel->TraditionalForm/@{Σ[n],n}]
}
],
AxesLabel->TraditionalForm/@{n,
{
StyleForm[Σ[n],FontColor->Red],
StyleForm[(1/2)(n^2)Log[n],FontColor->Blue]
}
}
]

ListPlot[PrimeSum[1000],PlotJoined->True,PlotStyle->Red,
Ticks->{Automatic,Table[{n 10^6,ScientificForm[n 10.^6]},{n,4}]},AxesLabel->TraditionalForm/@{Σ[n],n}]

ListPlot[MapIndexed[#1-#2[[1]]^2 Log[#2[[1]]]/2&,PrimeSum[100]],PlotJoined->True,PlotStyle->Red]

(∑_(n=1)^∞)(1/((Subscript[p, n])^k)) for odd numbers of prime divisors

Odd

OddPrimesQ[n_]:=Module[{f=Last/@FactorInteger[n]},
OddQ[Plus@@f]
]

Take[odd=Select[Range[10^5],OddPrimesQ],50]//Timing

Table[Plus@@(SetPrecision[1,20]/#^(2n)&/@odd),{n,6}]//Timing

Table[(Zeta[2p]^2-Zeta[4p])/(2Zeta[2p]),{p,6}]//Simplify

N[%,10]

even=Table[(Zeta[2p]^2-Zeta[4p])/(2Zeta[2p])/Pi^(2p),{p,6}]//Simplify

Through[{Numerator,Denominator}[even]]

Odd and Distinct

OddAndDistinctQ[n_]:=Module[{f=Last/@FactorInteger[n]},
Max[f]==1&&OddQ[Plus@@f]
]

a=Select[Range[100],OddAndDistinctQ]

Select[Range[220],OddAndDistinctQ[#]&&!PrimeQ[#]&]

2 3 5 7 11

Complement[Select[Range[100],OddAndDistinctQ],b]

even=Table[(Zeta[2p]^2-Zeta[4p])/(2Zeta[2p]Zeta[4p]),{p,6}]

even=Table[(Zeta[2p]^2-Zeta[4p])/(2Zeta[2p]Zeta[4p])Pi^(2p),{p,6}]

Through[{Numerator,Denominator}[even]]

N[%]

Table[PrimeZeta[2p,10^5],{p,6}]

Plot[{PrimeZeta[p],(Zeta[p]^2-Zeta[2p])/(2Zeta[p]Zeta[2p])},{p,1,6},PlotStyle->{Red,Blue},PlotRange->{0,4}]

<<Utilities`Typesetting`
<<Utilities`Plot`

ComplexPlot3D[(Zeta[2p]^2-Zeta[4p])/(2Zeta[2p]Zeta[4p]),{p,-5,5},ComplexPlotLabel->HoldForm[(Subscript[P, even])[z]],PlotPoints->100]//Timing

ComplexPlot3D[(Zeta[2p]^2-Zeta[4p])/(2Zeta[2p]Zeta[4p]),{p,-10,10},ComplexPlotLabel->HoldForm[(Subscript[P, even])[z]],PlotPoints->100]//Timing

ComplexPlot3D[(Zeta[2p]^2-Zeta[4p])/(2Zeta[2p]Zeta[4p]),{p,-10,10},ComplexPlotLabel->HoldForm[(Subscript[P, even])[z]],PlotPoints->150]//Timing

ComplexContourPlot[(Zeta[2p]^2-Zeta[4p])/(2Zeta[2p]Zeta[4p]),{p,-10,10},ComplexPlotLabel->HoldForm[(Subscript[P, even])[z]]]//Timing

Sums

(∑_(n=1)^∞)(1/(Subscript[p, n]))==∞

V5

Sum[1/n,{n,∞}]

Sum[1/Prime[n],{n,∞}]

V7

Sum[1/n,{n,∞}]

Sum[1/Prime[n],{n,∞}]

(∑_(n=1)^∞)(1/(Subscript[p, n]^k))==(PrimeZetaP[k])

V7

Sum[1/Prime[n]^s,{n,∞}]

Sum[((Prime[n])^(-s)),{n,∞}]

Sum[(1/Prime[n])^s,{n,∞}]//Timing

(∑_(n=1)^∞)((((-1))^n)/(Subscript[p, n]))==-0.2696

V5

Sum[(-1)^n/Prime[n],{n,∞}]

NSum[(-1)^n/Prime[n],{n,∞}]

NSum[(-1)^n/Prime[Round[n]],{n,∞},WorkingPrecision->1000]

ps=N[Prime/@Range[10^6]];//Timing

Table[Timing[(-1)^k,{k,#}].(1/Take[ps,#])]&/@{10^4,10^5,10^6}//ColumnForm

V7

Sum[(-1)^n/Prime[n],{n,∞}]

NSum[(-1)^n/Prime[n],{n,∞}]

(∑_k^∞)(((((-1))^k) k)/(Prime[k]))==?

Sum[(((-1))^k)(k/(Prime[k])),{k,∞}]

SumConvergence[(((-1))^k)(k/(Prime[k])),k]

(∑_(n=2)^∞)(((Piecewise[{{-1, (Mod[(Prime[n]), 4])==1}, {1, True}}]))/(Prime[n]))==0.33

Sum[((If[Mod[Prime[n],4]==1,-1,1])/(Prime[n])),{n,2,∞}]//Timing

Total[Table[((If[Mod[Prime[n],4]==1,-1,1])/(Prime[n])),{n,2,10^6}]//N]

(∑_(n=2)^∞)(((Piecewise[{{-1, (Mod[(Prime[n]), 4])==1}, {1, True}}]))/((((Prime[n])))^2))==0.094

PiecewiseExpand[If[Mod[Prime[n],4]==1,-1,1]]

Sum[((If[Mod[Prime[n],4]==1,-1,1])/((Prime[n])^2)),{n,2,∞}]//Timing

Total[Table[((If[Mod[Prime[n],4]==1,-1,1])/((Prime[n])^2)),{n,2,10^6}]//N]

(∑_n^∞)(((Piecewise[{{-1, (Mod[(Prime[n]), 3])==1}, {1, (Mod[(Prime[n]), 3])==2}}]))/(Prime[n]))==0.641935

PiecewiseExpand[Switch[Mod[Prime[n],3],1,-1,2,1,0,0]]

Sum[((Switch[Mod[Prime[n],3],1,-1,2,1,0,0])/(Prime[n])),{n,∞}]//Timing

Total[Table[((Switch[Mod[Prime[n],3],1,-1,2,1,0,0])/(Prime[n])),{n,10^6}]//N]

(∑_(k=1)^(p-1))(Floor[((k^3)/p)])==(1/4) (p-2) (p-1) (p+1)

A078837; Doster 1993

Sum[Floor[((k^3)/(Prime[n]))],{k,Prime[n]-1}]//Timing

Table[Sum[Floor[((k^3)/(Prime[n]))],{k,Prime[n]-1}],{n,20}]

Table[(((Prime[n]-2)(Prime[n]-1)(Prime[n]+1))/4),{n,20}]

Table[Times@@(Prime[n]-{2,1,-1})/4,{n,20}]

(∑_(i,j=1)^(p-1))(Floor[((i j)/p)])== (((((p-1))^3)-(((p-1))^2))/4) ==(1/4) (p-2)(((p-1))^2)

A331764; Babois 2020

Table[(((((Prime[n]-1))^3)-(((Prime[n]-1))^2))/4),{n,20}]

Factor[(k-1)^3-(k-1)^2]

Table[(((Prime[n]-2)(((Prime[n]-1))^2))/4),{n,20}]

Table[((Times@@(Prime[n]-{1,1,2}))/4),{n,20}]

Table[Sum[Floor[((i j)/(Prime[n]))],{i,Prime[n]-1},{j,Prime[n]-1}],{n,20}]

(∑_(k=1)^((p-1) (p-2)))(Floor[((k p)^(1/3))])==(1/4) (3 p-5) (p-2) (p-1)

sum[p_]:=Module[{k},
Plus@@Table[Floor[(k p)^(1/3)],{k,(p-1)(p-2)}]]

sum/@Prime[Range[20]]

Function[{p},sum[p]-(3p-5)(p-2)(p-1)/4]/@Table[Prime[n],{n,20}]

V7

Sum[Floor[(k p)^(1/3)],{k,(p-1)(p-2)}]

(∑_k^∞)(1/((((Prime[k])-1))^2))==1.37

Sum[(1/(((Prime[k]-1))^2)),{k,∞}]

NSum[(1/(((Prime[k]-1))^2)),{k,∞}]

Total[Table[((Phi[2,k]-EulerPhi[k])/k)Log[Zeta[k]],{k,2,10^3}]//N]

Phi[l_,k_]:=(k^l)Times@@((1-1/#^l)&/@FactorInteger[k][[All,1]])

(∑_k^∞)(((-1))^(k-1)) log(k) exp(-k x)==Derivative[1,0][PolyLog](0,-(e^(-x)))

Sum[(((-1))^(k-1))Exp[-k x]Log[k],{k,∞}]

FullSimplify[%]

(∑_(k=1)^∞)(x^k) log(k)==(∑_(k=1)^∞)(((MangoldtLambda[k]) (x^k))/(1-(x^k)))==-Derivative[1,0][PolyLog](0,x)

With[{x=.1},Sum[Log[n]x^n,{n,100}]]

TimeConstrained[Sum[Log[n]x^n,{n,∞}],300]//Timing

With[{x=.1},Sum[(Log[Prime[p]]x^(Prime[p]^k))/(1-x^(Prime[p]^k)),{k,5},{p,5}]]

With[{x=.1},Sum[((MangoldtLambda[k](x^k))/(1-(x^k))),{k,20}]]

TimeConstrained[Sum[((MangoldtLambda[k](x^k))/(1-(x^k))),{k,∞}],300]//Timing

Meissel-Mertens Constants

Limit[Sum[1/Prime[k],{k,PrimePi[n]}]-Log[Log[n]],n->∞]

N[Sum[1/Prime[k],{k,PrimePi[n]}]-Log[Log[n]]/.n->100000]

EulerGamma+Plus@@Table[Log[1.-#]+#&[1/Prime[k]],{k,10000}]

Sums of 2 or more consecutive primes

Code from Dan

knapsackPrimeSolve2[n_,nprimesmax_]:=Module[{solutions,avg,mm,j1,j2,primes},solutions=Table[avg=NextPrime[Floor[n/j]];
mm=avg-2;
j1=Ceiling[j/2]+k;
j2=j-j1-1;
primes={avg};
While[mm≥3&&j1>0,If[PrimeQ[mm],primes={mm,primes};j1--];
mm-=2;];
If[mm==1&&j1≠0,primes={2,primes}];
mm=avg+2;
While[mm<n&&j2>0,If[PrimeQ[mm],primes={mm,primes};j2--];
mm+=2;];
primes=Flatten[primes];
If[Apply[Plus,primes]===n&&Length[primes]==j,primes,Null],{j,2,nprimesmax},{k,-3,3}];
solutions=Select[Flatten[solutions,1],#=!=Null&];
Union[Map[Sort,solutions]]]

knapsackPrimeSolve2[70,4000]//Length//Timing

With[{n=36},Reduce`NaturalLinearSolve[{Prime/@Range[PrimePi[n]-1]},{n},True][[1]]
]//Length//Timing

With[{n=70},Reduce`NaturalLinearSolve[{Prime/@Range[PrimePi[n]-1]},{n},True][[1]]
]//Length//Timing

With[{n=75},Reduce`NaturalLinearSolve[{Prime/@Range[PrimePi[n]-1]},{n},True][[1]]
]//Length//Timing

ConsPrime[n_?PrimeQ]:=0
ConsPrime[n_]:=Select[Reduce`NaturalLinearSolve[{Prime/@Range[PrimePi[n]-1]},{n},True][[1]],Max[#]==1&&MatchQ[#,{0 ...,1,1 ..,0 ...}]&]

reps=Join[{{},{},{},{}},Table[ConsPrime[n],{n,5,75}]];//Timing

Take[reps,10]

Length/@reps

{#,reps[[#]],# Prime/@Range[Length[#]]&/@reps[[#]]}&/@Flatten[Position[Length/@reps,2]]

<=

A050936

Position[Length/@reps,_?(#≥1&)]//Flatten

A067372

Position[Length/@reps,_?(#≥2&)]//Flatten

A067373

=

Position[Length/@reps,1]//Flatten

A067372

Position[Length/@reps,2]//Flatten

Sums of one or more consecutive primes

ConsPrime[n_]:=Select[Reduce`NaturalLinearSolve[{Prime/@Range[PrimePi[n]]},{n},True][[1]],Max[#]==1&&MatchQ[#,{0 ...,1 ..,0 ...}]&]

reps=Join[{{},{{1}},{{0,1}}},Table[ConsPrime[n],{n,4,70}]];//Timing

l=Length/@reps

seq=MapIndexed[#1/Sequence@@#2&,FoldList[Plus,0,l]]//N

Log[2.]

<<Plot`

MakeBoxes[yaxis,TraditionalForm]:=RowBox[{FractionBox["1","n"],RowBox[{UnderoverscriptBox["∑",RowBox[{"k","=","1"}],"n"],RowBox[{"g","(","k",")"}]}]}]

IntegerListPlot[seq,Epilog->{Blue,Line[{{0,#},{Length[l],#}}]&[Log[2]]},PlotRange->{Automatic,{0,.75}},AxesLabel->TraditionalForm/@{x,yaxis}]