
// Make newform 150.6.a.h 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_h();".
// 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_h();".
// 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], [-164], [720], [-698], [2226], [356], [1800], [714], [848], [11302], [9354], [5956], [11160], [-14106], [7920], [-13450], [65476], [34560], [-86258], [-108832], [-10668], [10818], [-4418], [-102942], [69436], [-17412], [-203770], [212202], [-6140], [-205920], [-230334], [260756], [-29526], [125168], [43222], [293476], [-322200], [261918], [623544], [-61186], [737256], [-539162], [651174], [157328], [707180], [530740], [-120372], [772310], [-8838], [-775416], [-373438], [71976], [-1593558], [2054520], [-258486], [-1983976], [-1613258], [1378818], [-1458308], [988134], [393820], [1554480], [-1760498], [-2371122], [-980068], [-905834], [2950692], [-2157610], [-1288734], [-2269464], [-1046588], [-1798274], [-2184124], [-1784520], [-1109526], [-3895682], [-1206726], [5613626], [1150560], [-3830890], [155520], [-4143914], [6236528], [-4525068], [2564634], [5534086], [-7192110], [1139356], [-7361676], [-1362264], [-606428], [-5842776], [-1150444], [869664], [1434954], [10437138], [7759420], [-1102330], [-2482628], [-5735682], [-517092], [-6727662], [-10328980], [-9258338], [9571548], [11238810], [3726696], [6747338], [6833836], [433222], [5175690], [-151996], [10563512], [-5537550], [-8891324], [-2294736], [13633758], [-13123392], [17852174], [-13247114], [-10449066], [613308], [-21399196], [10977834], [1697318], [3713040], [-1380668], [-13815602], [4594628], [-8511744], [17122400], [1220182], [12032658], [-18895198], [-17211498], [-13297004], [-21563250], [26535546], [-14001484], [13228578], [7258180], [-18452748], [-24364042], [-15579336], [-30806186], [2020842], [-22479004], [9209424], [5362582], [13834746], [1660036], [8106120], [-4053596], [-13823328], [-37844296], [-27282246], [-43266554], [8501058], [-7104564], [53974146], [-36458324], [-52028616], [-127902], [15766656], [29941544], [50743966], [9984962], [16881606], [-3852672], [53746334], [-14104776], [46425310], [56762096], [20281698], [17052308], [44326842], [-58703228], [-32185186], [8990668], [-40948512], [5066470], [-22124814], [-68722920], [-69395766], [52905382], [10264708], [80801786], [-44238264], [-15634202], [35281572], [5278652], [36850290], [-54728316], [21573426], [86764850], [-40544906], [-39391590], [87539136], [-24114942], [72850208], [-15108002], [-1503886], [-76550400], [-56990850], [74916320], [472188], [61158930], [73612172], [56836678], [-20560998], [-41049716], [23674980], [-63704928], [-21826534], [-81717260], [116500314], [63760224], [99413646], [4412630], [5912000], [66741810], [-34510772], [-47649468], [-45727018], [-57234894], [107306640], [53766820], [-136189392], [57237862], [25964300], [18480344], [-97213662], [-153622868], [-17747904], [14217650], [85303206], [41647728], [-75335088], [-52991604], [129526220], [178424308], [159733478], [79731426], [-47851968], [157342468], [138198984], [-7765108], [74592096], [-47256722], [9865506], [-46870008], [121138106], [-166709154], [-74114688], [-164585554], [-121967348], [60500982], [31632622], [108732340], [89059548], [19114982], [-146753234], [-59064678], [-17915836], [123957330], [21326442], [175513564], [-11946], [-184258354], [41289820], [48372574], [-27413200], [-245220554], [26585548], [53786484], [-242546842], [-164374582], [53830080], [-79889328], [-175102480], [2816208], [151195910], [61413076], [56265144], [73408654], [226474662], [-109522912], [-78171774], [-81016590], [229122660], [-58712406], [-152382240], [220130446], [-161624862], [-26165584], [-121385418], [254184480], [203247292], [-21687650], [-263251938], [-175611880], [-127772508], [107616428], [41214574], [54268428], [-68791186], [48345888], [-84198386], [101948832], [-246658254], [-90047574], [-201660788], [-214703712], [61545626], [-138984552], [223156104], [235451350], [-43774590], [-170349196], [90646222], [-97707654], [342521356], [-127651686], [-165421438], [-162384820], [-31250156], [-137385192], [223206774], [-295164418], [-208096914], [-178587568], [257311380], [408361268], [-378878724], [-113981074], [-168419982], [100021514], [-331190300], [-199747826], [-245836662], [116022882], [28043120], [-458697042], [-522349176], [517534598], [-285443804], [-435822552], [463366902], [-173568100], [60363430], [-15281958], [435339652], [307797614], [-21872886], [-519829968], [-97488048], [269002794], [513189192], [455286430], [520420362], [-216519480], [-160960320], [237823972], [-434671562], [66931230], [-59815172], [459996506], [-105098424], [-402321196], [-486188088], [600234402], [-109381600], [332794318], [-239360376], [204868128], [502476814], [229432362], [-300874874], [-616303422], [-562518654], [-679957508], [143306898], [160184348], [435918792], [-363824752], [-107141354], [-548923628], [-351493824], [167686082], [-234384906], [-26961888], [-146960252], [414023064], [721964278], [587760152], [700013562], [37698620], [8786106], [481841054], [-588867510], [761947252], [437243634], [-718321710], [280802504], [307758574], [89478714], [-29709404], [368261232], [-304872578], [-559641114], [362913900], [-558059836], [-129374258], [-129162966], [-332490336], [224384572], [467649498], [-249318744], [-154715838], [430071166], [-29793768], [831387528], [-71295698], [-65765298], [892027956], [-463921926], [-712801060], [-780007704]];
    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_h();".
// 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_h(: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_h();".
// 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_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_150_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![164, 1]>],Snew);
    return Vf;
end function;