
// Make newform 150.6.a.i 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_i();".
// 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_i();".
// 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], [-79], [150], [137], [-2034], [-1969], [-1350], [-2946], [713], [-3238], [6564], [-19579], [-21150], [-25896], [25350], [50615], [-22519], [33900], [82442], [-81472], [25782], [103728], [-57343], [-91032], [191636], [9288], [-20635], [176892], [-256480], [177600], [260886], [-217684], [421794], [-101917], [-101773], [-202249], [231600], [-174222], [-642066], [-56071], [-209694], [-715597], [508854], [-986017], [119495], [48545], [-287652], [72065], [-569148], [696504], [576137], [-1224924], [972132], [1761900], [1743834], [-1704256], [1469717], [-1225302], [-637333], [35094], [2880395], [-2383050], [-1930813], [-2189952], [1414292], [1382081], [-283758], [2138090], [3160146], [-3595644], [-4620433], [-3519829], [595061], [-1300500], [620724], [1186223], [3133344], [567581], [-6090000], [3071390], [-669150], [-3254389], [1587593], [-213888], [3707244], [3831926], [5586720], [-4401424], [3352254], [909966], [-4035793], [379944], [-7424329], [2299884], [6737214], [-9268062], [11061995], [-13075435], [-1846048], [6487818], [3015378], [-3498102], [-12374905], [6806867], [7771128], [-15122220], [-1670124], [4122203], [6818696], [15946562], [-8219520], [-12332341], [-3019123], [-11805180], [-2853604], [-3401916], [-9391662], [9366588], [15774794], [-6645154], [-15778026], [-19665432], [990464], [6529194], [-20210647], [-22771950], [-7091863], [-13898242], [15485708], [159276], [11555360], [-6344023], [-11774772], [-24786853], [-13801668], [-15379549], [-23397780], [-28018824], [-1656409], [29738238], [-16010755], [25474752], [18997058], [39853854], [21917939], [-27221268], [37621376], [25199544], [2773067], [-13782744], [-4963219], [41263950], [16630844], [36499542], [6831899], [5051154], [8300231], [-48733242], [-7347774], [-35143704], [2311856], [-37358766], [-10266582], [29840436], [-23422171], [-26070934], [-30379963], [-1180374], [-37546722], [1997699], [16552614], [-31502275], [3017351], [-5488632], [21907223], [-59585718], [-12464743], [-71401621], [3653813], [23712888], [29071625], [30392346], [-69892950], [68093814], [36131897], [-43607617], [-45073459], [-359274], [-38538727], [19903572], [-34298623], [94882770], [70495734], [-42389394], [-94560850], [24008774], [33770130], [17973546], [67600188], [44532788], [-37412182], [5726354], [-16490100], [-36662130], [-52158265], [88128318], [106157220], [-78319543], [69217523], [74228442], [68682029], [-11629740], [-38558478], [-13704034], [-117955855], [36747774], [99221964], [29390586], [123405965], [32652635], [66989970], [-101882392], [843252], [101813147], [-106088634], [72439650], [138271295], [128118198], [-14674243], [-133721980], [-98949781], [-47151402], [70656692], [-129984744], [11040650], [-129416304], [-4209102], [58213992], [91432806], [6977945], [-52942057], [132334463], [-151857354], [-189499338], [79181723], [83733534], [79309577], [-31839714], [-16058602], [-113897634], [-31719948], [-82342219], [95724246], [-180627228], [113465381], [-68415988], [-78589248], [134207102], [-17976955], [-211512582], [107256662], [170710451], [36732762], [-66683056], [47889570], [105334272], [-890596], [45905634], [-129161029], [73071920], [-72292486], [203488685], [112688921], [102786053], [97472334], [139885523], [-28714297], [133113000], [24463212], [-39652840], [48518598], [15120815], [73588931], [115600434], [-215696191], [-254996868], [23048528], [-22974564], [128858970], [105828060], [35920404], [173385600], [68276711], [-133750932], [56885081], [-68356668], [-202452450], [41663732], [136272950], [91673652], [-260743795], [-253470558], [123638228], [-248164531], [90768948], [-282197851], [83979408], [28304534], [36882582], [121435476], [-109310244], [36775817], [-373594782], [-260740879], [-59371122], [27045804], [335208905], [-36328830], [-123052216], [-197349613], [-9511824], [145847921], [-100776006], [133370642], [167809895], [75908279], [330877998], [172550964], [345255917], [-166703154], [-75282523], [-132237390], [-4730977], [46533396], [447551951], [243640968], [-64851211], [203226320], [265203599], [-140009652], [196427382], [-100598065], [195533898], [142851654], [-275853547], [508345511], [-493852872], [392459892], [-97972105], [-191700070], [-309836238], [-176626933], [-476595181], [294643134], [80429652], [-320768058], [28195374], [-342942558], [236758955], [92363502], [-399665250], [225065400], [526967012], [-570031837], [535531320], [215340068], [-274270009], [-318992964], [345573449], [167622702], [-622088028], [-124620040], [-20876047], [156151884], [361164138], [-5796121], [-183830748], [626253461], [-161119362], [-359926134], [-67775128], [305253108], [141614108], [497940762], [515059553], [-722744074], [-286530388], [428197206], [457163117], [-45495156], [-266844648], [248123873], [-265334046], [-129661207], [164964977], [-537738528], [-345313855], [103563876], [181935314], [192199080], [630870167], [226206984], [-171914880], [455002904], [-282103591], [-697686156], [123859511], [-298172028], [657812447], [282760476], [-712643910], [-341140081], [-465247723], [480951324], [507498714], [222491327], [-88776852], [-48864864], [-156233568], [819805511], [-250944258], [74898738], [560136782], [725542572], [-54434004], [834371784], [-563110255], [-394101474]];
    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_i();".
// 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_i(: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_i();".
// 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_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_150_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![79, 1]>],Snew);
    return Vf;
end function;