/**************************************************************************
  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 p of the newform of weight two of level N (call it
   w) but I want to ignore the Euler factor at p, i.e., I want to ignore the
   Fourier coefficents a_n where n is divisible by p. 
*/

N := 14;
p := 3;

"N = ", N;
"p = ", p;

prec := 37;
"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(p));

M    := ModularSymbols(N,2,-1);
A    := Factor(M,1);
Print(A);
w    := To_pAdic(qEigenform(A,prec), p, q);
"w = ", w;


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


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

function Search(k1, k2)
   Rp2 := PowerSeriesRing(Integers(p^2));
   RZ := PowerSeriesRing(Integers());
   nearby_forms := [Rp2|];
   nearby_weight:= [Integers()|];
   nearby_level:= [Integers()|];
   for k in [w : w in [k1..k2] | IsEven(w)] do 
      "k = ",k;
      M := ModularSymbols(N*p,k);
      D := Divisors(N*p);
      v := &cat[
         [<d,f> : f in ZpRationalNewforms(OldModularSymbols(M,d),p,prec)] : 
                          d in Divisors(N*p)];
      "v = ", v;
      for f in v do 
         if IsCongruentToW(f[2]) then
            g := pDeprive(Rp2!(RZ!f[2]),p);
            Append(~nearby_forms,  g);
            Append(~nearby_weight, k);
            Append(~nearby_level, f[1]);
            "g = ",g;
         end if;
      end for;
   end for;
   return nearby_forms, nearby_weight, nearby_level;
end function;
