
// Make newform 62.8.a.a in Magma, downloaded from the LMFDB on 07 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_62_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_62_8_a_a();".
// 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_62_8_a_a();".
// 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 := [-3456, -947, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-1, 2, 0], [-630, -5, 1]];
    Rf_basisdens := [1, 1, 3];
    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_62_a();"
function MakeCharacter_62_a()
    N := 62;
    order := 1;
    char_gens := [3];
    v := [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;

function MakeCharacter_62_a_Hecke( : Kf := Kf)
    return MakeCharacter_62_a();
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]];
    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 := 8;
    raw_aps := [[-8, 0, 0], [-9, -1, 0], [50, -2, -1], [-499, 7, 3], [1656, 84, -18], [2455, 65, -58], [-1037, 37, 154], [2811, -175, 103], [-55185, -433, -108], [-58145, 1261, 340], [29791, 0, 0], [-337078, -1664, 660], [-98670, 4846, 1845], [-767, 2509, -1822], [-77822, 1490, 3484], [442420, -6418, 3514], [240417, 7811, -10095], [-758255, -26973, 14198], [-168800, 12092, 21908], [1506331, 18433, -1079], [-1603984, -25306, -15240], [194441, 64781, -7470], [-2079484, -5232, -16630], [1314447, -179851, 14616], [-6020638, -16886, -90477], [5782838, -112854, -62557], [-2842695, -20681, 41725], [5751311, -157867, -32593], [-9455410, -119666, -39507], [-2008920, -290528, 11259], [-6204950, -230546, -75550], [15613564, 187120, -84536], [-8243843, -140433, 260158], [-8503482, -215630, 230182], [20680266, 255004, 53604], [37540727, -288277, -167082], [2096934, 1199758, 43585], [3658511, -1227235, 47343], [42006262, -272274, 261112], [-3992450, -419576, -40976], [24484723, 837243, -405176], [34221491, 1560725, -56718], [2745075, -550987, 144843], [-107037300, -572124, -163997], [-52855460, 77150, -152282], [-97037796, -2095752, 607342], [-57773403, 97151, -1087319], [-84256232, -441848, -683692], [10682498, 1900566, 645788], [-265882624, 1468294, -13668], [-31308394, 1869142, 673427], [-30370679, 1148765, 182818], [-29494160, 4574558, 594356], [240855757, 2067481, -291374], [-95133798, -1751662, -2728053], [159057099, -6305325, -902676], [213238862, -1428128, 87974], [156684615, -2404237, 928510], [55565485, 4804299, 130544], [-104339382, -8129742, 567855], [-257037308, -3079688, 388712], [-90098652, -5288138, 1727400], [92918613, 3880027, -2504693], [-76798569, 11245893, -858699], [-144419757, 3067901, 386242], [-696640622, -95706, -3622313], [-177950416, 9257292, -3268866], [-642347479, -3214049, -902772], [-1340411, 12585077, -548192], [81422610, -9400596, 4169428], [-220633572, 20072742, 2184786], [377191177, -20262545, -4481003], [-366336792, 13901036, 1624270], [185921494, 15012422, 102281], [-285097844, -16846560, 8765744], [-189844560, -13977028, -612090], [394996290, 17326164, -2694474], [-746879826, 16722178, 4583935], [-348455035, 3886835, -9007060], [607590821, 22269887, 4348458], [700407963, 29640285, -1149243], [743336796, -24869488, -4811501], [-163298364, -39393452, 7702836], [-912019715, 12976387, -4848880], [706925451, -26167975, -5294135], [-206959473, 16414341, 6811443], [1868304912, 14273742, -3545004], [-101824482, -11449856, -4089938], [-1306327328, -3599138, 632488], [1209745854, 28091858, 11733766], [-1488166661, 33052813, 8070709], [2923855493, 12963735, 1281455], [-470512677, 9984539, -4322504], [-839127734, -17646022, -22341068], [-1826167346, 21757194, 13519778], [-1931687741, 30260713, -9608399], [-616797597, 19263345, -16883520], [-2139442138, 10785356, -11467792], [-4028175419, 11681277, 2184536], [2071338292, -51556380, 6480629], [-1060067725, -70790127, -260529], [729939762, -109092604, -1685670], [-3405945213, 10242669, -16971051], [2467231684, -57352178, -7706246], [1088602493, -51896923, 11131356], [3601740514, 8139600, -20085568], [339970278, -1370626, -21160248], [-100261236, 95738824, 35729049], [114343849, -70616429, 23103787], [3904638227, -66444735, -6553836], [4310245058, 149361714, -37212192], [6874357866, 18650072, 3470380], [-3292883156, -41516510, 25589272], [3117762533, -85753535, 21232170], [7912244538, -40710194, 2923294], [-2691225038, -47256476, -34253582], [-1968045754, -89903366, 41127054], [-4796354772, 77719300, -23768940], [-2180155600, 76088274, 1106480], [-3269730165, -148745835, 13931469], [2127009248, -56731560, -11605011], [-2784717981, 46505097, 10356256], [-7967867658, -121376412, 18581448], [-8142030639, -23268561, -26684613], [-2509459371, -169770481, 73618645], [4352057230, -6745458, -4873427], [-2632021380, 130540838, -26557610], [-3776000007, -52031235, 43206150], [2215014663, 171049757, -745751], [-1187493664, 266166780, 18225531], [10146694437, -178158943, -40798646], [-9038143903, -132857643, -21012634], [-11055239231, -97409553, 18602909], [3818177143, 137877789, 72953312], [-11450413662, -59644560, -39545088], [-3574466028, 252316164, 3446527], [1420640559, -144569259, 40568256], [17505850721, -36347907, 57137490], [-5398738656, 8812482, 104675058], [916271708, 279091046, -127979806], [-13967870444, -141494952, -72356608], [16822781775, 289291925, -62294508], [-652973593, 167634311, 54847920], [3298330017, -180100879, 128922720], [15423243934, -16516468, 17347568], [8458502796, 151098460, -39736176], [-12616657464, 29950194, 48585544], [-2841627850, 263286004, -140671180], [-5752100792, 15876648, 12677564], [18638202273, -12181083, 71081226], [-12156715138, -136659774, -138686625], [-9860515932, 343667582, -53405286], [8626898288, -30745880, -6969972], [26586210777, -69909509, -21803937], [17489569895, 258145137, 7385877], [12111948217, -187967507, -3195674], [-13524198306, -461626, 150514528], [-9326977198, -234072588, 155524130], [-1299403238, -323104072, -1065244], [7251592210, -274126616, 81273880], [-18932760908, 18832216, -86125094], [14228884711, -106739663, 140396434], [-5511958494, 256380842, -139600268], [-20620103740, 224366480, 92487464], [-7423611200, 443457340, -31117535], [-2994012090, -88655742, -204480558], [-20460244251, 568937205, 128912872], [-30004657736, -34432760, -114691831]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_62_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_62_8_a_a();".
// 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_62_8_a_a(:prec:=3)
    chi := MakeCharacter_62_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 8));
    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_62_8_a_a();".
// 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_62_8_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_62_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<3,R![-2016, -3564, 26, 1]>],Snew);
    return Vf;
end function;