
// Make newform 624.4.c.e in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_624_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_624_c_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_624_4_c_e();".
// 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_624_4_c_e();".
// 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 := [48, 0, 29, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 2, 0, 0], [0, 25, 0, 1], [29, 0, 2, 0]];
    Rf_basisdens := [1, 1, 2, 1];
    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_624_c();"
function MakeCharacter_624_c()
    N := 624;
    order := 2;
    char_gens := [79, 469, 209, 145];
    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_624_c_Hecke();"
function MakeCharacter_624_c_Hecke(Kf)
    N := 624;
    order := 2;
    char_gens := [79, 469, 209, 145];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [-1, 0, 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 := 4;
    raw_aps := [[0, 0, 0, 0], [3, 0, 0, 0], [0, 0, -1, 0], [0, 3, 0, 0], [0, 1, -1, 0], [-18, 0, 3, 1], [54, 0, 0, 0], [0, 3, -6, 0], [-30, 0, 0, 6], [-12, 0, 0, 6], [0, -9, -6, 0], [0, -24, -24, 0], [0, 2, 13, 0], [-266, 0, 0, -6], [0, -61, -21, 0], [-216, 0, 0, -18], [0, 17, -15, 0], [-570, 0, 0, -4], [0, 75, -12, 0], [0, 3, -23, 0], [0, 0, -54, 0], [-72, 0, 0, 16], [0, 69, 25, 0], [0, -2, -15, 0], [0, 168, 54, 0], [132, 0, 0, -30], [742, 0, 0, 30], [810, 0, 0, 18], [0, -96, -6, 0], [354, 0, 0, 12], [-744, 0, 0, 40], [114, 0, 0, 42], [0, 86, 151, 0], [-1310, 0, 0, 30], [0, 196, -123, 0], [0, 51, -186, 0], [-40, 0, 0, 42], [0, 75, 174, 0], [0, -57, -65, 0], [1536, 0, 0, 6], [1350, 0, 0, -90], [-1552, 0, 0, 42], [-402, 0, 0, -150], [0, -156, 12, 0], [0, 208, -21, 0], [1920, 0, 0, 40], [588, 0, 0, 40], [0, 363, -54, 0], [0, -15, 283, 0], [0, 372, -234, 0], [3726, 0, 0, 36], [0, -365, 497, 0], [0, -144, 174, 0], [828, 0, 0, 0], [2478, 0, 0, -132], [6204, 0, 0, 84], [2304, 0, 0, 18], [0, -81, 216, 0], [2642, 0, 0, -84], [0, -294, 479, 0], [-5388, 0, 0, 40], [0, 440, 271, 0], [0, -441, -216, 0], [654, 0, 0, -318], [-2280, 0, 0, -166], [0, -88, 175, 0], [0, 783, 132, 0], [348, 0, 0, -202], [-48, 0, 0, 132], [0, 1116, -168, 0], [0, 510, 401, 0], [0, 1203, 619, 0], [-1226, 0, 0, -234], [-5196, 0, 0, 122], [0, -489, -174, 0], [0, -1505, -301, 0], [2040, 0, 0, -30], [0, -420, 372, 0], [0, 418, -63, 0], [0, -1116, 114, 0], [150, 0, 0, -210], [0, 636, -1026, 0], [0, -553, 243, 0], [3618, 0, 0, 380], [706, 0, 0, -438], [-7962, 0, 0, 102], [0, 786, -763, 0], [0, -252, -186, 0], [0, -1652, -693, 0], [0, 1059, -900, 0], [-504, 0, 0, 540], [0, 1979, 453, 0], [0, 1671, 582, 0], [-6852, 0, 0, 240], [0, 831, -264, 0], [16632, 0, 0, 0], [0, 1468, 15, 0], [846, 0, 0, -72], [5926, 0, 0, 138], [0, 408, -978, 0], [-6302, 0, 0, 414], [0, 56, 751, 0], [-12846, 0, 0, 114], [-10722, 0, 0, 276], [9804, 0, 0, -608], [0, 1872, 180, 0], [0, -1427, 425, 0], [0, 746, -35, 0], [-17112, 0, 0, -264], [-7968, 0, 0, 50], [-11126, 0, 0, 306], [0, -1944, -540, 0], [0, -1398, 725, 0], [0, 699, 1488, 0], [0, -2217, 402, 0], [258, 0, 0, -228], [0, -321, -300, 0], [13896, 0, 0, -360], [-10140, 0, 0, 534], [5052, 0, 0, -96], [0, 852, 1308, 0], [-436, 0, 0, 42], [4128, 0, 0, 798], [0, 2133, -1169, 0], [0, -117, -48, 0], [27504, 0, 0, -126], [0, -1332, 2010, 0], [28638, 0, 0, 306], [144, 0, 0, 16], [0, 1236, -1530, 0], [0, -717, 2064, 0], [0, 3459, 985, 0], [9394, 0, 0, 522], [-17982, 0, 0, -592], [0, 2922, -517, 0], [0, -684, -1128, 0], [0, 2092, -2511, 0], [0, 867, 816, 0], [8292, 0, 0, -834], [3690, 0, 0, 180], [0, 2631, 1254, 0], [0, 2648, 1777, 0], [-878, 0, 0, -510], [0, -2819, 347, 0], [-3774, 0, 0, 392], [0, 1011, 121, 0], [0, -2004, 1140, 0], [21498, 0, 0, 528], [9432, 0, 0, 484], [0, -1089, -1097, 0], [0, 972, 1500, 0], [-21870, 0, 0, -504], [5832, 0, 0, -380], [-20118, 0, 0, -498], [-5856, 0, 0, -644], [-11094, 0, 0, 966], [8148, 0, 0, -1364], [0, 1994, 1789, 0], [5514, 0, 0, -580], [0, -3640, -155, 0], [0, -2719, -843, 0], [-7182, 0, 0, 1080], [0, 183, -750, 0], [28440, 0, 0, 324], [0, -4434, -349, 0], [0, 499, 2405, 0], [-43322, 0, 0, -330], [5558, 0, 0, -1272]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_624_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_624_4_c_e();".
// 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_624_4_c_e(:prec:=4)
    chi := MakeCharacter_624_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_624_4_c_e();".
// 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_624_4_c_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_624_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![8112, 0, 272, 0, 1]>],Snew);
    return Vf;
end function;