
// Make newform 324.6.e.f in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_324_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_324_e_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_324_6_e_f();".
// 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_324_6_e_f();".
// 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 := [100, 10, 11, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [100, -11, 11, -1], [-900, 2079, -99, 9], [279, 0, 0, 18]];
    Rf_basisdens := [1, 110, 110, 11];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_324_e();"
function MakeCharacter_324_e()
    N := 324;
    order := 3;
    char_gens := [163, 245];
    v := [3, 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_324_e_Hecke();"
function MakeCharacter_324_e_Hecke(Kf)
    N := 324;
    order := 3;
    char_gens := [163, 245];
    char_values := [[1, 0, 0, 0], [0, -1, 0, 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 := 6;
    raw_aps := [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, -1, 0], [16, -16, 3, 3], [-243, 243, -8, -8], [0, -104, 12, 0], [972, 0, 0, -20], [-316, 0, 0, -6], [0, -3402, 4, 0], [-5832, 5832, -38, -38], [0, -1664, -81, 0], [-4978, 0, 0, 60], [0, -6804, -58, 0], [-2480, 2480, -162, -162], [-9234, 9234, 264, 264], [-5832, 0, 0, 341], [0, -972, 376, 0], [-4088, 4088, 720, 720], [0, -45032, 450, 0], [-22356, 0, 0, -788], [-60607, 0, 0, 504], [-14384, 14384, -840, -840], [7533, -7533, -1752, -1752], [-89424, 0, 0, 358], [-44471, 44471, -1272, -1272], [101088, -101088, 1055, 1055], [0, -131936, -1260, 0], [92583, 0, 0, -1240], [-150226, 0, 0, -324], [0, 16524, 1350, 0], [-139768, 0, 0, 2835], [0, -261711, -952, 0], [-95256, 95256, -1670, -1670], [0, -163976, 1500, 0], [0, 40824, -2777, 0], [41416, -41416, -315, -315], [0, 113212, -7128, 0], [47924, 0, 0, 2544], [0, -222102, 4176, 0], [268272, -268272, -3963, -3963], [35721, 0, 0, 3224], [363536, 0, 0, 7584], [264384, -264384, -5812, -5812], [0, 590971, 2304, 0], [-511272, 0, 0, -1643], [290024, 0, 0, -6909], [0, 23476, 5178, 0], [429160, -429160, 1296, 1296], [308124, -308124, 1416, 1416], [0, 1192906, 4536, 0], [272160, 0, 0, 12074], [0, 205578, 9396, 0], [-32366, 32366, 10056, 10056], [-474336, 0, 0, 8864], [0, -1293732, -1632, 0], [486, -486, 15236, 15236], [672624, 0, 0, -4138], [709856, 0, 0, 1557], [-696848, 696848, -16200, -16200], [-1806948, 1806948, -12668, -12668], [0, 10036, -35802, 0], [0, -730944, -24254, 0], [-365236, 0, 0, 20412], [0, 375678, 23612, 0], [-1528661, 1528661, 12936, 12936], [-1174176, 1174176, -25873, -25873], [1395160, -1395160, 16422, 16422], [0, 1284718, 9960, 0], [0, 462915, -4152, 0], [-600554, 600554, 12828, 12828], [-1670868, 1670868, 29950, 29950], [-1352538, 0, 0, -10248], [49408, -49408, 25101, 25101], [0, -767732, -43116, 0], [-2124064, 0, 0, -24708], [0, 2530116, -3868, 0], [2482488, -2482488, 8177, 8177], [-1192552, 0, 0, -17820], [0, 1671840, -48004, 0], [0, 702265, 6432, 0], [0, 821340, -29040, 0], [-3869696, 3869696, -11832, -11832], [-2579202, 0, 0, 34096], [-1866859, 0, 0, 74520], [707584, -707584, 27945, 27945], [-774684, 774684, -77424, -77424], [4349700, 0, 0, -58374], [651145, -651145, 77112, 77112], [6837048, -6837048, 35713, 35713], [0, -2910848, 6105, 0], [4930227, 0, 0, -57184], [-5557410, 5557410, -52296, -52296], [-1935280, 0, 0, -55392], [0, -1279881, -149576, 0], [0, -1523672, 79218, 0], [5937462, 0, 0, 55140], [0, 2313360, -15067, 0], [628884, 0, 0, -11384], [-3156580, 0, 0, -13428], [5301692, 0, 0, 53448], [4661188, -4661188, 49356, 49356], [-1249992, 0, 0, 39583], [0, -6434397, 117336, 0], [-2288088, 2288088, 100292, 100292], [0, 4852948, -80544, 0], [500030, 0, 0, 36504], [-2441907, 2441907, 129848, 129848], [-3888000, 0, 0, -167126], [0, -3045762, -38696, 0], [1190533, -1190533, 92664, 92664], [0, 8475520, 127968, 0], [10498094, 0, 0, -76320], [0, -6956604, -130534, 0], [12170068, -12170068, 27432, 27432], [-2255104, 0, 0, 46437], [9345780, -9345780, -167630, -167630], [0, -3553280, 177876, 0], [6424920, 0, 0, -171048], [0, 11508480, -103901, 0], [-6103917, 6103917, -103504, -103504], [0, 9818446, 167220, 0], [9894211, -9894211, 12912, 12912], [624024, -624024, -161434, -161434], [-1960524, 0, 0, -256080], [-2100704, 2100704, 103356, 103356], [-6213024, 0, 0, 75533], [-189308, 189308, -266736, -266736], [-710532, 0, 0, -63264], [3186040, -3186040, -106677, -106677], [0, 2846674, 32724, 0], [-5301916, 0, 0, 328212], [0, -15240960, -164916, 0], [0, -9419288, 260115, 0], [1223882, 0, 0, 68472], [0, 2109240, 224760, 0], [0, 69583, -159792, 0], [13452480, 0, 0, -2106], [0, 7035520, 232416, 0], [0, -17494056, -223893, 0], [21978864, 0, 0, -226694], [6105836, 0, 0, -163134], [9789984, -9789984, -93214, -93214], [0, 9117904, 61347, 0], [16990560, 0, 0, 84448], [504314, 0, 0, 319368], [6443388, -6443388, -294876, -294876], [-14133854, 14133854, 256392, 256392], [-21433572, 21433572, -186324, -186324], [0, -19208840, -308208, 0], [-14604300, 0, 0, 412432], [0, -7548602, -504480, 0], [-31433508, 0, 0, -250072], [2184524, 0, 0, -577086], [0, 592920, 198068, 0], [-14374748, 14374748, -395706, -395706], [26267814, -26267814, 24000, 24000], [-17315800, 0, 0, 339471], [12649608, -12649608, -233244, -233244], [-885997, 0, 0, -151464], [0, 9288432, 422155, 0], [-130005, 130005, 271488, 271488], [14193144, 0, 0, 650148], [0, -12869456, -115803, 0], [-51366069, 0, 0, 80136], [0, -4420656, 3790, 0], [-22851234, 22851234, -81448, -81448], [12408992, 0, 0, 102285], [36702976, -36702976, 135108, 135108]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_324_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_324_6_e_f();".
// 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_324_6_e_f(:prec:=4)
    chi := MakeCharacter_324_e();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_324_6_e_f();".
// 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_324_6_e_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_324_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![11029041, 0, 3321, 0, 1]>,<7,R![878114689, 948256, 30657, -32, 1]>,<11,R![23560715025, -74598570, 389691, 486, 1]>],Snew);
    return Vf;
end function;