
// Make newform 115.6.a.a in Magma, downloaded from the LMFDB on 27 December 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_115_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_115_6_a_a();".
// 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_115_6_a_a();".
// 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 := [-455, -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_115_a();"
function MakeCharacter_115_a()
    N := 115;
    order := 1;
    char_gens := [47, 51];
    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_115_a_Hecke(Kf)
    return MakeCharacter_115_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]];
    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 := [[2, 0], [2, -1], [-25, 0], [31, -9], [-280, -3], [427, -21], [960, -33], [-737, -33], [529, 0], [3010, -150], [-5915, 147], [3932, 180], [1678, -501], [-15216, -168], [-13962, 354], [194, -888], [8288, -1218], [-5276, 1383], [6668, 3024], [-42382, -111], [-23892, -162], [-17244, -996], [-28398, -156], [68656, 264], [106924, 813], [-85670, 3882], [-96680, 3261], [-37986, -1602], [-78157, -4623], [107994, 1872], [9560, 8862], [31950, 5352], [168261, 1131], [-104236, 10026], [54085, 6675], [408498, -1491], [108422, 6870], [425859, 7677], [45156, -11484], [651066, 2625], [139146, 9894], [57751, -31539], [-331548, -12990], [-570812, -4602], [535630, -11673], [37742, -13152], [-394254, -2124], [-1144024, 10140], [144010, -38118], [437414, -17304], [-633944, 39330], [-369116, -44004], [452616, 23136], [-835127, -8871], [74152, 4290], [584032, 71559], [-92010, 10590], [-1053935, -30873], [410514, 5028], [267498, 41934], [2726, -71880], [1475514, 1272], [-1545566, 8673], [989284, 51048], [450831, -76575], [-1758369, 30051], [843680, -36738], [-1834859, 24051], [-571782, 135039], [135338, -28788], [-2294720, 996], [1501794, 48036], [-1151968, -140340], [-1178776, 140862], [-2088924, 130119], [-1768192, -7152], [2223952, -21927], [-3181814, -45249], [82952, -25170], [-429119, 201429], [-593232, -297588], [3920335, -52443], [524098, 150294], [277649, -176853], [-251923, -120897], [-705599, 74175], [95475, 127875], [4404346, 76296], [3474112, 186390], [796166, -10020], [1567368, 154494], [3973602, 151548], [-89452, 276894], [6006894, 119838], [-4874936, 165996], [-5531409, -177465], [-2934174, -192426], [3206670, 320772], [-382318, -12276], [5825704, -237312], [-7849659, -57249], [6059612, 86880], [-269600, 248256], [11532798, 126252], [3031268, 273909], [5544242, -238560], [8986718, 128799], [3606980, -344994], [-2409378, -225237], [-4324335, -295683], [-5861848, 439080], [3305326, 136140], [-5651372, -105921], [1248525, -131535], [257260, -497358], [-13253344, 312336], [6889522, -627906], [-6194618, -413520], [-13774473, 104739], [-449028, 336348], [-3608216, 760383], [-351566, -301428], [-3680118, -500040], [-5752849, -447795], [4864462, 109290], [-1972503, -342345], [11776884, 569421], [-1626025, -679935], [21813892, -61215], [11163302, 160944], [8749652, -299172], [6306463, -819237], [2735144, -1101042], [4102360, -813348], [-18643275, 70017], [1850510, 686580], [-14738572, 621228], [17324552, 271290], [619280, 1005522], [3020130, 1349505], [2698086, 471966], [26507770, 505092], [14625386, -304380], [14481136, -977874], [2411502, -1382112], [-19598406, -794094], [2917573, -458907], [-4235846, -332052], [-11293382, -787998], [38974152, 202374], [-9920102, 511419], [-20897156, -351132], [5828785, 1049451], [-22452488, 348960], [-34906, 1165038], [31886258, -215706], [-22294456, -849564], [27980670, -1088220], [-36326431, 158223], [-2242128, -109425], [1868069, 252063], [-3005536, 1362177], [-7824928, 1688730], [16482444, -264297], [324531, -1102059], [8936976, -2230995], [-12942886, -1006077], [14350130, -1593588], [-24905396, -409854], [16426722, 1256979], [18406772, 141108], [-15783694, -1132914], [14867694, 1765218], [-23110436, 1988817], [25574142, -1381227], [8031410, -229410], [-1396266, 2784468], [-6210624, -1052664], [-3126340, 486621], [12381881, 1670139], [8912264, -381222], [12902224, -2185977], [16478995, 1658331], [-20439878, -1999110], [28917636, 1317825], [34549813, 975087], [-8116909, -2973429], [22868708, 2293068], [-44207906, -372669], [73391962, 150165], [5490756, 3203070], [40680536, -815040], [25180132, -1225800], [23625072, 2788440], [32301522, -1284540], [-3083827, 271983], [-3822818, -2448750], [8262106, 2074800], [38431498, -1788816], [-42472626, 2048982], [15937312, -3083217], [64080085, 1247427], [-19023154, -1591989], [-86440552, 167352], [85134392, -78192], [43164878, 1552044], [-54970266, 1028076], [-16806410, 620001], [22352979, 140871], [54935458, 1718694], [-53908790, -928758], [-43194078, 3048300], [-1072013, -3572241], [-46901958, 2235630], [25656428, 1558572], [-43464594, 21006], [-3579524, -3416154], [6518314, -2929092], [-15781911, 4444413], [-399874, 159360], [-14415446, -1544382], [32819514, -747504], [-30811202, -357723], [-37222755, 3850581], [-32866860, -2880168], [68549614, 959586], [92806579, 1140717], [87620937, -3073197], [8659905, 11397], [46436412, -122520], [15758277, -188811], [-8124728, -2508687], [74765476, 1911276], [40530638, -4326861], [48145554, -3619518], [-6873276, 5898708], [-75152434, 491454], [-11990130, -3148494], [34455330, 1380690], [-89675418, 913095], [-37496234, -704370], [27354602, -1899540], [58184162, 3782484], [-51092696, 1536966], [-51659834, -5450310], [-31550705, 6556965], [-56008014, -2555274], [28649211, -3905589], [49345400, 3340995], [-9070504, 4951575], [64736100, 2966082], [13473880, 2909862], [125877093, 1325229], [-9598764, 2340924], [7408234, -2607228], [-26412636, 6812586], [9902548, -914811], [34116548, -1488666], [-62829849, 343431], [45219554, -4621272], [57977244, 2234187], [147842130, -759048], [-10622048, 1655748], [-192070242, 714018], [-17795950, -5952108], [-29509980, 5420445], [-39875340, -128685], [34658838, 735384], [174441316, -288630], [19322553, 2044653], [121120702, 3932250], [-76859128, -5530860], [-176843229, 3281565], [45860716, 3814104], [56431418, 612864], [171143576, 1832970], [-40915822, -9092271], [97202774, -6168654], [-135232078, 3753480], [-91719169, -752169], [-36433564, -2550240], [158047388, -2801376], [228264372, 1143465], [-95128906, -4217052], [-28667003, 1245315], [-96598290, 6987357], [100902438, -2223852], [8712648, 12866274], [-4390502, -8263473], [-12945630, -1405035], [-69169522, 2096904], [-9762048, -2744730], [56482668, -2671362], [12340973, 1729269], [68765018, -6642927], [-29576984, 889719], [-123886734, 5049006], [-16897050, -10503759], [-134948850, -5050680], [28369410, -243813], [20479067, 3917529], [157810554, -6400302], [-39281616, -1877634], [-174939168, -642336], [92326653, -165051], [-100925092, -2132826], [-46690842, -2844531], [81949149, -10264629], [36763666, 887094], [23498066, -5115615], [58168302, -1539066], [24495255, -2733555], [-236082440, 641202], [98477470, 11000631], [170319385, -3597663], [-238931594, 4223094], [11633582, 7754328], [95056695, 4817517], [-40001214, -10611720], [55350618, -2459313], [86716168, 10381539], [173919328, -1021731], [150691730, -5792388], [-187828354, -10282110], [-192455884, 638055], [-348432336, 2133168], [-367739325, 115875], [36353579, 8612937], [-309053177, 872979], [55010838, 2273238], [-118598760, 9072702], [-40091682, -1794231], [-130946848, -7073112], [-2206149, -2469495], [-139909772, -13285056], [-336403725, -4091343], [216336620, -8183025], [-259191594, 765720], [-224397938, -8829255], [298565944, 1590423], [147342798, 1147788], [296138940, -1091013], [108966324, -7205184], [-122140818, 13238130], [160183362, -2379396], [60325180, 15520980], [26703642, 6513840], [106268315, 7995837], [15624202, 12188340], [-242611674, 8483886], [220172198, 13500054], [-93474842, -2086236], [-174666508, -23910], [211009796, -6975105], [103664078, -523848], [16832934, 10840122], [50833560, 3723810], [219226515, 8363847], [175393446, 8045376], [80554558, -4323072], [353871444, 3610578], [-145147422, 4010784], [-234493988, -5453430], [-55293624, -18839001], [-36913642, 12458349], [-20175982, 21395628], [16017878, 11814939], [137151200, -11411064], [100005158, 9548334], [-216361526, 3952728], [-479911004, -5110446], [-59719346, 8305152], [21120900, -948015], [-425671640, 2387892], [82897649, -19521747], [290843074, 725286], [69257616, 3868806], [254786240, -18650259], [169045254, -15677814], [64119620, -20571528], [-60757140, -11815623], [105861900, 5600271], [131476628, 727854], [141881474, 1389228], [12185980, -7736460], [-61418072, -14748912], [68212869, -527337], [111392627, -11636445], [39810278, -389352], [-55230093, 12130755], [-74395934, 2810964], [-166348115, 7360701], [-286777756, -12594444], [260974184, -3541812], [-98267802, -6867276], [98422665, 26536011], [-5847126, -18711804], [-181580616, 6906156], [35482481, -22715679], [33971534, -12330192], [233856328, -11589498], [472001108, 1990458], [-140684764, 75696], [-92694005, -4127163], [-330755256, 14574336], [-563719110, -6099933], [398488022, -8004570], [14075777, 15875985], [-181454202, 5865078], [-429402468, -1390992], [306142964, -7453278], [34324602, 29068215], [-623772440, -7248504], [270163044, -13259667], [-280700527, -13687701], [176609118, 3545424], [-395174605, -3815415], [-392443118, -14971470], [150328048, 19650999], [18306923, -6389277], [265618836, 6885609], [238759582, 7291710], [-553803394, 11471886], [-178764206, -25461834], [-585799046, 7143282], [232194206, -22154784], [641395896, 13595760], [-43575339, -16513011], [62732380, 18887922], [407458898, 18071607]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_115_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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