
// Make newform 150.6.a.b in Magma, downloaded from the LMFDB on 24 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_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_150_6_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_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], [-32], [12], [154], [918], [-1060], [4224], [-7890], [5192], [-16382], [3642], [-15116], [-23592], [16074], [-14340], [-47938], [-33092], [51912], [-12026], [25160], [-35796], [-75510], [44158], [88662], [-149696], [189828], [18110], [-2346], [-43832], [87252], [-118002], [260900], [94470], [-306688], [-433862], [203164], [96528], [-255486], [-639900], [-550618], [16032], [137134], [-893862], [189200], [940652], [170104], [-19812], [1532870], [892494], [-654240], [-937678], [-733428], [-139002], [1654944], [562590], [1498232], [2102818], [-1885398], [-2110076], [-345606], [2220028], [3029352], [999094], [-2809182], [2411492], [3419038], [-1421772], [-2019010], [74454], [-1729080], [2521768], [-2659166], [-3433660], [-2261976], [-1770090], [-5950982], [-2019918], [1665530], [-4997100], [653702], [-4056048], [493054], [-3716320], [-710076], [-6144030], [-6112202], [-3421698], [7516504], [6135228], [5247840], [558448], [3568812], [3502700], [-813456], [8441070], [5245002], [-3320156], [934382], [-363812], [11785698], [-5163396], [13258650], [-10617868], [-8236802], [12324228], [9548694], [5695800], [-10148998], [11186488], [6222274], [1933518], [13076420], [-15901648], [5944242], [2339164], [-8266032], [10398594], [11209620], [-10477738], [-7213586], [2283018], [-11804796], [12751052], [5617422], [-4422010], [-4338720], [-9601952], [3695194], [-20801860], [-21828336], [1998872], [11784418], [24981882], [-4465630], [-21587526], [2790748], [-38382], [20561850], [22722212], [3826182], [634384], [742788], [-28545010], [4162440], [-16650446], [27744558], [41855300], [-26960616], [19564138], [-696798], [-18847316], [3080928], [-7452572], [-40452288], [28144640], [46253730], [18378358], [45482622], [13668828], [-14557986], [-17837072], [25237692], [-34992042], [-7673376], [5491352], [55115698], [-5445070], [12203994], [63814620], [19014542], [-37060248], [67275814], [-43361560], [-48943830], [-16818268], [71509302], [25796464], [-31187650], [6696328], [-5612028], [-28451726], [-34223202], [-1100616], [47629830], [-30922742], [1486444], [51539210], [-27920448], [-230546], [-16783356], [28604972], [-30960978], [-8430372], [43445694], [-56804878], [-86765846], [67869798], [-98575056], [-52572450], [-92885368], [-72638702], [18507650], [-23238180], [-12406302], [44365160], [55968204], [23190330], [85808852], [40360318], [40067142], [-80939696], [26767428], [-48492840], [7257002], [22589128], [-26650158], [18497808], [-127888206], [25556102], [-99684640], [100093650], [44660824], [13498428], [-44020570], [119186574], [-92500560], [-7030112], [-103703748], [-99613286], [-118883860], [-54232408], [-47841798], [-8324636], [-104561112], [-119450350], [-12797766], [-120656820], [82666152], [15014364], [69095252], [35483104], [22488590], [51547494], [158505960], [76115608], [76802532], [-123085900], [4849704], [8923258], [-77880798], [41058048], [74475050], [95849394], [-31403340], [-52618138], [108207508], [5283738], [163510198], [-2593256], [173100588], [-62971930], [18327274], [-57037002], [64299740], [-76000770], [89116122], [53493364], [-144187926], [67677182], [39390748], [-197951306], [122445080], [-100181762], [14747344], [21410868], [-59397250], [80280362], [201652932], [-161978136], [199002752], [19317408], [-100062058], [-130223132], [-81700848], [48621454], [-14649702], [130118000], [106635330], [-151242018], [256396428], [46656894], [-141533508], [-102649766], [-104558610], [-5771848], [-116369526], [-31052340], [-128882372], [37016614], [131268258], [27703640], [-136584996], [-14840668], [-157874402], [-133755852], [-123298930], [-153190200], [-31962926], [191169384], [-283540410], [265276002], [-128982356], [-34525152], [8901290], [6155940], [3127632], [366591694], [52351890], [-247204228], [-314932202], [77379822], [-255845576], [-154775586], [-166067278], [-75213700], [-27403196], [-283414152], [-138526326], [-293918098], [-124124622], [417602120], [-227439156], [-218831308], [-160175772], [-166086610], [-182520906], [324404522], [-398725832], [-388021406], [445550478], [334935510], [-502991968], [134908674], [412149060], [7293062], [-55939532], [415169472], [424936458], [308805452], [255278518], [-94486818], [-460143896], [171253430], [428059134], [-187852800], [-56421828], [-30358842], [-326435376], [492230578], [-533961078], [-285554232], [-178108980], [-363325412], [-7607786], [-135138702], [-523940816], [108339482], [273545652], [-176852140], [348604824], [182518950], [148576832], [-39945062], [448198260], [-605608848], [300292414], [-14178510], [-558335642], [-525808338], [-522447666], [313048528], [-111543402], [-394190020], [492593184], [-173668648], [378368578], [384406324], [-655969992], [-276185470], [-106213206], [62825580], [720742108], [-46129128], [344439334], [-476258920], [-158317350], [-447966028], [-22045818], [567327950], [223418934], [393543928], [395823198], [551959830], [309252512], [-817966742], [230222802], [-404870516], [-373833420], [-540501746], [-693525702], [50619924], [583835612], [467731558], [-89139618], [649526400], [556312288], [107797158], [714290304], [-730750290], [-212545262], [-146910072], [639145500], [-594933626], [452462898], [-54456276], [205223130], [-818728828], [-287995560]];
    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_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_150_6_a_b(: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_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_150_6_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_150_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![32, 1]>],Snew);
    return Vf;
end function;