
// Make newform 1200.4.f.m in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1200_f();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1200_f_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_1200_4_f_m();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_1200_4_f_m();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function ConvertToHeckeField(input: pass_field := false, Kf := [])
    if not pass_field then
        poly := [1, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_1200_f();"
function MakeCharacter_1200_f()
    N := 1200;
    order := 2;
    char_gens := [751, 901, 401, 577];
    v := [2, 2, 2, 1];
    // chi(gens[i]) = zeta^v[i]
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    F := CyclotomicField(order);
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),[F|F.1^e:e in v]);
    return MinimalBaseRingCharacter(chi);
end function;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1200_f_Hecke();"
function MakeCharacter_1200_f_Hecke(Kf)
    N := 1200;
    order := 2;
    char_gens := [751, 901, 401, 577];
    char_values := [[1, 0], [1, 0], [1, 0], [-1, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
end function;


function ExtendMultiplicatively(weight, aps, character)
    prec := NextPrime(NthPrime(#aps)) - 1; // we will able to figure out a_0 ... a_prec
    primes := PrimesUpTo(prec);
    prime_powers := primes;
    assert #primes eq #aps;
    log_prec := Floor(Log(prec)/Log(2)); // prec < 2^(log_prec+1)
    F := Universe(aps);
    FXY<X, Y> := PolynomialRing(F, 2);
    // 1/(1 - a_p T + p^(weight - 1) * char(p) T^2) = 1 + a_p T + a_{p^2} T^2 + ...
    R<T> := PowerSeriesRing(FXY : Precision := log_prec + 1);
    recursion := Coefficients(1/(1 - X*T + Y*T^2));
    coeffs := [F!0: i in [1..(prec+1)]];
    coeffs[1] := 1; //a_1
    for i := 1 to #primes do
        p := primes[i];
        coeffs[p] := aps[i];
        b := p^(weight - 1) * F!character(p);
        r := 2;
        p_power := p * p;
        //deals with powers of p
        while p_power le prec do
            Append(~prime_powers, p_power);
            coeffs[p_power] := Evaluate(recursion[r + 1], [aps[i], b]);
            p_power *:= p;
            r +:= 1;
        end while;    
    end for;
    Sort(~prime_powers);
    for pp in prime_powers do
        for k := 1 to Floor(prec/pp) do
            if GCD(k, pp) eq 1 then
                coeffs[pp*k] := coeffs[pp]*coeffs[k];
            end if;
        end for;
    end for;
    return coeffs;
end function;


function qexpCoeffs()
    // To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
    weight := 4;
    raw_aps := [[0, 0], [0, 3], [0, 0], [0, 20], [24, 0], [0, 74], [0, -54], [-124, 0], [0, 120], [78, 0], [-200, 0], [0, 70], [330, 0], [0, -92], [0, -24], [0, 450], [24, 0], [-322, 0], [0, -196], [288, 0], [0, -430], [-520, 0], [0, -156], [-1026, 0], [0, 286], [-1734, 0], [0, -452], [0, -1404], [1474, 0], [0, 1086], [0, 1244], [-2328, 0], [0, -2118], [2324, 0], [-258, 0], [808, 0], [0, -2378], [0, 52], [0, -3720], [0, 426], [-1440, 0], [-3130, 0], [-3576, 0], [0, 2666], [0, 2718], [-3832, 0], [-1100, 0], [0, -1964], [0, 660], [1906, 0], [0, -1458], [1176, 0], [866, 0], [-432, 0], [0, -2526], [0, -5448], [2574, 0], [3184, 0], [0, -3962], [-8286, 0], [0, 2716], [0, 6018], [0, 9236], [-1536, 0], [0, -7342], [0, 3894], [-3692, 0], [0, 8998], [0, 5244], [-6302, 0], [0, 3414], [4824, 0], [0, -3508], [0, 10802], [1460, 0], [0, 4872], [14046, 0], [0, 2734], [-15942, 0], [-8714, 0], [11976, 0], [11054, 0], [-720, 0], [0, -15622], [-9880, 0], [0, 16116], [-9018, 0], [0, 3670], [17562, 0], [0, -1172], [0, 6876], [2280, 0], [0, -3076], [18912, 0], [9956, 0], [0, 10656], [2766, 0], [10530, 0], [0, -12692], [18110, 0], [0, 3620], [0, 14166], [0, 13404], [18654, 0], [7684, 0], [0, 1726], [0, 10596], [0, 2862], [-23592, 0], [-9574, 0], [0, 17444], [0, -2374], [0, 12162], [8804, 0], [12688, 0], [-9150, 0], [0, -25292], [0, -2736], [0, 22218], [14520, 0], [-10618, 0], [0, 1370], [0, 13758], [0, -11988], [-32996, 0], [-25902, 0], [27394, 0], [34848, 0], [0, 28028], [0, 18002], [15284, 0], [0, 18768], [-8696, 0], [0, 38662], [23874, 0], [-23618, 0], [0, 11538], [0, -14884], [0, 11334], [-44730, 0], [42748, 0], [-31686, 0], [0, -11036], [0, 25884], [-15950, 0], [13800, 0], [0, -27862], [0, 7314], [-28780, 0], [0, 32688], [0, -36650], [-2646, 0], [0, -10892], [0, -43464], [0, -14884], [1248, 0], [-6640, 0], [-29946, 0], [0, -45002], [6090, 0], [0, 56388], [0, 10854], [0, -42316], [-24480, 0], [0, 6906], [0, -6960], [-47792, 0], [0, -9938], [2590, 0], [0, -7374], [-23064, 0], [-22282, 0], [7176, 0], [0, 40898], [-47608, 0], [41214, 0], [-38900, 0], [-5454, 0], [0, -9452], [-30710, 0], [0, 44660], [5784, 0], [0, -18934], [0, 32634], [0, -29112], [33630, 0], [0, 15766], [0, 46276], [-63722, 0], [47016, 0], [0, -29878], [0, -62796], [-4988, 0], [5466, 0], [0, 17244], [0, 31686], [-77614, 0], [0, 26426], [0, -37326], [0, -35568], [-16458, 0], [13912, 0], [0, -44642], [14254, 0], [-1512, 0], [0, -18810], [-9304, 0], [0, 75612], [-498, 0], [71476, 0], [0, 40822], [59442, 0], [0, -18740], [0, -29076], [-84576, 0], [32618, 0], [0, 75548], [80058, 0], [0, -52848], [0, 7962], [-29266, 0], [36632, 0], [-83490, 0], [0, 31804], [0, 87756], [-6590, 0], [0, -85722], [-58464, 0], [0, 57836], [36456, 0], [0, 84170], [34076, 0], [67984, 0], [-22782, 0], [0, 26044], [0, -16656], [-55442, 0], [0, 41778], [52296, 0], [26352, 0], [0, 99564], [-18524, 0], [0, 40372], [-88238, 0], [0, 63798], [28704, 0], [0, 15212], [93360, 0], [115004, 0], [0, -57888], [0, 83950], [85122, 0], [0, -41880], [102166, 0], [0, -61062], [-12168, 0], [-32938, 0], [0, 28244], [0, 56718], [0, -110162], [0, -2252], [0, -67020], [31138, 0], [0, -125854], [0, 36066], [-126412, 0], [85734, 0], [-38022, 0], [0, -125300], [0, -106014], [72614, 0], [0, -23884], [0, 46658], [21512, 0], [0, 61414], [0, 40012], [0, 144492], [-102350, 0], [506, 0], [31560, 0], [0, 23520], [-28424, 0], [0, 12720], [-108754, 0], [0, 17516], [109080, 0], [0, 79058], [0, 99822], [-63448, 0], [18270, 0], [-42054, 0], [0, 6876], [0, 25278], [-56904, 0], [0, -31102], [57270, 0], [141928, 0], [0, 39954], [-49320, 0], [0, -117052], [0, 49826], [0, -29898], [-26368, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1200_f_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1200_4_f_m();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
function MakeNewformModFrm_1200_4_f_m(:prec:=2)
    chi := MakeCharacter_1200_f();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(1999) - 1;
    while true do
        trunc_vec := Vector(Kf, [0] cat [f_vec[i]: i in [1..prec]]);
        B := Basis(S, prec + 1);
        S_basismat := Matrix([AbsEltseq(g): g in B]);
        if Rank(S_basismat) eq Min(NumberOfRows(S_basismat), NumberOfColumns(S_basismat)) then
            S_basismat := ChangeRing(S_basismat,Kf);
            f_lincom := Solution(S_basismat,trunc_vec);
            f := &+[f_lincom[i]*Basis(S)[i] : i in [1..#Basis(S)]];
            return f;
        end if;
        error if prec eq maxprec, "Unable to distinguish newform within newspace";
        prec := Min(Ceiling(1.25 * prec), maxprec);
    end while;
end function;


// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_1200_4_f_m();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function MakeNewformModSym_1200_4_f_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1200_f();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![400, 0, 1]>,<11,R![-24, 1]>],Snew);
    return Vf;
end function;