(* Notebook to demonstrate the use of the explicit formula to show the nonexistence
of elliptic curves with very small conductor.  David Farmer & Sally Koutsoliotas *)

(* define the digamma function *)

DiGamR[xx_]:=DiGamR[xx]=N[PolyGamma[xx/2],20]/2-Log[Pi]/2 (* $\Gamma_R'/\Gamma_R(xx) *)

(* now we set up the terms on the right side of (3-1) in Booker's paper *)

digamterm[Aa_,mulis_,eps_,ILim_]:=(1/Pi) Re[Sum[
eps Sum[DiGamR[1/2+mulis[[j]]+I y]h[Aa,y],{y,-ILim+eps/2,ILim,eps}],{j,1,Length[mulis]}]]
(* the spectral term, where we evaluate the integral as a Riemann sum of stepsize eps, summed from -ILim to ILim.  Try eps=1/5 and ILim =500 to get a few decimal places of accuracy *)

(* Note: for an elliptic curve L-function, the list of spectral parameters is {1/2, 3/2} *)

coeffterm[Aa_,Sumlim_]:=-2 Sum[c[n]g[Aa,Log[n]]/Sqrt[n],{n,2,Sumlim}]
(* the coefficient sum, where the upper limit is Sumlim. *)

(* we will test with functions of the form g[A,x] = g[A x], where we will decide later
which function g[] to use.  *)

g[Aa_,t_]:=g[Aa t]

h[Aa_,t_]:=h[t/Aa]/Aa

(* Here are three possibilities: g0, g1, and g2. *)

g0[t_]:=With[{Nt=Abs[N[t,20]]},If[Nt>1,0,1-Nt]]

h0[t_]:=(Sin[t/2]/(t/2))^2

g1[t_]:=With[{Nt=Abs[N[t,20]]},If[Nt>2,0,
If[Nt>1,4/3-2Nt+Nt^2-1/6 Nt^3,2/3-Nt^2+1/2 Nt^3]]]

h1[t_]:=(Sin[t/2]/(t/2))^4

g2[t_]:=E^(-t^2)

h2[t_]:=E^(-t^2/4) Sqrt[Pi]

(* we first try g[] = g0.  We are NOT claiming this is a legitimate choice! *)

g[t_]:=g0[t]

h[t_]:=h0[t]

(* Let's try computing the two main terms on the RHS with g=g0 and A=1. *)

digamterm[1,{1/2,3/2},1/5,500]

coeffterm[1,100]

%%+%

(* since c[2] is between +/- 2 Log[2], the worst case is c[2]=-2 Log[2] *)

%/.c[2]->-2 Log[2]

(* So, if g[0]Log[N] < 1.769917, then the RHS is negative, and so the L-function doesn't exist. *)

E^(g[1,0]*1.769917)

(* Assuming we are using a legitimate test function, we have just proven that the
level/conductor is at least 6. *)

(* now we make one function that assembles the whole RHS *)

rhs[Aa_,lev_]:=g[Aa,0]Log[lev]+digamterm[Aa,{1/2,3/2},1/10,200]+
coeffterm[Aa,20]

rhs[1,5]

%/.c[2]->-2 Log[2]

(* again we see that there is nothing of level 5 *)

(* Since we may encounter Dirichlet coefficients, we make more general substitutions for the Ramanujan bound. *)

ramabound[lim_]:=Table[c[n]->If[fi=FactorInteger[n];Length[fi]==1,-2 Log[fi[[1,1]]],0],{n,2,lim}]

ramabound[10]

rhs[0.8,6]

rhs[0.8,6]/.ramabound[30]

(* This failed to eliminate N=6, so let's try a different test function. *)

g[t_]:=g2[t]

h[t_]:=h2[t]

rhs[1.9,7]

rhs[1.9,7]/.ramabound[20]

(* So, with that choice of test function and A = 1.9, we eliminated N=7. *)