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


// To make the character of type GrpDrchElt, type "MakeCharacter_150_a();"
function MakeCharacter_150_a()
    N := 150;
    order := 1;
    char_gens := [101, 127];
    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_150_a_Hecke(Kf)
    return MakeCharacter_150_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 := [[-4], [-9], [0], [-47], [222], [-101], [-162], [1685], [-306], [7890], [-8593], [-8642], [-18168], [-14351], [1098], [-17916], [17610], [-21853], [-107], [-40728], [-34706], [-69160], [108534], [35040], [823], [-33828], [133444], [-81252], [-217015], [138324], [256048], [118452], [13218], [-350740], [109890], [-172603], [349993], [-192581], [-580692], [-738126], [497370], [-333163], [-40638], [-494651], [-552342], [685625], [749477], [-169271], [46488], [-90115], [-1064136], [1151580], [856217], [-207708], [1453188], [-169296], [-1581090], [822512], [546823], [-1092498], [2484799], [341394], [-2028977], [-206598], [3342229], [2532888], [602132], [-209777], [-4021662], [8330], [-1950006], [2270880], [-2861537], [-615311], [5398775], [-1086876], [-3484320], [-3265907], [-4273188], [-1451875], [559380], [-3914698], [-3574998], [-7159691], [1717895], [-3396696], [-3396060], [4528138], [-1278948], [7198624], [-4830342], [748650], [5163943], [8542872], [-4205875], [8183424], [3859230], [4554102], [-4822241], [362537], [-3114392], [7993038], [12323574], [10136430], [6530837], [1244533], [1334028], [11940144], [-7164300], [1151627], [13426768], [-12018386], [6985188], [-8206255], [-10768573], [19257132], [-10099916], [-7521132], [2671974], [6999480], [408122], [-17493926], [8674398], [-11847816], [9477752], [-22814658], [12743645], [2449290], [415033], [17287714], [5188340], [-4795716], [-18565408], [-28206797], [6561612], [22092995], [30078744], [3289543], [-6710532], [8742540], [-24841003], [21221862], [8706589], [-37118412], [1017650], [-33619410], [35257369], [31494108], [11934440], [-8704416], [-11799887], [-27384048], [8805769], [-250122], [32495548], [42459522], [14162885], [43729230], [-5735087], [-33739458], [30734238], [25184664], [-14455592], [-10697418], [8415678], [-38940876], [48459227], [-38473322], [38652125], [12026454], [45630270], [-19828993], [-26854998], [-45461621], [-32929135], [46887840], [-9676963], [-50978298], [-242231], [41017055], [14782453], [47874792], [-23265221], [48144678], [-74256846], [74970750], [-11226557], [-17339141], [12340565], [-53998698], [-67685681], [-66644496], [6604667], [-19121058], [-61049622], [10964994], [13133942], [24489274], [88035798], [47851734], [32695920], [-52388788], [11480518], [-78928150], [36279780], [-98229042], [-7189135], [88001034], [-31850580], [17855627], [112462093], [-118001118], [-34198331], [21914148], [39132150], [74093702], [73541593], [119133882], [-46307832], [30383634], [-130667023], [40802045], [53922690], [80416744], [-88327032], [-124315345], [-59593626], [-25850610], [-55792217], [-30952698], [-146648561], [32079620], [-78495643], [-19306698], [-9019796], [-106550952], [45014210], [89096124], [-126952290], [-103593948], [-134973726], [-59923573], [-6385961], [-52383445], [-90119526], [123277410], [-6526757], [102847662], [172428995], [-13882266], [-188157302], [-104821998], [-37819812], [-5165635], [43022454], [42338700], [101334497], [-134042972], [33676548], [153815938], [91852429], [42839478], [111984470], [-1548071], [73918278], [126846680], [-103041150], [186721992], [18382924], [157002174], [-129874513], [-36221672], [-90988826], [68277275], [238312663], [95503189], [120559758], [-27431065], [104331047], [169938912], [-96317376], [23686352], [212376498], [-165563293], [136817263], [88168902], [-79967921], [-197184192], [-137642080], [146217120], [25635162], [-121893852], [-75161196], [115636632], [-217615331], [-56911920], [-60639673], [-38585256], [-126757410], [-128984972], [54859834], [-167410452], [-37585645], [-87829206], [-230040388], [-251410277], [-267129492], [93028385], [332262660], [-18509366], [190115634], [68274060], [-149510148], [-124816211], [-216896082], [-68372935], [42063630], [-339614988], [-119212721], [-177101250], [178940192], [202295293], [-233230908], [-294347471], [251590014], [-265197958], [-122789755], [-393121181], [292369338], [157569864], [13176977], [-274997622], [-384707725], [227373294], [9887957], [467388708], [-312252565], [203815884], [262165517], [204826408], [141917269], [-194901912], [35312010], [423142337], [-184632126], [105422130], [51796097], [-269642957], [-489576108], [225399108], [-158696923], [-281241002], [353304462], [158724259], [171982295], [234242874], [97158600], [234274542], [-133913082], [-428799306], [-476749247], [-181251258], [41504418], [-474841920], [-515661572], [489474349], [-310803192], [-60302396], [132142487], [-267062748], [455121755], [-385343646], [-335456100], [232103312], [520041643], [332664240], [-26896098], [-405422591], [162074820], [-9758357], [-229136178], [-497871606], [-647177312], [-461755512], [424171700], [-635246166], [245506727], [312394618], [-586466876], [392048538], [411354845], [357132144], [69109260], [143987533], [-659003658], [725296759], [-282173185], [-305049180], [101243267], [-263055588], [706539050], [-676562196], [-79251617], [-606343692], [49264620], [-180636928], [-130235477], [200634552], [304189579], [-381440460], [309478609], [-270081132], [443937354], [93044597], [369198283], [439198812], [652291470], [-781317977], [-90302952], [688189044], [-517947240], [-456777947], [-340572282], [357955110], [-289958366], [285126288], [755672064], [-783114660], [-254109133], [659932230]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_150_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_150_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_150_6_a_a(:prec:=1)
    chi := MakeCharacter_150_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_150_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_150_6_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_150_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![47, 1]>],Snew);
    return Vf;
end function;