
// Make newform 441.4.a.v in Magma, downloaded from the LMFDB on 25 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_v();".
// 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_v();".
// 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 := [42, 0, -19, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-10, 0, 1, 0], [0, -15, 0, 1]];
    Rf_basisdens := [1, 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, 0, 0], [0, -1, 0, -1], [0, 0, 0, 0], [0, -1, 0, 3], [-25, 0, 1, 0], [0, -26, 0, 2], [-61, 0, -11, 0], [0, 46, 0, 2], [0, -45, 0, -1], [-45, 0, 20, 0], [-81, 0, 25, 0], [0, -72, 0, -16], [-223, 0, -27, 0], [0, 44, 0, 16], [0, -1, 0, 7], [0, 73, 0, 17], [-310, 0, 46, 0], [463, 0, -19, 0], [0, 0, 0, 36], [-441, 0, -7, 0], [23, 0, 42, 0], [0, 189, 0, 21], [0, 314, 0, -22], [-798, 0, -91, 0], [0, 478, 0, -26], [-509, 0, 3, 0], [0, -71, 0, 1], [-255, 0, -5, 0], [0, -288, 0, -124], [105, 0, -206, 0], [0, 269, 0, 17], [0, 98, 0, -86], [291, 0, 125, 0], [0, 46, 0, -154], [-1180, 0, 207, 0], [-214, 0, 358, 0], [1912, 0, 170, 0], [0, -738, 0, 130], [0, 26, 0, -114], [0, -604, 0, 104], [647, 0, -461, 0], [0, 748, 0, 16], [-2665, 0, -162, 0], [0, -126, 0, -58], [-3372, 0, -4, 0], [784, 0, -88, 0], [740, 0, 235, 0], [0, -557, 0, -193], [487, 0, -477, 0], [0, 406, 0, -118], [0, -162, 0, 78], [-830, 0, -615, 0], [0, 1557, 0, -11], [0, -1198, 0, 174], [0, 296, 0, -240], [0, 865, 0, 221], [-4924, 0, 265, 0], [2641, 0, -91, 0], [0, 18, 0, -314], [-4861, 0, 391, 0], [0, -747, 0, -103], [-4375, 0, -245, 0], [0, 748, 0, -316], [5221, 0, 702, 0], [0, -1961, 0, -109], [299, 0, -861, 0], [-4835, 0, -568, 0], [0, 836, 0, 416], [-5782, 0, 616, 0], [0, 352, 0, 324], [0, 154, 0, 42], [1017, 0, -340, 0], [1211, 0, 375, 0], [5343, 0, 307, 0], [0, -2314, 0, 346], [0, -1522, 0, -494], [-4779, 0, -403, 0], [0, 640, 0, 44], [-5033, 0, -966, 0], [0, -2916, 0, 444], [-11131, 0, 405, 0], [0, -1432, 0, -572], [-1291, 0, 1903, 0], [-1308, 0, -415, 0], [0, -125, 0, -685], [0, 486, 0, 18], [-1319, 0, -82, 0], [0, -342, 0, 386], [4339, 0, 1847, 0], [0, -3484, 0, -824], [0, -2384, 0, 220], [-4301, 0, -40, 0], [0, -4221, 0, 223], [5425, 0, 1235, 0], [0, 378, 0, 714], [0, -2899, 0, -603], [0, 1864, 0, -544], [-7447, 0, 1531, 0], [341, 0, 1989, 0], [9160, 0, 458, 0], [0, 1493, 0, 393], [0, 1441, 0, 1329], [0, -4598, 0, 538], [-7723, 0, 477, 0], [14117, 0, -1340, 0], [0, 1719, 0, -437], [0, 350, 0, 238], [0, -3610, 0, -866], [15633, 0, -256, 0], [-8747, 0, -720, 0], [-12914, 0, -2308, 0], [0, 5076, 0, -252], [293, 0, -215, 0], [19796, 0, -87, 0], [0, 5660, 0, -512], [8227, 0, -1383, 0], [0, 1900, 0, 556], [0, 2989, 0, 137], [0, 3564, 0, -456], [13121, 0, 1849, 0], [-8285, 0, 1922, 0], [0, 1043, 0, 1351], [0, 3401, 0, 1129], [325, 0, -2547, 0], [0, -6453, 0, 915], [13266, 0, -2036, 0], [0, -2890, 0, 862], [8821, 0, -618, 0], [14823, 0, 2603, 0], [-21423, 0, 2047, 0], [0, -7506, 0, -1122], [-25859, 0, 110, 0], [5570, 0, 2310, 0], [0, 9566, 0, -1046], [-9455, 0, 3174, 0], [0, -2690, 0, 1342], [18392, 0, -944, 0], [0, -657, 0, 967], [0, 1268, 0, 928], [6808, 0, 1770, 0], [0, 5995, 0, 219], [25188, 0, 2884, 0], [0, -1269, 0, 411], [5095, 0, 4041, 0], [0, -1278, 0, -1670], [-11243, 0, -4905, 0], [0, -3860, 0, 1068], [-29384, 0, -648, 0], [0, -5210, 0, -778], [-15962, 0, 1646, 0], [0, -7074, 0, -942], [11483, 0, 879, 0], [0, -1846, 0, 1962], [6911, 0, -4635, 0], [0, 432, 0, -1980], [-12949, 0, 1191, 0], [0, -2512, 0, -804], [18789, 0, 488, 0], [0, 2755, 0, 571], [0, -1052, 0, 396], [0, 4284, 0, -80], [38599, 0, -1846, 0], [0, 4859, 0, -1469], [0, -12628, 0, -116], [0, 7624, 0, -1084], [-16651, 0, -288, 0], [42689, 0, 43, 0], [-25259, 0, -3910, 0], [0, 2555, 0, -441], [0, 5525, 0, 2977], [-8886, 0, 146, 0], [0, 370, 0, 1562], [749, 0, -1032, 0], [-46349, 0, 774, 0], [0, 2304, 0, 1016], [5779, 0, 1739, 0], [0, 12077, 0, 1029], [-16524, 0, -3352, 0], [10049, 0, -71, 0], [-7171, 0, 5736, 0], [0, 14715, 0, 1863], [-43183, 0, -2145, 0], [0, -14518, 0, -1554], [0, -13762, 0, 310], [0, 7363, 0, 2911], [24490, 0, 590, 0], [-13111, 0, 6559, 0], [16837, 0, -70, 0], [0, -62, 0, -2190], [50519, 0, -812, 0], [0, 11745, 0, 1785], [46688, 0, -3738, 0], [0, -2494, 0, -170], [0, -14437, 0, -1701], [0, -13994, 0, -1282], [-20077, 0, 453, 0], [12138, 0, -7934, 0], [0, -4644, 0, -2628], [0, 6668, 0, 4456], [0, 8477, 0, -2095], [-14939, 0, -915, 0], [31518, 0, -1492, 0], [-41710, 0, -2204, 0], [0, -10116, 0, 1700], [0, -5363, 0, 3625], [-7020, 0, -1780, 0], [0, 2773, 0, 2729], [0, 7074, 0, 234], [-26344, 0, -8618, 0], [12039, 0, 7321, 0], [0, -11313, 0, -2493], [21244, 0, 6179, 0], [0, -9253, 0, -2701], [0, -23030, 0, 2086], [5825, 0, 3463, 0], [-8572, 0, -7059, 0], [0, 4510, 0, 198], [0, 20854, 0, -2246], [0, -17550, 0, -2850], [66365, 0, 2961, 0], [-76669, 0, -3581, 0], [0, -5336, 0, -396], [11756, 0, -969, 0], [0, -11061, 0, -1513], [2846, 0, -8622, 0], [0, 7298, 0, -4798], [0, 16892, 0, -1108], [-63527, 0, -150, 0], [0, -23264, 0, 548], [64405, 0, 3857, 0], [-29704, 0, 9568, 0], [-51637, 0, -1842, 0], [0, -13078, 0, -2790], [-25017, 0, -1927, 0], [0, 16426, 0, -850], [6731, 0, -4838, 0], [0, 15085, 0, 3297], [0, -1944, 0, -4800], [0, 20286, 0, 2282], [0, 24560, 0, -1772], [20067, 0, 12275, 0], [-38793, 0, 1538, 0], [74854, 0, 3056, 0], [0, 10422, 0, 2526], [0, -5608, 0, 1868], [1337, 0, -5054, 0], [0, -620, 0, 2992], [-50528, 0, -664, 0], [0, 7992, 0, -5496], [1217, 0, -9837, 0], [0, 24488, 0, 604], [0, 21374, 0, -4410], [-65989, 0, 5173, 0], [0, 4429, 0, -4335], [0, -13049, 0, -3309], [2813, 0, -687, 0], [-37851, 0, 1229, 0], [0, 14121, 0, -2847], [11974, 0, -10473, 0], [60371, 0, -4797, 0], [0, -7137, 0, 1579], [-77561, 0, -3519, 0], [-17291, 0, 1017, 0], [0, 17092, 0, 5836], [-67673, 0, -1875, 0], [0, -22707, 0, 4665], [0, 234, 0, 5974], [36712, 0, 8732, 0], [0, 9953, 0, -1779], [-54175, 0, 361, 0], [-2416, 0, -8346, 0], [-36469, 0, 1300, 0], [14423, 0, 816, 0], [-21406, 0, -10913, 0], [37972, 0, 11052, 0], [0, 13393, 0, -2567], [-31341, 0, 15169, 0], [23695, 0, 3125, 0], [0, 6020, 0, 5712], [0, 3592, 0, 1240], [25599, 0, 10378, 0], [0, -11682, 0, 3158], [-56479, 0, -4019, 0], [60856, 0, 9006, 0], [0, -5966, 0, -5470], [-99215, 0, -2614, 0], [0, -36531, 0, 4029], [-80297, 0, -9702, 0], [0, -4104, 0, -4692], [0, 1754, 0, 186], [0, -1601, 0, -2973], [0, 9820, 0, -5296], [0, -6156, 0, -7836], [-35849, 0, -10639, 0], [0, -22265, 0, -9525], [-46777, 0, -8513, 0], [0, 10890, 0, -3922], [0, 17612, 0, -3024], [125989, 0, 729, 0], [-25770, 0, 1952, 0], [0, 27649, 0, 125], [53524, 0, -7231, 0], [0, -22725, 0, -4921], [-37719, 0, -4547, 0], [64281, 0, -3413, 0], [0, 8387, 0, -5597], [8283, 0, -11323, 0], [0, -12014, 0, 5506], [49243, 0, -7903, 0], [0, 21482, 0, -1562], [0, 5606, 0, 4922], [0, 19774, 0, 3950], [-9576, 0, -9776, 0], [0, -8298, 0, 2542], [-47405, 0, 10761, 0], [0, -33291, 0, -867], [0, 21986, 0, 8638], [61547, 0, -2876, 0], [0, 27432, 0, 6048], [-26849, 0, -5277, 0], [-41309, 0, 1337, 0], [0, 13041, 0, 6237], [6815, 0, -23049, 0], [0, -33652, 0, -212], [-1405, 0, -26618, 0], [121507, 0, -4093, 0], [120967, 0, -5691, 0], [0, -18386, 0, 78], [0, 21789, 0, 9693], [-105623, 0, 4217, 0], [0, 7109, 0, -5987], [-87329, 0, -1665, 0], [0, 37972, 0, 284], [-13709, 0, 11945, 0], [0, -16452, 0, -800], [116630, 0, 9420, 0], [0, -3016, 0, 2584], [-46601, 0, -9852, 0], [-2641, 0, -11294, 0], [17551, 0, -7609, 0], [0, -32166, 0, -9086], [0, -10719, 0, -6015], [2797, 0, -24022, 0], [0, -18413, 0, -2901], [0, 17721, 0, -6955], [-40525, 0, 1537, 0], [56608, 0, -10474, 0], [0, 21006, 0, 5214], [0, 46961, 0, 3309], [97112, 0, -8318, 0], [7926, 0, 13279, 0], [0, 50742, 0, -466], [-8412, 0, 14927, 0], [-6833, 0, 2099, 0], [0, -5256, 0, -2260], [0, -20404, 0, 4096], [0, -33911, 0, -3391], [0, 15400, 0, 1956], [0, 50922, 0, -3486], [93486, 0, -10946, 0], [0, -34336, 0, 356], [0, 17522, 0, 7594], [0, 12772, 0, -5316], [70399, 0, 8757, 0], [-54518, 0, 12383, 0], [0, 36378, 0, -1030], [65329, 0, 2801, 0], [-23622, 0, -8291, 0], [0, -17047, 0, -10895], [69759, 0, 27047, 0], [0, 52534, 0, 2642], [0, -53217, 0, 2451], [-73019, 0, -20163, 0], [-2231, 0, -21973, 0], [0, 9892, 0, 7344], [0, 31518, 0, 7226], [83662, 0, -15123, 0], [0, -34642, 0, -5186], [-98925, 0, 5273, 0], [0, -40454, 0, -1730], [0, 16092, 0, -3996], [25876, 0, 22556, 0], [0, -21862, 0, 10118], [3000, 0, -7372, 0], [0, -51884, 0, -1652], [140255, 0, 10287, 0], [-39586, 0, -22202, 0], [74315, 0, -1563, 0], [0, 63558, 0, -4566], [8809, 0, -1864, 0], [0, -27982, 0, 2986], [0, 33047, 0, -4349], [89125, 0, -17607, 0], [0, -5318, 0, 8082], [-48506, 0, 5903, 0], [-16348, 0, 23491, 0], [0, -72630, 0, 3810], [157527, 0, -5531, 0], [0, -57691, 0, 3853], [-185174, 0, -11124, 0], [0, 8902, 0, 9858], [39868, 0, 22664, 0], [0, 8702, 0, -650], [0, 43957, 0, 3833], [-94513, 0, 10666, 0], [82170, 0, -956, 0], [0, 43704, 0, -992], [134083, 0, -1557, 0], [0, 27017, 0, 14725], [78958, 0, -12771, 0], [0, 10045, 0, 297], [0, -23175, 0, 7093], [82456, 0, -8116, 0], [28401, 0, -28889, 0], [0, -53731, 0, 2521], [0, -5264, 0, 9944], [36511, 0, 13155, 0], [0, -8046, 0, -5190], [0, 62540, 0, 4216], [0, 3689, 0, -7439], [-125227, 0, 463, 0], [0, -17316, 0, 11260], [0, 31653, 0, -6763], [19606, 0, 34764, 0], [0, 47134, 0, 2810], [0, -15911, 0, 13609], [0, -36018, 0, 7278], [129624, 0, -9334, 0], [0, 26956, 0, -3676]];
    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_v();".
// 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_v(:prec:=4)
    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_v();".
// 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_v( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_441_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![42, 0, -19, 0, 1]>,<5,R![32928, 0, -433, 0, 1]>,<13,R![602, 51, 1]>],Snew);
    return Vf;
end function;