
// Make newform 495.6.a.d in Magma, downloaded from the LMFDB on 17 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_495_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_495_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_495_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 := [11, -15, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-1, 2, 0], [-10, 0, 1]];
    Rf_basisdens := [1, 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_495_a();"
function MakeCharacter_495_a()
    N := 495;
    order := 1;
    char_gens := [56, 397, 46];
    v := [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_495_a_Hecke(Kf)
    return MakeCharacter_495_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 := [[1, 1, 0], [0, 0, 0], [25, 0, 0], [-69, 14, -11], [-121, 0, 0], [152, -25, -31], [81, -34, 57], [-1351, 119, 136], [2284, -372, -164], [-1185, -93, -580], [-764, -920, 764], [1324, 410, -1312], [-3331, 521, -140], [-11831, -2, -37], [1248, 640, -1004], [4102, 2226, 2746], [26476, -3292, -844], [-22180, -3326, 916], [-13726, 496, -4474], [21206, -1080, 26], [-3802, -8443, 3773], [9101, -5831, 10742], [34496, 4559, 2095], [-24872, -2204, 12390], [-104024, 10816, 3142], [-86929, -10727, 5842], [-42184, -4836, -14060], [-52212, 355, 9951], [-31110, 2098, 8586], [10116, 14380, -4230], [-102257, 11144, -18661], [-61944, -21166, 206], [80094, -8934, -5766], [-117267, 11341, 26834], [-230647, 29871, 27314], [133853, 24329, -9170], [-163586, 5298, -8646], [-37604, -42796, 26044], [9772, 7453, -56419], [-29715, 41186, -38163], [125362, -14030, 32184], [-129106, 39258, -37934], [-90430, 23116, 67066], [35596, 57283, -26871], [145265, -19534, 29129], [85578, 78934, -6600], [211297, 45839, 60544], [72398, 21716, 116130], [130624, 42541, -22451], [-475858, -2416, 95648], [-22101, -41166, 121391], [-413710, -135548, 17310], [-202916, 91276, -48898], [770994, 45930, 53448], [671376, 133606, -105000], [-88032, 93219, -141561], [159114, 31774, -188846], [-112305, -58497, -60626], [-920828, 140639, 25685], [-719115, 114001, 57460], [302065, 212110, -177341], [-57593, 100214, 183483], [578495, -288680, -244397], [79164, 246258, 34594], [189104, -75190, -221064], [-6948, 14214, -31724], [1415626, -52382, 79600], [740406, 9621, 66021], [65876, -320581, -257033], [1437572, -17138, -136048], [-197994, -470848, -126240], [-1590440, 177066, 187210], [208870, 290788, 109706], [-630150, 46951, 209115], [-1854760, -210268, -134712], [-756444, 175506, 183178], [-841884, -186168, 220054], [2709204, 126356, 199914], [680846, -68594, -144450], [-1450176, -218934, -126816], [2476262, -263294, 149836], [3011886, 321162, -182022], [3753786, 341486, -144400], [-1734844, -732, 165526], [-1531829, -177199, -795356], [-542656, 646012, 223008], [-2408476, 106384, -602802], [892102, 580191, -305193], [1469945, -103473, -727334], [-1478166, 267612, 441694], [5212176, -345814, -51418], [-2103930, -425520, 67158], [2734690, 125864, 333658], [2291978, -477222, 281816], [-4998, -394962, 638420], [-2459932, 992833, 482505], [-5363626, 675314, 338546], [574338, 133242, 277094], [880669, -609076, -779323], [1430906, -480454, 1060498], [-1547163, 97576, -473383], [-12124673, -170416, -12435], [3223626, 135295, -901343], [-7474825, -96327, -912818], [-2018925, -274905, 82986], [306938, 803250, -320622], [-920208, -898490, 575410], [-9303341, 732052, 729593], [-11180412, 234202, -667934], [1979486, 385110, 497010], [-3266129, 390656, -461677], [2022022, -1335449, -919729], [-7647304, -1914264, 630674], [4574950, 1231306, 431164], [5784550, -1221206, -774304], [-4787252, -572084, 9554], [-13566556, -614344, 445552], [-3628480, -1293930, -475502], [-7836856, -174044, -674010], [-4317840, -437772, 1313928], [787226, -1591300, 772632], [-2939168, -1229785, 2048353], [-5217395, -2030168, 745459], [7595780, -974318, -1476894], [-16426636, 2920, -248168], [8009161, 1600329, 318428], [-259702, 447766, 632698], [7831770, 740620, 651034], [2610436, -2384020, -1596944], [-9702948, -987767, -414049], [-1387709, -920677, -210338], [-5581802, -1177091, 932695], [-5375522, 1100246, -192116], [-7775418, -2743806, 2086834], [504127, 2405569, 369470], [-2145154, -987962, -1873822], [614084, -118796, -1181678], [-5282723, 906230, -400865], [-8445380, -456806, -97008], [-1142457, 2014311, -182940], [1104453, -2476871, 778526], [6978999, -4053805, -958180], [-26140308, 607088, -712748], [12135396, 4195051, -1357721], [15595246, 2386222, -637786], [19156432, -1643474, 309754], [770966, 2374403, 591499], [-11556459, 201766, -1896131], [-15936722, 1644046, -439008], [13049104, -2068138, 1114818], [3173474, -950281, -2648645], [-2430492, 2822354, -1736224], [-15778276, 636440, -809496], [-7669858, -35513, 1717921], [-6465058, -103876, -107978], [2637242, 2424992, 295822], [25972635, -636667, 3441664], [5371492, -3864094, -2382456], [1382844, 1330017, 231519], [2650387, -1552543, 3309654], [9151716, -2572994, -3570354], [8171001, 3254944, -437085], [-34373821, -2775108, 1056651], [-1029492, 5278436, 1106724], [19929502, 2811214, 1051078], [20737532, -1558730, 85566], [16567412, -220708, -3408992], [21918350, -872565, -773949], [5219972, 2009288, 4146738], [-15018102, -6365850, 3494154], [11017444, 997252, -1696964], [1916078, -1969934, -522590], [344512, 2021502, -565642], [-30971314, -2831041, 854471], [9428018, 5698870, -2518096], [30692524, 1992786, -1306448], [26413623, 4566431, 86710], [-24602994, -5242258, 1447782], [-44073661, -2432812, -1019717], [13209716, 4653068, -3514874], [-12408012, -2650936, 215772], [1768168, -1172288, 397476], [44854, -2047758, -2316366], [18036297, -4613064, -4387781], [-1302492, 5251412, -4731772], [-13814620, 373178, -790712], [-1564680, -1770767, 1055547], [6363558, 5772180, -2671890], [-21976148, 2456646, -1600024], [-2848274, -3528058, -3976308], [16523118, 1052682, 2302350], [3300072, -641881, 2086295], [35650534, 2057798, 719896], [30469212, 6764100, -3647870], [10755598, 5625923, -3966583], [-20678756, 1254942, -8448284], [-7648054, 3563282, 4029490], [-30030634, 2768828, 595972], [-10228151, -2032084, -5835433], [-17513378, -3211679, -5251909], [3052853, -7046295, 5173256], [26641685, 2617183, 479444], [21063650, 908340, 7667952], [-4765880, 8050240, -6940330], [-50164002, -2776130, 1707688], [-2720504, -4870282, 891744], [61108724, -1543520, -3164516], [1307350, 7961695, 1275221], [-82053765, -1352857, 677240], [-11277836, -415668, -5812204], [-13680996, 9023457, -4368033], [28838732, 2331978, 1249792], [24552684, 5200200, -4190804], [-33607216, 10241918, 2642386], [37266720, -10638074, -7118018], [-4387242, 1525288, 9062436], [-32813759, -4006528, 5241637], [52961281, 509415, 1478342], [-12163740, 5316762, -1771062], [-15319800, -6809560, -10323990], [-50022210, 6404568, 2151212], [-3027611, 3618621, 13454666], [-41750020, -4734746, -4259612], [80423752, 13070372, -6506516], [13626986, -8263779, 3930215], [58402184, -3245096, 10824350], [78020674, -2293090, 8742042], [9659016, -2937962, 876690], [18682385, 2723750, 1330075], [-33442410, -1273172, 6542398], [45267176, 11722036, 1856774], [-3467599, 10944809, 4335634], [-54798607, -5759593, 6192536], [59553135, 3342791, 11717420], [4399586, 12808136, 4176750], [-27944502, 2076921, 7810967], [38044594, 4794350, 842374], [10480635, 2663590, -1927841], [37512074, -13234198, 3487392], [82891680, 8738070, -747790], [67299196, 15604144, -2819296], [-72138341, -13615899, 10338528], [-6277636, 9998860, 162704], [-52350762, 943446, -14771218], [-62079525, 320826, -512705], [60318108, 2934854, 10208346], [-76881574, 9088040, -147334], [90146850, 6605826, -2813088], [101452883, -6681641, 4791530], [15906762, -693219, 15232451], [-65424520, -2691541, 1531277], [32492113, 7924111, -6140834], [24325560, 1026326, 5110178], [-89089742, 5123740, 6231908], [65837583, 15085160, 5001381], [-62657586, -9297042, 4674896], [-53333666, -6627378, 3090654], [-65600865, -833334, -12119603], [57348592, -248294, -10697676], [-10376524, 7685673, -6088073], [-9608779, -1950396, -22690091], [-44993154, 3726939, -26599287], [-132075662, -9178780, 2135380], [-49234838, -18778271, 6857413], [-47561114, 3609332, -24345748], [-27871610, -18109486, 3384524], [-5215644, -12409118, -11624616], [32492656, 4029346, -15397916], [-56350109, 4787080, 8458975], [102649521, -14216804, -12446453], [30052382, 3348936, 7353888], [-96431474, 3969868, 6347774], [130735022, 10572974, 1546474], [118611871, -8644939, -8350460], [13825010, 4109507, -20198345], [178184002, 5627640, -4540918], [14801516, -9176026, 12461478], [-63946820, 13625782, 4811432], [-120410430, -4971914, 14914406], [81213788, -3917886, 2389226], [39358728, -8420721, -17532781], [-85064996, 26120876, 15970600], [-89348306, 339733, -14663017], [-74815208, -12709204, 2838706], [-56523319, 3643464, -35889915], [-27380808, 2410310, 25492650], [129375552, -14614892, 5180018], [-174839539, -3923680, -13666133], [-81378604, 16471112, -9846164], [107753757, 4189467, 2602102], [-83185608, 25721456, 11561130], [130580204, -7043380, -14204908], [-108935301, 5677542, 16844195], [13160460, 3972258, 15247314], [-12961382, -22286703, -4474539], [-396167, -10865709, -29490290], [69444030, 18190818, 7830912], [-14495144, -7310508, 14799334], [-11872318, 22807434, -8204680], [91226663, -1593648, -7309125], [-42858380, -16426703, 1845567], [-204239421, -11591172, 13830861], [106034081, 9156119, -13006360], [130214404, -1326470, -16898902], [-12340752, 10835768, 13442140], [76901316, 20455722, -22962940], [164170208, -8579362, -10895358], [-104402762, -23110580, -467404], [-83732300, 17206130, 20247186], [-5160274, -5336945, -13993], [-36715312, -3317843, 24820537], [-14270280, 39348972, -788074], [-38977735, 5015455, -39344106], [20499878, -4989472, -34863774], [-163034880, -2624171, -22781423], [-184942056, 33231124, 21086066], [194965056, 34153788, -7028576], [-247720484, -17226362, 1925706], [-48524854, 25122702, -11040594], [-99828961, -1801387, 9140794], [8327437, 2294995, -24232536], [-140925262, -31624030, 7941410], [104498745, -13327935, -8035548], [91301130, 11639640, -8620566], [42617691, -31381742, 25990783], [-174805058, -1353246, 18214230], [112050332, -26359236, 15027780], [-114804704, 18229748, 1531960], [-53096788, -27638381, -8062029], [7463601, -13618062, -619319], [110966986, 3902556, -31386492], [-111221426, 40492636, 2709116], [3399293, -27786127, 26534758], [-172392012, -6538527, -11543115], [3755887, -23241599, 24859648], [168094504, -2257376, -1382700], [-166240554, 1777960, -4230184], [-134296781, -39405238, 24575639], [-96014466, 3570826, -6170682], [-44562973, 38717902, 28722509], [92825072, -19206280, 11482834], [-6144254, 8482536, -11021804], [144514181, -4327097, 195366], [-13754874, 12693294, -12624012], [-178426176, -49112960, 6307906], [-27190238, 31374660, 30058898], [-224250930, -3934860, -1586604], [-39629640, -14964416, 25317884], [-163569648, -33655896, 19366304], [13857616, 18491392, 1509130], [348848437, -23694631, -13909738], [75461806, 9973980, -6928416], [119746248, 22475826, 18887796], [-39881729, 8688264, -16329093], [-91473196, -6724526, -22958092], [-81458439, 33244350, -21244743], [-27053082, 25115812, 26844046], [74159782, 17708128, 4006210], [-256773575, -27712600, -9466461], [-114502472, -19425702, 26084678], [-80789950, -49983955, 11691913], [-346008291, 18824799, -17747822], [192975184, 33044516, 17769440], [233866370, -8890408, 26212758], [-199951820, -23802336, 12562200], [-166276474, -25768566, -32825442], [-261605901, -26698300, 26206901], [392176491, -4572270, 23346593], [36220986, -60980822, -33632886], [-219987340, -9568764, -49190044], [-132066298, 7058694, 19814208], [-287603246, 14948889, -23954785], [-17371265, -28773967, 39120810], [488997315, -8615699, 20737848], [-25484742, -1109130, 59453730], [147350490, -20674286, -13594952], [-350218334, 9236980, 17742286], [67749596, 12467601, -2200025], [-144386805, 1559641, 38999658], [106894586, -30241313, 43054667], [-239157932, 27222896, 38151830], [-203091888, -15544954, -39277624], [340121335, -26082936, -31018581], [-415418055, -6869074, -39149311], [-146556073, 61397873, 48959296], [-465449900, 22816690, 10619882], [181975006, 42012922, 3629968], [-5958300, -14980968, 26006670], [-193098119, 12879496, 12391757], [268558340, -22233638, -1517286], [167721438, -37416562, 35377170], [268623906, 27205714, 38791534], [271991718, -13561530, 7150392], [-276783534, 26610552, -50149386], [121062900, 7966846, 24637966], [49736498, 55400739, 14782359], [85057977, -20011781, -6529564], [-537208058, -12422212, -23292204], [-14259576, 70730180, -33745512], [1140999, -37309521, -37387864], [213513508, 69258180, -49329018], [42474480, 85501204, 8610070], [288338071, 2555202, 270477], [202997604, 5789718, 32722380], [363223401, 16909575, 18856746], [-62833507, 8791065, -46591530], [-295633364, -18110240, -56000426], [41854773, -48925357, 16916966], [-42735926, -66228192, 7599150], [348338822, 67309350, -35085992], [-48979420, 10921865, 17483095], [243221967, -35868586, -20766733], [380653532, -28260808, -21891664], [46856059, 82152023, -22955974], [-27224650, 775529, -54208111], [242213062, -1845084, -17700572], [-214731126, 14719630, -14857976], [211249916, -52934424, 1966788], [-469113510, 20474916, 36854496], [-152606528, -56401635, 18954497], [49401464, -46933054, -42885876], [629636378, 31752545, -16723643], [-158516156, 56693350, -63327458], [477894966, -6147416, 38325754], [-85592398, 49627116, -43808700], [-113007428, 28100488, -17576362], [332441604, -42229080, -27236192], [-26041035, 57205987, 52820542], [-139471908, -67885176, 20236896], [441809334, -34488692, 9610026]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_495_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_495_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_495_6_a_d(:prec:=3)
    chi := MakeCharacter_495_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_495_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_495_6_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_495_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![88, -60, -2, 1]>],Snew);
    return Vf;
end function;