
// Make newform 441.4.a.t in Magma, downloaded from the LMFDB on 17 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_441_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_441_4_a_t();".
// 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_441_4_a_t();".
// 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 := [6, -24, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-16, -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_441_a();"
function MakeCharacter_441_a()
    N := 441;
    order := 1;
    char_gens := [344, 199];
    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_441_a_Hecke(Kf)
    return MakeCharacter_441_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], [4, -1, 1], [0, 0, 0], [-12, 1, 3], [-19, -5, 1], [16, 0, 4], [65, 7, 1], [-80, 24, 4], [-26, 25, -5], [39, -22, 2], [81, 19, 1], [82, -2, -14], [143, -69, -3], [-46, -72, -28], [-154, 69, 11], [358, 69, -29], [-10, 100, -20], [-215, 17, 47], [-66, -120, -12], [-363, 101, 23], [299, -36, 48], [156, 51, -27], [532, 170, 22], [-24, 53, -49], [794, -20, 68], [865, 51, 45], [-862, -23, -1], [519, 331, -47], [-686, -26, 22], [573, -80, 4], [-944, 311, 61], [-1000, -42, -94], [-39, 353, 143], [-1736, 6, -14], [-334, 129, -117], [1562, -158, 166], [-980, 596, 20], [-142, 404, 176], [-828, 406, -162], [2890, 26, -86], [1265, -317, 97], [458, 646, 62], [1703, -18, 66], [364, 310, -50], [192, 236, -52], [-1040, -874, 146], [-358, -491, -41], [2884, 369, 43], [-2375, 87, 189], [-1298, -270, -14], [3558, 186, -162], [2860, -15, -21], [3458, -511, 191], [2706, -260, 120], [3960, -122, 186], [-2360, 333, 31], [1574, 403, 241], [3727, -1291, -241], [1640, -262, 266], [233, -395, -101], [310, 667, -479], [-3313, -275, 163], [1462, 354, 22], [-995, -654, -618], [-3254, 21, 175], [2393, -1449, -63], [3037, -52, -52], [2296, 20, 136], [4358, -416, 40], [2166, -2302, -342], [4080, -814, -162], [4089, -886, 290], [3989, 63, 165], [-4323, 1135, -167], [-1960, 1626, -118], [-2026, -1824, 572], [-4413, -1363, 527], [268, 372, -440], [751, -1830, -834], [5538, -90, -246], [4823, 1671, 285], [-10, 150, -826], [9311, -377, -299], [12438, -1837, -271], [-3926, -1281, -335], [2286, -2682, -666], [-2255, 686, -742], [-1184, -2738, 874], [1273, 1019, -979], [1490, -510, -46], [-736, -1298, 86], [-4769, -1534, -358], [-3646, 479, 509], [-617, 287, -31], [-750, -750, -570], [-2532, -1655, -609], [472, 1086, -782], [1511, 1537, -497], [9059, -1629, -39], [-4268, 812, 788], [-15588, -623, -861], [6972, 2147, -291], [1286, 2734, 386], [-97, -789, -411], [-7879, -464, 400], [-2362, -577, 533], [-12418, -558, 446], [4088, 2442, -1186], [-159, 2060, 1220], [-3527, 1182, 702], [5086, -646, 182], [198, 984, 1032], [6887, -2729, -359], [-490, -2529, -1635], [9380, 3282, 314], [1489, -891, -597], [-142, -284, 1124], [-4112, -5331, 895], [-8028, -1236, -1680], [-11665, 3247, 925], [-9869, 146, 398], [-14074, 3225, 803], [12278, -1359, 239], [4339, 5457, -1161], [11202, 2013, 771], [1974, 568, 1624], [14582, -648, 896], [-1847, 2388, -2088], [2289, 4877, -97], [1515, -437, 2461], [-15282, -384, 384], [-11567, 2336, -1180], [4298, 684, 84], [-12280, 5292, -232], [4861, -3714, -222], [-25618, -2576, -88], [6380, 1594, 2662], [19322, -5899, -853], [8822, -2358, 1274], [-4604, 3138, 798], [-1500, 1775, 1569], [9288, 3472, -800], [-9360, -3807, 639], [11557, -3477, -783], [3788, -4444, -868], [-12125, -2997, -1431], [-16236, -3694, 966], [-16724, -1662, -1362], [7750, -924, 1564], [8470, 50, -1618], [5076, -2610, -2250], [12197, -2673, -1143], [35826, -1538, 138], [27605, 1167, 1569], [-11868, -5202, -930], [14561, 2403, 549], [-16074, -6020, 864], [20865, 4436, -4], [-9562, 7537, 1535], [24438, 6482, -906], [8672, 3830, -2650], [-10745, 6872, -1468], [11594, 6759, -31], [8522, 4860, 2132], [30532, -8208, -884], [-10279, -7254, -774], [-2773, 715, -1487], [865, 2102, -910], [-27918, -2723, 519], [-19030, 2529, -133], [-28710, -808, -1816], [3796, -1392, -3248], [-45955, 960, -648], [175, 3264, 228], [-39032, 4228, 4], [-1463, -2683, 1091], [22224, 3169, -57], [27216, -7168, -1240], [20063, -4901, -2591], [3989, -9366, -654], [-8394, -6609, -1683], [3239, 7563, 897], [-15648, 2134, -2226], [-15730, 264, -3040], [18878, -4427, -2305], [-506, -64, 152], [8867, -7889, -1295], [-35315, -3226, -502], [13854, 1742, -1494], [3263, 9568, 904], [-24348, 3423, 2889], [-976, 2364, -660], [-70912, -126, 98], [498, -4193, 1041], [100, 6174, 2170], [-19603, -9963, 279], [23382, 9880, -1160], [-51606, 516, 348], [20240, -2046, 3890], [-3140, 4601, 2395], [-929, 7149, -2349], [-14526, -9040, -496], [-1954, 2920, 4192], [-8390, -3602, -326], [-11524, -9083, 1127], [30288, -8368, -952], [-22448, -13461, 3817], [4236, -8124, -900], [22256, -6470, -3458], [-231, -1931, -1121], [34650, 10941, -2913], [10222, 3269, 2831], [24130, 731, 3853], [67772, 2656, 452], [-8425, -9701, 1393], [47870, -2277, -1935], [15252, -7108, 2052], [2624, -1514, 2558], [49734, -7188, -264], [13727, -6411, 3495], [-33979, -1457, -5159], [-4194, 2336, 4620], [-10870, 15549, 2199], [-47012, -5579, 3463], [62438, -1278, -2706], [55204, 998, -758], [24010, -8590, -1538], [-47651, 16320, 2028], [34, 978, -3710], [16747, 8243, -1351], [43076, 12292, -2996], [-32749, 2004, 864], [45378, -13976, -720], [-7299, 5945, -169], [-23354, 9222, 22], [-31993, -10274, 10], [-35556, 2957, -3753], [-22836, 9576, 912], [26278, -3710, -4142], [47702, -7410, -4186], [37233, -4405, -3259], [16623, 11564, -3088], [20686, -6340, -5116], [-9456, 13644, -876], [34876, 15320, -836], [50369, -2096, 3796], [39110, 8518, -3514], [35080, 872, -1648], [81096, -1992, 312], [-29173, -9477, 777], [5300, -7410, -4498], [-39690, 13348, 2340], [39605, -15947, -2225], [-57642, -2953, -2955], [8046, 1703, 3669], [-39529, 13455, -1539], [1479, 809, 5663], [35676, 8145, 1575], [-24680, 10983, -6051], [-43747, -7857, 2289], [-23914, -805, -4687], [21157, -5175, -2181], [4495, 1737, 3003], [-35770, 22972, 4604], [22621, 2445, -1365], [4896, -14751, -4005], [58694, -20098, -1330], [-77612, -5920, 56], [-51252, 6133, 4935], [-27553, 22957, -545], [-12568, -6330, -102], [8723, 22480, -2744], [71, 16410, -3726], [18836, 13915, -431], [69388, 3012, -4620], [-4588, 3391, -7015], [49197, 2599, -4451], [-8339, -4747, -1129], [-22776, -18896, 2748], [3668, 9238, 194], [-46221, 5608, 3172], [24214, 2878, 2386], [-66421, 6421, 2503], [-18056, 18174, 7314], [52534, 4674, 5830], [46765, -12958, -1402], [-64068, -2739, 5427], [-47297, -13128, 1356], [-12450, -15978, 582], [-11688, 1870, 2466], [-5910, 21227, 873], [55318, -7074, -1586], [-24708, 17544, 3960], [81001, 9095, -2179], [16044, -20533, -6663], [25673, -5213, 5773], [-47768, 2842, -3878], [-32118, -3878, 2778], [-53285, -11817, -7887], [-55662, -280, -1888], [-33920, 57, -11261], [-10094, -181, -1903], [-15158, -8513, -9779], [-101409, 799, -5279], [44979, -845, 12361], [23192, -8799, -5233], [633, -15691, 3551], [-32164, -3962, -3910], [41149, 9293, 8327], [-25648, -10050, -1906], [-14882, 6068, -6392], [34138, -2718, 8686], [1728, -3584, 2440], [-109864, 7136, -2800], [9745, -13899, 5703], [-81600, 5235, 5301], [32096, -18816, -4444], [1079, 21316, -404], [-35214, 11310, 4194], [-77171, 13551, -2679], [36913, 12701, -4729], [-16368, 1713, 9003], [-57727, 20811, 1581], [-38482, -5646, 4022], [168011, -4142, 214], [79861, -5755, 3299], [-97799, 15081, 3207], [87936, 4334, 7602], [-85620, 2841, 1383], [98047, -1, 3125], [-107452, 7893, 3203], [-26831, -16821, 4437], [47662, 14466, 1126], [-57359, -4879, -5401], [-126946, -3466, -4690], [3230, -4794, -7518], [-57688, 8142, -7606], [-51125, -8460, 6684], [20375, -13052, -8336], [45097, -10447, 7811], [-60328, -6916, 5060], [17502, -30525, -5067], [18049, 92, 1424], [-18312, 10919, -1023], [-68024, 16783, 2077], [-1471, -2435, 31], [8776, 17282, 2198], [76782, 8196, 12204], [33372, -6995, 4575], [66500, -26168, -1280], [-56784, 6343, -13259], [-19802, 6940, -1148], [-5886, -3679, -2557], [51001, -20671, -4789], [-52814, 20896, -1100], [51422, -23364, -3184], [-6074, -29211, -4493], [73560, -14284, -6168], [89970, -6432, 7704], [32418, 1336, 6712], [31378, -15898, -10634], [-75070, -12540, 884], [-1590, -28366, 6150], [-118055, 10635, -2379], [-88268, -16405, -8239], [-16004, 31834, 2470], [-48977, -25603, 6131], [-40368, 33949, 2911], [-9682, 24981, -2125], [-9963, -17497, 9449], [47494, 41172, -4424], [-13824, -1425, -3723], [-42761, -19155, 6963], [-70565, 17825, -5845], [-104520, -7096, -732], [102352, -644, -4136], [8116, -39027, 2679], [85448, 16290, 1598], [-3135, 4733, 8783], [37340, -10346, 398], [-100344, -1782, -5370], [200848, -208, 2936], [-22268, -7576, 12172], [58128, -31570, -4654], [-30280, 2842, -15802], [-70423, -7149, 8661], [79718, -27002, 3946], [63269, -1725, -6579], [-6942, -29958, 5634], [-111671, -30928, 7424], [93758, -11100, -6052], [18146, 36135, -8779], [-42197, -35157, 3693], [156390, -25996, -6492], [27496, -26389, -4831], [145382, -8987, -689], [72162, 22728, -7176], [-127359, 12667, -6419], [85820, -25131, 1571], [-63962, 3558, -7326], [-88452, 46892, 3480], [-5216, -23380, 7844], [70202, -9624, 6344], [83068, -1935, 12739], [2483, 23488, 13012], [33462, 11560, -9656], [-61720, 11222, 3434], [-164351, 2601, -9705], [-22762, 5121, -14149], [23008, -37635, 1407], [32034, -2365, 11073], [92018, 38981, -6937], [95704, 7610, 1430], [-45273, -1385, -11219], [-67468, 5313, 2555], [70858, 7626, 142], [-18335, 18963, 2157], [49092, 35484, -7644], [-69796, 5358, 2678], [141662, 8367, -3439], [-3433, -9329, -15827], [74156, 16058, 9998], [35728, -47201, -2447], [68290, 17316, 7380], [106762, -26268, -10400], [-228988, 14191, 737], [-120, -43392, -3288], [115344, -7798, -1234], [-138128, 24228, -1244]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_441_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_441_4_a_t();".
// 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_441_4_a_t(:prec:=3)
    chi := MakeCharacter_441_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_441_4_a_t();".
// 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_441_4_a_t( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_441_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-6, -24, 1, 1]>,<5,R![1236, -192, -11, 1]>,<13,R![-18452, 425, 62, 1]>],Snew);
    return Vf;
end function;