
// Make newform 2310.4.a.a in Magma, downloaded from the LMFDB on 23 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2310_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_2310_4_a_a();".
// 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_2310_4_a_a();".
// 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_2310_a();"
function MakeCharacter_2310_a()
    N := 2310;
    order := 1;
    char_gens := [1541, 1387, 661, 211];
    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_2310_a_Hecke(Kf)
    return MakeCharacter_2310_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 := [[-2], [-3], [-5], [7], [11], [26], [78], [-16], [-132], [198], [-4], [206], [414], [260], [-216], [498], [-492], [-394], [-412], [-768], [1238], [560], [-900], [-954], [182], [-270], [-592], [264], [-10], [1542], [992], [900], [-2274], [1328], [-1170], [920], [-1126], [-3460], [-1080], [1770], [-2316], [3446], [-4896], [-3238], [738], [3932], [6020], [1304], [-5340], [14], [5214], [-4464], [-5686], [1140], [5646], [8220], [-3510], [1820], [5222], [-2838], [7508], [-6462], [4676], [3048], [6998], [2970], [-7780], [11882], [4344], [5126], [1758], [9288], [104], [1838], [8324], [12408], [10902], [-3454], [666], [6602], [-7788], [-8866], [-4968], [-7618], [-17356], [5376], [-6318], [18362], [3930], [14120], [180], [14184], [8600], [-7908], [3788], [14112], [-7782], [19374], [12692], [4070], [5132], [22818], [-18468], [-23982], [25292], [-24082], [6228], [-27906], [3384], [27434], [-5464], [25622], [9030], [-12184], [18200], [8610], [-19132], [-4920], [21402], [12660], [15638], [-3982], [-34014], [11856], [-16504], [-7578], [-2050], [15696], [-10264], [29162], [6788], [12900], [10616], [-12634], [-35634], [-29998], [-23838], [13484], [2634], [-25710], [25376], [-7722], [-2224], [-72], [-29266], [-40224], [-2854], [46326], [-7960], [-11388], [34382], [11814], [-28276], [-44208], [6452], [-38688], [7616], [-5490], [31358], [18882], [53088], [-6906], [-22240], [15468], [25566], [-50136], [30008], [14762], [-12814], [45666], [22404], [566], [30528], [9794], [-42148], [-66066], [22052], [49158], [21944], [-28930], [19712], [-32820], [30518], [-19290], [-9540], [-57558], [25982], [19676], [-43846], [23352], [-17674], [53448], [-59812], [-71886], [-11736], [-59274], [33506], [79694], [414], [-66840], [48942], [29708], [-31702], [-38278], [42636], [53226], [-14308], [-9552], [6546], [39272], [-67630], [3330], [43856], [18996], [-43848], [56498], [-37720], [-15378], [-58716], [-45558], [101918], [-28660], [26970], [-21688], [45540], [-38050], [100902], [90264], [-17248], [60732], [53246], [86960], [-13936], [97602], [-12292], [-46704], [-29734], [-56142], [-53460], [62904], [-28464], [-61888], [77672], [-64378], [-37554], [13512], [77456], [23652], [-93724], [-49092], [-116386], [55806], [10452], [43202], [69930], [-10740], [29054], [9812], [78306], [-107098], [-78928], [-44208], [69878], [16634], [-30354], [-21544], [21534], [-50034], [-46348], [77898], [-69658], [84884], [-322], [79784], [-42394], [103448], [-33456], [54566], [58490], [52644], [26352], [125624], [-60408], [86966], [-116860], [-1968], [-153238], [-127254], [-29932], [-666], [-138594], [98412], [129198], [122052], [-61114], [87354], [-28132], [-18798], [-23556], [133724], [-4738], [95874], [-134488], [-7968], [-56884], [48914], [69864], [-29626], [1056], [-123586], [-83232], [177246], [62586], [108668], [123636], [-68686], [46764], [158952], [-23722], [92154], [91400], [-2206], [-5478], [20168], [159294], [-78910], [-65404], [-81916], [138516], [13602], [142022], [59082], [-145540], [124092], [260], [-148476], [-68218], [-29682], [137450], [-47536], [92774], [90054], [-131670], [-376], [21402], [39732], [53918], [-115276], [-162696], [-23934], [143552], [205682], [190494], [-201184], [-74194], [57702], [48288], [-146676], [91326], [-117828], [-141874], [-18450], [-12492], [7740], [20636], [-195262], [-90054], [9680], [-130870], [162468], [212312], [34860], [75390], [-212140], [116246], [104844], [161880], [-26338], [-69426], [-24298], [231954], [-40002], [-74224], [-201018], [73544], [66720], [5144], [-40030], [29636], [148104], [-136558], [-1950], [102924], [-18796], [18624], [-248110], [131300], [270750], [-125380], [-177762], [43166], [216678], [-89800], [-186762], [-177270], [210908], [-111706], [-89262], [-27244], [20316], [-229210], [-205614], [156384], [-229612], [31394], [-148182], [-166608], [76088], [-95442], [-24096], [-91986], [-15334], [-120588], [-6540], [275798], [-289830], [95856], [29154], [-29920], [-251736]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2310_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2310_4_a_a();".
// 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_2310_4_a_a(:prec:=1)
    chi := MakeCharacter_2310_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_2310_4_a_a();".
// 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_2310_4_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2310_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<13,R![-26, 1]>],Snew);
    return Vf;
end function;