freeze;
 
/****-*-magma-* EXPORT DATE: 2004-03-08 ************************************
                                                                            
                     MODFORM: Modular Forms in MAGMA
 
                              William A. Stein        
                         
   FILE: tests.m

   $Header: /home/was/magma/packages/modform/code/RCS/tests.m,v 1.4 2002/04/13 07:27:10 was Exp $

   $Log: tests.m,v $
   Revision 1.4  2002/04/13 07:27:10  was
   *** empty log message ***

   Revision 1.3  2001/05/30 18:57:44  was
   Created.

   Revision 1.2  2001/05/16 04:00:52  was
   initial code entry.

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


forward RandomBasisG1, 
        NewformsG1, 
        NewSubspaceG1,
        TestModpG1, 
        TestpAdicG1, 
        TestComplexG1, 
        TestCharpoly;

NS := NewSubspace;
CS := CuspidalSubspace;
ES := EisensteinSubspace;


intrinsic BugHunter(tests::[RngIntElt], rep::RngIntElt, how_hard::FldPrElt)
{}
   if #tests eq 0 then
      tests := [1..100];
   end if;
   for n in [1..rep] do
      if 1 in tests then
           "BG -- RandomBasisG1 -- ", n;
            RandomBasisG1(how_hard);
      end if;
      if 2 in tests then
           "BG -- NewformsG1 -- ", n;
            NewformsG1(how_hard);
      end if;
      if 3 in tests then
           "BG -- NewSubspaceG1 -- ", n;
            NewSubspaceG1(how_hard);
      end if;
      if 4 in tests then
           "BG -- TestModpG1 -- ", n;
            TestModpG1(how_hard);
      end if;
      if 5 in tests then
           "BG -- TestpAdicG1 -- ", n;
            TestpAdicG1(how_hard);
      end if;
      if 6 in tests then
           "BG -- TestComplexG1 -- ", n;
            TestComplexG1(how_hard);
      end if;
      if 7 in tests then
           "BG -- charpoly test -- ", n;
            TestCharpoly(how_hard);
      end if;
   end for;
end intrinsic


function G1(how_hard)

   N := Random([1] cat [1..Round(how_hard*100)]);
   k := Random([2] cat [2..Round(how_hard*20)+2]);
   return  ModularForms(Gamma1(N),k);
end function;

function RandomSpace(how_hard)
   N := Random([1] cat [1..Round(how_hard*100)]);
   k := Random([2] cat [2..Round(how_hard*20)+2]);
   if Random([1..2]) eq 1 then
"Gamma0";
      M := ModularForms(Gamma0(N),Max(k,2));
   else
"Gamma1";   
      N := (N div 2)+1;
      k := k div 2;
      M := ModularForms(Gamma1(N),Max(k,2));
   end if; 
   if Random([1..3]) ne 1 then
      if Random([1..2]) eq 1 then
         p := NextPrime(Random([1..10]));
      else
         p := NextPrime(Random([1..1000]));
      end if;
   else
      p := 0;
   end if;
   printf "N=%o, k=%o, p=%o\n", N,k,p;
   return M, p;
end function;


procedure RandomBasisG1(how_hard)
   assert Type(how_hard) eq FldPrElt;

   M := G1(how_hard); M;
   print "qExpansionBasis(M);";
   [PowerSeries(f,20) : f in Basis(M)];
   print "qExpansionBasis(EisensteinSubspace(M));";
   [PowerSeries(f,20) : f in Basis(ES(M))];
   print "qExpansionBasis(CuspidalSubspace(M));";
   [PowerSeries(f,20) : f in Basis(CS(M))];
end procedure;

procedure NewformsG1(how_hard)
   assert Type(how_hard) eq FldPrElt;

   M := G1(how_hard); M;
   print "N := Newforms(M);";
   N := Newforms(M);N;
   print "q-expansions";
   for orb in N do
      "-------------------------";
      for f in orb do
         PowerSeries(f,10);
         Degree(f);
      end for;
   end for;
end procedure;

procedure NewSubspaceG1(how_hard)
   assert Type(how_hard) eq FldPrElt;

   M := G1(how_hard); M;
   print "NS(M) := ", NS(M);
   print "NS(ES(M)) := ", NS(ES(M));
   print "ES(NS(M)) := ", NS(ES(M));
   assert Dimension(NS(ES(M))) eq Dimension(NS(ES(M)));
   print "CS(NS(M)) := ", CS(NS(M));
   print "NS(CS(M)) := ", NS(CS(M));
   print "qexp(NS(CS(M))) := ", [PowerSeries(f,20) : f in Basis(NS(CS(M)))];
   print "qexp(ES(NS(M))) := ", [PowerSeries(f,20) : f in Basis(ES(NS(M)))];
end procedure;

procedure TestModpG1(how_hard)
   assert Type(how_hard) eq FldPrElt;

   p := 0;
   while p eq 0 do
      M, p := RandomSpace(how_hard);
   end while;
  
   M;
   N := Newforms(M);N;
   print "q-expansions";
   for orb in N do
      Reductions(orb[1], p);
   end for;   
   
end procedure;


procedure TestpAdicG1(how_hard)
   assert Type(how_hard) eq FldPrElt;

   p := 0;
   while p eq 0 do
      M, p := RandomSpace(how_hard);
   end while;
   M;
   N := Newforms(M);N;
   print "q-expansions";
   for orb in N do
      pAdicEmbeddings(orb[1], p);
   end for;
   
end procedure;

procedure TestComplexG1(how_hard)
   assert Type(how_hard) eq FldPrElt;

   M := RandomSpace(how_hard);
   M;
   N := Newforms(M);N;
   print "q-expansions";
   for orb in N do
      ComplexEmbeddings(orb[1]);
   end for;
   
end procedure;

procedure TestCharpoly(how_hard)
   M := RandomSpace(how_hard);
   M;
   n := Round(Random([1..100])*how_hard)+1;
   while GCD(Level(M),n) gt 1 do
      n := Round(Random([1..100])*how_hard)+1;   
   end while;
   printf "n = %o\n", n;
   //printf "f_%o on M := %o\n", n, HeckePolynomial(M, n);
   // printf "f_%o on ES(M) := %o\n", n, HeckePolynomial(ES(M), n);
   printf "f_%o on CS(M) := %o\n", n, HeckePolynomial(CS(M), n);
   //printf "f_%o on ES(NS(M)) := %o\n", n, HeckePolynomial(NS(ES(M)), n);
end procedure;
