(*
	(c) 2011 Alex Kontorovich
*)

(* Size of pics *)
NN=30;

(* Psi = Sum of von Mangoldt *)
psi[x_]:=Sum[MangoldtLambda[n],{n,1,Floor[x]}];

ran={{0,NN},{-.5,NN}};  (* plot range *)
(* Plot Psi *)
vonM=Plot[psi[x],{x,0,NN},PlotStyle->{Thick,Red},PlotRange->ran]

(* Plot Psi vs Exact Formula, using num zeroes*)
numZerosPic[num_]:=Module[{j,zs,pic},
zs=Table[N[ZetaZero[j]],{j,1,num}];
pic=Show[vonM,Plot[Re[X-Log[2Pi]-Log[1-1/X^2]/2-Total[X^(zs) / (zs)+ X^(1 - zs)/(1-  zs)]],{X,1.1,NN},PlotStyle->Thick,PlotRange->ran]
];
pic
];

numZerosPic[0]

numZerosPic[60]

(* Plot just the fundamental freq *)
Plot[Re[X-Log[2Pi]-Log[1-1/X^2]/2],{X,1.1,NN},PlotStyle->Thick,PlotRange->ran]

(* Plot num-th harmonic *)
ranR={{0,NN},{-1,1}};
HarmPic[num_]:=Module[{zs,pic},
zs=ZetaZero[num];
pic=Plot[Re[-X^(zs) / (zs)- X^(1 - zs)/(1-  zs)],{X,1.1,NN},PlotStyle->Thick, PlotRange->ranR
];
pic
];

HarmPic[1]

HarmPic[60]

(* Add a random harmonic on the line *)
randZ=1/2+20I;
Plot[Re[-X^(zss) / (zss)- X^(1 - zss)/(1-  zss)]/.zss->randZ,{X,1.1,NN},PlotStyle->Thick, PlotRange->ranR
]

zs=Table[N[ZetaZero[j]],{j,1,60}];
pic=Show[vonM,Plot[Re[X-Log[2Pi]-Log[1-1/X^2]/2-Total[X^(zs) / (zs)+ X^(1 - zs)/(1-  zs)]]
+
Re[-X^(zss) / (zss)- X^(1 - zss)/(1-  zss)]/.zss->randZ,{X,1.1,NN},PlotStyle->Thick,PlotRange->ran]
]

(* Add a random harmonic OFF the line *)
randZ1=.7+20I;
randZ2=.7-20I;
Plot[
(
Re[((-X^(zss) / (zss)- X^(1 - zss)/(1-  zss))/.zss->randZ1)
+
((-X^(zss) / (zss)- X^(1 - zss)/(1-  zss))/.zss->randZ2)]
)
,{X,1.1,NN},PlotStyle->Thick, PlotRange->ranR
]

zs=Table[N[ZetaZero[j]],{j,1,60}];
pic=Show[vonM,Plot[Re[X-Log[2Pi]-Log[1-1/X^2]/2-Total[X^(zs) / (zs)+ X^(1 - zs)/(1-  zs)]]
-
(
Re[-X^(zss) / (zss)- X^(1 - zss)/(1-  zss)]/.zss->randZ1
+
Re[-X^(zss) / (zss)- X^(1 - zss)/(1-  zss)]/.zss->randZ2
)
,{X,1.1,NN},PlotStyle->Thick,PlotRange->ran]
]