
// Make newform 74.6.a.e in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_74_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_74_6_a_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_74_6_a_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 := [481504, 121361, -2235, -870, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [2440911, -192751, -23978, 287, 26], [-1722289, 487896, -75525, -1575, 148], [5176462, 444606, -46630, -931, 61]];
    Rf_basisdens := [1, 1, 41713, 125139, 41713];
    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_74_a();"
function MakeCharacter_74_a()
    N := 74;
    order := 1;
    char_gens := [39];
    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_74_a_Hecke(Kf)
    return MakeCharacter_74_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+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 := [[4, 0, 0, 0, 0], [4, -1, 0, 0, 0], [19, 0, 1, 0, 0], [34, -1, -1, -1, 1], [177, 11, -6, -1, -5], [276, 6, -1, 3, 9], [402, 46, 2, -2, -10], [468, 38, 16, 2, 16], [396, 66, -11, -15, -21], [604, -14, 31, 43, -7], [-1165, -146, -95, -44, -34], [-1369, 0, 0, 0, 0], [-2961, 215, 89, -46, -71], [-1350, -16, -98, 38, 130], [-3844, 227, 99, 5, -41], [-4783, 551, 130, 11, 190], [-3464, -410, 12, 406, -226], [-3727, 290, -191, 302, -254], [-16955, -560, 343, -254, 446], [1548, 601, -685, 37, -493], [-2118, 349, -229, -137, 458], [9742, 180, 677, 567, -669], [5236, 289, 237, -749, 263], [46614, -262, -1700, 140, -1118], [49974, 1174, 810, -542, 434], [68359, -959, 738, 493, 374], [50133, -684, -1591, -270, -18], [27140, -4754, 1445, 475, -145], [23200, -7454, 1060, -794, -40], [72700, 2240, -922, -1024, -26], [-37228, -1775, -1657, 673, 383], [-55476, 8234, 2580, 782, -878], [-72825, -8096, 711, 202, -2722], [-38060, 4374, -2809, 1701, -987], [-57695, -5539, 4100, 17, -410], [-15378, 15888, -2530, 1680, -552], [93451, -19439, 4930, 2317, 1670], [-53604, -19912, 4298, 860, 3082], [-158865, -5730, 2409, -300, -2118], [211765, -2621, 3734, 1135, 2546], [-40614, -6976, 286, 1274, 5410], [406951, -10681, 6538, 1793, -1268], [-195267, -1018, -3977, -4816, -3332], [364064, -11412, 5624, 1038, 1842], [88295, -17827, 3926, 3437, -674], [-25820, 176, 1020, -6682, -3422], [147459, -19257, 1220, 6363, -3237], [274124, -6229, -18157, -451, -2693], [-440572, 5742, -3286, -8664, 4338], [225639, -11403, -3216, -6573, 8688], [-670940, -12222, 5155, -4401, 2607], [-493279, -45108, 6093, 6534, 8178], [439798, 36092, 10470, 698, 11032], [-85434, -3292, -15710, -6394, -6476], [-248182, -13790, 6818, 5422, -6370], [97620, 49931, 8087, -67, -4397], [-466008, 39048, -11204, -4194, -6798], [780906, 6181, 12891, 2179, 6845], [263053, -67046, -11363, -6542, -3460], [-844982, 30878, 2220, -5848, 16318], [-136498, 53402, 4040, -4660, 17392], [-411022, 47504, 662, -3382, -24206], [-509240, -38331, 5172, -6000, -11868], [368676, -56, 10983, 14083, -5959], [-17618, -16780, -5956, 2756, -25706], [314136, -69524, 17540, -11594, 12062], [-35054, -82716, 7530, -6162, 13836], [1750294, 67853, 2375, 10007, 30454], [567782, 76852, 16002, 490, 23354], [-625118, -4256, 5366, -2726, 10430], [-114298, -34230, -47316, 7704, -5268], [693756, 92257, -2797, -26363, -19849], [855688, 42048, 166, 10542, 36294], [-905171, 24051, 13448, 16557, -12492], [-2064692, 64681, -26120, -11348, 16520], [1829366, 148082, 24080, -10780, 6418], [-1062340, 59220, -17239, 8121, -9141], [-147041, -52379, -19656, -19433, -7804], [1958466, -88904, 22144, -11444, -3826], [-1340550, -18542, -39592, -30512, -11236], [-1049104, -128619, 13958, -6798, 13962], [-493064, -56960, -30341, 2947, -12991], [1494848, -16100, -15796, -35726, -17218], [-1317187, -124243, 33023, 34814, 44827], [-1458766, -3164, 20757, 15319, 11735], [-2284205, 27849, 15626, 51297, -1539], [-1073352, -21698, -44944, 14122, -6904], [576404, -82772, -42126, -57680, -7600], [562224, -177676, -33266, -21004, 15430], [-3358238, -16314, 55359, -22407, -14427], [-755902, 96380, 354, 6806, -8336], [915930, 26406, -63503, -20025, -67497], [886128, 45422, -33614, 8960, 44992], [2021560, -60062, -41233, 19909, -26275], [2098438, 106050, 34138, 10902, 89496], [-1112787, 41938, -26761, 37660, -77434], [176003, 211491, -72028, -5193, -44634], [4648881, -93207, -7788, -14787, 35472], [-1078870, 85720, -104584, -27608, -12010], [2099971, -86270, -116325, 706, 72896], [-1775564, 211298, 3262, 36968, -142070], [1642033, 271980, -28001, -9504, 50904], [3566286, -64804, 19164, 59300, -56060], [3753408, 138998, -8574, 11516, -133472], [-1523680, 165045, 170846, 45354, 32514], [-5270610, -189206, 127806, -32270, 100412], [-5284800, -343094, 106492, 12694, 81416], [-3880850, -92283, 50399, 102867, -4218], [-511664, 436625, 12151, 5213, 17851], [309459, -154092, 87127, 126786, -5346], [-5888868, 321860, -158515, -10987, 10711], [-634753, 398465, 20836, -57109, 129772], [4835061, -182147, 35329, 28720, 7061], [2347593, -212721, -4038, -8601, -3297], [44896, -52764, 80279, 87, -116739], [-1745753, 232795, -115399, -49010, -16927], [-3925128, 163408, 30958, -60392, -25168], [-574446, 133144, 123703, -46283, 43949], [4386028, -145536, -212643, -51603, -90597], [-12813828, -119161, 73038, 28778, 39898], [2272344, -197284, -147261, 40955, -188375], [-8663329, -438489, -202219, 68130, 58833], [-4729949, -355289, -106048, 111835, 4886], [-3682356, 146160, 44996, -27846, -81534], [6481572, -55304, 124628, -55532, 52928], [-7883585, -130626, 113363, 57882, 95766], [2917681, 81110, -27479, -87538, 112654], [-4237346, -257133, -91943, 3513, -16593], [18474599, -16470, 17949, 28920, 56208], [-12896501, 54277, 302274, 45313, 147398], [5294033, 257119, -247830, -123833, -195781], [-5316140, -10507, 122693, -30889, -11519], [-2128856, -33155, 146799, -22391, 50735], [15249513, -298440, -41889, 34044, 145218], [13655993, 382629, 26767, -26586, -174345], [-345692, 198236, -61086, -3892, 32986], [8505965, 186117, -74366, 15423, 188064], [4428368, -920773, 240731, -50527, 91033], [8261194, 51180, -313539, -41409, -219897], [4429748, -706464, 75590, -40164, 145896], [-5791507, 191451, -213426, 125763, -22605], [-1601675, 797271, -100886, 53751, -252630], [-10226992, -205660, 169732, -39256, 23152], [-12669278, -40480, 49092, -64756, -204050], [828962, -514052, -223959, 64411, -48373], [18029858, -78124, -47518, 13592, 137368], [8042863, 527096, 195013, -27568, -14924], [12588090, 298438, 11222, 119962, -143158], [871078, -417498, 89382, 129114, -84210], [-27410544, 272508, -34872, -69564, 19260], [-1298146, 932820, 50540, -12060, -60252], [-5255259, 557132, -357599, 46514, -85298], [-10480876, -152282, 152602, -28136, -55528], [8524584, 658061, -12481, -47359, 188263], [4188942, 361306, 457686, 326794, 194774], [12037304, -886432, -128972, -120754, -96086], [4312538, -203804, 38466, -198710, 511760], [1869953, -190256, -29563, 147550, 66638], [-21969047, -413395, 115149, 24812, 126385], [14185382, -153224, 563850, 177874, 13994], [-1838222, 174126, -103188, 76188, 10794], [-1446176, 288887, -231309, 165869, -231926], [-7057399, -413292, -329279, 105618, 21966], [-19236697, -505732, -206851, -85510, 44266], [6909316, 20530, 137392, -236306, 274904], [29169334, 10697, 249007, -91441, 107425], [9447968, -789162, 417205, -1455, -8469], [-15629664, 607736, -206210, -220012, -332630]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_74_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_74_6_a_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_74_6_a_e(:prec:=5)
    chi := MakeCharacter_74_a();
    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_74_6_a_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_74_6_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_74_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-876276, 62745, 12131, -726, -19, 1]>],Snew);
    return Vf;
end function;