/*

   Code for computing GCD(F_k(p*T), F_{k+2}(T)).

   William A. Stein

   May 04, 2000.

   $Header: /home/was/people/coleman/pk_pkplustwo/RCS/code.m,v 1.2 2000/05/04 12:30:25 was Exp was $

   $Log: code.m,v $
   Revision 1.2  2000/05/04 12:30:25  was
   Initial function is done.


*/


F    := RationalField();
R<x> := PolynomialRing(F);

function GCDkk2(N,   // RngIntElt, level
                p,   // RngIntElt, a prime number p
                k,   // RngIntElt, weight
               fk)   // fk, second argument returned by GCDkk2(N,k-2,...)

   assert Type(N) eq RngIntElt;
   assert N ge 1;
   assert Type(k) eq RngIntElt;
   assert k ge 2;
   assert Type(p) eq RngIntElt;
   assert IsPrime(p);
   assert Type(fk) eq RngUPolElt;
   assert fk in R;

   if fk eq 0 then
      M  := ModularSymbols(N,k,F,+1);
      fk := charpoly(HeckeOperator(M,p));
      DisownChildren(M);
   end if;

   Mk2 := ModularSymbols(N,k+2,F,+1);
   fk2 := charpoly(HeckeOperator(Mk2,p));

   DisownChildren(Mk2);

    // this is switched from coleman's email because
    // we are considering the characteristic polynomial
    // instead of the characteristic series, which is reversed.
   return GCD(fk, Evaluate(fk2,p*x)), fk2;
end function;

procedure Range(N, p, k1, k2)
   fname := Sprintf("gcdkk2_%o_%o_%o_%o-%o", N, p, 
                        Characteristic(F), k1, k2);
   file  := Open(fname, "w");

   fk    := R!0;
   for k in [k0 : k0 in [k1..k2] | IsEven(k0)] do
      g,fk := GCDkk2(N,p,k,fk);      
      fprintf file, "gcd_%o_%o[%o] := %o;\n", N, p, k, g;
      Flush(file);
   end for;
end procedure;


ShowIdentifiers();

