
// Make newform 483.4.a.b in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_483_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_483_4_a_b();".
// 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_483_4_a_b();".
// 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 := [1048, -8, -76, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [48, -42, -3, 1], [-38, -3, 1, 0], [-608, 56, 17, -1]];
    Rf_basisdens := [1, 28, 2, 28];
    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_483_a();"
function MakeCharacter_483_a()
    N := 483;
    order := 1;
    char_gens := [323, 346, 442];
    v := [1, 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_483_a_Hecke(Kf)
    return MakeCharacter_483_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 := [[1, 1, 0, 0], [3, 0, 0, 0], [-6, 0, -1, 0], [-7, 0, 0, 0], [-13, -2, -1, 1], [-30, -9, 5, 0], [-3, -6, -1, 7], [14, -9, 8, -10], [-23, 0, 0, 0], [46, -7, 4, -10], [-57, 30, -11, -1], [-35, 64, -1, -19], [-88, 53, -8, 0], [14, -39, 5, 20], [-183, -21, -5, 3], [-182, -50, -7, 12], [161, 23, -8, 21], [294, -55, -3, -22], [100, -10, 71, -16], [-725, 76, 8, -11], [-246, 71, -44, 82], [-124, -19, -28, 46], [408, 61, 52, -4], [-374, 169, -3, -64], [567, 234, 27, -15], [-180, -44, 31, -36], [-492, -20, 12, 64], [-302, 215, -69, 48], [292, 72, 41, -74], [37, -233, -12, 63], [-299, -128, 72, -29], [-1416, 215, 6, -54], [-318, -151, 22, 22], [915, 111, -62, 7], [-453, 409, 33, -79], [-1016, 106, -134, -16], [-1147, -171, -153, 99], [-1155, -315, 120, -107], [571, 136, -79, -185], [-857, -338, 135, 33], [-465, -181, -244, -33], [993, 288, 99, -79], [464, -70, -6, 84], [510, -494, -170, 252], [-1185, -248, -208, 243], [1067, 97, 44, 135], [-948, -423, -112, -62], [62, 66, -63, 72], [1471, -601, -18, -159], [336, 1494, 93, -110], [-1819, 559, 192, -277], [-3587, -741, -132, 49], [2893, -242, -95, -33], [-540, -1324, 208, -146], [-1282, -488, -318, 260], [-2944, -83, -336, 234], [-1762, -33, 241, 72], [5345, 286, 105, 125], [-2135, 14, 108, -331], [-1788, -1180, 120, 122], [1857, 213, -184, -405], [1941, -167, -23, -69], [-952, 929, -86, 154], [142, 883, -519, 410], [4851, 687, 365, -13], [-1285, -23, -396, 225], [-2988, 1006, -100, -484], [255, 1354, -416, -49], [2920, -1573, -158, 626], [-5128, -500, -135, -32], [-1426, -813, 778, -378], [763, 531, 124, 343], [-723, -28, -776, 715], [-2527, 68, 623, -135], [1029, 2809, -5, 213], [-762, 185, 440, 36], [-2175, -1666, 273, -79], [-5445, -791, 131, 207], [1068, -653, 538, -752], [2036, -111, -100, -680], [-3527, -111, 242, -393], [-5290, -2039, -941, 438], [1219, 18, -452, -563], [-5353, 1151, -621, 371], [3429, -2356, 67, -751], [-3990, -250, -194, 398], [-1767, -2017, 134, -561], [-9361, -1653, -596, 93], [-8266, -822, -567, 430], [-3174, -719, -880, 656], [-930, -1879, -374, -510], [-6954, -1417, 510, -28], [1002, 255, 1228, -1108], [-10317, -1542, -444, 377], [-2067, 2899, -104, -543], [-12029, -3737, 1228, -209], [1667, -795, -517, 651], [2871, 985, 473, 295], [1334, -2184, 304, 656], [3558, -4408, -498, 1088], [-1701, -535, -130, 247], [-615, 2937, -29, 435], [7273, 4716, -472, 365], [12748, 2076, -550, 506], [-7801, -330, -1299, 393], [-6874, -820, -744, 632], [4331, -2962, -218, -963], [9610, 2874, -518, 108], [3617, -3308, 566, -549], [1999, 1153, -878, -883], [8340, 2481, -641, -44], [591, 4814, -841, -373], [1243, -974, -54, -301], [9629, 56, -338, 665], [7172, 1633, 1694, -1378], [3241, -1786, 1084, 885], [11593, 3024, -450, 21], [12184, 1504, -633, 702], [1061, 1931, -352, 991], [3647, 482, -125, -855], [-4067, -1200, -221, -235], [-3268, 6633, -256, 220], [-12368, 7, 751, -872], [4990, 6155, -292, -788], [12433, 372, 1058, -173], [-11356, 2268, -603, 202], [-8334, -2523, -747, 246], [6501, -1648, 9, 749], [6090, -47, 198, -924], [4173, -1363, 623, -1357], [19130, 239, -494, -56], [-3595, 4417, 734, -239], [-67, -1527, -1400, 1769], [-4619, 1658, 1703, -939], [2442, -1638, 912, 20], [8645, 1541, -303, 1581], [6699, 7058, 1109, -749], [12515, -1459, 462, -2019], [1051, 221, -23, -1735], [19125, -2010, 352, 305], [16766, -2935, 398, 1768], [8988, 2682, 1460, 118], [11947, 1193, -432, 1823], [8504, -4346, 1291, 1576], [6721, -1328, -1523, 2583], [-20027, 1286, -414, 27], [-8709, -2649, -149, -1429], [-16542, 2230, 1014, 544], [-9758, -2672, 766, 1662], [13012, -3660, 1666, -2064], [-7506, -2550, 3076, -1648], [-11351, -1783, -2075, -543], [31061, 5656, 2654, -453], [8088, 689, 1083, -104], [21174, 7090, -2417, 1098], [-7488, -514, -3150, 2932], [20766, 7395, 760, -400], [4405, -381, 2766, 691], [-15427, -8960, -77, 363], [-14215, -2379, -691, -1905], [-5938, 268, -3106, 6], [-2945, 3742, 938, -1677], [-12976, 5326, 668, 852], [19083, -6736, 284, 363], [-12643, 3130, 2288, -1991], [-14712, -10553, 2458, 214], [7059, -2084, -2308, -291], [-3747, 544, 389, -3149], [-5745, 2247, -3504, 2901], [-9126, -2573, 1001, 1888], [1796, 3645, 1471, -2270], [4893, -3173, 2851, -1947], [-867, 6456, 2378, -3593], [1882, 5623, 126, 282], [-1653, -1221, -901, 2849], [-1077, -9506, 911, 125], [-14069, -6760, 3016, -1179], [11331, 3493, -2968, 1277], [16697, 14967, -1908, 177], [-11124, 1642, -2523, 1594], [-9679, 2559, -748, -2339], [3663, -7096, -1182, 1903], [6133, -989, 1854, 1239], [-2529, 3810, 2804, -3705], [8412, 10957, 334, -2], [-29220, -6803, -561, -28], [-7738, 3568, -3028, 1440], [-24556, -6183, -2756, -1248], [17565, 59, -958, 443], [-12743, 2320, -513, -2107], [-18137, 5387, 2560, -635], [11159, 601, 1202, 691], [24665, 2701, -2447, -743], [-51161, -3814, -2545, 341], [19374, 13605, -3035, 916], [126, 9401, -1963, 900], [42309, 1690, 1376, 1521], [20719, -169, -1543, 2997], [-17441, -6247, -1311, 363], [14192, 9060, 2223, 1510], [-11527, 10639, -227, 2107], [33885, -4671, -843, 879], [-17424, -880, -1617, -908], [-22900, -8709, -1995, 1246], [-33962, -13977, 5316, -914], [19991, -2015, 2713, -3253], [-11214, 5445, 1012, -424], [19827, 141, -310, 3799], [465, -6485, 4284, -3557], [31110, -4757, 1194, 2976], [28414, 2636, -3002, -140], [-22852, -9978, 4975, -1184], [2790, -12315, 102, -1764], [7510, 3522, 1444, -420], [-32664, -7213, -223, 2184], [-27104, -11242, 815, 632], [-12552, -2347, -728, 1234], [2893, -4642, 1706, -635], [-5188, -10227, 1820, 2742], [-48654, 6995, -818, -338], [5669, 1592, 2728, -2671], [17646, -4796, -2210, -1590], [-29373, -9162, -990, 2271], [22870, 4034, -2966, 3166], [17280, 12645, -2348, 710], [-5385, -3089, 1244, 1109], [1107, 7796, 4103, -3879], [-29770, -11138, 2666, 442], [12387, -11370, -650, 593], [25596, 4425, 1118, -3662], [-36588, -13719, -2612, 1240], [40083, -6604, 1958, -4357], [24303, -9319, 2420, -4553], [-26514, 2234, 1032, 1708], [43069, 3908, -848, 2301], [10635, 9708, -1234, 3509], [20865, -1281, -2519, -3667], [17599, -570, -1559, 4915], [-17102, 3439, 2800, -1048], [22257, 9524, 2379, 2813], [23645, 2476, 1397, -5961], [45407, 11471, 4178, -377], [-27621, 2455, 3685, -4275], [23606, 22843, 1644, -802], [20300, 10983, 1832, 3108], [3534, -2209, -1135, -2342], [24993, -1367, -5191, 4963], [-8538, -13294, -464, 3288], [-61489, -1330, 1151, 2553], [-37648, 19491, 784, -4122], [-23791, -21408, 3699, -299], [24105, 9495, -3533, 777], [-63510, -1149, 2812, -2372], [-5403, 1986, -781, 2647], [18207, 7862, -2011, -2391], [19896, 6260, -4094, -3980], [-28623, 8102, 2991, 817], [-31952, -1389, 3626, 1336], [-63068, 12751, 2607, -4498], [-47920, 14689, -1152, 3076], [-56435, -6724, -2204, -857], [49025, 8539, -5913, 4185], [-9846, 18502, 63, -5890], [18459, -7210, 7759, -4877], [-31359, 16928, 3556, -3959], [-19900, 1451, 4464, -580], [-10473, 549, -4773, -27], [36031, 13070, -6293, 1217], [-2895, 13212, 3467, 2235], [-11541, 221, 5950, -4355], [-4177, -3650, -205, -175], [8469, -15812, -1059, 1019], [396, -363, -3709, 4470], [-33096, -734, 1146, 2628], [-86646, 10809, 1466, -1434], [-33343, 23267, -363, 2559], [-59958, 14197, 1392, -2668], [-7170, -19225, 1816, -722], [-83508, 10399, 228, 2620], [-27336, 6191, -2344, 5308], [-191, -3101, -4661, -1381], [-64301, -1032, 1480, -3895], [48788, 14203, -2138, 1538], [24001, -14158, -3465, -2323], [-7741, -17187, 6764, -1997], [-43052, 3307, 3134, 2590], [-29054, -18295, 3706, -2558], [-85217, -15287, 6963, 861], [33328, -8737, 3237, 320], [6890, -10602, -6580, 7560], [-12788, 27233, 5651, -6964], [8541, 6870, 392, -6007], [3369, -9840, -8484, 4773], [2456, -6937, 3582, 832], [-51164, 4048, 3166, 834], [-23501, -18594, 1293, 3071], [49180, -8972, -6452, 8012], [18178, 11999, -6563, 1632], [-39938, -11671, 5602, -4300], [-66072, 5733, -5714, 5894], [65610, 6205, 3337, -616], [33837, 3771, -8407, 9319], [18336, -12909, 1024, 3518], [-20427, -11257, 3414, 6609], [4779, -27085, -1599, -1289], [-48958, -2939, 3192, -3886], [72033, 7923, 5200, 1109], [47403, 11364, 627, -2529], [-63054, -15782, 3512, -86], [38025, -1436, 2890, 4281], [9109, -28922, -1647, -3847], [-40251, -2354, -6593, 1245], [43893, -28009, -1712, 875], [9462, -4385, -3848, 460], [23262, 16211, 1782, -4680], [10155, -9841, -6987, 2543], [54030, 2559, -418, -4696], [11160, 1091, 5250, 1146], [44471, -8974, -1683, -2463], [-38990, -14272, -5222, -112], [20912, 28454, 4554, 2186], [-113467, -10744, 4386, -2275], [62476, -7234, 3715, -3304], [-21642, 3037, -872, -8940], [66370, 11305, -8780, -1502], [108546, -4436, -753, 466], [-16887, 12402, 6627, -2337], [-32357, -1343, 6222, -9173], [-9738, -6668, -3228, 2986], [11213, 397, 1031, -5793], [-64400, -5588, 9870, -3578], [-65378, -27119, 6466, 3614], [28826, 32359, -2829, -1646], [-28891, -23199, 5704, -1787], [-60045, -11899, -5917, -1221], [-34, -22212, -9234, 5458], [-27379, 8921, 5019, 2375], [-10181, -13159, -8469, 1971], [-57477, -16885, -11338, 3145], [-36043, -27171, 5412, -207], [-13584, -25151, 7872, -440], [71692, 14954, -3322, 1846], [45220, 271, -5251, 3238], [80058, 33409, -9380, 864], [-33571, -18109, -3023, -4857], [-50255, -3942, 5608, -5549], [-17738, 35350, 825, -5006], [29519, 26447, -6472, 1671], [71613, -3913, 2632, -9107], [11721, -36636, -2087, 5765], [47253, -8436, 6070, 923], [23186, 27663, -7050, 2790], [45270, 19293, -1270, 1490], [-11919, 17651, -4446, 1409], [-48451, -9946, -3747, -1455], [55528, -20472, 4274, -3082], [7662, -25654, -7576, 10110], [6752, -8869, 5458, -6220], [35032, 20233, -846, -4392], [38526, 28993, 8664, -812], [-24249, -15700, 6471, 5479], [-44832, -12367, -5836, -1720], [-24870, -11661, 5540, -8212], [-70477, -14549, 4241, 3999], [13740, -9702, -5258, -9244], [10626, 7922, 1024, 920], [-13450, 13153, 9317, 1744], [-55266, -17692, 7152, -1862], [-47253, 12578, -9564, 1799], [43735, -13728, -4188, 9817], [72072, 23889, 11238, 1386], [-15144, -16208, 4112, 3984], [-97995, -16491, -1705, 4791], [-59936, -9164, 5768, 7948], [-97332, -46623, 760, 1044], [89269, 6063, -7414, -3235], [-84597, -3011, 3844, -5189], [-12545, -31003, 7163, 2915], [111219, -2311, 11573, -8005], [-77134, -1735, 5850, 9614], [-25963, -15760, -5299, -4931], [16199, 13674, -10766, 10755], [26456, 14138, -3626, 4912], [142689, 10612, -1056, -3467], [92827, -17507, -6332, 597], [-13704, -25029, 2045, 12496], [4761, 34128, 1400, -625], [44079, 23845, -9147, 8875], [-29419, -29466, -9459, 259], [42256, -4340, -4286, 136], [-5016, 20075, -2818, -10932], [4344, 39150, -601, 6712], [25104, -3738, 12128, -13648], [-14990, -6416, -7608, -2994], [-81627, 3722, 4704, 10499], [-38765, -54573, -1198, -4451], [-21782, 14343, 5178, 4164], [71367, -26280, -3831, 15149], [25630, -22379, -761, 13176], [102842, 44215, -14522, 3542], [2673, 5634, 9353, 4151], [27187, 13090, 8038, -3077], [79690, -19342, -1116, -3782], [70506, -9085, -1905, -7036], [21204, 7489, -7179, 9458], [-128396, -18987, -10427, -352], [-108315, -45783, 12813, -3545], [-55152, 22116, -1984, -5034], [16668, -59480, 2482, -1246], [21115, -25755, 3492, -10397], [-126039, -18274, -1376, 3361], [34094, 20660, 13958, -8548], [-86371, -29035, 8915, -7], [15476, 16631, 737, 2094], [6261, 21200, 11888, -8427], [-116527, -38305, 11311, 3369], [-80040, 6521, 6020, -9710], [212709, 17068, 1003, 1281], [-146979, 14754, 413, -797], [88092, -4078, -7514, 6976], [-65883, -18064, 2935, 8437], [77529, -30318, 9019, -15871], [20863, -7363, 1518, -9113], [37005, -10402, -4124, -4841], [-35491, 33704, -6174, -9519], [-82235, -1261, -14495, 12509], [26100, 33747, -111, 462], [-12384, 11992, -16420, 8802], [111651, -11489, -322, -8233], [23282, 999, -12623, 12670]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_483_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_483_4_a_b();".
// 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_483_4_a_b(:prec:=4)
    chi := MakeCharacter_483_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_483_4_a_b();".
// 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_483_4_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_483_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-10, -1, 1]>],Snew);
    return Vf;
end function;