
// Make newform 560.6.a.l in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_560_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_560_6_a_l();".
// 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_560_6_a_l();".
// 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 := [-16, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_560_a();"
function MakeCharacter_560_a()
    N := 560;
    order := 1;
    char_gens := [351, 421, 337, 241];
    v := [1, 1, 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_560_a_Hecke(Kf)
    return MakeCharacter_560_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, 0], [0, -3], [-25, 0], [49, 0], [252, 97], [-262, -53], [146, -251], [-272, -86], [672, -902], [2470, 945], [-264, 924], [-5082, 1260], [-1022, 3818], [13100, 922], [11432, -1575], [-28018, 454], [-32392, 5184], [-23070, -5706], [24956, -4568], [-43024, 5304], [-8862, 4192], [17080, 17635], [-52952, -3924], [-21686, 5722], [-41198, -13943], [50218, -21172], [3968, -20579], [-29468, 29970], [-133946, 18567], [52610, -19812], [-2136, 10736], [-286336, -21062], [22202, -5318], [147072, -76994], [-240714, -49772], [-159928, 62267], [-338086, -16012], [180628, -57194], [480208, 25933], [-245238, 40909], [-185956, -95088], [-477758, 97210], [-304200, -4979], [442018, -156198], [-248290, -59494], [-345424, 109048], [-112452, 23175], [-690464, 126085], [251128, 30393], [318722, 91346], [-1255430, 28478], [-69408, -155129], [-122230, 336604], [526800, 245506], [-131030, -20444], [-130408, -37322], [557258, -93336], [-635264, -286656], [-416994, 131224], [1982602, -28975], [-1439648, -211617], [2373898, 27657], [144936, -709953], [-1737512, 237530], [-28934, -720569], [-1014682, 365120], [106860, 227736], [-345230, 227476], [1917868, -147062], [-882662, -503936], [1369994, -839455], [2951576, -181272], [1158688, 430593], [-3113314, -8514], [2683900, -667880], [135240, -845068], [-25618, 458771], [1095722, -745243], [4179234, -189449], [556098, 1015924], [1187000, 808820], [-3681898, -544185], [-1191984, -521311], [1035074, 395360], [-2635512, -443286], [3143940, 664602], [5205042, -338699], [2946826, -841546], [-5796038, 862990], [7522608, 213536], [-211704, -356573], [3217160, -1744510], [-389184, -928538], [-2310636, -951277], [-1606164, 1353413], [-2440376, -307381], [2190618, -1201736], [2992802, -898500], [-4182784, 832940], [-356082, 2592713], [676388, 611828], [-6397370, 375106], [-1674688, 493548], [912474, 944072], [975164, 933008], [5255738, 761595], [728968, 800728], [-4291222, 234227], [4642160, 573305], [659466, -2503388], [-4515152, 441363], [-5081930, 1168788], [7656202, -1717928], [9253832, 693906], [4152640, 380521], [-3294590, 153024], [-14720352, 349981], [1774704, -1615784], [-5315362, -2247548], [6387268, -460331], [-3677078, 1001750], [7637266, -1896014], [-9289422, -1229525], [2534100, 2919012], [-2673552, -2935340], [471798, -4203227], [2871742, -4408319], [6229320, 1735810], [-16855744, -1227928], [-13200526, 1142295], [5265732, -3715079], [-17370416, 2996284], [-5585536, 3236363], [-20982426, -516102], [-5255694, 4356892], [13262922, 591356], [-18757046, 3397915], [-539704, 845017], [-3112486, 130893], [22937098, -3089521], [-31242232, 244570], [-12544730, -4413741], [-1872696, 523564], [6966532, -513270], [-9806590, -4650670], [-5849072, -2979266], [-33980222, 746052], [665578, -3083000], [-14295200, 5973340], [-12081536, -378976], [5505758, 261340], [6270242, -2983970], [14178812, 2519368], [-14689456, 8388616], [5953124, -9517554], [26241728, 607040], [13173856, -2631497], [-3522342, 2295474], [-3967838, 5700097], [672818, 351278], [5684164, 4171236], [11812362, 7538014], [34591760, 4067074], [23948808, 6709920], [22508770, -2563564], [44437696, -2256405], [-22817832, 4104200], [6037994, 8164473], [19961106, -8757877], [558370, 123528], [20215524, 5599172], [28138666, 1314872], [-1180672, 4494685], [-11914086, 2642880], [22544648, -7810966], [6706330, -4032390], [1834644, -11105707], [-8840962, 10791963], [-10949720, 2655492], [-17198510, -582730], [-1396344, 3639852], [5226152, 837412], [39416118, -6301648], [10790866, 14555204], [18060872, -13166972], [12402114, 6994752], [-19666298, -3372558], [-36100488, 1649533], [-25920822, 5621199], [21973848, -4837320], [-48727174, -7392744], [1935940, -8703638], [13276748, -10135165], [-40888950, -82786], [11918588, -8519032], [35183010, -5394237], [15615282, -307515], [-32439074, -5138554], [-9709446, -9853587], [-8207400, -505883], [94321566, 529568], [-33356344, 7124434], [11738282, -8188328], [6883218, 18573304], [-51982424, -5359562], [86684402, -234663], [-24029720, 7279170], [62272596, 1267120], [47701722, -13534404], [-22597936, 12104208], [-46209422, -6049790], [-91379846, 7264656], [16482560, -13929428], [-36513856, 1669681], [12774616, -5192902], [-23700398, 6113890], [-26370192, -6566462], [-43924214, 3378362], [-26808296, -6877094], [-29298450, -11020232], [-70441522, 2739068], [45655336, -15038862], [12353554, 17141267], [6259160, -8929518], [-48811160, 23671009], [24884014, -3369848], [-44792846, 6571425], [-87250592, -5112911], [-2161448, 2291565], [-24039588, 14601352], [65260350, 16830758], [98743704, 2478422], [-82036344, -181336], [-4419494, 30299087], [-82960224, 6246345], [-73188544, 23582197], [-107330646, 6749662], [52444206, 1898866], [19266596, -5944077], [84412248, -7785110], [-81934060, -17319388], [-25263064, 5833344], [9686024, -11082391], [-96637186, -10027048], [34527034, -6862525], [-27277376, -10782138], [33522240, -3522296], [54078704, -5952582], [1670540, 18758575], [115726992, 8896758], [44058102, -33893228], [58431122, -14430800], [111151912, 6782380], [-136116886, 1954542], [17020530, 24938068], [-119482660, 15252405], [-119711698, 10531400], [-178473192, 6549108], [-19938150, 25282011], [-117880070, -13739869], [56328, -5897674], [-1366220, -33985866], [39403242, -31980534], [104123474, 17077015], [-46173934, 4432384], [32330280, 13094490], [40557806, 5715003], [48847546, -43740008], [-118168044, 7424960], [571366, -36194204], [-34450774, -15103178], [145278500, -23686976], [-30602366, 13115105], [-97378992, -12066396], [-51850822, 21975820], [143129816, -25750615], [64740428, 28487088], [-128412322, -6054716], [14769546, 41689527], [1233008, 6796730], [96418784, -18062611], [83739504, 38801243], [17490320, 17738784], [-9893158, -62913100], [108484400, -10623791], [-85451872, 7664265], [4695074, 23518100], [10663822, -32790028], [39570352, 9537516], [1490866, -33493582], [81997294, 2043251], [259338888, 6544323], [50104186, 23488246], [-34384424, -54771116], [124220374, -24127540], [-145943526, 52597422], [38543008, -15849550], [117886722, 39513859], [144380384, -19198468], [53109152, 8335525], [67405146, -32486099], [18986062, -8191968], [-101098536, -36178683], [195140980, -7976068], [74438780, -32119589], [-8948430, 42176136], [70476860, 22382074], [-76826686, 28853982], [21053896, -14814512], [86514590, -35056262], [-21807728, 41675928], [88513710, -76894555], [173956146, 31245212], [203546148, 34618946], [132171944, -67001434], [-195262278, 13677946], [-104259672, -7393406], [-229187240, -502559], [118011386, -45474699], [-188088030, 40911995], [-90089016, 1757598], [91393866, 14741374], [107318594, 57323376], [-75351008, 37496588], [60895530, -45168812], [-31783478, 30832130], [81667412, -49075269], [-231082720, -32257548], [-7335768, -80069160], [30445318, 38791662], [-120630258, 30505400], [48703694, -63822322], [-142330216, 1304622], [38986576, -3111345], [-66455820, -7975104], [-108033072, -1615867], [138990102, -31676889], [-180117046, 8746680], [316738218, -43935492], [210164616, 46252017], [-161951634, 31043676], [1718522, 53927822], [-141479726, -31460208], [247841632, -65756123], [60329406, -58111264], [-137462860, 12374640], [-189075566, 19812716], [-120294500, 61150144], [23683616, 30357594], [134192122, -36013563], [330719768, -57409920], [-137553926, -67802042], [-195611058, 23278115], [-91008488, 44776633], [-106385082, 44770099], [-377048078, -3079236], [30117368, -31972866], [-88473384, -45196386], [-380533598, -11288888], [3292288, 26782506], [-114870546, 15376098], [207305002, 61190590], [-38297928, -80011840], [-176378588, 14861661], [-244401144, 65057852], [248084170, -52206632], [227526858, 64151445], [195084576, 78990050], [-129427302, -28806037], [26818460, 61956701], [-246583776, 72574912], [148716912, -89290232], [-112415770, 16310125], [-252373000, 21572926], [120409430, 79017076], [-144071840, 26610680], [18381648, -13495275], [-205402646, 2311115], [-185712518, -62589684], [249146170, -33843529], [-134854566, 37509836], [-47620598, -51645796], [-91370056, -50246404], [-172482046, -65506012], [-114903864, 118172648], [36853800, -60862923], [-368529000, 37846001], [25333066, -95060141], [-162807980, -281088], [2295288, 74900503], [-591204542, 3487319], [128350010, -76024087], [-261696300, -28952785], [-17682240, 143574164], [47625992, -138379263], [54985034, -65212610], [-286993560, -31627140], [-225271150, 42613630], [-251497100, 93154481], [-61400498, 58516580], [111050210, 27725050], [358579634, 86129730], [-77560240, 30903794], [349038250, 100063921], [42235394, -80089558], [-92613520, 83506826], [352116246, 38728244], [143657202, 7639325], [-178632400, -106482708], [188176776, -62423532], [590850026, 26294641], [-129755178, -52827968], [-54174132, 101026506], [-88889076, -23498152], [-183476102, -106742460], [-377610950, 123327694], [-179126296, 32912937], [594098784, -79074124], [470737826, 57137784], [-184020664, 2325245], [164800054, 63834247], [-39679366, -145886372], [-359386320, 74877834], [195114592, -92945084], [209725514, 9938295], [-93032174, 201281749], [537667556, 20961100], [-291110214, -70515072], [354639872, 26219832], [-224921696, 143969312]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_560_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_560_6_a_l();".
// 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_560_6_a_l(:prec:=2)
    chi := MakeCharacter_560_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_560_6_a_l();".
// 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_560_6_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_560_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-144, 3, 1]>],Snew);
    return Vf;
end function;