
// Make newform 150.6.a.l in Magma, downloaded from the LMFDB on 18 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_l();".
// 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_l();".
// 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], [-233], [-498], [-809], [1002], [-1705], [-1554], [7830], [977], [4822], [-8148], [-19469], [-8418], [-17664], [35910], [3527], [-57473], [-7548], [646], [-22720], [-11574], [-78960], [-54593], [105552], [177436], [183792], [169685], [-263484], [256912], [-219048], [-228678], [339740], [306450], [198827], [-361283], [-338159], [-430248], [-603354], [-374370], [-232423], [-846198], [155581], [103482], [-140425], [-462673], [735271], [-967188], [-83695], [873876], [-1060560], [-756823], [-635148], [-30708], [189516], [1109970], [211952], [-1047413], [34002], [281101], [1558506], [839917], [-292698], [-127859], [-648048], [-3393148], [1620847], [1286382], [-2730550], [2136486], [3264060], [4150777], [2142421], [-1946995], [-2650524], [282540], [2620657], [-286248], [4120685], [-2379480], [-741298], [-187398], [-6551099], [270065], [-2779344], [7866300], [-6233558], [-4683048], [382816], [1935402], [-5569170], [-4224503], [6962952], [-9295825], [-6341364], [-7383090], [4196202], [3579421], [4955477], [5318032], [4257942], [4376166], [3577170], [1946927], [-6955763], [-2418528], [9583956], [-1520700], [3882827], [107992], [-7499234], [1226952], [9513395], [-15644923], [-9603948], [8243956], [4073532], [-16819314], [2878260], [13338602], [-6373454], [22720962], [15361176], [8050352], [7278402], [13749785], [-9055830], [22097887], [-2073374], [14884940], [-25885644], [-7986448], [11556967], [3167052], [8215595], [-11970804], [17115397], [28075332], [9908160], [5725727], [-5965698], [19777771], [-20404488], [-27718270], [-7798410], [-6225539], [-33975708], [-14728240], [18859416], [18211237], [-7654248], [597451], [-2068878], [-7833308], [40813302], [6215795], [-4648470], [13360297], [33256902], [-42153018], [-22469064], [17499952], [54292002], [-25592538], [4824876], [1184477], [25817782], [-57251515], [14744166], [-5420730], [19884227], [-21903498], [-6799949], [-62929585], [-59651400], [-19926673], [-58026798], [50892991], [38881595], [-40306253], [-74530248], [-38521769], [-12649818], [-38710314], [66183510], [-58992473], [13950121], [38995805], [6659502], [77955511], [17975316], [67902377], [-79934598], [-5713278], [-20123694], [-54430498], [13864666], [8554302], [-34611954], [-10520220], [15967652], [57940822], [15375650], [24255660], [66523962], [91841855], [30394026], [-98866860], [28179377], [20312557], [105575802], [30789211], [-13960308], [-55098030], [-62128498], [97313287], [-77074698], [-78717348], [-27486354], [79555277], [53323475], [85010610], [-20907704], [53297412], [-57429445], [96427026], [18955890], [11090857], [-125778498], [39018211], [16223060], [55585427], [-89881098], [-89859524], [-10843128], [132430490], [-12829944], [-41388750], [89699952], [37054146], [-29639023], [-147317519], [-17285425], [19431786], [-49978890], [24761677], [56973702], [-79190095], [23461026], [47482282], [-59253498], [5358492], [104222885], [-22952334], [-106617180], [16792277], [-168619388], [41640072], [69247042], [-98371709], [-217025298], [-69541930], [-69736019], [-157857018], [-183884800], [183377010], [-43332048], [-198304604], [82170126], [-14451973], [-34338368], [127178086], [-153204715], [-140142713], [179432851], [3323922], [-19133485], [-17143273], [70184952], [190771596], [-129009448], [157601682], [147121727], [224738677], [32945202], [-122350529], [-177454788], [-110873920], [-131654460], [-171008598], [-312218508], [10400316], [152975952], [-243326999], [-275657100], [21321377], [-35124204], [256924230], [272294572], [-109449494], [63503532], [10593125], [171314286], [61919252], [-262064573], [263384412], [293125205], [285982440], [-97017014], [204969666], [-230068380], [15998652], [-188645249], [115148022], [87705665], [-103492650], [-60843348], [-255807209], [-142032870], [367821752], [390665197], [-387946248], [166831831], [-331138314], [-179841598], [327243455], [94169761], [-259615158], [-152032284], [135306077], [15249522], [398660765], [227271606], [172331927], [-257038548], [-36968305], [287445696], [-458688523], [-83019728], [7606081], [-92905668], [-83794290], [148024727], [-115504674], [-383967210], [-308664523], [-244916543], [-347094048], [339877692], [382366127], [248071462], [337593402], [-61594499], [116210915], [508037106], [48474300], [-440394498], [-150508998], [-410244954], [-481947803], [-46724898], [-190160118], [237393960], [-44209748], [-345412979], [431324712], [-240296564], [-235860073], [-86819748], [239991665], [-326196294], [-289656300], [-41227048], [-524315633], [-173296620], [-627877398], [-391845719], [-298910940], [209695627], [-3082098], [-580744674], [170658232], [-251415708], [351912860], [-163214634], [124799177], [332576362], [120667876], [-621820878], [-483117235], [-139522644], [199803600], [235955767], [219589602], [254892391], [-205868455], [650155080], [-314475223], [-673427148], [119413250], [395588736], [498457777], [295414512], [-662479560], [-576815848], [124269607], [767623452], [150086161], [-54821580], [-589479599], [428591172], [376140006], [-162501673], [-765522533], [-324894948], [188473530], [-610758503], [-441217668], [296044536], [-48468240], [-19776023], [162355362], [315429090], [13749586], [-366145908], [204381516], [-364501680], [-55223623], [-550333050]];
    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_l();".
// 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_l(: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_l();".
// 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_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_150_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![233, 1]>],Snew);
    return Vf;
end function;