
// Make newform 360.6.a.l in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_360_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_360_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_360_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 := [-32, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-6, 12]];
    Rf_basisdens := [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_360_a();"
function MakeCharacter_360_a()
    N := 360;
    order := 1;
    char_gens := [271, 181, 281, 217];
    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_360_a_Hecke(Kf)
    return MakeCharacter_360_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, 0], [-25, 0], [26, -1], [-280, -2], [694, 4], [-74, 28], [-500, 12], [1226, -41], [-670, -104], [-1124, 18], [-2970, 72], [-11538, 52], [8842, 113], [1454, -295], [2706, 180], [-31292, 168], [7054, -368], [-42706, -181], [-23604, 182], [-33726, 436], [-32952, 836], [-54362, -237], [27510, 488], [73834, -1540], [-51366, 1480], [-65474, -435], [-79230, -135], [13934, -360], [-137538, -1432], [-167886, 959], [-52920, 34], [-154666, 1568], [36588, -3768], [74986, -3368], [-396652, -862], [215038, 2152], [43186, 6569], [-107730, 4461], [-10574, -2536], [-172868, 3104], [8966, -8368], [-203924, -902], [565210, 4372], [-148030, -1964], [-11800, -2656], [-181480, 3318], [-504106, -5875], [915282, 1637], [629014, -10720], [468270, -2268], [1086888, 6516], [812570, -4484], [-109704, 9118], [1011150, -11080], [-1166886, -2313], [1102786, 4800], [253764, -14090], [48086, 3912], [377006, 892], [-1505206, -8471], [-176854, 1264], [792670, -20021], [-132188, -36142], [-816502, 4488], [2324922, 15340], [853008, 43270], [747490, 19352], [-2295662, -807], [901326, 11312], [-1834034, 1768], [2354136, 22064], [-2343910, -12285], [-943466, -56488], [2587060, -37860], [-1578390, 33347], [-2722518, 40736], [1311094, -5916], [-1559442, 30432], [2117842, 51364], [-1631364, 13544], [-2799258, -16408], [-1048628, -49486], [-4041766, 332], [487384, -86656], [1990014, 76675], [1475958, -18668], [-4414838, 14064], [896658, -107160], [-1912938, -83387], [-726230, 77889], [126056, -75396], [-2153246, 683], [-5953176, 7630], [9136364, 7564], [-4722558, 49643], [894194, -80736], [-863530, 97920], [-980486, -41943], [4366558, 28200], [-3202402, 113667], [-5625422, -93832], [5540582, -134973], [3069550, -3924], [4328272, -163074], [-2655262, 20560], [5765130, -95259], [-4761714, 56176], [1938432, 158436], [-7688846, 11988], [-3513054, -5257], [409326, -41052], [2196078, 12868], [2580980, 87188], [-3056492, 170194], [932694, -69596], [-2045310, 236209], [-717378, -3595], [-4690214, 74900], [14536284, 69024], [-9311994, -163664], [-9709926, 8644], [8290130, 68316], [9175398, -8937], [-2718400, -108558], [10069186, 139464], [11308070, 180744], [-9238072, -223948], [-9914086, -111609], [3190062, 289264], [18651684, -80024], [13676658, -172901], [-14853060, -34422], [7460294, 187968], [12292902, -84288], [-305774, -359496], [-9768126, -190668], [7263542, 123055], [18748362, 56820], [1946550, 302144], [2048408, -36078], [3190538, -285640], [-14154746, 198481], [13433538, 88145], [34042894, -1968], [-3500912, -49084], [-26031538, -11060], [-5365962, -58072], [18529676, 275520], [-3257790, 123911], [-6742850, 16272], [2831670, 43100], [20219498, 85749], [-29830666, -39007], [-18213690, -190189], [-31315564, -66178], [-22033168, -138492], [15899798, -241132], [20110114, -5548], [13538690, 112512], [-13675294, -474667], [-31621050, -235248], [-27708822, 69559], [-29794592, 111106], [44622742, -113940], [46413786, -16145], [-6065236, -451862], [-14705298, -399420], [9592994, -405880], [2903266, 317836], [3535468, 318484], [25578574, 561952], [-52880300, 188978], [-29966158, 171996], [-5256256, 181960], [-15365994, 355960], [-47578112, 321558], [9362410, -376864], [29515750, -213703], [-24987170, -378752], [-5017942, 664835], [10936680, -421966], [-7601746, -921132], [-35188834, 237916], [963346, 195975], [-500630, 355720], [33732926, -502904], [28088450, -43807], [-50469118, 59092], [-5363596, -71818], [12953858, 1069280], [20730606, 468355], [17785856, 1088066], [50143570, 255952], [8501642, -594935], [15708862, -604548], [16273770, 765300], [17621766, -799244], [25316254, -697136], [32717986, 194003], [798930, -122776], [45239764, 557454], [34809758, -878460], [-39146526, -217792], [-37231068, 862528], [55835314, -661616], [34740256, -98896], [47856158, 912319], [-3152826, -449848], [66528704, 649038], [26255194, 537436], [-2666966, 250168], [28499366, -739599], [69418506, -197923], [12448784, 975252], [-15466734, 670604], [-25675886, 591431], [-88005842, 593504], [-21804306, 1022805], [-3200182, 506164], [-3302698, -1043632], [-54710528, -129364], [34876718, 314024], [32853246, -49135], [28735962, 700617], [-79019354, 880608], [-6941474, -1225164], [82710544, -388760], [-72482710, -280473], [15404080, -812950], [-4518266, 440044], [-35654292, 620204], [43699604, 673542], [94997630, -497444], [-12964254, -302539], [41313294, 1749081], [13901370, -752260], [-44131902, 272204], [-59200420, -185620], [-29983740, 1207786], [37009094, 552051], [59622568, -681518], [77960590, 455733], [-69598658, -711056], [-69847394, -625208], [57467800, -391528], [105478498, -1070345], [-110839712, -197402], [-63211220, -394760], [24965146, -682829], [7178118, 1745940], [31241726, -1322912], [-25349154, -1733627], [-11550526, -762332], [-100906142, 51888], [-28667388, -478964], [-35865130, -492360], [-18660594, 1065943], [-123248070, -816152], [-33032934, 888480], [8230462, 818569], [29115250, 1191109], [5459574, 244736], [-92430034, -902096], [45693334, 553668], [-2124356, 1635996], [-115723198, -941184], [35161158, 1957264], [-67782654, 1649725], [133965914, 748040], [-59986690, 671312], [-150918986, -577329], [101206818, 277580], [-67560832, -1599568], [-12767086, -1563792], [52474382, 422989], [19922426, 2385909], [19486718, 528424], [29829218, -1783404], [-80965608, 333522], [-181835934, -504297], [-63692244, -3128802], [12735286, 795489], [-36651338, 1601504], [-43128938, 1913931], [117776564, 1279438], [33089258, -2050380], [80263746, 226220], [119923968, -1531236], [-1473066, 1717332], [-74871502, -2718184], [23283882, -1679503], [143783166, 1952180], [-38186280, -440378], [154763806, 689712], [171002082, 968712], [166393724, 454946], [63057018, -1771552], [25117868, 3810516], [85420902, 122895], [-12751446, 1985600], [204084018, 10312], [137186648, -560388], [-216147362, 720919], [101533368, -1478470], [-101444390, 2636804], [118842810, -2472259], [331335598, -183064], [13527480, 1931608], [-93277978, 219960], [-22887190, 1314843], [-24003942, -1396208], [-261057282, -1419344], [-267323270, -648859], [-57692018, -687747], [83416762, -1967736], [130686116, -944500], [41559492, 48622], [-28931342, 1694984], [173717990, -356812], [-124870576, 1093050], [284937818, 16848], [152631762, 1537264], [-65260490, -2231331], [102739046, 2608232], [4111482, 4682572], [-122090132, -1179596], [-158249710, -687835], [151137502, -146839], [11633586, -685684], [223689614, -2153560], [30876530, -2147696], [353207512, 429204], [91691702, 1634483], [-122133896, 239090], [-70378254, 1377001], [64701566, 2132648], [52548318, 4001536], [-121480094, 1853188], [70965066, 2818603], [-73248634, -1501568], [-148230618, 1519936], [3094394, -1310664], [287738228, -607926], [-16629886, 3887032], [-178097404, 3536324], [-407813354, -368816], [348220990, 382343], [308539428, -2708442], [-190397358, 1673652], [-109865912, -917514], [-37620390, -5254136], [-260713150, -426720], [164363438, -1363367], [-269626810, -912352], [-91200274, -1960948], [304810584, 212804], [41995136, -6647774], [132083510, 2833932], [-118194638, -2867501], [-214441138, -433756], [-260893546, -2455712], [-238531178, 3685909], [245486244, -4340344], [-117929274, -1844465], [85436962, 2045908], [-124612326, 887300], [-169947178, 6260049], [-341179486, 517692], [195951960, 5685034], [-15601612, 8924404], [-190727990, -162373], [23687754, 2294264], [-71210700, 5862466], [-7976122, -7002988], [-245105388, -2910236], [-84582092, 4611846], [-406669342, 2697248], [-449329434, -1165436], [263549258, -783352], [-422785166, -973728], [-301854298, -5371944], [9152346, -6167961], [-446616354, -285088], [-221588004, -809876], [-404913910, -1583889], [553675348, 603230], [-447013194, 3700328], [-157596942, 210917], [217644014, 4817649], [-198950774, 4177228], [-384382758, 1602504], [-170529660, 3403072], [429896086, 4397375], [-50861060, 260630], [86995706, 3106144], [461053736, 1523164], [199743990, -2836896], [330082376, 2181306], [-119232582, -1658656], [95661918, -4131544], [61811094, -964428], [-137650982, -3463405], [241720518, 3814816], [-99851478, -6272976], [201062964, -8824614], [103924582, 5958780], [-367226898, 109168], [-180196550, 1637517], [75351564, 3109040], [234221122, -3127544], [-5312694, 2631304], [-403987274, -2043369], [-141447560, -4244850], [204915106, 2228596], [252749106, -4621912], [268348736, -2874240], [-209933438, -1849589], [-99356442, -840124], [36329826, -9486261], [-194299182, 1496496], [-82301042, -6532780], [-645042562, 2210705], [-557922988, -4353280], [322024650, 695792], [251756754, 7352024], [-257519778, -2404041], [20701518, -5124212], [7259120, 5110686], [155158408, 5347088]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_360_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_360_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_360_6_a_l(:prec:=2)
    chi := MakeCharacter_360_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_360_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_360_6_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_360_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![-3968, -52, 1]>,<11,R![59824, 560, 1]>],Snew);
    return Vf;
end function;