/* Question.

-------------

Find a normalized eigenform

          f = sum a_n q^n in S_2(Gamma_1(3^n*331))

such that E_f = Q(... a_n ...) = Q(sqrt(-2)).

-------------


1. Enumerate all quadratic characters of level 3^n*331. 
   There is no need to mod out by conjugacy, because
   conjugation acts trivially. 

2. Compute charpolys using fast Buzzard algorithm and look for one
   with a quadratic factor f(x) such that Q[x]/f(x) is isomorphic
   to Q(sqrt(-2)).

*/

procedure analyze(eps)
   time M:=MS(eps,2,+1);
   if Dimension(M) eq 0 then
      print "Skipping:\n", M;
      return;
   end if;
   print "Analyzing:\n", M; 
   for p in [11,13,17,19] do
      print "p:", p;
      time T := HeckeOperator(M,p);
      time f := CharacteristicPolynomialDeligne(T,2,p);
      time F := factor(f);
      print F;
      for fac in F do
         if Degree(fac[1]) eq 1 then
            d := Discriminant(NumberField(fac[1]));
            if d eq -8 then
               print "****** FOUND ONE!!!!!!";
               print "fac =", fac[1];
            end if;
         end if;
      end for;
   end for;
   print "\n";
   DisownChildren(M);
end procedure;

for n in [3] do
   print "Analyzing level",3^n*331;
   G:=DirichletGroup(3^n*331);
   e:=Elements(G);
   for i in [2..#e] do
      print "Analyzing character", e[i];
      analyze(e[i]);
   end for;
end for;

