/*************************************************************************
   11-06-01.m -- code to check whether a certain modular symbol is old.

   William Stein, November, 2001
 *************************************************************************/

intrinsic JE(p::RngIntElt, ell::RngIntElt) -> BoolElt, ModSymElt
{True if and only if the modular symbol
(1+w_p)(1-w_2)\{-1/4,1/4\} in S_2(Gamma_0(2*p^2);GF(ell)) 
is not old.  Use ell = 0 to do the computation in characteristic 0.}
   require ell eq 0 or ell ge 389 : 
        "Using a small prime for argument 2 is a bad idea.";
   t := Cputime();
   N  := 2*p^2;
   printf "Creating space of modular symbols of level %o mod %o.\n", N,ell;
   /* I'm just computing in the -1 quotient by complex conjugation, since
      it suffices to check your condition for the -1 and +1 quotients,
      and I tried a bunch of examples of +1 quotients and your symbol
      is always 0 there.  You should prove its image in the +1 quotient
      is 0.  I always assume below that your symbol is cuspidal.
   */
   if ell eq 0 then
      K := RationalField();
   else
      K := GF(ell);
   end if;
   time M  := ModularSymbols(N, 2, K, -1);
   time S  := CuspidalSubspace(M);

   if DimensionCuspFormsGamma0(N,2) ne Dimension(S) then
      print "WARNING: Dimensions are off because of spurious torsion -- quiting!";
      return "NONSENSE";
   end if;

   print "Computing Wp";
   time Wp := AtkinLehner(M,p);
   print "Computing W2";
   time W2 := AtkinLehner(M,2);
   print "Computing x = {-1/4,1/4}(1-w_2)(1+w_p).";
   x  := (S!<1,[-1/4,1/4]> * (1-W2))*(1+Wp);
   print "x = ", x;
   assert x in S;

   print "Computing old subspace (this takes the most time, by far)";
   time Old := OldSubspace(S);

   print "Dimension of old subspace = ", Dimension(Old);
   print "Dimension of new subspace = ", Dimension(S) - Dimension(Old);
   print "Total time = ", Cputime(t), " seconds";
   return not (x in Old), x;
end intrinsic;
