
// Make newform 405.4.a.i in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_405_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_405_4_a_i();".
// 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_405_4_a_i();".
// 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 := [18, -14, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-10, 1, 1]];
    Rf_basisdens := [1, 1, 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_405_a();"
function MakeCharacter_405_a()
    N := 405;
    order := 1;
    char_gens := [326, 82];
    v := [1, 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_405_a_Hecke(Kf)
    return MakeCharacter_405_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 := 4;
    raw_aps := [[0, 1, 0], [0, 0, 0], [-5, 0, 0], [-10, 5, 3], [17, 7, 5], [-20, 13, -13], [14, -8, 8], [-5, 10, 14], [-22, 15, -19], [95, 65, -13], [211, 5, -1], [-156, 54, -2], [59, 2, 62], [-288, 28, -8], [56, 67, -31], [186, -53, 21], [159, 58, -90], [6, -122, 58], [38, -154, -18], [177, -79, -69], [-226, -32, -12], [-184, -82, -54], [648, -210, -30], [-297, 39, -3], [112, -336, 32], [329, -393, 5], [-402, -153, -143], [1870, 12, 16], [631, -15, -133], [-646, 412, -136], [-954, 319, -227], [723, -252, -60], [-1108, 378, 38], [-43, -522, -78], [254, 32, 152], [1131, 391, -59], [-1932, -351, 139], [-170, 666, 206], [74, 570, -46], [794, 507, -211], [-477, -344, 360], [-981, -561, -83], [669, -97, 213], [40, -708, 488], [392, 243, -175], [144, 160, -200], [-1697, 702, -574], [1004, 60, 360], [-1694, -622, 538], [502, 878, -718], [-688, 24, 260], [1808, 322, -682], [2713, 349, -457], [2628, -465, -291], [-1026, -24, -876], [1498, -1147, -581], [-1963, 1561, -301], [-1976, 1162, -682], [-3860, 11, 5], [2686, -855, -701], [-946, 986, 102], [2960, -429, -715], [-2012, -2132, 452], [815, -441, -283], [1696, 168, 272], [-6340, -1351, 203], [-549, 557, 463], [2612, 1558, 270], [5806, -1124, 604], [-787, 1621, 951], [7952, -474, 566], [-2075, -27, 871], [-1706, 458, -178], [6442, -956, -604], [9888, -113, 517], [3464, -843, -37], [3886, 702, 82], [-5910, -1364, -236], [8090, -1155, -169], [2230, 3519, -1363], [-7276, 1580, -916], [4341, 793, 1291], [1339, 861, -1121], [-5998, 2230, 618], [1587, -1877, -1151], [4552, 1434, 958], [-3687, -590, -1218], [5120, -344, 1752], [-475, 1275, -1399], [-5054, -1681, -595], [-106, -1384, 2084], [-5107, 873, -1933], [2864, -1047, -1737], [-4445, -358, 622], [-2689, 2668, 108], [-13308, 1772, -1656], [1030, 3112, 1240], [-7926, 2549, -153], [5596, -182, -1318], [5775, -1903, -485], [6608, -188, 0], [1144, -1953, 2797], [6148, -2328, -1940], [-7739, -342, -1970], [2873, -4437, 1689], [738, 1110, 2914], [7364, -4422, -478], [-5694, -4372, 768], [-5353, 335, 1781], [6793, -1788, -2476], [-8304, -3032, 1696], [1720, -4637, -127], [-1400, -1362, -1874], [-11708, -5331, 287], [14107, 2629, -889], [-10081, -4989, 1361], [-10384, -6712, 684], [-9970, 1330, 1502], [3064, 698, 2338], [6024, -2777, 1581], [101, 991, -3411], [-8474, 200, -820], [-3666, 6117, 1251], [-4932, -4926, -426], [-5612, 2779, 2657], [2447, -1837, 1625], [-9758, -1436, 1196], [4575, -7053, -231], [-2380, -3963, 2235], [2870, -3492, 4056], [9157, 7447, -2995], [22434, -3554, 1158], [-2232, 5470, 1090], [6228, 4627, 385], [-17519, -1422, -1682], [11145, -315, 1351], [-15940, 1986, -4918], [20114, -2804, -2532], [-10000, 5102, 1262], [16647, 2054, -1158], [7395, -4699, 271], [8995, -3213, -239], [-4110, -1182, -3662], [15868, 3400, -3356], [-7421, -2299, 1439], [-9991, 107, 161], [-5266, 5204, 996], [-7392, 5734, 3978], [7779, -6191, -581], [-4830, -3523, 4659], [28772, -5815, -69], [5919, -521, 5229], [9902, 4128, 1452], [6264, 6477, 3771], [-11234, 5972, -3472], [-7589, -7325, 313], [-1323, -4229, 3337], [-20503, -2707, -265], [-538, 38, -3450], [-20962, -6988, 1316], [29902, -4734, -470], [-14336, 9952, 2212], [-1738, -7398, -3162], [21121, -3252, -3956], [-5272, -4286, 746], [2766, -1998, 5622], [5595, -8259, 5431], [23418, -3253, 5569], [-20427, 4050, -2114], [3206, 6131, 2225], [-6575, 5904, 976], [11795, 3049, -4893], [-15171, 5589, -2025], [-35786, 2066, -2518], [-29304, 130, 1870], [-4585, 9816, -3880], [17564, -1447, 891], [-6827, 4389, -8657], [-12832, -1368, 1944], [-10321, 3175, 381], [51068, -2076, -180], [-3192, 8357, -3225], [13022, 13969, -777], [-18302, -1570, 3754], [4144, -6471, -617], [-32337, -4661, 2577], [-5010, 7331, -5327], [-6754, 2824, -1788], [-4145, -3834, -5926], [34808, 2446, 122], [-3838, -512, 2436], [17004, 2434, -3546], [31200, 3596, 4420], [-3673, 2479, 2597], [-844, -2292, 9584], [7374, 146, 534], [19761, -3656, 10000], [28096, 7613, -6289], [-5394, 576, -648], [-936, -8569, 2781], [-19769, -14409, -1979], [17229, 2363, -4151], [24674, 2099, -5751], [-8903, 6064, -4072], [10168, -19500, -3284], [58592, -5529, -31], [18271, -2421, -7423], [52764, 1786, -3174], [14462, 8556, -7204], [14668, -1992, 9248], [-45798, 1788, -224], [8291, 13241, -2149], [20580, -1987, 1759], [27340, 2968, 6664], [-20331, 4779, 4737], [-15347, 990, -526], [-28622, 10054, 3014], [23205, 45, 2151], [36554, -6331, -1021], [-6706, -18732, -3208], [17633, -22607, -3885], [18489, -6951, -197], [-34197, -3870, 7902], [-388, -5489, -4323], [-3874, 10286, -3262], [12987, 8061, 1663], [-46514, 2736, 1240], [46884, 3362, 870], [-18404, -22847, 4859], [32056, -1659, -4601], [11102, -12229, 2673], [-23887, 8158, 474], [-57272, 9528, -11272], [-1302, 2497, -6117], [7872, -5820, 6568], [-36886, -9687, 635], [24251, -16006, -3402], [26126, -13528, -11152], [65604, -7437, 3801], [-35445, 6369, 339], [42414, 12726, 114], [19140, -11359, 4387], [-2624, -13601, -79], [-39762, 2912, 5632], [77748, 1290, -966], [54763, 6475, -5183], [-32708, -8139, 2159], [26484, -1025, 9525], [34907, 12078, -5814], [-3056, 9892, 4120], [7932, 358, 3466], [84289, -11120, -992], [5004, -15180, 3060], [-10289, 764, -5980], [10308, -4375, -5409], [38420, -14325, 17561], [45211, 7063, 5573], [-79962, -4170, -3230], [38906, -1869, 7889], [-10734, -24294, -5102], [71580, 9349, 3235], [38708, -16738, 13526], [-29619, 11607, -155], [12364, -8917, -13183], [15440, -13500, 1292], [-29235, 20260, 8716], [13314, 12160, 6936], [10581, 24032, 4056], [-26680, 23280, -8196], [-52874, 6865, -18485], [-31393, 10155, 9777], [-14468, 22900, 3344], [35948, 9174, 3798], [13825, -19609, 16037], [13242, -18172, 9016], [2800, 24276, -1648], [-13994, 25026, -15542], [36241, -7615, 11747], [-96694, -3409, -1587], [-32944, 12081, -11029], [-30976, 5837, -18241], [43016, 6952, -12336], [-63362, 17027, 49], [29778, -3346, -14270], [-50578, -6814, -5490], [1241, -45, -2623], [8012, 6430, 7938], [79052, 4923, 8033], [43343, 11469, 7143], [-24046, -9168, -4936], [-51961, 5759, 437], [51352, 25340, -3728], [54666, 3252, 1224], [67609, 267, 11977], [-4130, -14991, -16453], [-34039, -27651, 8183], [73499, 12675, -4359], [29598, -11796, 12756], [-62409, -8238, -9354], [-13198, 7968, 5328], [-63246, -2362, 1414], [-16942, 21313, -1945], [95785, 4171, -775], [9118, 11760, 2920], [-73441, 5992, -10512], [71674, 7500, 5048], [-32078, 17388, 1252], [-63587, -23607, -2101], [-13, 12231, -14371], [-27156, -50602, 7282], [-41082, 15270, -702], [-27861, 27591, 4677], [-46691, -19014, 7654], [64752, 9228, -5060], [74574, 19610, -5034], [129097, -7400, 8768], [-27199, -10746, 12434], [-57147, -26949, 6249], [-81132, 10028, 11320], [-36931, 9045, 18863], [-42304, -6831, 17643], [-2090, 3270, 5882], [60875, -25607, 1667], [-25890, 20962, -13610], [-37204, 14550, -16066], [51649, -27170, 7010], [-87165, 8793, 3283], [-97318, 1030, -4278], [33164, 15309, -5665], [39574, 25999, -12395], [-16851, 12593, -4541], [71056, 9967, -10775], [49265, -4431, 8403], [-128114, 7520, -9980], [25681, -21432, -18160], [84076, -15496, 9892], [21823, 16803, -10903], [-50706, 24470, -10194], [-8179, 20256, 18696], [-30340, -16381, -10263], [64648, -24731, 7715], [27330, -25318, -14022], [53109, -28101, -2295], [-4152, 26570, -14642], [43162, -8381, -22367], [48244, -29112, 22936], [42921, 8229, -281], [-69268, 1138, 9546], [52035, -36777, 21453], [-81332, 17579, 7741], [130653, 13706, -4442], [126200, -970, -11370], [11734, 7214, -7670], [-142398, -20111, 8431], [-26835, 17363, -20735], [74770, -1080, 8152], [80691, -28963, -2097], [27903, 19536, -17184], [61274, -39372, -19996], [-148708, 2755, 11009], [20192, 32518, -8706], [40989, 9016, -6744], [-75542, -28221, 7249], [4511, 24676, -4012], [-21400, 47790, -7338], [8232, 42064, -728], [-6788, 8493, -28337], [91560, -19108, 1456], [37817, 34698, 3606], [-76943, 16398, -5726], [43924, -20023, -8029], [-16682, -29819, 14995], [22977, -10641, -11571], [-43661, -13441, 18173], [88274, -25367, 25491], [66745, 4666, 5422], [-9579, 873, -4149], [62460, -11856, 15964], [162173, -13383, 4883], [-11586, -20258, -26582], [59674, 17132, 16660], [36426, -40854, -10122], [-65644, -11015, 16707], [83746, 7364, -18068], [75325, -35269, 3545], [12938, -881, -2719], [-37652, -24984, -16648], [83866, 4341, -5305], [-137354, 27224, -3628], [-158482, 12579, 5453], [49862, -29608, -7536], [16868, -11957, -9967], [-34324, 27232, -13072], [-100524, 42234, 886], [-337, -5633, 2885], [-26152, -49014, 17406], [-125757, 24963, -18335], [94014, -41169, 29565], [137900, -2627, 17391], [-75977, 13833, 3475], [-116413, -12131, 11799], [52684, 52398, -19046], [-107466, 6853, 19987], [57374, 3650, 22370], [4441, 12173, 33967], [-624, 31186, 15502], [-98926, -35547, 4179], [-4142, 34121, 259], [-12696, -24742, 12034], [-138161, -8619, -19697], [3002, -61504, 18900], [60702, -13224, 31332], [49842, -41030, 17574], [-45883, 12542, -18678], [181496, -5220, 12948], [29498, 24922, 19454], [157685, 13787, 1361], [40758, 20626, -22214], [-3654, -32892, 25956], [-193866, 12962, -13878], [154518, -30814, 30102], [166980, -17087, 24043], [251700, -14097, -10311], [142253, 21730, 5630], [-151196, -2460, -10996], [3984, -4145, -19095], [-113100, 43676, 36348], [109862, -51777, -23515], [-45763, 57879, -17307], [-108032, -5888, 14272]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_405_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_405_4_a_i();".
// 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_405_4_a_i(:prec:=3)
    chi := MakeCharacter_405_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_405_4_a_i();".
// 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_405_4_a_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_405_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![18, -14, -1, 1]>],Snew);
    return Vf;
end function;