
// Make newform 441.4.a.u 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_u();".
// 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_u();".
// 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 := [194, 36, -35, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-79, 100, 3, -2], [-182, 12, 11, -1], [-392, -265, 12, 11]];
    Rf_basisdens := [1, 57, 19, 57];
    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 := [[-1, -1, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 0], [-22, 6, 0, 0], [0, 0, 6, 1], [0, 0, 1, -9], [0, 0, -11, -4], [-92, -8, 0, 0], [-58, 14, 0, 0], [0, 0, -38, 4], [50, -6, 0, 0], [0, 0, 31, -3], [170, 70, 0, 0], [0, 0, 26, -32], [-22, -36, 0, 0], [0, 0, -49, 20], [0, 0, 68, -27], [-524, -76, 0, 0], [-548, 28, 0, 0], [0, 0, -37, -25], [-356, -188, 0, 0], [0, 0, -1, 8], [0, 0, 157, 75], [0, 0, -189, 91], [0, 0, -8, 7], [0, 0, 14, 132], [-932, 20, 0, 0], [-314, -370, 0, 0], [460, -238, 0, 0], [464, 140, 0, 0], [0, 0, -111, -56], [-428, 20, 0, 0], [0, 0, 305, -284], [398, -512, 0, 0], [1632, 204, 0, 0], [0, 0, -350, 183], [386, -314, 0, 0], [0, 0, 362, -152], [0, 0, -358, 233], [-932, 412, 0, 0], [0, 0, 498, 83], [-1884, -204, 0, 0], [-1280, 554, 0, 0], [-170, 1092, 0, 0], [0, 0, -118, -28], [-964, 84, 0, 0], [0, 0, 152, 156], [0, 0, 129, -340], [0, 0, -50, 315], [1560, 664, 0, 0], [-1668, -1064, 0, 0], [0, 0, -75, -99], [0, 0, -521, -144], [0, 0, -593, -183], [-2332, 412, 0, 0], [0, 0, -334, 543], [0, 0, 456, -380], [-3338, -440, 0, 0], [-5728, -336, 0, 0], [0, 0, 633, 96], [0, 0, 532, -385], [0, 0, -673, -496], [0, 0, 232, 544], [0, 0, -655, 395], [3422, 132, 0, 0], [-3982, -258, 0, 0], [898, -742, 0, 0], [118, 34, 0, 0], [0, 0, -214, -689], [0, 0, 77, 237], [-6224, 1364, 0, 0], [0, 0, 1860, 332], [7218, 512, 0, 0], [-7586, 490, 0, 0], [0, 0, -1138, 880], [-162, 1126, 0, 0], [0, 0, -42, -743], [-7470, -1142, 0, 0], [0, 0, 615, 79], [0, 0, -775, 712], [-1930, 952, 0, 0], [-13532, -456, 0, 0], [0, 0, 515, -543], [0, 0, -572, 284], [-3732, 1980, 0, 0], [-2270, 2576, 0, 0], [-4584, 2346, 0, 0], [0, 0, 1538, 289], [4608, 3080, 0, 0], [0, 0, -393, 268], [0, 0, -822, 44], [4236, 1744, 0, 0], [-1612, -3108, 0, 0], [4964, 1604, 0, 0], [0, 0, 1380, 132], [0, 0, 1082, -577], [0, 0, -739, 1361], [0, 0, -1065, 1036], [-2078, -5032, 0, 0], [-14642, -2310, 0, 0], [14566, 972, 0, 0], [0, 0, 2039, -556], [19046, 174, 0, 0], [-2890, -3646, 0, 0], [0, 0, 941, 1405], [0, 0, -77, 1204], [0, 0, -651, 407], [-13168, -3480, 0, 0], [0, 0, -1555, 827], [0, 0, -1460, 416], [5034, -3758, 0, 0], [20746, 1890, 0, 0], [0, 0, 2475, -1872], [10684, -1876, 0, 0], [12102, -1618, 0, 0], [0, 0, 353, -1452], [0, 0, 3430, -1156], [650, -1422, 0, 0], [-11846, 1582, 0, 0], [0, 0, -2788, -361], [9508, -28, 0, 0], [0, 0, -1054, 61], [1756, -2276, 0, 0], [0, 0, 959, 2176], [13690, -3374, 0, 0], [-2190, 3130, 0, 0], [0, 0, -3254, -1176], [0, 0, -2474, 2544], [0, 0, 380, -1893], [11418, 4558, 0, 0], [-12224, 1764, 0, 0], [11404, -2792, 0, 0], [-16182, 3122, 0, 0], [0, 0, 4101, -845], [0, 0, 3585, -1779], [0, 0, -2992, 1969], [0, 0, -335, -1036], [0, 0, -5046, -841], [15056, 1602, 0, 0], [0, 0, 2525, 1360], [33018, 664, 0, 0], [-26648, -720, 0, 0], [20452, -3724, 0, 0], [0, 0, -2868, 1077], [0, 0, -962, 3188], [0, 0, 3922, 1307], [0, 0, -4065, 991], [0, 0, -2365, 2784], [-4348, -5300, 0, 0], [3242, 8674, 0, 0], [0, 0, 2695, 2499], [-16476, -6916, 0, 0], [0, 0, 5390, 1912], [21596, 1044, 0, 0], [11688, 8484, 0, 0], [-32864, 1912, 0, 0], [0, 0, -1143, -2097], [0, 0, -221, 2503], [0, 0, -2492, 699], [-9206, 4430, 0, 0], [-27638, -5628, 0, 0], [2676, 1456, 0, 0], [0, 0, -5737, 1412], [3716, -10508, 0, 0], [0, 0, 2050, -140], [-11360, -9960, 0, 0], [0, 0, 6264, -817], [8192, 5670, 0, 0], [0, 0, 5202, -3605], [-4964, 1476, 0, 0], [0, 0, 130, -2951], [-22324, -5356, 0, 0], [7960, 8072, 0, 0], [0, 0, 2366, 2024], [0, 0, -5273, -3043], [5084, -3836, 0, 0], [15798, 6670, 0, 0], [0, 0, -5424, -120], [0, 0, -1676, 3355], [-25948, -1504, 0, 0], [0, 0, 4117, -2556], [31446, -322, 0, 0], [0, 0, -479, -1711], [25752, -7652, 0, 0], [0, 0, 598, 4581], [4222, 260, 0, 0], [0, 0, 1493, -148], [48700, 1884, 0, 0], [0, 0, 2130, -5988], [0, 0, 3557, -4755], [-19308, 7868, 0, 0], [-10604, 7876, 0, 0], [0, 0, 966, 799], [-24228, -6756, 0, 0], [0, 0, -7727, 6347], [38242, -3814, 0, 0], [42274, 5818, 0, 0], [0, 0, 1879, 2363], [0, 0, -5840, -2300], [-47678, 2204, 0, 0], [0, 0, 4602, -3300], [0, 0, -9928, 2521], [0, 0, -3999, 4917], [0, 0, 9337, -5900], [0, 0, 9540, -1603], [0, 0, -6930, 1196], [-44346, -2038, 0, 0], [16868, 1106, 0, 0], [0, 0, 3877, -6760], [29898, 14274, 0, 0], [0, 0, 6092, -177], [-45344, 7420, 0, 0], [0, 0, -9169, 4200], [0, 0, 1328, 316], [0, 0, -1013, 5429], [3200, 20000, 0, 0], [0, 0, -2551, -971], [552, 5816, 0, 0], [-20582, -17150, 0, 0], [-706, -4122, 0, 0], [0, 0, 3960, -4828], [51218, 356, 0, 0], [-37876, -2792, 0, 0], [0, 0, 627, -7564], [-45218, 630, 0, 0], [0, 0, -10099, -2437], [-12132, 10800, 0, 0], [0, 0, -2008, 4044], [4346, -10018, 0, 0], [59886, 2262, 0, 0], [0, 0, 1333, -4328], [24768, -9912, 0, 0], [18318, -16892, 0, 0], [0, 0, 5333, -2288], [0, 0, 2024, 4436], [0, 0, 8543, -2727], [35846, 10856, 0, 0], [-14884, -3332, 0, 0], [0, 0, -9580, -584], [-36702, 10142, 0, 0], [0, 0, -3257, -2484], [0, 0, 4268, 5764], [-30890, -5508, 0, 0], [0, 0, -4719, -5907], [0, 0, 8802, 348], [0, 0, -6356, 672], [0, 0, -1317, 2296], [16290, -8826, 0, 0], [-65256, 6104, 0, 0], [-12262, -6272, 0, 0], [0, 0, -1651, 4669], [32780, 2708, 0, 0], [0, 0, 1691, -5443], [0, 0, -8276, -2477], [-10284, 7132, 0, 0], [-36490, -1266, 0, 0], [0, 0, -5803, 540], [0, 0, -4048, -1377], [0, 0, 8593, 1073], [-23036, -24632, 0, 0], [-45810, -14182, 0, 0], [0, 0, -12536, -2751], [0, 0, -4664, 2179], [0, 0, 10923, -9125], [0, 0, 12879, 4732], [-25090, 10696, 0, 0], [0, 0, 5261, -1957], [41204, -16380, 0, 0], [-45270, -9934, 0, 0], [0, 0, -11626, 2343], [10662, -5102, 0, 0], [0, 0, -9769, 1629], [-12928, 18180, 0, 0], [0, 0, 4199, -4927], [0, 0, 9236, -5184], [-26090, -24718, 0, 0], [71954, 3340, 0, 0], [-138228, -1378, 0, 0], [0, 0, -9851, 4504], [0, 0, 8540, 2652], [-25304, 9976, 0, 0], [0, 0, 314, 10032], [0, 0, 17780, 2065], [0, 0, -8435, 11864], [6152, 27572, 0, 0], [-11682, 1884, 0, 0], [278, 3444, 0, 0], [0, 0, -9794, -3624], [0, 0, 10523, -2109], [10618, 21076, 0, 0], [0, 0, -17075, -2008], [92714, -6686, 0, 0], [0, 0, -807, -8048], [78262, -1008, 0, 0], [0, 0, -4686, -6529], [0, 0, -2040, -9364], [0, 0, 12818, -12531], [0, 0, -7283, 5632], [0, 0, 3715, 5560], [0, 0, -15905, 4263], [-40342, -17102, 0, 0], [-37400, 4880, 0, 0], [143358, -7294, 0, 0], [62714, 3158, 0, 0], [13764, -6188, 0, 0], [95094, -1590, 0, 0], [0, 0, 4468, -7667], [7804, 26256, 0, 0], [-75634, 3536, 0, 0], [0, 0, -10024, -2372], [108086, -722, 0, 0], [-127212, 5620, 0, 0], [-96886, -19634, 0, 0], [-57892, -3276, 0, 0], [0, 0, 3973, -8221], [0, 0, 3671, -4476], [-51864, 8000, 0, 0], [0, 0, -13409, 1579], [72952, 10024, 0, 0], [0, 0, 15069, -872], [-65036, -28412, 0, 0], [0, 0, -22072, 12181], [-107756, -2604, 0, 0], [-16920, -18278, 0, 0], [0, 0, 1029, -3137], [-82354, 1170, 0, 0], [0, 0, -14145, 4400], [7664, -35540, 0, 0], [34130, -27734, 0, 0], [59578, 17620, 0, 0], [-68454, -5566, 0, 0], [0, 0, -11766, 3576], [0, 0, 14081, -10596], [26860, -2428, 0, 0], [0, 0, -8343, 6572], [-98362, -30338, 0, 0], [0, 0, 67, 1859], [0, 0, -11055, -2847], [0, 0, 19830, -13244], [36002, -21580, 0, 0], [-46622, -7910, 0, 0], [0, 0, -682, -2923], [-3708, 23884, 0, 0], [-5678, 10058, 0, 0], [124458, 20118, 0, 0], [0, 0, 10818, 3533], [53390, -5158, 0, 0], [0, 0, -2912, -9828], [0, 0, -4900, -11759], [0, 0, -23839, -3616], [46838, 15184, 0, 0], [-102286, -4452, 0, 0], [0, 0, 10994, 6612], [79290, 3452, 0, 0], [0, 0, 22599, -6499], [0, 0, 27270, 4084], [0, 0, 26957, 7020], [-36002, 28076, 0, 0], [83396, -3472, 0, 0], [1122, -2800, 0, 0], [0, 0, 3965, -695], [-84568, -23780, 0, 0], [111348, 10884, 0, 0], [0, 0, -9227, 15164], [-75270, -4206, 0, 0], [0, 0, -13662, 15657], [61076, 29240, 0, 0], [-75080, -12166, 0, 0], [105692, 1980, 0, 0], [0, 0, 19401, 8052], [111600, 6656, 0, 0], [-104946, 14560, 0, 0], [0, 0, 11572, -2016], [8058, -2288, 0, 0], [0, 0, -8677, 6212], [-149060, -24584, 0, 0], [0, 0, -10729, -5125], [0, 0, -30973, 7363], [0, 0, -4233, -4993], [0, 0, 21646, -15263], [17904, 37058, 0, 0], [-4408, -2744, 0, 0], [53094, -92, 0, 0], [0, 0, 811, -2372], [0, 0, -17548, 7740], [55756, 57324, 0, 0], [0, 0, 16188, -21857], [-105300, 2836, 0, 0], [0, 0, -16202, 2804], [-79966, 28602, 0, 0], [0, 0, 15776, 927], [35132, 11612, 0, 0], [0, 0, 12045, 11320], [-115760, 12844, 0, 0], [220172, 1100, 0, 0], [0, 0, -3978, -5884], [0, 0, -35995, -4031], [148668, 18788, 0, 0], [-31186, 48726, 0, 0], [0, 0, 23884, 5907], [-25838, -24144, 0, 0], [18880, -21664, 0, 0], [0, 0, 17193, -847], [0, 0, 25422, 477], [0, 0, 8318, -21836], [-165178, 5440, 0, 0], [-11776, -1050, 0, 0], [0, 0, -15841, 8128], [0, 0, 9239, -2308], [0, 0, -19799, -11891], [-77638, 32626, 0, 0], [251466, -10290, 0, 0], [-76964, -23092, 0, 0], [-63488, -30688, 0, 0], [0, 0, -20674, 12751], [-68356, -56148, 0, 0], [0, 0, -12598, -14624], [0, 0, -3013, 7395], [0, 0, 30900, -17172], [-25054, -50198, 0, 0], [0, 0, -9792, -18993], [-175352, 14616, 0, 0], [0, 0, 6489, 1400], [0, 0, 7559, 15821], [0, 0, 2108, -11181], [223082, -20378, 0, 0], [49656, -7224, 0, 0], [0, 0, 19975, 5128], [0, 0, 25326, 12816]];
    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_u();".
// 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_u(: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_u();".
// 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_u( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_441_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-16, 1, 1]>,<5,R![784, 0, -186, 0, 1]>,<13,R![2458624, 0, -3234, 0, 1]>],Snew);
    return Vf;
end function;