
// Make newform 900.4.a.j in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_900_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_900_4_a_j();".
// 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_900_4_a_j();".
// 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_900_a();"
function MakeCharacter_900_a()
    N := 900;
    order := 1;
    char_gens := [451, 101, 577];
    v := [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_900_a_Hecke(Kf)
    return MakeCharacter_900_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], [-2], [30], [4], [-90], [-28], [-120], [210], [-4], [-200], [240], [136], [120], [30], [-450], [-166], [-908], [-1020], [250], [-916], [1140], [-420], [-1538], [450], [1150], [1620], [-1702], [-1350], [-2450], [690], [-2070], [-1924], [2910], [176], [-2348], [1996], [-3120], [-1770], [-2130], [-1654], [1740], [-86], [2490], [-832], [2084], [1174], [3120], [-58], [5910], [3300], [-2986], [-6630], [1530], [-2640], [-7350], [3512], [5368], [-3060], [5044], [2010], [2752], [9540], [-9254], [-150], [1892], [7378], [-6720], [5186], [-3330], [9000], [8758], [-4724], [7292], [-14520], [7110], [11488], [780], [5402], [-2190], [-7162], [9360], [-12806], [11288], [8520], [-1260], [13750], [-3210], [12850], [8220], [-7020], [8122], [-13470], [2468], [4440], [-11190], [-4020], [9076], [-7486], [-7400], [-11490], [19320], [8340], [21044], [-1418], [22020], [-25230], [8280], [-18874], [-10550], [-11000], [11310], [-17572], [1604], [31320], [31300], [-10920], [3210], [-11910], [-3382], [-15950], [-32190], [-22140], [-6172], [19170], [-21898], [16680], [-6518], [23200], [-16324], [120], [30548], [-16952], [-20220], [-20722], [-4350], [-41972], [39510], [16680], [-15484], [4170], [30226], [14760], [-9934], [-23520], [-29816], [35430], [-36196], [-480], [-28532], [-20340], [10756], [-600], [-25400], [-36240], [6572], [2340], [-2522], [-52770], [-28200], [15570], [8350], [43650], [-18810], [25320], [-6736], [20500], [-18202], [-23010], [59550], [48494], [48120], [-41006], [56012], [-52980], [-16924], [38310], [-43646], [2078], [59578], [810], [42136], [4650], [-54000], [36270], [15292], [-43076], [40742], [-41340], [8434], [-43080], [17156], [-570], [-49980], [54930], [64802], [-19100], [-34590], [44400], [31350], [-77092], [4300], [36686], [-84450], [78210], [87308], [-46680], [-55860], [12836], [16162], [7470], [-76634], [1320], [-50940], [35138], [75718], [15180], [75720], [40590], [35054], [47432], [70680], [-59150], [3780], [61358], [-50190], [1080], [61162], [17190], [76084], [-77596], [78344], [40740], [-74900], [38400], [63074], [-102750], [87870], [-47580], [-21360], [-67204], [-25214], [-31582], [-65970], [9060], [89542], [42150], [-30892], [73800], [-59600], [65280], [-94200], [-57502], [30870], [-14310], [55706], [-64100], [8430], [-89750], [-71954], [6240], [-84994], [22336], [13290], [-113236], [-52530], [-124680], [56500], [-103710], [90686], [-66800], [2050], [-43948], [-88718], [-44906], [73200], [55562], [37274], [103050], [-29880], [-85192], [93240], [-129034], [-118592], [20580], [45526], [-20430], [21584], [84480], [-98730], [69180], [132990], [-3330], [75544], [-129090], [31724], [31470], [21270], [-153200], [48850], [-107670], [53432], [37260], [-57868], [-97442], [-156540], [36158], [86820], [47500], [-81120], [17250], [22140], [-20456], [-174120], [34262], [33510], [103740], [-62654], [15720], [-124108], [18922], [74490], [1714], [-70890], [-79018], [63308], [79216], [-13920], [-69330], [200006], [161310], [141212], [-109380], [41924], [-30540], [-29578], [-57690], [-197254], [184750], [-99836], [70230], [91530], [-5416], [49830], [-60570], [-31786], [-126512], [132060], [-159090], [128756], [78550], [-171750], [-18506], [157562], [93870], [-134160], [-103890], [-146670], [10800], [181828], [-167040], [65520], [-25890], [45700], [-45074], [179670], [-119450], [119606], [-87210], [206012], [144360], [45330], [78248], [25552], [-183450], [225240], [-20714], [-64140], [242158], [176070], [-60270], [161350], [-13290], [-198196], [-201360], [219044], [151000], [161800], [-119040], [251438], [85110], [-22170], [-82748], [-159120], [-250754], [124328], [181560], [-130996], [115350], [-6514], [-176430], [108742], [17130], [114810], [112772], [102088], [198780], [-64916], [167970], [80806], [-110910], [133260], [229724], [-398], [-31230], [93240], [-49922], [-191910], [-149760], [-277170], [-62108], [-3360], [-261870], [-217550], [-129390], [75780], [7920], [224156], [150480]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_900_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_900_4_a_j();".
// 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_900_4_a_j(:prec:=1)
    chi := MakeCharacter_900_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_900_4_a_j();".
// 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_900_4_a_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_900_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![2, 1]>,<11,R![-30, 1]>],Snew);
    return Vf;
end function;