
// Make newform 441.6.a.z in Magma, downloaded from the LMFDB on 21 May 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_6_a_z();".
// 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_6_a_z();".
// 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 := [674, 60, -59, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-139, 172, 3, -2], [-1558, -86, 51, 1], [34, -67, -3, 2]];
    Rf_basisdens := [1, 105, 105, 15];
    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 := 6;
    raw_aps := [[2, -1, 0, 0], [0, 0, 0, 0], [0, 0, 8, -2], [0, 0, 0, 0], [494, 12, 0, 0], [0, 0, 56, 64], [0, 0, 152, -7], [0, 0, -78, -53], [1612, -344, 0, 0], [446, -784, 0, 0], [0, 0, 772, 246], [-2326, -48, 0, 0], [0, 0, 224, 1103], [4622, -980, 0, 0], [0, 0, -1644, 590], [24434, -2592, 0, 0], [0, 0, -2914, 1425], [0, 0, -680, -3326], [-11540, -11632, 0, 0], [40612, 4312, 0, 0], [0, 0, -5080, 4407], [-20540, 4264, 0, 0], [0, 0, 6230, 4425], [0, 0, 1016, -6259], [0, 0, 7448, -5873], [0, 0, -2648, -6], [0, 0, 6460, 1234], [55876, 11024, 0, 0], [42430, 9200, 0, 0], [25996, 15680, 0, 0], [-89920, 18032, 0, 0], [0, 0, -1126, -24665], [144148, -9760, 0, 0], [0, 0, 17514, 6695], [-31162, -22688, 0, 0], [-141936, 54336, 0, 0], [0, 0, -5416, 14360], [210278, -5732, 0, 0], [0, 0, 22260, 27134], [0, 0, -42664, -2100], [-217052, 27424, 0, 0], [0, 0, -54152, 6656], [248124, 139992, 0, 0], [509344, -880, 0, 0], [-2354, -51744, 0, 0], [0, 0, -53212, 23190], [-414076, -47040, 0, 0], [0, 0, 25984, 17824], [0, 0, -58886, 19487], [0, 0, -84232, -54316], [-627912, 106672, 0, 0], [889236, 53704, 0, 0], [0, 0, -37896, 113577], [0, 0, 5558, 36473], [0, 0, -9904, 179663], [95036, -62456, 0, 0], [0, 0, -143096, -56312], [0, 0, -35344, 66640], [468814, 157600, 0, 0], [-749632, -261072, 0, 0], [0, 0, -260622, 36111], [0, 0, 104664, -173138], [0, 0, 32102, -224727], [0, 0, 19360, -103320], [0, 0, -37024, 141921], [-1190362, -63456, 0, 0], [-1542298, -248772, 0, 0], [-191966, -440608, 0, 0], [1451314, 333940, 0, 0], [0, 0, -294168, 223136], [0, 0, 39520, 347785], [989536, -414688, 0, 0], [0, 0, 29416, -178636], [1084410, 784736, 0, 0], [154282, 98980, 0, 0], [0, 0, -215172, 121610], [-1728954, 236080, 0, 0], [0, 0, 130136, 27568], [738642, 612352, 0, 0], [0, 0, 248768, -59549], [0, 0, 370818, -12889], [2435246, -86240, 0, 0], [4082572, 281496, 0, 0], [0, 0, -391832, -55661], [0, 0, 465576, -149228], [-4634124, -35232, 0, 0], [4549858, -370048, 0, 0], [-2532840, 576192, 0, 0], [0, 0, -168840, 40196], [1610688, 954128, 0, 0], [0, 0, 911366, -61607], [0, 0, 706228, -39898], [-1717020, -268616, 0, 0], [4696844, 529200, 0, 0], [-944932, -868720, 0, 0], [0, 0, -478296, -673212], [0, 0, -1296952, 189648], [0, 0, -537616, 430233], [0, 0, -1029442, 133081], [-2363174, -513568, 0, 0], [10251082, -54684, 0, 0], [5177806, -1437984, 0, 0], [0, 0, 979886, -737727], [4950038, -115200, 0, 0], [10295666, 273044, 0, 0], [0, 0, 267696, 854873], [0, 0, 1836814, -116907], [0, 0, -317120, -927859], [4020944, 74688, 0, 0], [0, 0, 1100792, -844899], [0, 0, -195000, -784844], [-3263838, 227824, 0, 0], [2112346, 616224, 0, 0], [0, 0, -354282, 73053], [-3712028, -721672, 0, 0], [8277798, 1946432, 0, 0], [0, 0, 409570, -249497], [0, 0, -1317780, 1234762], [3703058, 2874192, 0, 0], [1839598, -2432948, 0, 0], [0, 0, -268504, -591930], [-4818140, -1341424, 0, 0], [0, 0, -475656, -130516], [-8747420, 558304, 0, 0], [0, 0, -86346, 815705], [-587582, -1499792, 0, 0], [19633962, -429680, 0, 0], [0, 0, 1019348, -29362], [0, 0, -121156, 1635938], [0, 0, 454600, 211678], [5019822, 302668, 0, 0], [2088784, 2700096, 0, 0], [1803268, -818936, 0, 0], [23431074, -485296, 0, 0], [0, 0, -302560, -738563], [0, 0, -3331272, -500403], [0, 0, -866280, -209410], [0, 0, 2934906, -953681], [0, 0, -2455544, -317248], [4315280, -1247808, 0, 0], [0, 0, -1647366, -777061], [-12884478, 861664, 0, 0], [-34311848, 314736, 0, 0], [-2622692, -2181088, 0, 0], [0, 0, 2721000, -185526], [0, 0, -1491588, -1627070], [0, 0, 1742328, -416096], [0, 0, 710288, 251611], [0, 0, 1214254, 2150701], [11526524, 5364568, 0, 0], [10647026, -2203088, 0, 0], [0, 0, -2404528, -1190077], [-24312132, -2058784, 0, 0], [0, 0, 886908, 1989482], [13858820, 1111392, 0, 0], [254952, -5992896, 0, 0], [-44874272, 560512, 0, 0], [0, 0, 3229416, 366753], [0, 0, 1268344, -1421409], [0, 0, -4020424, 1434710], [2929054, 3175052, 0, 0], [-33035270, 1110144, 0, 0], [-21881508, -539000, 0, 0], [0, 0, 2929550, -3393447], [-45863548, -215504, 0, 0], [0, 0, -234908, -2182578], [257344, -5538384, 0, 0], [0, 0, 557272, -2434390], [13452896, 3793776, 0, 0], [0, 0, 948200, -228176], [-3569660, -1319040, 0, 0], [0, 0, 7642600, -1023516], [8453972, -6759208, 0, 0], [-19445192, -1705744, 0, 0], [0, 0, -6361108, -690246], [0, 0, 891912, -2182241], [12146276, -4103456, 0, 0], [-26299458, 1257520, 0, 0], [0, 0, 543648, 3090240], [0, 0, -69224, 2220198], [53496812, -107848, 0, 0], [0, 0, 733082, 2256995], [-11258658, 2101904, 0, 0], [0, 0, -2013528, 2144461], [16514712, 7081408, 0, 0], [0, 0, 4226360, 1457672], [-14146682, -8157952, 0, 0], [0, 0, 2355362, -5763861], [8863804, -3262272, 0, 0], [0, 0, -1411020, 1964238], [0, 0, 307264, -7357679], [22416588, -9643984, 0, 0], [-6441332, 10208416, 0, 0], [0, 0, 731480, -6357836], [-45123900, -7357632, 0, 0], [0, 0, 3625368, 2134153], [-27904958, 12134432, 0, 0], [26708554, 9702736, 0, 0], [0, 0, 3724224, 3143683], [0, 0, -8432192, -2259864], [-23815046, 5248640, 0, 0], [0, 0, -5442108, 6223494], [0, 0, -7732488, -825658], [0, 0, -3281808, -2994603], [0, 0, 4608898, 3135735], [0, 0, -1305656, -397774], [0, 0, -6146372, -1509646], [28906194, 2981012, 0, 0], [46487012, 7149296, 0, 0], [0, 0, -2800110, 1540315], [-79023030, -6018816, 0, 0], [0, 0, -7683704, 3727414], [5681104, 6988576, 0, 0], [0, 0, 3633694, 7177369], [0, 0, -6186672, 4975976], [0, 0, 8094288, 944515], [-41476768, -10441072, 0, 0], [0, 0, -4293144, -1588459], [14000856, 1831472, 0, 0], [-21067454, -5836880, 0, 0], [-91283194, 3344496, 0, 0], [0, 0, -752528, -4437760], [-15279598, 4745600, 0, 0], [-424636, -13773752, 0, 0], [0, 0, -10234658, 5407181], [-56086490, 1437072, 0, 0], [0, 0, -4581016, -7022931], [18576660, -11632728, 0, 0], [0, 0, -1706048, 697648], [34551134, 9878252, 0, 0], [-47382234, -10709424, 0, 0], [0, 0, 17437786, 1472091], [37900032, 16593360, 0, 0], [-10996674, 1178560, 0, 0], [0, 0, 6634362, 2818355], [0, 0, 3425840, -13102320], [0, 0, 4789672, 3956263], [-70714306, -4535392, 0, 0], [-17455804, -8722784, 0, 0], [0, 0, 11096568, -179812], [-40036986, -18183748, 0, 0], [0, 0, 6785918, -9361927], [0, 0, -5536200, -7611460], [-94096130, 10294656, 0, 0], [0, 0, -14498064, -3414459], [0, 0, 5628372, 13090062], [0, 0, 8578136, 8380484], [0, 0, -9908194, -9952403], [-86419050, -10397028, 0, 0], [36571176, 25158560, 0, 0], [-94032622, -15985760, 0, 0], [0, 0, -18489120, 6452393], [-51817804, -25118536, 0, 0], [0, 0, 5519528, 1742331], [0, 0, -1050296, 15173982], [77395404, 473584, 0, 0], [-26159074, -21148944, 0, 0], [0, 0, 8199634, -13109597], [0, 0, 3776248, -14076494], [0, 0, -21330912, 3595621], [40315180, -6444968, 0, 0], [-144391830, -7461916, 0, 0], [0, 0, 10200920, -3249562], [0, 0, -15827672, -8854158], [0, 0, 5178920, -11184713], [0, 0, -1429282, 8725609], [-2744506, -6958784, 0, 0], [0, 0, 17470040, -7190691], [5346476, 18131568, 0, 0], [-102001854, -18876496, 0, 0], [0, 0, 9551800, -1274924], [-21109806, -4989164, 0, 0], [0, 0, -14849000, -3771329], [27629936, -31695600, 0, 0], [0, 0, -21573664, 4562727], [0, 0, 14853880, 5125228], [77890738, 7600340, 0, 0], [28163978, -6717632, 0, 0], [102918156, 19175024, 0, 0], [0, 0, -10428158, 15668067], [0, 0, 10603528, -12136148], [73747768, 10860880, 0, 0], [0, 0, -3937388, 14114878], [0, 0, 5892936, -9676534], [0, 0, 8488458, -17009333], [172937480, -3265312, 0, 0], [-130600194, 6040512, 0, 0], [-24419026, 25655616, 0, 0], [0, 0, 16113596, -7814086], [0, 0, -5812688, -14175905], [-55267502, -28763744, 0, 0], [0, 0, 25507410, -13779845], [71069210, -9167264, 0, 0], [0, 0, 8882930, -6208193], [22049470, -28101696, 0, 0], [0, 0, 21405592, 2619080], [0, 0, 10170208, 4095344], [0, 0, -16435832, -13428164], [0, 0, -21047774, -10318605], [0, 0, 24456502, -6203139], [0, 0, -16241296, 12828155], [-86658094, -12542384, 0, 0], [248727832, -2588416, 0, 0], [62431962, 15531236, 0, 0], [-124492930, 37246028, 0, 0], [299059140, -728336, 0, 0], [91988754, -17403948, 0, 0], [0, 0, -30253496, -4364334], [226991284, 1551192, 0, 0], [89588966, -32119744, 0, 0], [0, 0, -2622864, -19235344], [-183119170, 26949424, 0, 0], [133962516, 19675312, 0, 0], [-28966690, 43653388, 0, 0], [56194724, -3018792, 0, 0], [0, 0, -14201976, 3494485], [0, 0, 1024030, -30052655], [-22457256, 48153824, 0, 0], [0, 0, -14096096, -1229637], [228583864, 25056640, 0, 0], [0, 0, -22178854, -14696573], [127968244, 37712704, 0, 0], [0, 0, -1034040, -13328818], [263567404, 4921560, 0, 0], [137399784, -11813216, 0, 0], [0, 0, -7612648, -15573563], [64709258, -16441116, 0, 0], [0, 0, -44734082, 8786489], [81724064, 4396720, 0, 0], [31938506, -49071344, 0, 0], [-96012590, 16859872, 0, 0], [-16292286, 31126352, 0, 0], [0, 0, -5438076, -33509442], [0, 0, -19465406, 10713271], [9022996, 46157120, 0, 0], [0, 0, -7209230, 9104759], [174767294, -23839088, 0, 0], [0, 0, 45432192, -11248793], [0, 0, 43834728, 6898845], [0, 0, -3010708, 24008506], [145610762, -23874016, 0, 0], [-365496014, -7965440, 0, 0], [0, 0, 6702584, -14974824], [-82815108, 42718984, 0, 0], [6397498, 23432240, 0, 0], [295522302, -30316692, 0, 0], [0, 0, -19903448, -5757796], [60752858, -14548540, 0, 0], [0, 0, 24575264, 817544], [0, 0, -36125928, -264574], [0, 0, -7442590, 45631071], [89511782, 63428416, 0, 0], [-315797302, 2267328, 0, 0], [0, 0, -5756924, 42191374], [-22892382, 22954688, 0, 0], [0, 0, 7691656, -23259169], [0, 0, -45453652, 8569738], [0, 0, 47361466, 12620227], [-178198466, -21606208, 0, 0], [-102608116, -33694360, 0, 0], [-240881814, -55750240, 0, 0], [0, 0, -461544, -8529487], [-179460088, -53862272, 0, 0], [173045868, -1168896, 0, 0], [0, 0, 758466, -40237589], [-153581430, -4508832, 0, 0], [0, 0, 10637592, 269988], [28813340, -41721496, 0, 0], [-163678856, 60212768, 0, 0], [282962180, 56053632, 0, 0], [0, 0, 31751082, -18018657], [20479440, 39101264, 0, 0], [183277638, 47424160, 0, 0], [0, 0, -31361272, -1445956], [-328163502, 23351392, 0, 0], [0, 0, 17322590, -16759947], [30264148, -34313720, 0, 0], [0, 0, -11682256, 13245843], [0, 0, 58921416, 3341759], [0, 0, -35544320, -20584909], [0, 0, -33148712, -10536600], [-50738256, 70867328, 0, 0], [-184478824, 81267088, 0, 0], [-254354586, -84707072, 0, 0], [0, 0, 23398438, -12830691], [0, 0, -17269016, -50793596], [-250328012, 15880776, 0, 0], [0, 0, -36139864, -38300954], [123092436, 85761712, 0, 0], [0, 0, -36611988, 49092250], [106206242, 68335008, 0, 0], [0, 0, 5154136, -12617246], [483493028, -38359792, 0, 0], [0, 0, 64422266, -21957293], [376274656, -23128736, 0, 0], [-164192116, 35750528, 0, 0], [0, 0, 7839820, 10548122], [0, 0, -36338736, -12049519], [-41790012, -55331584, 0, 0], [-504065194, 10652304, 0, 0], [0, 0, -17608648, 21956510], [319381330, 56135232, 0, 0], [119350432, 16738352, 0, 0], [0, 0, -7655024, -63069283], [0, 0, -19455480, 42598512], [0, 0, -66592884, -16499086], [-419702770, 6501952, 0, 0], [241043360, 91772688, 0, 0], [0, 0, -28287138, 37630673], [0, 0, -1780498, 49813953], [0, 0, -54359264, -10531779], [-1055374, -113847728, 0, 0], [147474318, -1711668, 0, 0], [-511464956, 20169920, 0, 0], [-209784608, -59186512, 0, 0], [0, 0, -18112968, 13500428], [175026308, 30459624, 0, 0], [0, 0, 1286868, 1967534], [0, 0, 490168, 63517303], [0, 0, -92041704, 8149716], [410602826, 13403920, 0, 0], [0, 0, 59434584, -21411390], [-33072776, -20438880, 0, 0], [0, 0, -72610454, -20517049], [0, 0, 64660064, 6031047], [0, 0, 62207416, -2188802], [-490080610, -43247156, 0, 0], [27954456, -84250992, 0, 0], [0, 0, -49086938, -35567223], [0, 0, 32264076, -3356118]];
    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_6_a_z();".
// 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_6_a_z(:prec:=4)
    chi := MakeCharacter_441_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_6_a_z();".
// 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_6_a_z( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_441_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![-22, -5, 1]>,<5,R![11669056, 0, -7632, 0, 1]>,<13,R![76158337024, 0, -1260672, 0, 1]>],Snew);
    return Vf;
end function;