
// Make newform 150.8.a.e in Magma, downloaded from the LMFDB on 29 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_8_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_8_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 := 8;
    raw_aps := [[-8], [-27], [0], [1576], [7332], [3802], [6606], [24860], [-41448], [-41610], [33152], [36466], [-639078], [156412], [433776], [-786078], [745140], [-1660618], [3290836], [5716152], [-2659898], [3807440], [-2229468], [5991210], [4060126], [-17281938], [14362312], [-6454404], [-884410], [-12132498], [-6868064], [-39520788], [-19174074], [13244900], [57362430], [-31087288], [33783466], [-62665868], [-62707224], [27052122], [-134280900], [114660542], [16360512], [154198462], [-83228814], [-76172200], [35244572], [189131392], [176100276], [65039630], [251318502], [213079440], [257283602], [123057972], [443333886], [-298924728], [208907910], [-11274928], [658964386], [-105122838], [-330161108], [87100242], [391708996], [-204935928], [-877202378], [440830506], [1112230052], [-288198194], [1106006316], [-1321843690], [-1203951138], [-1320572520], [-1751069744], [487945282], [1110068660], [-1869115008], [-273895410], [-624551654], [555500082], [-2157700630], [1677967500], [-525233458], [170592912], [1687969582], [-1178496280], [-715754868], [-1373583870], [-1847520314], [3094137222], [-3004508048], [2992515876], [1840414560], [426675976], [60754692], [3245877500], [744381432], [-444155370], [3049626042], [1403064412], [4211059862], [-1999559564], [3374032986], [5580213252], [-888309750], [-1791706828], [-3821026754], [-4362188964], [-6385307058], [804297000], [-4871616598], [-7175168384], [-3478905038], [239378406], [-5529588220], [-6136833688], [10703801922], [1398026452], [5316047496], [-3244034118], [-5165059620], [-3225154018], [2006334622], [-10021103214], [5848606332], [2586855932], [-1744599978], [-11205076690], [-936568080], [-4204452104], [11549138602], [-13965501940], [-14383247448], [-670840528], [19156941826], [17911981002], [-21407177470], [755162802], [-20466541724], [10309775946], [-416427750], [-5826870268], [-20833271778], [-4234025768], [-5705967924], [25161237110], [22704795960], [-28687212638], [-5349500394], [-14032979500], [-32499400608], [33869400826], [-15270829038], [11204511172], [-6972321864], [-1180948004], [12791515632], [35235279560], [-21776443230], [-11579464154], [-38393035098], [-11184090684], [5198349942], [269243176], [4372831332], [37499076366], [30618970392], [-17270335168], [3750774706], [9803562770], [-30242677278], [-45744859020], [44762203382], [67337088312], [14725699462], [-40588029040], [44255594730], [-25601556268], [-42544978578], [-54453966968], [-948936250], [-50789572064], [-2265747348], [42746707282], [-69999950394], [27232099152], [-421380930], [-32215360214], [-1454360588], [9874299290], [52895060352], [-42189687938], [-34244025828], [11338686812], [-59841679818], [99902998836], [-60319556058], [22847866322], [75551006602], [92003730366], [-12109613688], [23040668550], [31198312592], [-84538146974], [115907516450], [121340653380], [-47516594454], [-72477878560], [42062389332], [-68293089030], [-28924472668], [53959797646], [-77590425858], [112752270712], [694077996], [-43113134760], [26027620442], [-8505327344], [-43796333838], [142094186136], [18914922762], [-54778378738], [-146920255960], [-192673881150], [-88380951248], [-134629049244], [-79451887330], [-186585690858], [202835705760], [-176787187064], [161742179652], [-29120625158], [-195905156740], [-26956367968], [126102725562], [-24477129188], [48684813456], [41419123250], [-104831848638], [29858449620], [-69793700328], [-129338708028], [231581335412], [177543205672], [-72670264090], [-189603228018], [-273485982360], [217103767936], [-58867295028], [-265574659900], [245239085232], [-64158221174], [-229585649598], [-163429268664], [-50327575750], [155863873722], [143260358940], [-98522576098], [161136039916], [164469823506], [-24205688714], [-167461663328], [-53602221804], [-102634500370], [279577095082], [46480685406], [-61678236340], [219536991270], [-1906685238], [-281661885428], [25479016242], [71492605862], [143655392356], [303291533782], [72644256320], [236306786926], [37789208152], [59750301516], [293238610550], [192519075962], [-233464086948], [-6085597728], [-144528241288], [-47558660424], [474066702062], [-420991279844], [-225925222608], [-45810561458], [488952583746], [-145357319800], [-105830692830], [408953729382], [-146718836604], [-344334637578], [-27106085148], [249978855322], [482186960310], [-129913248448], [-168929338398], [-71397166860], [-227107840364], [-67884250298], [-87191655174], [-439695784240], [584225923812], [-586156930348], [-650991856034], [-135315531204], [420424725830], [-5040871800], [16707200722], [-306851713008], [-637474458690], [347719718562], [-631687684748], [-225691968024], [-35507207590], [-334157529540], [276283719552], [-335798909378], [521757842610], [200066187932], [274576221526], [-603313949898], [451443504832], [-293207463258], [166803492242], [-520959577300], [-157808179988], [-617359143264], [703271257362], [-192399921658], [788280346986], [762146110880], [-880206936108], [1145853092], [-327275456724], [582688895510], [-260927429538], [1058782621082], [327892262416], [132185810242], [-213384213834], [-719302793010], [413870486552], [-698533024758], [763252096140], [-632633201458], [555670990396], [154216278672], [589749563106], [209434688492], [-52238294714], [1120125183942], [-775129197968], [470943871070], [-105301140138], [-123546213600], [-634271907708], [-444004476114], [1117872580152], [1015906840786], [-1008390014598], [-301227349104], [-82577085420], [495655484596], [-635877404378], [-624016705254], [967853243752], [98021050922], [758052955212], [-477141702460], [1160964917232], [-611645282850], [-119306374168], [-1419917703734], [-926542636260], [551677316832], [1320313660702], [339274449810], [-590775440714], [-1572743576298], [-688664496378], [-446885371784], [-367330186914], [655364364620], [1118414567592], [1039391567792], [-541706788094], [232775294092], [355210034496], [-246296168830], [625630921842], [1582514702820], [-27390841244], [-1553230526808], [-1143736865258], [-488689650880], [-1045604677350], [1071891785732], [-1624574011938], [839413210550], [-532777088898], [924577985776], [-645965512554], [1034418002670], [1197383075192], [1430201050426], [1674035611602], [519374893252], [-1913464797780], [1024273770382], [746856653826], [862609463532], [-1788033913588], [-1475218459994], [358576281702], [-1013277326400], [852023265256], [1368579344526], [-2400348578088], [1024412761590], [-958010303054], [2015831279856], [1123467208500], [-1780809737978], [7900142586], [-567750191388], [925461928170], [783024446612], [1803931634760]];
    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_8_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_8_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, 8));
    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_8_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_8_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_150_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<7,R![-1576, 1]>],Snew);
    return Vf;
end function;