
// Make newform 50.12.a.b in Magma, downloaded from the LMFDB on 15 April 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_50_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_50_12_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_50_12_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_50_a();"
function MakeCharacter_50_a()
    N := 50;
    order := 1;
    char_gens := [27];
    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_50_a_Hecke( : Kf := Kf)
    return MakeCharacter_50_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 := 12;
    raw_aps := [[-32], [318], [0], [70714], [238272], [2097478], [-5955546], [10210820], [3535758], [-139304850], [-101002348], [524913814], [284590422], [1253635078], [216106434], [4881275358], [8692473300], [3296491802], [-18275027966], [-13287447588], [32505250798], [9297455960], [22741484838], [-93378882390], [5811134014], [62936756382], [-134666895722], [136264211754], [103465903610], [185470350438], [-500128288886], [397121483712], [-167637802146], [55242512420], [627642305250], [-1205732079748], [-586706594786], [-433241051402], [358129197834], [-2346255958482], [-3335047942260], [3819204873902], [-2562504457668], [193904625958], [-368562008826], [-7198560742120], [5673983461712], [-7992465118322], [5393003159034], [-12223865406970], [784141067958], [4352182798200], [4459364814542], [-8618515558848], [-4595195917626], [26603874813558], [-21237835548150], [4439693045852], [2635254629374], [-29985568366218], [-505204656002], [-49562883184842], [-11624461165406], [-10310549335068], [40499755863718], [-73861733511666], [25120559007992], [15463133283934], [131168050069554], [-150977654254690], [-60491420130642], [-33094662413880], [209977858911154], [112372549945918], [1714196186300], [-153136756371042], [261487665256770], [229527590909254], [-354324368305278], [-138194511543730], [143460745046940], [-36239017978078], [-142358406084468], [-482775079782242], [204059674428440], [-333038010397962], [-724364128384410], [-430780674212906], [415819013897862], [-200145949250522], [-475882127255166], [-470642345846280], [602089525403314], [-553669468807488], [568166028117380], [123359243000598], [1275698951725230], [-1155961555122678], [63087872771038], [317732151583382], [1809759283866394], [-407238427291866], [1075346167746318], [2239645387706190], [797473289111672], [-690255331092266], [-408704728472406], [280244529817038], [1581215380792320], [-1679842938221338], [-683438983516526], [-943749277670762], [2650312243643574], [-2478750142436020], [-76963582243348], [-1722642052211058], [-2906664987703922], [-1879098960661566], [-2337820806480642], [-5004311951685540], [3073833028206482], [990717367831918], [4763070080179014], [-386750412789402], [2550330419108792], [-2639670479538438], [-2450618640214570], [-6032373255555720], [-9091022278199126], [747227091902878], [-3440527085278420], [3266537078146158], [5581032952014932], [-4347038821587026], [-777252552821478], [1553286181037570], [2197493007478518], [-9742295814909446], [-2199081302694306], [1542023837894730], [-5243509453550128], [14887533669985842], [-17796319227298322], [-16707593850222606], [-8539517445866470], [-10576832981254800], [-8276012168247482], [-1705836741703746], [3033390055746020], [12491699070492318], [7835886114371854], [7146422109172782], [-1259324374103762], [-3314036448983766], [-25737521232034046], [26575674993684612], [36957665204734160], [8618350278580470], [-11316263185883066], [-20862649019517738], [38575053264004914], [-27967886995825002], [-24387566000763326], [-7425711149837928], [47855261797716174], [41026085992007958], [-7806294931676908], [-39327491471811746], [32048025455322770], [38865946830609318], [30893041432123260], [-46745787727065898], [-13554298596981468], [748809642053998], [-48260116326752560], [-49003340268919590], [-2823489201102088], [9334629247255182], [-6233080592507042], [-80722776158648950], [30590329525505554], [-16940646692905968], [25068370587021838], [84396643063809294], [-62294564023740402], [-13058242944462090], [57401719131355414], [-82194195075115442], [38652145764585230], [83522623842496452], [132746319007384918], [49335118478814918], [122798365101969512], [-62421571513403718], [136003807464087354], [45306596289978678], [-34809857627084338], [124575217572420718], [-36855335479410786], [-114915651248209242], [-4749081218605170], [136208153559440972], [-124952836467521426], [-61185491013977710], [143463081245682660], [164139937735905294], [72924828571925600], [-38103976967576802], [-61828482499690230], [-177349988621981368], [-177730832211540986], [-56342878302499758], [71180764223839798], [159580348354139274], [-45570633833592720], [248940767602895942], [70886137165609114], [111867138053817522], [56515984534780074], [233524986390641238], [290795806906889762], [-19540133957833120], [322007251505935890], [100149845238136438], [271696051464757674], [268653384224984210], [431556082296809838], [-197739941829724800], [-466989253438565246], [428698489305888792], [130607312572118518], [346382701358107700], [269134081090391852], [-142174362991232058], [-192386402551335602], [-109222901644985526], [-217854077089246330], [42953968195887918], [-93415101232594980], [570651650778210612], [-483473294419642602], [19626407176460672], [643304161285492318], [281889268762493630], [-564437504653089282], [-671331078980086200], [331663113009294394], [-299543327887940088], [-514001457355332700], [369942164255543718], [392914761900022774], [422648287807296402], [-577751434487934126], [-378943621230221410], [420211157762382318], [-581241981721801740], [422692782675990782], [98854920441415714], [80846083891709454], [268557288615999574], [860018463794778238], [-344776668577403286], [-43323166973060410], [-955325736992494922], [397252108825092054], [854752191269842580], [-492569153427950130], [-827335404563500518], [-344226864472101962], [-892827453238458522], [522228375898954022], [-1231449947821898846], [-414598718445138122], [-1052868600182470960], [-536667400055781386], [797890581754172878], [1103029379145131874], [-3528058098235810], [-911984278808488138], [563668573313628912], [-502274738438194002], [482122122358018292], [-135947955762830046], [-13021150508833378], [156702165870135034], [-1245653123260425228], [989824887673858438], [-359344695437986986], [1513835302672503920], [-1249851694746767370], [-325688580542440758], [547837000076402634], [300601897291928958], [861893208656193552], [-984711905242659122], [167397046105878570], [1364636325765653252], [726151975555504518], [-1536681124666823460], [-931260149512863086], [884542656916501438], [-1790248344042593826], [1743055668890446520], [1010798101085342478], [-1550502910039432288], [-20291933359168706], [-3998521568229966], [899225698843155710], [1976083415712695880], [933039134861966038], [255485853021648558], [1428573855365415030], [-2101129993936982238], [-1655391581682987602], [3042769016792190234], [-1208500221842485990], [-1695653176131630300], [1342821062562171972], [-1268255534568593882], [-2550546795786036330], [-1590510733150627528], [-2182580207472020786], [-1462900703302151238], [-1918197040083376682], [-3975159982719715122], [3154214348562486302], [4452642688578109940], [3245471474742122278], [-781276837036638606], [-1190011643901725202], [-2128208973529165078], [-4365941814181969506], [-3698739873239101240], [-1017066034749175722], [1867893093601744592], [156930620012170314], [-3510217323764985910], [-2042536429955580762], [4230156738939264422], [2443273213495454314], [5254447878055405558], [2002745657969058534], [1300787896834892370], [-2536156073753075908], [-4041648899712720042], [5272195874982332340], [1955645389773587522], [-1312760489944346366], [4784541707602174452], [4747689075428302374], [6493772097478551152], [4101963580513736614], [-2543678568983957718], [4442603386502465878], [-3253573011176331850], [5461164990451423518], [2319180318041790360], [-2076534734268620088], [65062976364302574], [6154712794224055038], [5267586683463792814], [6554297918193441882], [3581626824398062674], [-2406295652829864060], [3112007729654642554], [1134312454257709798], [-7435856247541625946], [5939425611222398758], [-3369056017362699418], [-3775545374760594288], [-7254670900703364580], [-10136324631014537562], [-4380292435584538110], [-2118533327688428068], [-15624727864295306], [-3372086019871732620], [6461131278777466692], [2385065130712729198], [4436664346809552390], [-6499840649095609586], [-7255078480658531658], [-5795564429764373442], [10827545881876543234], [10199835259932303534], [6831868807231817540], [-6162922682317402962], [-13613014253041564468], [-10123480445210037626], [-6880231968501137642], [-1096839534384129006], [-10380770233793525290], [3006008052734344398], [9381035596193422020], [10600744497518255314], [-11123191579373178708], [-5474645965301120642], [-328018171334292520], [7924373661160796490], [-9978053180334374368], [-5273614031568883278], [-1979659994747755510], [4898190279143308518], [-8115854331715329806], [-1967172476412533826], [3787584000733620450], [-8057423806281643588], [-952285638570051986], [17272467008074528242], [7223849981443046278], [-2698251990037892100], [-9927011016434394482], [13658472391399178214], [2600079762001075038], [-2097958990951128928], [620971118189310814], [2873152821368380902], [13272661381321842720], [-10466422118791143686], [-5060680414379607426], [4852456453468577358], [-2214482376686986950], [-9394113294387881066], [13651461673567490754], [-6322113372871282140], [-14671770534152273882], [4997241885480865614], [14196108173469115278], [-20145973330229984850], [-550072161921600808], [6055390495978267320]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_50_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_50_12_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_50_12_a_b(:prec:=1)
    chi := MakeCharacter_50_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 12));
    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_50_12_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_50_12_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_50_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<3,R![-318, 1]>],Snew);
    return Vf;
end function;