
// Make newform 483.4.a.a in Magma, downloaded from the LMFDB on 25 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_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_483_4_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 := [-10, -13, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-8, -2, 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_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], [3, 0, 0], [1, -2, 1], [-7, 0, 0], [2, 7, -9], [9, 1, 4], [-26, -1, -7], [6, 15, -1], [-23, 0, 0], [-113, 6, -8], [-156, 7, 9], [-85, 38, 34], [51, 62, -40], [-129, 33, 34], [-3, -113, 51], [-6, -49, 94], [-564, 97, 10], [-174, 64, 9], [-14, -87, -110], [430, 52, -87], [-102, 141, -177], [294, -9, 121], [-598, -151, 99], [-226, 54, -287], [-549, -170, 20], [-628, -137, 62], [-7, -361, 233], [-120, -328, 217], [-477, -68, -277], [-407, 300, 215], [65, -511, 298], [1284, 87, -3], [345, -360, -332], [1099, 160, 435], [-1356, 52, 318], [-11, -565, -349], [-24, 10, 340], [202, -29, -480], [-2562, -213, 65], [728, -281, 431], [143, 356, 365], [1256, -667, -347], [-2756, -136, 334], [469, -711, 81], [-1229, 135, -46], [881, -664, -573], [1022, 513, -741], [-1504, -877, 144], [245, -46, 13], [3474, 49, -522], [3228, 535, 438], [2018, -387, 354], [1593, 78, 104], [467, -1353, -453], [-1506, -602, -256], [2225, -1116, 384], [-470, 1364, -1207], [-1202, -183, 1005], [4528, -1520, -417], [1389, 625, -155], [1260, -13, -12], [-3818, 1170, -382], [1117, 1032, -396], [-600, 1578, -833], [-2238, 926, -498], [-395, 2868, -645], [-1028, -254, -394], [-304, 1080, 15], [-7397, 876, -266], [1904, 185, 2602], [669, -280, 1054], [-5577, 1826, 617], [5259, -267, -902], [1844, 753, 2175], [-3163, 3427, 513], [2022, -873, -639], [2360, 1441, -711], [962, -1222, -528], [-3112, 391, 7], [-5138, -1269, -581], [-5010, 3791, 942], [-3695, -3839, 2108], [-1657, 1361, -54], [-3749, -521, -105], [-5608, 2371, 765], [-2381, -543, -1389], [-6676, -243, -2234], [6546, 3503, -2394], [3988, 3031, -2370], [-6259, -714, -1304], [2251, 2438, -174], [24, 321, -2371], [3921, -3604, 578], [-5228, 4200, -983], [-8196, 3207, -472], [12060, 2119, 344], [2536, -720, 614], [11678, 248, 1428], [5022, -4, -524], [-9188, -376, 654], [112, 4111, 796], [-2460, -1650, -4248], [6511, 891, -542], [-5571, 1763, 409], [19890, -663, 959], [-6514, -4540, 1008], [-9928, 2016, 737], [-5527, -1059, -339], [-10828, -2100, 1929], [1446, -2777, -4498], [-3070, 1944, -1139], [741, -3574, 2256], [-2486, 3748, 181], [8502, 4650, -4495], [-5862, 877, -1363], [13321, 935, 1498], [3774, -2046, 897], [5278, -4775, 450], [-1889, -4720, -287], [-8318, -3353, 7], [8404, 4365, -1623], [-7961, -478, 1838], [4962, -7936, -451], [13622, -4917, -1797], [-4165, -645, 2024], [3130, -3623, 5150], [-5118, 3218, 1445], [5471, 3314, -3528], [19666, -1019, 3417], [-3128, -2630, -1944], [9216, -6793, -1455], [5130, -5057, 2556], [-4014, 1113, 1732], [-12244, -5401, 4237], [-4786, 3190, -7710], [-3415, 5717, -2555], [-7403, -1444, 2366], [18998, -1661, 512], [-28409, -999, -1903], [-18692, 1388, -5721], [17535, 7682, -2704], [-5578, -6462, 4084], [8775, -3666, -2409], [8492, -3261, -6108], [-23964, 4255, 2383], [10514, 6778, -2881], [3683, 3419, 3559], [-7395, 1565, 7317], [2941, -4611, -2517], [-3380, -4050, 2452], [1852, 2148, 56], [1698, 3520, -1322], [3902, -4762, 6743], [-24044, 5378, -289], [543, 8876, 1281], [12093, 11055, -6629], [4054, -6547, 2673], [-3465, 3244, -1037], [25351, -3156, 6376], [3643, -4183, 1331], [-16201, 1595, 2449], [10450, -828, 8229], [13184, 9550, -3162], [11572, -162, -3275], [-25789, 3749, 864], [9616, 8301, -4101], [-18224, -2322, -3805], [-19608, 2175, -2885], [-2324, -5019, 516], [-16952, 8490, 3799], [4858, 3508, -2713], [29869, -3807, -4277], [-8901, -4463, -2226], [32588, -2257, 7173], [23084, 9688, -2312], [-41800, -1739, 4901], [7706, -11068, 397], [-26436, -10263, 4510], [56561, 794, -2129], [-276, -3069, 2396], [-7542, 1485, -2082], [15821, -12393, -4270], [5738, 17703, -8504], [-22617, -5337, 6968], [-4193, -4624, -4634], [23159, -12371, -4420], [-8134, -14744, 5608], [27450, -1519, 3619], [1915, 7886, 11033], [-22325, 8296, -4328], [33236, 1825, -1106], [-3603, 8934, 7625], [36528, 1882, -1928], [10688, -1933, -1905], [-11326, 15094, 4165], [-28012, 896, -6669], [-7718, -9322, 499], [-21310, -1020, -2226], [36174, 7680, -6184], [-53783, 1438, 4053], [-22998, 8340, -7484], [31700, -3640, -3784], [11623, -944, -8327], [12074, 14208, -11587], [19827, -5674, 7104], [-32440, 17698, 2978], [33173, -9920, 1700], [28546, -279, -7058], [-27540, 2027, -11950], [25466, 3337, 13265], [-14623, -257, -13961], [19444, 6541, 948], [-59030, 5369, -3569], [16272, 2728, 17140], [-34625, -10833, 1624], [4544, -3125, -3536], [-18070, 13061, -5881], [-17383, 2131, 11284], [48725, -10940, 996], [-18489, -9098, -1046], [3204, -7474, 13789], [55892, 11386, -6778], [2494, -5228, 12695], [12780, -2704, 7652], [-42886, -47, 1693], [-14140, -10861, 12132], [-12158, -5595, -8003], [-21420, -1008, -4640], [28665, 5595, -7344], [5794, -22105, -3757], [-39848, 5925, -33], [-13466, 9890, 4211], [26346, -979, -4418], [-13048, -18928, 2320], [5404, -4406, 4231], [-41260, 1762, -8555], [-21481, -20307, 6353], [-1676, -11787, -4181], [-33975, 24440, -1538], [4794, 10301, 3779], [11712, -15871, -5719], [-31438, 4573, -794], [51680, 5178, 10356], [14220, 5679, -7725], [18025, 8058, 11728], [57699, -9509, 5990], [34006, -28330, -3698], [-42501, -11707, 8919], [9329, -2476, -3726], [41121, -810, -9410], [-49259, 23780, 6900], [15986, 18036, 7308], [-6699, 1842, 13136], [4769, -14348, 3560], [17846, -10453, -5815], [19029, -2639, -367], [-1365, 17468, -2244], [-14912, -965, 11267], [33130, 2014, -1809], [-38338, 20167, 11543], [-35264, -14042, -3349], [-63418, -1384, 4808], [-14949, -12778, 23537], [-23148, 5323, -14823], [-26, 12890, -3165], [59704, 6417, -8921], [-81658, -2952, 2140], [1634, -21845, 6431], [-26875, 26134, -11594], [7592, -16709, 16990], [-31961, -9724, 6694], [-34826, -12869, -1341], [-27387, 6613, -21414], [-15362, -1930, 14924], [69596, 12403, 1915], [29122, -20220, 13728], [-42177, 3084, 8334], [-84840, 13243, -5245], [56156, 3633, 3947], [27973, 22516, -1784], [-53315, 33899, 5299], [103518, -6176, 1947], [-19904, -1175, 6015], [-466, -26103, 7209], [-80237, 6468, -12719], [22308, -11581, -9653], [-72598, -10585, -3415], [-20798, -3936, -1536], [-89542, 6316, -14481], [37705, -31565, -10987], [-2556, -8594, 6081], [-13799, 8343, 17054], [-44680, -7118, 13305], [35779, -1028, 538], [-114598, 7506, 5658], [-109556, 16665, 589], [-92313, 12977, -793], [-5508, 18178, 5415], [40264, 23033, -7579], [82475, -7306, 7566], [-12005, -3015, 17046], [-6548, 42122, -10622], [11144, -17205, 12889], [-779, -20168, -16767], [495, 24621, -25589], [-81143, 29332, 7586], [-6801, -21756, -8965], [-28302, -21857, 21545], [-19591, 21401, -7483], [-83834, -606, -8749], [-375, 18862, -23112], [73940, -4329, -383], [-76440, -13179, -8638], [-22474, 24319, -16905], [-21762, 16135, 2809], [970, -13106, 6018], [-35014, -1779, -2787], [-53274, 29653, 7293], [-17741, -34464, 12168], [-6120, -1032, 1870], [55138, -6804, 17372], [108186, -5806, 2829], [-92484, -36211, 22328], [-44597, -1728, 24650], [-33403, -566, 12636], [-42404, -7215, -20048], [34298, 27183, -6639], [24175, -4866, 29269], [68637, -27653, 10747], [74152, -37394, -11600], [47712, -12056, 5920], [23483, 17044, -12192], [59766, -31534, 12173], [73506, -30739, 886], [56463, 13021, -21279], [106696, 26662, -3850], [-9583, 19233, -38219], [105158, 11174, -7276], [41212, 4607, -28118], [18311, 30318, -9125], [55496, 4041, -21165], [5509, 10445, 12307], [-120338, 20300, 2831], [-32458, 31175, 5975], [113664, 15794, -8670], [12853, -25897, 8764], [81707, 22164, -15783], [-51740, 4083, 24410], [78662, -5635, -18452], [-33557, -5636, 6760], [-10912, -4378, 9833], [-75811, 2408, -8688], [-20627, -11330, 6462], [47602, -27097, -13028], [40563, 2510, 5864], [80119, -843, -24529], [-35074, -18076, 38694], [1906, -1915, 6797], [79310, -4751, 22529], [-35252, 16039, 33379], [-19156, -25043, -18511], [182595, -3610, 8896], [-35446, -40669, 34127], [-27616, 28588, 15588], [-35927, -28997, 2355], [88041, 9899, 23445], [-75676, -28724, 8577], [33948, 49984, -31070], [-30668, -55128, 26455], [17856, -4830, 25895], [39953, 1096, -27028], [-107870, 24490, 20230], [136004, -19946, 19004], [40416, 11876, -26684], [-85002, 16927, -10047], [-86276, 9151, -4342], [36231, -20952, -7385], [60085, -3509, -3053], [144686, 14720, 15000], [-70474, 10741, 24797], [-81892, -31325, 15505], [-20034, 41380, 25517], [-35344, -48048, 3682], [88522, 3048, 17151], [-54830, 50585, -19016], [-33089, -42365, 18224], [37311, -5009, 14276], [-85151, 14041, -41109], [-10625, 6324, 3794], [-23630, 35720, 37018], [-70204, 17435, 615], [118904, 6609, -4120], [-153003, 29605, 3479], [4997, 45539, 11719], [-80220, -20772, -25723], [9240, 14131, 46132], [103955, -41530, 4640], [-73602, 26079, -9895], [45623, -41141, 4370], [-96209, 34206, -23842], [174091, -1066, -1192], [70914, 26632, 4931], [-154634, -3392, -14450], [55268, 8660, 47273], [64806, 10630, -8947], [58026, -34498, 16245], [-31517, -14787, 4331], [110052, -9098, -26792], [155816, 12580, 21476], [-117342, 7633, 12700], [138146, -60896, -8487], [-44799, -5829, 28627], [15540, 6620, 10980], [57720, -8778, -23365], [67066, -44356, 25561], [72364, -8334, 36666], [-106372, 22003, 2121], [65796, -9345, 59765], [50072, 1007, -37805], [-149338, 31042, 19476], [-34920, 17561, -28661], [23378, 59869, -35283], [54430, 45921, -31602], [-664, 32094, -34613], [-211388, -6782, 12513], [52328, 25664, -2426], [-63528, 11870, -11577], [103196, -32042, -17704], [-9603, -38494, -13971], [-178111, -15219, 5780]];
    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_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_483_4_a_a(:prec:=3)
    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_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_483_4_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_483_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-1, -8, 4, 1]>],Snew);
    return Vf;
end function;