
// Make newform 280.6.a.d in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_280_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_280_6_a_d();".
// 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_280_6_a_d();".
// 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 := [-9, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-2, 4]];
    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_280_a();"
function MakeCharacter_280_a()
    N := 280;
    order := 1;
    char_gens := [71, 141, 57, 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_280_a_Hecke(Kf)
    return MakeCharacter_280_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], [13, -1], [25, 0], [-49, 0], [-7, -22], [157, 5], [-73, 21], [1424, 71], [1996, -71], [3003, -96], [610, 3], [3616, -825], [3258, 611], [-1168, -509], [6465, 1521], [1608, -1232], [3364, 3036], [-378, 2157], [5872, 2608], [-952, -952], [11306, 2554], [31243, -3218], [7600, -462], [21422, -3005], [41411, 2365], [-59820, -1305], [43133, 8733], [-3510, 5310], [45733, -9098], [-74536, 12449], [221268, -1600], [118740, 1211], [-92526, -25143], [224854, -14292], [-110962, 14154], [319879, 8656], [-86902, 23352], [-348402, 19972], [253701, -4835], [-355717, -243], [-19572, 8892], [-543392, 19768], [-208767, 35676], [-90710, -17595], [-604414, 12061], [-245264, -9758], [-567389, 42364], [44737, -33281], [128269, 68761], [-1176174, 5495], [88784, -60796], [-340589, -75520], [-268696, -83109], [265834, 4872], [323494, 107594], [-27482, 3888], [-76050, 75654], [858178, -42069], [1670726, 25578], [-882153, 67254], [-1478125, 15183], [340295, -85475], [-52677, -50457], [1208072, -118513], [-310603, 184865], [2019218, 23618], [69292, -219760], [-676982, -13872], [2610012, 77395], [-3402572, 53893], [211615, 98631], [2024, 291808], [-35559, 140269], [3198478, -110069], [-2558036, -10156], [1204888, -178966], [1363017, 284746], [2929567, 144947], [1308985, 194128], [-2449858, -17630], [-2173136, -202280], [1276337, 328972], [367953, -117074], [-1728818, -51928], [2768442, -30028], [1760528, -285801], [-914477, -411986], [2268070, 193447], [-365200, 426392], [-4363354, -151907], [6398591, 25703], [-2469756, -368213], [-165654, 387904], [-2921213, -26798], [-1517355, -70742], [-5624977, 30489], [3007066, 70280], [-4712052, -411741], [-506508, 328288], [-1678917, -608140], [405594, -925877], [11781240, -56796], [-5102388, 200892], [-1628702, -774404], [602656, 600618], [-2249383, -105063], [5554228, 117614], [-7038519, 198933], [8558425, -486458], [-10304446, -301624], [4997575, -454159], [-896678, 585768], [560250, 791550], [5970672, -43951], [-7890267, -603584], [17676954, 210364], [4197413, -1247517], [2873772, -465014], [12717840, -321099], [6422649, 91504], [2244804, 565098], [-2331830, -522943], [5864057, -563249], [11922990, -242127], [6563368, 233554], [12394767, -951588], [-4912505, -581806], [17181400, 521381], [2753124, 1511630], [6351009, 761641], [15745537, 533814], [9588036, 96042], [-2989285, 2186674], [1247652, 1815558], [4347596, 340225], [-12997334, 136368], [2814509, 603685], [9554193, -1391709], [7638211, -1067475], [4692041, 898860], [-8706202, 363110], [-910443, 2917776], [15851782, -1240119], [-18102806, -573356], [-1501414, -1040481], [24664048, 390727], [7246730, -702648], [7228086, -1884936], [-11077996, 2218184], [21566834, -899455], [-900272, 842285], [12340264, -1844268], [-20506070, 1107013], [-6876944, 1070600], [6075564, -261275], [-21296996, 1201790], [10850211, -1033560], [5833996, -867342], [-26515553, -1574193], [34645806, -820899], [3658930, -898563], [43249578, 711893], [-32303594, -531006], [-11049306, 922427], [26264740, -1308271], [-9373657, -638303], [-8044768, -2847636], [-8841041, -27159], [-12439463, 1732230], [10381002, 2297222], [-5902472, 869912], [-23626814, 2350902], [-30937795, -1131934], [-20906646, -1883890], [17867092, 475841], [-1338588, 357756], [-38941111, -1040672], [-35619839, 678914], [-1326472, -278878], [-14270750, -2579485], [-15698098, -2438761], [-16534798, 3765533], [25435560, 389031], [-19250638, 2893084], [-60079550, 796469], [6565148, 2822079], [-33189336, -109070], [-30145291, 1048295], [-20364663, 1496632], [-20563750, -1092989], [4524662, -499540], [-35257692, -3281787], [14717479, 4962452], [-5309666, -2357973], [-392648, -3166438], [44596889, -64115], [-17174189, 257978], [59451718, -587259], [17485151, 327953], [-20704659, 4218925], [30155662, -5032756], [-16854410, 5420704], [-23678390, -4853310], [86743588, -75903], [21077164, 5593075], [47098075, 4420631], [16138426, -299944], [39407882, 5040065], [52574990, -1991732], [1815802, -9240717], [3874546, -1232041], [-76704702, 2587500], [-15753774, 543983], [16325869, -5525219], [22169074, 1374694], [-15186226, 3941151], [-76029948, -4139627], [57084062, -1222339], [-51288112, 6156797], [60958402, -206524], [-55179538, -2295138], [102631374, 2128496], [-15145415, 235094], [75866670, -3858650], [73274357, -5267887], [42940130, 5796218], [-93007073, 1239419], [-80868199, -3456142], [19380909, 6603517], [25846512, -7736166], [-55471522, -1524681], [64218454, 3880790], [-39744812, 4306334], [29127389, 8095262], [40759069, -1007427], [23945329, 11587163], [-139802098, -2075417], [-15792316, -7324118], [-87918385, -2698216], [-64714560, 321741], [-36003368, -8653084], [44443396, -4524738], [63847477, 3462375], [-70254602, -5756052], [7001689, -8270219], [-62361268, -554033], [80132204, -8333442], [-18329662, 2790550], [-27260785, -1309806], [34493228, 912509], [47130948, -9556301], [-138707606, -3440590], [-37719804, -2482710], [29325604, -10509898], [-96335314, -6521982], [-103977091, -7234190], [-173894910, 875846], [98469756, -5493892], [-64188459, 6816945], [-29719227, 5726263], [12205400, -363697], [40498194, -3011210], [12604780, 3531606], [-120328579, -2591821], [58503018, 1202850], [-24660596, -3372237], [-104643343, 5220274], [135433998, -3358076], [74357864, -13441676], [-58021176, -4561403], [-171421866, 2847383], [82269490, -5424557], [42185679, 675623], [-183299700, -5801304], [-22569370, 8391818], [97535773, -6245509], [-65529796, 2603020], [65252306, -8382152], [63198385, 7429896], [56888546, 9776702], [-6621579, -15136851], [-16160733, -14150146], [120870592, -2045000], [3505842, -16052802], [69380877, 10693205], [-109552719, 6459822], [-24209852, -5365639], [62442416, 12179953], [-8131680, -3308660], [189189880, 5337184], [-150848275, -4583644], [14914855, -21534881], [-127127758, 10325557], [-135787866, 4771125], [-54923332, 5882127], [119094666, -9188511], [-67080426, 3607562], [-165796851, -988359], [-251535080, 185322], [190336261, -3702533], [163534179, -3135829], [184999250, -8236196], [-47949483, 6296218], [79035424, 2179100], [23879403, -4390574], [-89185376, 14982403], [-60670660, 14776493], [47653760, 22366380], [-98116716, 1370814], [135141920, -10082066], [-199266772, -8093814], [208850707, -4811798], [132384014, 1548296], [282283422, -4595456], [144918920, -7291373], [73100506, -4598443], [29295838, -16662960], [53999421, -11356680], [-164450233, -7755687], [-143275915, -3941404], [-169874770, 11367378], [-9343570, -12868209], [-96900714, 8578938], [40927190, 10566585], [-32233506, -20486280], [-27523708, 23444190], [-27562553, -27160556], [118474512, 23020474], [95418614, -5660081], [-24532138, 12114689], [-14676714, 6050412], [103946290, 6623775], [31386898, 15075466], [-151516405, 19679635], [228691704, 2865354], [-423970539, 3383095], [-62778879, -9601712], [132024982, -1325164], [-94928980, -10330253], [-192205563, -7352329], [-5393650, -1358676], [-204599724, -1554876], [137071900, -3767353], [-2224867, -10250142], [-240869812, 13307763], [3152116, -6371144], [-355287134, 2834682], [21970106, -24154683], [-158149440, -9340119], [-41655289, 1889699], [146886308, 4428016], [-345099150, -13319569], [-207407559, -14388354], [-19303659, -25727705], [229861485, -21699140], [-470652306, 4817826], [-415452354, -1550582], [288296, -27134273], [-183621876, -3452169], [170628302, 29966936], [-142820074, -4714943], [-30183852, 18010800], [-89683594, -9943057], [65693917, -7581666], [-243718900, 6525900], [245663036, 28752319], [-247563433, 19345975], [372445340, 3046235], [116207173, -36114884], [462993773, -12474930], [93413498, -9050197], [-67004948, 27769164], [-82998653, -2471458], [-38059670, 44444540], [179356002, 25868884], [281426532, 18634878], [341541649, 7783376], [26921621, -43885333], [-114508034, -32613716], [-450513871, 8524515], [-41455018, -51941338], [27486350, -21499886], [394603184, 1075700], [-336520482, 1592290], [403051782, -4930093], [171532065, -16218021], [-127032667, -20725236], [-378494863, -6321397], [176495488, 20165966], [-292366561, -6389621], [-351004447, -1582008], [600094819, 1254839], [412441339, 286708], [-140805044, -19449880], [390237093, -3709164], [-86561308, 4592682], [-252743082, 31077263], [184869478, 40686019], [-69988559, 39686134], [4618010, 29524252], [165976194, 36643717], [-399280, -28889632], [-422350220, -8079683], [-141235373, 28766897], [188464332, 25972308], [-164617714, 37473092], [259488422, 12009040], [145663959, 35105624], [325464884, 18220348], [95299124, 53937436], [626003743, -9243989], [110248146, 38150394], [132930260, -6315477], [238433508, -41191492], [-563488712, -8636663], [476616, -13038624], [-203347291, 7443376], [55783528, -7551266], [-14494150, -62710526], [124998501, 5356461], [621116489, -7445064], [143817218, 24735580], [320471234, -24608108], [354744048, -37472742], [-271251839, -22806189], [1816531, 27190489], [269862600, 47445650], [42970054, -22809914], [-239378290, -55900569], [520197702, 7737285]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_280_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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