
// Make newform 405.4.a.j in Magma, downloaded from the LMFDB on 17 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_j();".
// 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_j();".
// 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 := [1, -13, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-11, 4, 1], [-9, -2, 1]];
    Rf_basisdens := [1, 2, 2];
    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, 0, -1], [0, 0, 0], [-5, 0, 0], [-14, 2, -1], [0, 3, 11], [18, 1, 13], [56, -1, 3], [-58, -3, -7], [-60, -12, 3], [107, -10, -4], [-138, -11, -51], [126, -17, -7], [-49, 23, 17], [-198, -29, 37], [-202, 5, 54], [220, -8, -62], [72, 36, -118], [-473, -25, 45], [-630, 7, -48], [2, 83, -7], [-108, 64, -20], [-90, 64, 48], [242, -118, 13], [-629, -80, -88], [-120, -20, -58], [68, 38, -20], [-822, 19, 113], [-298, 164, -179], [-429, -41, 287], [-450, -84, -178], [-1018, -15, -16], [402, -240, -108], [242, -70, -368], [-152, 8, 424], [-1587, 153, -143], [-600, 67, -401], [1672, -22, 448], [126, 85, 191], [2956, 37, 236], [28, 106, 86], [-1278, -93, 53], [1319, 102, -408], [-404, -179, -57], [-562, 363, -369], [1026, 36, 1074], [-82, 57, 209], [40, 5, 649], [500, 33, -696], [2020, 133, 429], [489, 40, -942], [-530, -347, 359], [-2766, -336, 194], [-2909, 239, -201], [284, -115, -1037], [2498, 152, 112], [1622, 101, -397], [-2007, 189, -19], [-2582, -73, -333], [-1900, 219, -533], [1881, 375, -813], [-1520, -532, 179], [1228, 343, 1223], [-3208, -216, -19], [-2916, -723, -297], [3884, 75, -1491], [2056, 151, -99], [-776, 14, 1640], [82, 890, 696], [-2474, 523, -887], [-761, -856, 528], [-5140, -268, -236], [1664, 593, 475], [-2786, -595, -2413], [-2520, 124, -1190], [-3802, 666, 974], [6618, -117, -183], [-1901, -509, 857], [-2546, 884, 1032], [-3548, 502, 1448], [-1426, 390, -1254], [-2064, -9, 1675], [1458, -326, 2878], [4866, 414, 42], [-2936, -151, -2175], [8298, -296, 802], [3484, -491, 1988], [-3892, -844, -42], [-122, 461, -909], [-3443, -260, 2], [-188, 287, -985], [-6330, 1329, -545], [-3986, 130, 2174], [-4148, -943, -3407], [-314, 178, 4212], [-5794, -732, 2738], [-3284, 553, -2010], [1997, -196, -3132], [2267, 818, -1804], [12550, 587, 3054], [12533, 882, -2246], [20, 456, -3979], [-354, -1404, -1488], [-2872, -139, -3440], [-7758, -168, -4224], [-6604, 1344, -72], [8196, 784, 62], [-9368, -608, -5173], [2550, 1203, -5735], [7558, 1546, -714], [-3098, -166, -3410], [-3526, 2847, 2162], [10952, 813, -127], [-5726, -128, 2294], [366, 1135, 3599], [-9706, 792, 2546], [11133, 1053, 2037], [4952, -15, -4742], [12932, -43, 3996], [19914, 561, 1759], [10970, 548, -3534], [12566, -588, -1240], [444, -671, -5613], [-14844, -1209, -1251], [-4906, 1247, 3745], [3274, -1822, -834], [-7851, -825, -971], [4945, -2206, -3612], [-14512, -316, -2546], [10410, -431, 8], [18994, -328, 2392], [-22432, -414, 2132], [4506, 1854, 3563], [-5206, 519, -5467], [14146, -2893, -249], [-5881, -568, 4078], [17423, -1848, 1146], [11260, 1540, 7256], [-9766, -1383, 191], [-10744, -2635, -5329], [19632, 1566, 1972], [-24170, -556, -4036], [-17811, -321, -7287], [4502, 27, -3264], [-24160, -319, 858], [14221, 971, 3881], [1066, 2995, -6213], [13848, 1957, 6915], [-2282, -1541, 3151], [-12318, 1279, 853], [3016, -1469, -6876], [334, -1657, 4235], [-21489, -237, -3103], [-17144, -1045, 4084], [-9958, 689, 1123], [-12688, -1155, 6808], [17480, -2758, -3360], [35550, 982, -410], [-8346, 438, 6550], [-7414, 24, -2978], [-4639, 4226, -5632], [-4646, -2543, -364], [23616, -3933, 221], [10952, -660, 2055], [10158, -675, 5169], [-6068, -2447, 6907], [20348, -3634, 1729], [44, -354, 8496], [-1136, -1816, 2690], [26135, -2730, 2592], [6474, 1083, -5999], [-18758, 4786, 1400], [32341, -1132, -672], [-4388, 2413, -5587], [22942, 3662, -9568], [4620, -3128, 2956], [-18284, 1336, 3722], [-31098, 3490, 3576], [-22584, 1152, 5070], [10716, -458, 4271], [-16867, -711, 10979], [-27090, -347, 3023], [-14184, 2037, 4735], [-33764, -1735, -1755], [15926, 1517, -3451], [42574, -443, 4100], [-11623, -1714, 10002], [13148, 2376, -6932], [14086, -2134, 1443], [-5521, 2529, 10623], [-4220, 2146, 9544], [33124, -937, 333], [18358, 1123, 16192], [-39932, -1909, 2333], [-12065, -1193, -1481], [-5840, -1601, -5788], [-3466, -2563, 13577], [6019, 3581, 14121], [11346, -398, 11316], [-9398, 5575, -3319], [5704, 5506, 10137], [45338, -3484, 2680], [-45110, 5, -5965], [-29224, 408, -8036], [24819, 3490, 4096], [880, -278, 3590], [-3782, -3995, 3737], [14540, -855, 669], [-3448, -2260, -9927], [14779, 94, 12998], [25626, -4034, 7388], [6526, 2900, -8504], [47002, -2636, 228], [11816, -6507, 7972], [-22006, -1255, 3135], [57300, 1431, 11751], [7175, 2583, 219], [-14520, -2264, -11045], [654, -7260, 1992], [22422, -1083, -4910], [-34774, 6656, 46], [-46605, -1841, -10967], [-26504, -4201, 6019], [10627, -1832, -18136], [-40230, -2870, -9551], [47618, -1429, 6386], [-21984, 160, 4718], [51410, 2735, -10655], [-66338, -1937, -6135], [-33368, 29, 1386], [-18838, -1435, 6781], [6808, 1100, 12098], [-20660, -5479, -14583], [-4210, 1257, -2961], [-36859, -3355, -7503], [-39576, -4367, -1630], [51538, 742, 4601], [10435, 1595, -20035], [-62482, 1973, -835], [-40566, -2571, 15285], [-42416, -4133, -24193], [-94406, -1346, -3583], [-5322, -1643, 12879], [-484, 4047, -4822], [-39091, 798, 1864], [-17000, 5107, 8687], [32804, -235, -1605], [-38880, 6184, 3923], [-23542, -3805, 9687], [-45748, 801, 7563], [49470, -252, -4855], [12658, 5573, -21273], [32759, -6196, 1290], [-31072, -2893, -14225], [-20653, -3651, -23789], [25992, 6570, -21986], [23164, -4958, 4118], [-6740, -2116, -7086], [-18866, 4553, 790], [20294, 3083, 1273], [-11252, -9433, 16627], [-2072, 10793, 1320], [61698, -1161, -7550], [-320, 2858, -25220], [26624, 3552, 17746], [54854, 1997, 16525], [11730, -3146, -10358], [19728, -5586, 10280], [-16017, 3186, -16568], [4420, 6491, 1636], [65368, -4814, 2368], [4676, 11400, 11382], [-4188, -3326, -6077], [-27584, -2581, 3331], [-33808, -7212, -2882], [-43240, 216, 20692], [-3268, -5457, 1518], [49422, 873, -21672], [8944, -5638, 11768], [-5431, -2835, -16157], [30994, -6437, -16603], [8690, 2861, -27709], [12722, -3771, -2725], [-43380, -6309, 19435], [39193, 4358, 2426], [-143950, 24, 1975], [-88872, -3864, -16224], [50320, -181, -1107], [9972, 12390, 5946], [27196, -64, 16204], [-53677, 12005, 9085], [-64244, 3484, -5166], [78070, 5287, 15897], [90106, -3959, 6131], [-24884, 7729, -7189], [34874, -1155, -4353], [33513, -4383, -19563], [69662, 2499, 7161], [8586, -1362, 10920], [-18226, -8026, -19334], [-41926, 11229, -1173], [63406, -12313, -4615], [24322, 9094, -284], [35492, 1545, -20329], [-22160, -4313, 7739], [-22540, -3108, 2570], [-5602, -7209, 6699], [19440, 1980, 2439], [89269, -4492, -1466], [-83666, -905, 8123], [-65736, -10124, 12444], [-21566, 199, -20107], [45365, 10958, -3110], [36192, -2562, 3984], [123538, -2050, 847], [72042, 6843, 25489], [-25617, 4972, 20458], [20618, 3770, 1354], [-47156, 151, 4799], [41780, 13326, 12304], [-33772, -3004, -22346], [15606, 8302, -17320], [-68448, 5275, 11537], [24314, 254, 31770], [97708, 6539, 29775], [24132, -5760, -1002], [86889, 2143, 877], [-10288, -5097, 17601], [30474, -6452, 31009], [93760, 3709, 4064], [-40956, -4362, 22952], [-62415, -9443, -27435], [-57116, -1511, -23051], [74282, -2238, 7512], [-95790, 1659, 17881], [-63512, -484, -29918], [24966, -13833, 154], [-51005, -7399, -14915], [117214, 4960, 22662], [64751, 1377, -10803], [-11622, 3523, 22749], [-173952, 5092, 1180], [-85528, -10948, 20864], [40097, 9605, -8267], [-38004, -9248, 8130], [-44608, 11933, -9687], [-25102, -13876, 9430], [61506, -6080, -8608], [-144128, -52, -22143], [-126358, -298, -13466], [-108604, 5828, -508], [74900, 2580, -21938], [-43972, 9411, 17785], [30991, -5507, 29745], [107946, 5266, -2399], [-110137, 9096, -7028], [93736, 7711, 19223], [74478, 648, 33070], [4360, 1330, 34250], [-149428, 2798, 7174], [-28826, -13757, 10666], [-104258, -7846, -6624], [58173, -1248, 5180], [117608, -11845, 7615], [-7076, 2713, 16249], [24194, -12381, 4581], [-24008, -13207, -25035], [19858, 3715, 21311], [104148, 2287, 38982], [-36258, 22174, 2750], [77172, 7533, 10143], [-18098, -1486, -1180], [-33940, 2258, 14781], [-43755, -4029, 7503], [89540, 6618, -19118], [-64122, 3484, 28618], [-46180, -2311, -15207], [47862, 14424, -27510], [-121618, -1290, -12804], [-15975, -3279, 9171], [-29658, 10861, -34421], [109703, 5594, -31030], [-117474, -11673, -7857], [-8204, -10585, -16848], [-17620, -20053, -18691], [-35660, -1597, 2141], [-15098, -10391, 13807], [203464, -1285, 5797], [12788, -2958, 57318], [31472, 2118, -47831], [44502, -21750, 225], [-97085, 6683, -21331], [48526, 15463, 21343], [82808, 7286, 20688], [40762, -10141, -3839], [774, -2484, -12208], [-24768, -18590, 11480], [44280, -8222, 45272], [-49632, 14118, 20544], [-102794, -12952, 9192], [-77896, 3212, 38614], [77159, -3819, -37855], [186658, -590, 15782], [59830, 5975, 1593], [-179136, 75, -9329], [6207, 1281, -41309], [-50516, -16345, -11337], [-81488, -3064, -44708], [55519, 640, -7974], [70920, 2554, -13191], [155776, 4588, -17254], [29830, -10348, -15886], [-138366, 12354, 10596], [-66386, -4865, -35612], [-78506, -14620, -44746], [-31174, 2487, -7785], [-48635, -10040, -13034], [-54422, -7457, -14787], [117598, 1331, 20409], [29704, 1972, 22808], [32948, -2821, -20824], [131991, -5991, -761], [73454, 15684, -12490], [-18986, 24739, 6245], [-80036, 2560, 5890], [-52132, 17895, -1965], [-46872, -2928, -412], [110584, -3671, -33636], [-88818, 22410, 9714], [-56804, 9455, -3941], [-98374, -4252, 8460]];
    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_j();".
// 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_j(: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_j();".
// 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_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_405_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![3, -17, -1, 1]>],Snew);
    return Vf;
end function;