Chebyshev Bias

Author

Eric W. Weisstein
April 12, 2011

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

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

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

By 3

a3=Accumulate[If[Mod[#,3]==1,-1,1]&/@Prime[Range[10^5]]];//Timing

g1=ListPlot[Take[a3,10^4],AxesLabel->{n,Subscript[Pi,Row[{3,",",2}]][Prime[n]]-Subscript[Pi,Row[{3,",",1}]][Prime[n]]},Joined->True,PlotStyle->Red]

Old code

1+Position[Rest[FoldList[Plus,0,Mod[Prime[Range[2,10^5]],4]/. 3->-1]],0]//Flatten//Timing

By 4

Must take p==2 into account:

a4=Prepend[Accumulate[If[Mod[#,4]==1,-1,1]&/@Prime[Range[2,10^5]]],0];//Timing

g2=ListPlot[Take[a4,10^4],AxesLabel->{n,Subscript[Pi,Row[{4,",",3}]][Prime[n]]-Subscript[Pi,Row[{4,",",1}]][Prime[n]]},Joined->True,PlotStyle->Red]

https://oeis.org/A096628

Position[a4,_?Negative]//Flatten

Position[a4,0]//Flatten

Position[a4,_?Positive]//Flatten

Old code

1+Position[Rest[FoldList[Plus,0,Mod[Prime[Range[2,10^5]],4]/. 3->-1]],_?Positive]//Flatten//Timing

Combined Plot

GraphicsRow[{g2,g1},Spacings->-30,ImageSize->400]