/**************************************************************************
  thickness.m
  William Stein
  December 12, 1999

  There is a computation that might be easy for you to make, that might
shed light on whether or not the topological closure of the set of modular
Galois representations (in the universal deformation space) contains an
open set. Tell me whether or not this is feasible. Start, say, with the
Fourier expansion mod 3 of the newform of weight two of level 11 (call it
w) but I want to ignore the Euler factor at 3, i.e., I want to ignore the
Fourier coefficents a_n where n is divisible by 3. Now look for eigenforms
of arbitrary weight, of level 33, whose Fourier coefficients are in Z_3 and
are congruent to those of w modulo 3 (ignoring the Fourier coefficents a_n
where n is divisible by 3). Every time you find one, RECORD its Fourier
expansion modulo 9 (again ignoring the Fourier coefficents a_n where n is
divisible by 3). Count the number of these ( Fourier expansion modulo 9
ignoring the Fourier coefficents a_n where n is divisible by 3)  that you
get. Do you get 27 of them?

***********************************************************************/




/*
   Step 1: Start, say, with the
   Fourier expansion mod 3 of the newform of weight two of level 11 (call it
   w) but I want to ignore the Euler factor at 3, i.e., I want to ignore the
   Fourier coefficents a_n where n is divisible by 3. 
*/

prec := 131;
"Precision: ", prec;

function To_pAdic(g,p,q)
   return &+[pAdicRing(p)!(Integers()!Coefficient(g,n))*q^n
            : n in [1..Degree(g)]];
end function;

R<q> := PowerSeriesRing(pAdicRing(3));

w    := To_pAdic(qEigenform(ModularFactor("11k2A"),prec), 3, q);
"w = ", w;

/* 
   Step 2:  Now look for eigenforms
   of arbitrary weight, of level 33, whose Fourier coefficients are in Z_3 and
   are congruent to those of w modulo 3 (ignoring the Fourier coefficents a_n
   where n is divisible by 3). 
*/


function IsCongruentToW(f)
   return CoefficientValuationPrimeToP(f-w,3) ge 1;   
end function;

function Search(k1, k2)
   R9 := PowerSeriesRing(Integers(9));
   RZ := PowerSeriesRing(Integers());
   nearby_forms := [R9|];
   nearby_weight:= [Integers()|];
   for k in [w : w in [k1..k2] | IsEven(w)] do 
      "k = ",k;
      v := ZpRationalNewforms(11,k,3,prec) 
                cat ZpRationalNewforms(33,k,3,prec);
      "v = ", v;
      for f in v do 
         if IsCongruentToW(f) then
            g := pDeprive(R9!(RZ!f),3);
            Append(~nearby_forms,  g);
            Append(~nearby_weight, k);
            "g = ",g;
         end if;
      end for;
   end for;
   return nearby_forms, nearby_weight;
end function;
