
// Make newform 5.14.a.b in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5_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_5_14_a_b();".
// 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_5_14_a_b();".
// 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 := [-18720, -4466, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-1, 2, 0], [-5949, -16, 2]];
    Rf_basisdens := [1, 1, 3];
    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_5_a();"
function MakeCharacter_5_a()
    N := 5;
    order := 1;
    char_gens := [2];
    v := [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_5_a_Hecke(Kf)
    return MakeCharacter_5_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 := 14;
    raw_aps := [[47, -1, 0], [138, -3, -1], [15625, 0, 0], [150090, 1879, -99], [-2199208, 6050, -330], [-11149994, 62372, 10380], [28026506, 957764, 7788], [32906092, 1339580, 112404], [103206534, -6456303, 179931], [738621118, -21088280, -779784], [2502765372, 26951650, 1649910], [10520598278, 108165384, -6455208], [-3637063598, -180118100, -21811740], [5631483610, -44724103, -8620077], [10711842434, 246549119, 45223509], [-74021249842, -833062228, 81563364], [-17258471524, 3593888840, -67120488], [166423129582, 2927210000, -180786000], [152550574686, -1675384061, -29283327], [171523294612, -6972263750, 455730750], [833124544834, -5146299628, 505636956], [999761067528, 8052774820, -593544564], [1709555617002, -9286132203, -817515513], [-6468325746486, 18339769560, 291050568], [-3698595835606, -12890819556, -5428709196], [-9011218387578, 71604156600, 2024849640], [7537131647438, -12451007403, 7381040199], [4835863600110, 36146349279, -512674059], [-1196484207154, -139797230760, -5350254648], [2040707726786, 122267094872, -6240354360], [2675049968482, -150457924201, 7463684445], [-5917878365448, 475128287550, -9644350230], [-48736946577942, 74413087584, -38858228448], [31183809044684, -983049404040, -14292475992], [-125238286584650, -284944232600, 24446983800], [-15235865455628, 74829496850, -17670998010], [79730382413150, 1553048958504, -55287282504], [159250585411586, 114896853297, -48660950085], [-178066991552574, 289741668939, -22310361447], [194851951086894, -123640720728, 181505912376], [-5015438177692, 2868359166320, 125649116496], [325401431143142, 341048538000, 236876305200], [-94789066733708, -3776777952650, -360194315310], [623496044375450, -452393135628, 384960274428], [-209762099139426, -2572990282356, 607400351364], [-437929810592600, 3462551211200, 535350177600], [-354171610670248, -724681156650, -905948096910], [-1968477968731546, 491922542997, 776849924871], [531657374654302, -3502388584301, -448407902415], [443254234705398, -18879986475680, 267289126176], [-95521786675758, -3983033220228, -568196145708], [-684672858232936, -23897739811540, 2166675719268], [1773369790215322, 4671055809500, 1517024781300], [816137733262152, -5039478066750, 1850530454550], [-1674587643411150, 2475191975304, 1164844673496], [815937178386166, 39630463717297, -1923619750725], [-1763862602311138, -17384076080320, -1438989550656], [5991626717385892, 23474806586150, -1234244933790], [1400565897926262, -2282340505976, -2172205326120], [-7157374375264878, -41366023547100, 3658078011660], [4140439499664282, -87010731961103, -6104045659653], [-1192030008523530, 8601295533072, -5014389790032], [11846287965796750, 9804755624579, 6169225070721], [-15811182883750788, -69685497902850, 3790992605610], [-2360138870202934, -117014839737528, -2141368161000], [-8670096283166234, 143213945334964, 9746064757308], [18469965026287632, -44035248861050, -9163919996670], [685357175865058, -214597399627816, -12056114200248], [4668635022826334, 8042994659519, 221028233109], [6546463324570990, -173966179613200, 23699152057680], [25842882521220018, 74721115894872, -19140173743416], [-14244746449666584, 63971244345840, -31544427058608], [-45450783214271094, -29524637965061, 6194867414313], [14915485813899574, 445425517806872, 19276925686536], [-8141543680063532, -86512566220180, -20087991822684], [-2372348902267098, 287757752886597, -58114466615913], [23774248569833334, -2451052043040, 61037223227808], [15049898875026454, 323979399168644, 30954191994924], [11702648457567762, -836288809999200, -11979250363680], [36089561083883666, -377256329212860, -22589361205908], [-5437078130497628, -405888179900120, 68728330148664], [5152080226692742, 728156338159400, -27820088583240], [4695239618578452, 280744355567550, -237401278230], [-41154755345254118, -264631789687828, 17695872913572], [-134348317076042216, 665751418513760, -35038567706592], [33768498055531410, -1696292545714203, -90198928973577], [70142397566080010, 1262963316807500, 2516282926020], [-181041136174789430, -964869887460496, -37767795772464], [101580447173442702, -1212491162279400, -45606659744760], [-178717243063549914, 251432693803597, -30592414624785], [323458709309154886, -687249824800361, -52657568565027], [-182739855872805672, -221703193026780, 46953978636], [4459868131916498, -2270113560608541, -78715217112543], [333477873324868312, 560712251866450, 408761941830], [48837649264115020, -577438487080900, 240319588289940], [-212103887951595122, 162659723087197, -163407132602721], [187546682237476526, -151492653892960, -114820527821088], [261718744924705642, 4187949251862400, 212242872960], [215839034874191434, -1336253264596303, -262792132099269], [7048895596352382, -2948896648554200, -548963328580680], [484772423388624334, 1483203585442619, 556428655720809], [-414018580970156370, 2974537686940104, -115350120989544], [-407723028051349974, 5936967754991397, 361856614317495], [-29120799782974638, -2217211520251020, 245570574994044], [-443683397607875248, 2793314196013950, -48258666851670], [-571675520981531038, -3225056564454576, -405935929963920], [-290617043923663962, -747182275010541, 381588583925937], [590657030317269490, -4848788280716528, -316852380531792], [-1202892263110607360, 2895408339070300, -335482997755020], [-220861798132318798, 391811017024500, 517106635362300], [681695013145152850, -12402033051977521, -195401989150779], [1124959800805871566, -6967778750167228, 231667821576300], [237483969217968786, 8955600013007964, -1014758559757452], [-470238533685116908, -6660335479361820, -1064817955430196], [-495654741382366988, 7598892636742850, -254880802709610], [-283961361265276758, -11057590780200900, 1075085842309140], [584531097572697810, -6683605420770503, 1051105834075923], [1308730608199160114, 9528475389242819, -1167358629562431], [486312244135471558, -8894495790808628, 78430677181764], [-2525533355926230844, 9771791199641840, 112213823185872], [-165159974529342938, 21950177649892400, -604042171565040], [79955676524433114, 14987940744382372, -1587111372775284], [-1267121896723233138, -9164078941833276, 208528126399980], [-566939561848681878, 6746259594328497, -804516466168773], [-525598941852819008, 14901175034260850, 2167597926727590], [-1418191024112450018, -21118212416846600, -1249390625495640], [1380396992855670406, -16797321805354360, -554906206661928], [77143852488940152, -20228376494310420, 1552508145871524], [5145958397105716682, -7427963877922401, 99513748715445], [-407449944028288498, 8628556729401072, -22512555565488], [3992280385678105924, 28919457053968760, -2022221637396312], [967442635456474910, 41116210352159597, -1200774037209777], [3812384829263968732, 1373240352642650, 931383326081310], [-1827260743060533530, 23599298078083904, 1240587306419136], [2327745758275183002, 25951306192257600, 5078550799055040], [-1247570380221235438, -58650027303901320, -467049492503256], [-1627119224879970786, 39692220669516972, 2942619926796516], [3056153094464844838, -5160436707664441, -2038041284735763], [1916388945671249494, -8937669799191956, 593829899655204], [184699721574001546, 75022283023253440, -3249330380192448], [1026784080908346072, -5510141386585550, -5386130431538970], [-1097818610890407018, -71909627990513400, -2644138720488360], [-910523760463001386, -92390741857892103, -2786363861758509], [-9161907424255865938, 24808490207089799, -2320813575344595], [-9437341796585065362, -150768555640880, 828198757199856], [1852776615152629744, 68598498676710460, 166923737060628], [-72982288410362322, -23962568249471828, 2867184530405604], [5029184795764635530, 29924315914244504, 488612919634056], [3649008593791406956, 13903348852381040, 1890366188296272], [12271080545545530766, 22654270532500897, -2336712695687925], [2094941385025654302, -90883732947076976, 2559989942541360], [1688357599305118922, -25874757893607100, 11112435777687660], [-1686933573650367238, -59783283637941603, -2730335152200993], [782581295253720378, -11514448466346441, 3861918323814717], [-9168395097326952330, 64970058999747979, -7889057460710439], [-3452437182162459508, 16154680212876050, -4002942412302330], [6002622555294877552, -79121383732932220, -44153211537876], [-8246982718498512662, -79595033095193780, 96717188745156], [-3758585792177155422, 132255857707660084, -11923453099056708], [-3435945269524475618, 88898821383764800, -4253479625878080], [8559299738109601614, 128531372265861219, -7947202208465631], [-19115355077316217222, -138151104965027728, 9965943069149904], [7407468334362756506, -9411364822171761, -5710137692571387], [-15501954704746213728, -141926429690208450, 15643603697531370], [16879276176436221482, -253672959553243276, -8954153856200580], [4944174777410879862, -36343041520810503, 12156708789764307], [33036305078165766092, 107147669452841850, -10101503271035010], [-16806305135387370546, 157495832446345444, 13183981723048524]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5_14_a_b();".
// 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_5_14_a_b(:prec:=3)
    chi := MakeCharacter_5_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 14));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_5_14_a_b();".
// 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_5_14_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,14,sign)));
    Vf := Kernel([<2,R![901248, -11144, -142, 1]>],Snew);
    return Vf;
end function;