intrinsic DensityWithCharpoly(E::CrvEll, p::RngIntElt,
                  f::RngUPolElt, ell_max::RngIntElt) -> FldRatElt 
{The density of primes ell <= ell_max such that the charpoly
of Frob_ell on E[p] is f.}

   R := PolynomialRing(GF(p));
   f := R!f;
   a := -Coefficient(f,1);
   det := Coefficient(f,0);
   i := 0;
   j := 0;
   ell := 2;
   for a_ell in TracesOfFrobenius(E,ell_max) do
      if a_ell eq a and (ell mod p) eq det then
         i := i + 1;
      end if;
      ell := NextPrime(ell);
      j := j+1;
   end for;
   return i/j;
end intrinsic;

intrinsic DensityIfSurjective(p::RngIntElt, f::RngUPolElt) 
  -> FldRatElt
{The density of elements z in GL(2,GF(p)) such that the
characteristic polynomial of z is f.}

   R := PolynomialRing(GF(p));
   f := R!f;
   G := GL(2,p);
   a := [z : z in G | CharacteristicPolynomial(z) eq f];
   return #a / #G;

end intrinsic;