
// Make newform 1450.4.a.h in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1450_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_1450_4_a_h();".
// 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_1450_4_a_h();".
// 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 := [-54, -42, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-27, -4, 1]];
    Rf_basisdens := [1, 1, 3];
    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_1450_a();"
function MakeCharacter_1450_a()
    N := 1450;
    order := 1;
    char_gens := [1277, 901];
    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_1450_a_Hecke(Kf)
    return MakeCharacter_1450_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 := [[-2, 0, 0], [-1, 1, 0], [0, 0, 0], [-8, 0, 4], [3, 1, -2], [4, -8, -11], [18, 12, 16], [-52, -8, 10], [66, 6, -12], [29, 0, 0], [-25, -11, -36], [10, 12, -38], [186, 4, -6], [-11, 15, -2], [-207, -33, -2], [-276, 116, 27], [90, -86, 4], [134, -80, 40], [88, -36, 72], [-18, 2, -4], [178, -40, -30], [-691, -37, -38], [150, -162, -12], [282, 68, 154], [-14, -176, 34], [1098, -16, -66], [154, -90, 176], [-552, -116, -272], [2, -170, 109], [-666, 48, -12], [-1028, -132, -2], [300, 72, -90], [246, -84, -154], [-874, -18, 4], [-132, 120, -345], [-460, 196, 112], [142, 208, 42], [1849, 215, 116], [-2334, 126, 172], [-510, -112, 36], [-1890, 22, -156], [-70, 2, -341], [-1668, 396, -78], [1006, -380, -150], [1026, 520, -60], [2588, 132, 200], [-1357, 509, 4], [-1946, -46, 640], [-3606, -254, -472], [1310, -84, 582], [2112, 472, 309], [354, 174, 716], [2288, -396, 261], [-6087, 247, 124], [-2538, 374, 307], [-2331, -137, 652], [-1758, -36, -772], [-1087, -181, 216], [2842, 256, 20], [-2772, 404, 543], [-386, 414, -616], [-2190, -248, 12], [2917, -385, -814], [1092, 60, 186], [-3014, -182, -1005], [834, -864, -540], [-6133, -307, -436], [-2570, -952, 1064], [-2874, -1066, -1592], [-1948, 68, 157], [-5586, -160, -384], [-459, -381, 1518], [4336, 72, -282], [-6422, 570, -699], [-1720, -716, -430], [-2016, 1520, 680], [-5874, 540, 670], [-2930, 118, -327], [8088, 656, 767], [2726, -1660, -432], [-1914, 2374, 264], [-2062, 1732, 932], [-954, 58, 108], [4162, 360, -882], [-4462, 1022, -276], [-3204, 936, 186], [-2742, -224, -756], [262, 1104, 1488], [1230, -2488, -1832], [7474, 1254, 1020], [-4083, -513, -1754], [-1587, 1039, 1776], [-836, -708, -2700], [2553, 2227, 670], [-694, -854, -308], [-3933, 1209, -1016], [840, -1952, 29], [3138, 1606, -1549], [-4712, 60, 640], [10682, -984, 470], [-2348, 776, 1472], [11562, -1480, 748], [-6855, 1351, -772], [-4554, 2980, 872], [10232, -588, 448], [-9458, -664, 140], [-1206, 2538, -1272], [1746, -434, 1501], [-1911, -1313, -2274], [-5362, 1112, 622], [-1805, -191, 2456], [-1610, 1770, 275], [7446, -2468, -538], [8867, -1555, -2712], [-10, 146, 408], [1866, 1440, -948], [-10064, 204, -564], [12930, 1878, 248], [10182, 2328, 4346], [1509, -3221, -880], [2966, -3240, -3088], [17284, -512, -1881], [-13146, 476, 952], [-10944, 604, -2748], [-11212, 168, 2564], [19080, -1004, -1905], [17240, 1548, -2361], [-13170, 3730, 1508], [32164, 492, -762], [5950, -2184, 2702], [-5731, 547, -3824], [1380, 2924, 1586], [-7744, 2168, -1130], [1150, -684, 864], [3498, 760, 3684], [-8422, -3152, 732], [-3390, -2892, -2670], [6430, 630, 424], [13482, -176, -1240], [-6702, -3836, 4214], [-13708, -1776, -3584], [-7980, 2504, 459], [4564, -4500, -4986], [-6879, 2239, 72], [6470, 1872, 2616], [3771, 3205, -850], [-9278, 4824, 5108], [-19590, -2150, 4363], [7157, 1135, 5226], [-426, 5450, 3184], [-12284, -2748, -5837], [-1482, -964, 928], [-18536, 5740, 280], [-12675, -2537, 4248], [18940, 3224, -3662], [18441, -285, 1872], [27230, 218, -3292], [17634, -3672, 60], [8830, -4032, -2076], [-558, 1686, 1317], [20253, 1455, -3162], [-3972, 2972, 7405], [3697, 999, 1446], [-24180, 5568, 2738], [8658, 2858, 7059], [-4911, -6065, -1582], [-27766, 878, -2372], [40906, -1756, 230], [42806, -362, -207], [1914, 492, -7870], [-27252, -4080, -4468], [-13138, 6002, -1095], [-28086, -66, 636], [-22130, -4072, -3448], [-14254, -1706, 5488], [906, -768, 2952], [-15496, -3212, -3040], [14790, -5808, -1908], [5059, -675, 4958], [18998, 3312, 4264], [29503, 537, 5198], [-5349, -843, -6444], [-9278, -5440, -9280], [-20442, 7198, 5243], [-14088, 8680, 4340], [-22974, -5238, -8157], [-12110, 1040, 7468], [24832, -7044, -1938], [13394, 4376, -6008], [-35376, -4520, 5520], [-15080, 508, -5745], [-48249, 3945, 1644], [-11425, -4259, 1462], [10470, -7604, -4946], [-23904, -1892, 3266], [2646, -1328, 352], [-12850, 7664, 7198], [-12710, -832, -3712], [-36084, 10128, 2499], [-21504, -1880, -3000], [-6330, 4428, 5886], [1670, -3606, -3168], [-20498, 10072, 4050], [43250, 1636, 7730], [12936, -396, -3154], [28350, 2350, 2021], [10373, -2605, -2046], [22662, -8346, -4560], [-43206, 3118, -4381], [-43543, -6109, -8450], [38962, 1128, -7338], [29910, 4040, 504], [-17657, 10837, 2336], [17505, 4339, 7830], [-18780, -4356, -2766], [-44326, 11762, 1645], [-57476, 1916, 2636], [-23826, 3760, -5674], [30456, 4880, -3432], [29106, 8432, 9708], [55670, -2824, -1520], [38348, 4796, 7108], [-40194, 4708, -3592], [-72989, -3555, 5234], [-45960, 2180, 2532], [2786, 4172, -616], [47958, -1884, -1470], [-26292, 12988, 9766], [-21167, 967, -10330], [1692, 13216, 1400], [55126, 1584, 4182], [31844, -6048, -244], [-7684, -6116, -11414], [21258, 5052, 3462], [-31478, 11162, 7292], [43908, -6188, 1082], [30506, 3024, -1428], [-57582, 1812, 6666], [-33144, -5516, -9128], [12771, 11809, -1516], [-34557, -4319, 7518], [15062, -818, 8252], [-57854, -2970, -3144], [-19318, 3664, 4922], [-37746, 9624, 4764], [-16554, -5502, 5328], [8446, -12182, -2112], [-63858, 1142, 7844], [60890, 7250, 564], [8055, -12271, 3598], [-21626, -7036, -11128], [43410, -962, 8435], [-27057, 7909, 6932], [47702, -9224, 1770], [-7002, 3368, -8814], [-79008, 3812, 2680], [-15490, -4284, -854], [9451, -4947, 6464], [19074, 3672, 11308], [-25640, 7308, 4187], [-70028, -3884, -3054], [12897, -4373, -8418], [-10186, -8296, 9000], [55774, -1812, -4096], [-43650, 7280, -8720], [-63901, -4095, 2410], [4242, -3952, -3506], [29562, 7328, -16240], [-32060, 10592, -478], [-23610, 7130, 8035], [-33256, -7704, -4511], [-4886, -1902, 7808], [17728, 12188, -569], [20540, 6188, 20706], [66154, -12488, -6142], [58561, 6819, -9072], [56616, 1692, 8082], [-11842, -3482, 5795], [-48418, 20792, 8046], [-25542, -2054, 5892], [38214, -9406, -3224], [2042, -6930, 14728], [-26436, -10108, -4512], [-28450, -6392, 8068], [53860, -1104, -9530], [-7716, 9196, -13114], [49654, -17832, 2568], [-51918, 8700, 758], [97388, -10828, -1976], [-59196, -248, 5201], [89442, -6686, -341], [-20094, -11590, -380], [-42540, 3184, -11877], [64449, -15329, -6012], [-10214, -9008, 3344], [34464, -1252, -7521], [18347, 1493, 10082], [-58488, 3512, 1675], [-47544, -3860, 14004], [37660, -10544, 10610], [-12326, -18964, 4592], [-53406, -4504, 16736], [55796, -11148, -2778], [-33267, 6503, -10990], [-388, -9024, -6690], [50734, 3126, 5039], [-49599, 29903, 12280], [-74032, 7316, -3093], [-17724, 19356, 19444], [-11570, -16810, -13987], [-56490, -14838, 13120], [34194, 8920, 25742], [37434, -2256, -11868], [2254, -16290, 10656], [-40236, 1476, 18552], [-41812, -5260, -137], [47292, 2200, -4254], [43806, 2258, 10660], [-28550, -16758, -4001], [-63558, -4632, -9720], [-73099, 3667, 14092], [-35138, 16766, 5199], [30174, 4344, 7400], [-1433, -21131, -17980], [21876, -17876, 12617], [-98794, 10848, -5374], [26174, 20078, 6240], [-1592, 3556, 5240], [-37761, -7647, -4894], [178566, -3790, -1121], [42074, -14448, 3346], [-35988, 12888, 18065], [-8764, 10468, 5316], [-45588, -15920, 13602], [-51499, -15769, -6458], [-116220, -9704, -792], [-120658, -4040, 8864], [45666, -16324, 3792], [-28522, -1380, -15020], [40060, 21836, 31376], [430, -9788, 1488], [95334, 12512, -7272], [54426, -32892, -13424], [97772, -21820, -5864], [39162, 7944, -25212], [-97605, 8065, -12378], [94694, -9304, 2384], [-115292, 9072, -3206], [-13275, 16251, -706], [-63798, 31328, 3300], [-21838, -966, 1416], [105118, 11576, 15824], [-42390, -13092, -31944], [-115454, -5306, -13044], [4934, 18480, -12852], [-87198, -6604, 21432], [-78945, 20085, 9264], [98508, 5632, 17564], [18774, 8032, 17788], [-24918, 29966, -7908], [26602, -21398, -11755], [100428, 17480, 8617], [66591, -9895, -19802], [-9858, -17202, -13896], [56401, -6637, -11038], [4150, 700, 23814], [35226, 7172, -23486], [71902, 3570, -13692], [43430, 24284, -9284], [124527, -4535, -11272], [-145546, -10802, -11868], [-23916, -23932, -20456], [-68946, 2792, -15188], [-87226, 14170, -1292], [-113306, 5194, -2625], [18348, -6408, -12322], [-122355, 13543, 788], [-47858, -18096, 1008], [-94014, -8050, 21227], [36010, 13170, -12721], [19746, -29176, -17494], [132270, 3662, -5609], [4933, -24589, 5470], [-4350, 4620, 18312], [4100, -12248, 1036], [86556, -10852, 11836], [-127180, 18452, -1694], [-95336, -16428, 17673], [127729, 13375, -20688], [44556, 10172, 12294], [-32182, -10392, 8072], [59412, 20820, 8951], [-51951, 4711, 28728], [-82217, -7987, -15234], [-107637, -21679, 10136], [-46298, 9974, 12735], [-57592, -3528, -25112], [25782, -5592, 618], [43682, 5010, -21192], [-38442, 6496, 11900], [121958, 10080, 3840], [9402, -14124, -36768], [-29396, 9836, 8818], [-168012, -10128, -11253], [89796, 20064, 10215], [-19534, -26242, -7080], [-190238, 5486, 6311], [-56034, -19420, -23936], [143701, -11233, -17262], [80508, -24704, -4816], [-83594, -12816, 18964], [-13572, -25308, 20523], [-17652, -11496, 6752], [46514, -8830, 300], [36898, 18848, -15618], [-72966, -25676, 17516], [-16935, 18427, 35148], [69514, -8042, -24880], [-62574, -8872, -14578], [-71733, -3867, -27314], [-17754, 4248, -8020], [-8786, 38396, 29260], [46383, 15653, 13872], [20745, -31717, 3490], [-13712, 38920, 12405], [-55386, -35038, 9571], [94638, 26006, -11160], [-2226, -23064, -5546], [40850, 594, 25624], [-34971, 4727, 5316]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1450_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1450_4_a_h();".
// 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_1450_4_a_h(:prec:=3)
    chi := MakeCharacter_1450_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_1450_4_a_h();".
// 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_1450_4_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1450_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-96, -41, 2, 1]>,<7,R![-5376, -496, 24, 1]>],Snew);
    return Vf;
end function;