
// Make newform 1800.4.a.bh in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1800_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_1800_4_a_bh();".
// 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_1800_4_a_bh();".
// 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_1800_a();"
function MakeCharacter_1800_a()
    N := 1800;
    order := 1;
    char_gens := [1351, 901, 1001, 577];
    v := [1, 1, 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_1800_a_Hecke(Kf)
    return MakeCharacter_1800_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 := 4;
    raw_aps := [[0], [0], [0], [26], [59], [28], [-5], [109], [194], [32], [10], [-198], [-117], [388], [68], [18], [-392], [-710], [-253], [612], [-549], [414], [121], [81], [-1502], [234], [-1172], [-1125], [-1234], [-567], [-2358], [1692], [-229], [2781], [-1472], [1322], [298], [-341], [-684], [2344], [1111], [2042], [-5270], [613], [-1174], [3428], [2339], [3932], [-6084], [4996], [-3222], [-2736], [1673], [-5355], [5490], [-3150], [-176], [2394], [-6256], [4802], [2123], [8834], [1369], [10426], [-3574], [-9036], [10233], [4627], [-4901], [-4482], [1210], [9882], [-11260], [-3230], [11575], [18], [-10710], [-3788], [10539], [5581], [-5193], [4788], [-8006], [-2395], [1864], [-5463], [-12969], [18313], [-12492], [4428], [1084], [13082], [-3014], [3564], [-15796], [10908], [-21946], [6395], [-5615], [-4112], [-2167], [19444], [-20416], [3127], [-22580], [-829], [-7119], [8217], [90], [-17117], [-15120], [-6570], [-18846], [16316], [20170], [12726], [2196], [16884], [4018], [-19071], [17424], [-5382], [4496], [-3249], [-13399], [18148], [4868], [17366], [21824], [-31428], [-14292], [-13950], [-38736], [-3664], [-19557], [-13283], [-24840], [18044], [6174], [1998], [-7156], [-27922], [22636], [-26559], [12580], [11344], [14786], [29259], [-13651], [-29016], [21412], [1170], [-12655], [-32764], [-29844], [-15628], [42974], [-13342], [-3005], [-16204], [30200], [29583], [-6480], [40171], [-50801], [58338], [-51202], [1764], [-52579], [-41288], [-13775], [-49670], [2074], [-14005], [47096], [-42111], [-7613], [-22982], [49528], [30106], [-12844], [-513], [-25786], [30353], [62428], [43420], [-18982], [-30763], [74177], [-2560], [-55441], [50733], [23219], [-9734], [73499], [-41306], [43875], [15282], [35077], [-590], [-59562], [52036], [-27664], [-4653], [-62316], [39262], [36442], [5540], [-16110], [40328], [-81566], [26158], [58832], [-31761], [47750], [-44487], [23194], [87115], [63738], [67190], [-4474], [84340], [75335], [-12762], [26271], [81550], [41737], [62896], [-76348], [74785], [-19502], [-38745], [35450], [-53887], [69192], [85914], [36045], [91800], [-98995], [106308], [-82129], [32239], [51922], [38116], [-42899], [82624], [-8594], [-49028], [23815], [50152], [32976], [4325], [-8550], [67427], [-48344], [77985], [105200], [67815], [-114282], [59517], [39142], [-50171], [-86472], [-89236], [-73589], [-49727], [67370], [-104670], [-76527], [67262], [15956], [-86321], [-52281], [-24184], [-81694], [114812], [76271], [-52120], [-30034], [50103], [-8820], [85230], [-107384], [1684], [23635], [52808], [-76546], [-43488], [43200], [70110], [-8914], [11196], [26613], [94581], [52156], [-89478], [117962], [-94104], [67964], [-117081], [125937], [-114102], [25856], [-20525], [40563], [97849], [-42804], [-148706], [-5994], [-64474], [150962], [73206], [-182169], [-16136], [136372], [88966], [-40621], [-133272], [-63665], [-116419], [-112516], [-134731], [28404], [119746], [-29434], [3618], [-95165], [-136540], [-43250], [-171828], [-58636], [88574], [56206], [-93037], [-110231], [154728], [29240], [182718], [151615], [166410], [-45784], [68535], [-88582], [-94420], [-10750], [90572], [-117692], [-9917], [-146448], [148266], [-45449], [-77166], [22010], [-1684], [-81334], [-225859], [-180036], [-100921], [44402], [-146588], [83978], [110813], [37498], [-111492], [-208593], [144523], [-6552], [-128248], [65645], [-76068], [-78355], [177988], [138564], [-207072], [76238], [-233829], [-1634], [-139429], [144567], [94994], [4270], [-191785], [25416], [141849], [16272], [-98986], [-9872], [177120], [-52128], [-189058], [-141605], [-53748], [-140931], [-108953], [-128210], [-126091], [-134668], [-137817], [16109], [-10890], [212904], [-220005], [151516], [-73233], [129456], [97992], [51994], [17046], [156628], [10341], [-31265], [37296], [-254183], [97660], [101143], [74610], [133754], [-221030], [133407], [-39006], [124704], [78886], [-84874], [212513], [-105507], [34272], [-211608], [-69867], [-71767], [67018]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1800_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1800_4_a_bh();".
// 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_1800_4_a_bh(:prec:=1)
    chi := MakeCharacter_1800_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_1800_4_a_bh();".
// 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_1800_4_a_bh( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![-26, 1]>,<11,R![-59, 1]>,<17,R![5, 1]>],Snew);
    return Vf;
end function;