
// Make newform 150.6.a.e in Magma, downloaded from the LMFDB on 20 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_e();".
// 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_e();".
// 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], [-1], [-210], [-667], [114], [581], [-4350], [-126], [7583], [-3742], [-2856], [-18241], [-23370], [-21684], [-32310], [-7165], [59579], [-43080], [-28942], [27608], [-1782], [50208], [142793], [-164052], [-107236], [21012], [237545], [233388], [138800], [-161340], [69054], [224396], [-407646], [216053], [-188617], [-422251], [41700], [266142], [-51846], [499349], [705906], [-519973], [-200394], [553673], [777365], [-776185], [919992], [-1132195], [823128], [1328364], [94937], [-128124], [-1722852], [692160], [690894], [-1046896], [-1071367], [-1404162], [1682033], [1762926], [471905], [-1644390], [2379083], [1326792], [661172], [-1536751], [3865758], [-4233910], [-2414586], [2948016], [679793], [-3608881], [-386809], [-645060], [-812976], [-988813], [2145804], [-5776579], [-5073180], [-3012970], [5594490], [5634539], [860663], [-2753352], [-2831676], [-4662346], [-5271540], [-7169536], [4304406], [190506], [-128887], [-304296], [6419741], [-1555344], [-541506], [-888762], [7699505], [-3018775], [7234808], [-9887118], [946362], [-4515522], [7578245], [11168843], [1010532], [11367360], [2567316], [15983723], [-10162576], [5830418], [-15102900], [-5385151], [-5593453], [-10007220], [-9950356], [-9169044], [-17712678], [-20794872], [-1517446], [-2904826], [-7060494], [3814152], [-8951656], [8452974], [-11803267], [-26808870], [-2006377], [-9165538], [15589748], [-3783036], [12472640], [1871213], [25363788], [-14372893], [-16418472], [-14631991], [26179620], [29905116], [-31287259], [-32429082], [19170035], [-98052], [5774258], [-16935426], [5043911], [12882948], [-35952184], [22034496], [13453103], [23633136], [34958759], [31116810], [-19731964], [-44071998], [-43362091], [16523454], [20354639], [-51240642], [27973554], [26833704], [-52483096], [50102934], [-45018078], [-32690676], [6246059], [28501034], [3206237], [-43559286], [-30016722], [-37318081], [54295434], [1002005], [14165441], [29545728], [22029293], [10705302], [-37086937], [-37464001], [16563227], [-70380312], [-58259515], [-73516326], [74272590], [-24574146], [-3561667], [-41979883], [1345781], [51942246], [40623377], [-28507872], [6760427], [-53307090], [-18469434], [30198654], [87838550], [42462086], [25481610], [87970074], [11675328], [32472428], [86980922], [89428874], [-27159900], [2980770], [25098305], [44391942], [109600140], [-88193413], [-17699533], [-49713438], [-29039989], [109321500], [-47701578], [10388966], [59280215], [-85946646], [55465416], [-28187106], [-44856655], [111477965], [-40674750], [-27923848], [75246888], [-105233233], [-106591446], [115918830], [-1071895], [-67854282], [22139633], [-58843420], [-126060331], [124693878], [24669428], [50719464], [-6536350], [-54647916], [-44239842], [122614932], [-170943186], [152101595], [-80706823], [-159821557], [74477094], [37506402], [24250037], [54578334], [48525107], [-80719206], [-182274058], [178493346], [-32316732], [-127419619], [-162829446], [52487052], [-17479039], [108813308], [30420588], [33180158], [59179715], [-24605478], [-1987498], [-36545881], [-201768582], [56987384], [187264290], [155190312], [174721076], [103789026], [-121450129], [-110056120], [120459866], [-154816885], [76932329], [27380507], [70153266], [-28717657], [104810183], [215098560], [-74081232], [-102585520], [89974782], [921155], [-48683071], [69411654], [211495601], [-3798192], [104013248], [-101979984], [-225855750], [-131171460], [-71234484], [69360120], [-71334781], [79245408], [135100151], [-88877832], [-263645490], [233414348], [-194966650], [228073428], [61257635], [-185868042], [40256828], [-119333179], [-195410508], [135310529], [-54969132], [-220435594], [-96417282], [-59241684], [88686396], [-342955357], [-239471358], [2357081], [-367065282], [-266803596], [-147364495], [149640750], [132914624], [-240252157], [14994516], [-102803041], [88936866], [7323482], [-182880235], [195497741], [-405334218], [-422916984], [-159402703], [261366774], [-386276413], [158124450], [-471828187], [-114453156], [267803051], [42050532], [120002189], [126908120], [-444250549], [-135215928], [-61998918], [-13895695], [416227182], [407256594], [110027393], [232136669], [-167393532], [24378588], [30908405], [215875370], [-105489378], [312359213], [-33072841], [170143206], [-105614088], [-23465538], [387534186], [107184858], [-63974305], [559715622], [392516910], [92340960], [-439485532], [347779187], [2207160], [59526812], [-136553929], [16870116], [-491353141], [289591278], [208308732], [-17274160], [-324133483], [58810464], [-182464482], [-301580449], [-197607228], [-202654891], [647339118], [-192649626], [-263074912], [134975112], [-67681612], [-213000522], [84721943], [-727012666], [430517468], [-279825546], [-565794403], [163825056], [-420705828], [479697827], [150918774], [-710531863], [444214127], [-46422348], [-530117005], [4114236], [-325490806], [118570500], [-675158287], [182180316], [355360860], [395323904], [-250447339], [474323784], [-46700731], [136747092], [754455503], [-53200596], [-550764810], [-158304091], [31700693], [-106379556], [-31188786], [370649033], [571288152], [96142524], [666209592], [388945979], [-401726022], [-446292282], [-165261922], [144048768], [-374187216], [-249226836], [249667235], [936069366]];
    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_e();".
// 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_e(: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_e();".
// 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_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_150_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![1, 1]>],Snew);
    return Vf;
end function;