
// Make newform 441.6.a.x 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_6_a_x();".
// 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_x();".
// 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 := [756, 0, -111, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [0, -96, 0, 1], [-56, 0, 1, 0]];
    Rf_basisdens := [1, 1, 3, 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 := 6;
    raw_aps := [[0, 1, 0, 0], [0, 0, 0, 0], [0, -3, 1, 0], [0, 0, 0, 0], [0, 45, 1, 0], [-210, 0, 0, 16], [0, 131, 31, 0], [-1708, 0, 0, -16], [0, -237, 47, 0], [0, -496, 32, 0], [1204, 0, 0, 48], [1634, 0, 0, 240], [0, 809, 29, 0], [2700, 0, 0, 128], [0, 2582, -114, 0], [0, 1510, 14, 0], [0, 1642, -174, 0], [-3206, 0, 0, 240], [50828, 0, 0, -96], [0, -1287, 717, 0], [-4942, 0, 0, -1120], [8264, 0, 0, -672], [0, -9296, 112, 0], [0, 1453, 113, 0], [-109326, 0, 0, -224], [0, -16557, -529, 0], [-9548, 0, 0, -1584], [0, 2129, 2197, 0], [18290, 0, 0, -1440], [0, -17936, 1840, 0], [-36216, 0, 0, 512], [0, -17148, 3028, 0], [0, 9414, 3742, 0], [64848, 0, 0, 7264], [0, -35430, -3598, 0], [67976, 0, 0, -2208], [42938, 0, 0, -496], [-207868, 0, 0, 7008], [0, -52690, 1286, 0], [0, 23087, 219, 0], [0, -61265, 3467, 0], [31150, 0, 0, -3792], [0, -63515, 201, 0], [345470, 0, 0, -8016], [0, -49506, -4122, 0], [517552, 0, 0, -9216], [-593532, 0, 0, 4640], [378616, 0, 0, -11808], [0, -95910, 15170, 0], [-203546, 0, 0, -16944], [0, -31414, 13138, 0], [0, 28375, 1795, 0], [-484694, 0, 0, 3648], [0, -115086, -7110, 0], [0, 156573, 7393, 0], [0, 130959, 20731, 0], [0, -78943, 18325, 0], [958972, 0, 0, 5232], [1796726, 0, 0, 12432], [0, -49438, -7606, 0], [-1010156, 0, 0, 27600], [0, -50761, -20413, 0], [628236, 0, 0, 24976], [0, -100274, -20634, 0], [-474754, 0, 0, 35456], [0, 205210, -9390, 0], [537988, 0, 0, 21280], [553166, 0, 0, 51840], [0, 13199, 9675, 0], [-619710, 0, 0, 4144], [0, 56355, -18337, 0], [0, -327691, -15911, 0], [-1920016, 0, 0, 26624], [-241370, 0, 0, -33920], [-1624044, 0, 0, -27232], [0, 310788, 36628, 0], [0, -79836, -47900, 0], [-106358, 0, 0, 60240], [0, -541926, 25730, 0], [-1165262, 0, 0, 14784], [0, -444478, 12938, 0], [-3038026, 0, 0, 26640], [0, -184499, 73937, 0], [-2817402, 0, 0, -8192], [3488240, 0, 0, 30176], [0, 357283, 68655, 0], [0, -164820, 39996, 0], [4334102, 0, 0, 9024], [0, 107371, 15655, 0], [-3638080, 0, 0, -85248], [0, -375866, 7838, 0], [0, 204810, -40942, 0], [5071576, 0, 0, -27872], [0, -43961, -94013, 0], [-529204, 0, 0, 69312], [0, 594384, 70224, 0], [0, -327939, -94079, 0], [0, -324781, -34577, 0], [4309648, 0, 0, -99072], [-6038546, 0, 0, -22256], [2788620, 0, 0, 26816], [0, -560762, -87922, 0], [0, 374830, 146022, 0], [0, -298838, -166830, 0], [2059156, 0, 0, 125056], [2882110, 0, 0, -5568], [0, 1100686, -151034, 0], [0, 220507, 39767, 0], [0, -660823, -6339, 0], [-10500042, 0, 0, -77120], [2546936, 0, 0, 263456], [2828246, 0, 0, -22944], [0, 187954, -143654, 0], [-9077096, 0, 0, 41568], [4284744, 0, 0, 5888], [0, -86166, -223214, 0], [-6549732, 0, 0, 5872], [0, -1910086, 158530, 0], [0, 680520, 209240, 0], [0, -75751, -199363, 0], [5221370, 0, 0, 111056], [-3526714, 0, 0, -250032], [0, -627109, -53193, 0], [0, -515957, -65545, 0], [-1035944, 0, 0, -130560], [0, 1540800, 21456, 0], [-8113942, 0, 0, 110688], [0, -1551512, -44920, 0], [-13157004, 0, 0, 193168], [19449766, 0, 0, 62352], [-7237180, 0, 0, 232032], [0, 2676937, -204035, 0], [12738568, 0, 0, -54272], [-13789974, 0, 0, 78176], [0, 1495569, -159611, 0], [10689910, 0, 0, 224832], [0, 153911, 273571, 0], [-6265952, 0, 0, 250272], [0, 1019387, 96407, 0], [0, -243512, 214472, 0], [14709520, 0, 0, -175296], [0, 529690, 216018, 0], [-5856640, 0, 0, -410592], [0, 1836153, 41469, 0], [6136382, 0, 0, 214832], [0, 1820722, 178138, 0], [-6915398, 0, 0, 348912], [0, -1142271, 140405, 0], [306964, 0, 0, 238320], [0, -1558897, 13819, 0], [-20263330, 0, 0, -250848], [0, -3004413, -259425, 0], [1709468, 0, 0, -407616], [0, -1704186, 255358, 0], [4019924, 0, 0, 785280], [0, -3187051, 57977, 0], [14023376, 0, 0, -297888], [0, 4983401, -228579, 0], [-6014610, 0, 0, -852128], [0, -940559, 269541, 0], [0, -835787, -131415, 0], [0, -3112476, 207828, 0], [-22844400, 0, 0, -124288], [0, 1103896, 320312, 0], [0, 4770386, 165978, 0], [0, 3644556, -166084, 0], [-9962632, 0, 0, -59424], [25266682, 0, 0, 288912], [14032482, 0, 0, 443792], [0, 364875, -241913, 0], [0, 3021849, 304573, 0], [-12883094, 0, 0, -316080], [0, 5255937, -546379, 0], [21848338, 0, 0, -279632], [30033640, 0, 0, 130176], [0, -463045, 631991, 0], [39680076, 0, 0, -350848], [0, 4807828, 435092, 0], [39568452, 0, 0, 93424], [32603410, 0, 0, -331440], [-27626672, 0, 0, 604000], [0, -6320036, 493132, 0], [25017918, 0, 0, 781712], [0, -1545845, -694393, 0], [0, 1727951, -893925, 0], [0, -213345, -542869, 0], [-22083790, 0, 0, -412032], [1175720, 0, 0, -491008], [-20987326, 0, 0, -1240848], [0, 1233308, 700684, 0], [-79382926, 0, 0, 57344], [0, 1831133, 698033, 0], [21406724, 0, 0, -480480], [0, -1103521, -156693, 0], [0, 5102749, -942991, 0], [0, 1327999, 341259, 0], [86597062, 0, 0, 263632], [-24893578, 0, 0, 1494096], [0, -4454339, -875807, 0], [0, 1775506, -257926, 0], [0, -3187402, 219006, 0], [-11276160, 0, 0, 308704], [-21316442, 0, 0, -82128], [-7042070, 0, 0, -1384032], [0, 6327876, -750060, 0], [0, 6153071, -395813, 0], [30777712, 0, 0, 68256], [0, -2163015, 563837, 0], [0, 1577924, -646252, 0], [51868180, 0, 0, 482544], [-4370110, 0, 0, 672192], [0, -583147, 1044761, 0], [6795864, 0, 0, 72992], [0, -5066632, 1224600, 0], [0, -206906, -1197378, 0], [-67831610, 0, 0, 552096], [-74267768, 0, 0, 522400], [0, -9297549, -384913, 0], [0, 5366819, -760481, 0], [0, -1069388, -109196, 0], [-46483462, 0, 0, -1074528], [48162492, 0, 0, -431600], [0, 10200768, -60448, 0], [-5544872, 0, 0, -1851008], [0, 11754164, 231620, 0], [-132052398, 0, 0, 193904], [0, -15094879, 1234005, 0], [0, 237595, 408503, 0], [-35482972, 0, 0, 1490288], [0, -3158525, 220239, 0], [11141122, 0, 0, -332192], [62831636, 0, 0, 90320], [78915576, 0, 0, 1154144], [0, 12673928, 795432, 0], [67404372, 0, 0, 1842256], [0, 9716976, -1175056, 0], [10305218, 0, 0, -2006176], [0, 2886086, 523726, 0], [0, -349577, 1359763, 0], [0, 565488, 287280, 0], [0, 2800347, -278969, 0], [2373728, 0, 0, -545536], [1087520, 0, 0, 1408160], [-98052574, 0, 0, 1092912], [0, 11444645, -718903, 0], [0, -14150146, -278634, 0], [133840812, 0, 0, 1106224], [0, -18863078, 1033026, 0], [-26272364, 0, 0, -1392320], [0, 4516083, -239025, 0], [-18111438, 0, 0, -8320], [0, 8904055, 2727779, 0], [0, -12833479, 1272621, 0], [-73818318, 0, 0, -1661408], [0, -5739417, -2003053, 0], [0, -5628571, 744889, 0], [-28861762, 0, 0, 1523472], [-16887836, 0, 0, -2063568], [0, 7839639, -414429, 0], [-82241866, 0, 0, 1308128], [76163536, 0, 0, 2735584], [0, 13795931, 1273319, 0], [-64897154, 0, 0, 1378512], [-72219462, 0, 0, -2509328], [0, 9334327, -2055357, 0], [-107748200, 0, 0, 17952], [0, 4525374, 2050470, 0], [0, 17887171, 1616575, 0], [119417804, 0, 0, 783936], [0, 9320564, 1999860, 0], [15390074, 0, 0, 1020560], [-51446116, 0, 0, 672096], [-23260286, 0, 0, 3959520], [94730072, 0, 0, 1114752], [-238269710, 0, 0, 223104], [-116198852, 0, 0, -1722480], [0, 8810577, 941141, 0], [5487026, 0, 0, -1208592], [19241078, 0, 0, 3656112], [0, -20902294, 289170, 0], [0, -4841684, 1000284, 0], [93050840, 0, 0, -234048], [0, 23714332, 662476, 0], [54133674, 0, 0, 1056592], [-54593504, 0, 0, 3863232], [0, 13607621, -384983, 0], [120913694, 0, 0, -2178816], [0, -14033126, -3134798, 0], [107797228, 0, 0, 2866416], [0, 8166057, -373155, 0], [0, -3856458, -3160130, 0], [0, -12184300, 1244260, 0], [0, 11341818, -12862, 0], [0, -24508450, -1764394, 0], [-132830178, 0, 0, 1990592], [0, -19632797, -1426401, 0], [-2053856, 0, 0, -5780352], [0, 7061065, 1315357, 0], [0, -19646102, 1292690, 0], [-47377848, 0, 0, 262432], [156868726, 0, 0, 2217120], [0, -13073896, -2858456, 0], [-36559424, 0, 0, -3983168], [0, -16750487, -1276499, 0], [132479540, 0, 0, 1019520], [-116678466, 0, 0, -4153024], [0, -25151721, -786029, 0], [-25015130, 0, 0, 4133520], [0, 27850773, -1166407, 0], [-14752406, 0, 0, -3240272], [0, 12021692, -1379412, 0], [0, 34401208, -90904, 0], [0, -23399450, -891522, 0], [118298228, 0, 0, 2205696], [0, 12520371, 1386927, 0], [81385570, 0, 0, 743136], [0, -13465412, -3829844, 0], [0, 31870151, -745101, 0], [-83895798, 0, 0, -2600288], [0, -9132722, 1906534, 0], [-7371196, 0, 0, -4463920], [-159711122, 0, 0, 4634896], [0, -44921457, 3422139, 0], [81702024, 0, 0, 1329248], [0, 2118984, 2109832, 0], [189361018, 0, 0, 610944], [176376260, 0, 0, -1987488], [47262796, 0, 0, -169680], [0, -27181835, -4664199, 0], [0, -11251320, -242472, 0], [-222498238, 0, 0, 523584], [0, -12537448, -3536088, 0], [197811460, 0, 0, 156144], [0, 5349858, 354794, 0], [-237536956, 0, 0, 719904], [0, 30281850, -2568222, 0], [-196417842, 0, 0, 3251552], [0, 26005689, -1557011, 0], [10321122, 0, 0, 598816], [-10068380, 0, 0, 4237872], [256634918, 0, 0, 3038784], [0, -28613218, -1692586, 0], [0, -15764311, -3735619, 0], [-2184184, 0, 0, 1326336], [0, -21175940, 4638588, 0], [0, -22500123, -3664743, 0], [-398189330, 0, 0, -1898256], [189599980, 0, 0, 5149696], [0, -37033148, 3157396, 0], [0, -37375841, 2795627, 0], [-31689812, 0, 0, 4209456], [202712378, 0, 0, -3933552], [0, 16785082, 3326962, 0], [-266252560, 0, 0, 2636000], [175065734, 0, 0, -2437824], [0, -6235077, -534153, 0], [0, 24973896, 6894376, 0], [0, -40327312, 3240880, 0], [0, -16529388, 3342980, 0], [0, -26420455, 5435885, 0], [75797430, 0, 0, -8666752], [0, -24555331, 430305, 0], [0, 16022893, -1610383, 0], [0, -27758579, -91263, 0], [-3890264, 0, 0, 6698496], [15997166, 0, 0, 1646736], [0, -29800811, -3445991, 0], [60682616, 0, 0, 170976], [-199281210, 0, 0, 3987824], [0, -34198341, -5131673, 0], [352087708, 0, 0, -4851312], [0, -8932695, -5820643, 0], [0, 39585122, -5191750, 0], [276348548, 0, 0, 1922288], [137939582, 0, 0, 7478352], [0, -28089188, -3208116, 0], [0, -13434165, -5105241, 0], [-469751618, 0, 0, -1410048], [0, -1562873, -475693, 0], [77518378, 0, 0, -5035488], [0, 11705247, -6556597, 0], [0, 10738984, -7096856, 0], [-299670072, 0, 0, -389056], [0, -865092, -2210900, 0], [387949968, 0, 0, -114368], [0, -25834396, -1306508, 0], [232018184, 0, 0, 7383072], [-128237186, 0, 0, -5031024], [-162578804, 0, 0, -6488000], [0, 29636282, 2435714, 0], [-1752294, 0, 0, -7474576], [0, -75858463, 3621621, 0], [0, -15788795, 2388761, 0], [-518216972, 0, 0, 557136], [0, -43583831, 3113085, 0], [172168310, 0, 0, -7093056], [93867928, 0, 0, -2953728], [0, -3462953, 4714723, 0], [-12258468, 0, 0, 6669248], [0, 24398336, 4361904, 0], [263075666, 0, 0, -3393520], [0, 16817180, -4714964, 0], [-173794064, 0, 0, -1779968], [0, 79523097, -7209203, 0], [0, 35737649, 3127333, 0], [282995440, 0, 0, 7642368], [103306526, 0, 0, 10266000], [0, 59049032, -421240, 0], [-37755704, 0, 0, 7217760], [0, -8644078, 6870426, 0], [422651222, 0, 0, 6392864], [0, -87703148, 7226580, 0], [0, 43090407, 722595, 0], [614609852, 0, 0, 569088], [-166846062, 0, 0, -2682064], [0, 25429225, -2302147, 0], [0, -2808217, 7093075, 0], [571866260, 0, 0, -3858160], [0, -51025857, -634965, 0], [0, 35474550, -5950226, 0], [0, 31094400, -772496, 0], [-552694478, 0, 0, 5849904], [0, 43846409, 2800733, 0], [0, 12903284, 8759300, 0], [-178040618, 0, 0, 5122464], [0, -76631957, 5725959, 0], [0, 85326187, 872535, 0], [0, -50634234, -2521602, 0], [85224776, 0, 0, 6067520], [0, -10082946, -5531818, 0]];
    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_x();".
// 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_x(: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_x();".
// 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_x( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_441_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![756, 0, -111, 0, 1]>,<5,R![148176, 0, -7752, 0, 1]>,<13,R![-547484, 436, 1]>],Snew);
    return Vf;
end function;