
// Make newform 2304.4.a.be in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2304_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_2304_4_a_be();".
// 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_2304_4_a_be();".
// 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
        poly := [-3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 2]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_2304_a();"
function MakeCharacter_2304_a()
    N := 2304;
    order := 1;
    char_gens := [1279, 2053, 1793];
    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_2304_a_Hecke(Kf)
    return MakeCharacter_2304_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, 0], [0, 3], [0, 1], [0, 0], [0, 16], [90, 0], [-116, 0], [0, -30], [0, -75], [0, -87], [0, -10], [-54, 0], [-20, 0], [0, -114], [0, 141], [324, 0], [0, -166], [116, 0], [0, 318], [-1106, 0], [0, -43], [-1152, 0], [918, 0], [190, 0], [0, -3], [0, -229], [-252, 0], [0, -132], [2214, 0], [0, -201], [-2268, 0], [522, 0], [-676, 0], [0, 423], [0, 689], [0, 582], [388, 0], [0, -636], [0, -57], [2844, 0], [0, 28], [0, 924], [-1342, 0], [0, -279], [0, 515], [-2764, 0], [0, 1239], [-5688, 0], [0, -1608], [2718, 0], [0, 1032], [4490, 0], [-4608, 0], [-4626, 0], [0, 576], [0, 909], [0, 1543], [0, 1884], [-1170, 0], [-5740, 0], [0, -2307], [-5452, 0], [0, -636], [1034, 0], [0, 765], [-4132, 0], [-458, 0], [-11016, 0], [0, 730], [-5562, 0], [0, -2562], [0, -3695], [0, -1438], [9892, 0], [0, -2532], [0, 2859], [0, -30], [-1062, 0], [8614, 0], [-10440, 0], [0, 260], [0, 114], [12958, 0], [0, 3303], [-1800, 0], [13626, 0], [-12602, 0], [0, 531], [0, 3179], [-9144, 0], [0, 1782], [0, 925], [396, 0], [-12436, 0], [0, 4758], [0, -2643], [7650, 0], [-18332, 0], [0, -4868], [1684, 0], [0, -657], [7992, 0], [-5526, 0], [-13420, 0], [-10178, 0], [18684, 0], [5094, 0], [0, -5610], [-27722, 0], [0, 7703], [0, 4882], [17694, 0], [13652, 0], [0, 2645], [5202, 0], [15892, 0], [0, 138], [0, 7119], [28260, 0], [0, -7466], [190, 0], [0, 1443], [-8064, 0], [-19244, 0], [0, -1791], [0, -4336], [0, 8874], [0, 3501], [0, 3576], [11180, 0], [0, -10248], [0, 10961], [0, -11272], [-12222, 0], [-34030, 0], [0, -1407], [30988, 0], [0, 2067], [37530, 0], [10852, 0], [0, -9051], [0, -9511], [-10044, 0], [0, 2828], [0, -6078], [0, 11750], [-18342, 0], [-26324, 0], [0, -3684], [0, -710], [-37314, 0], [18244, 0], [0, 5184], [-16388, 0], [0, 7248], [0, -7839], [-48006, 0], [-7894, 0], [0, 771], [-22356, 0], [-14958, 0], [0, -5045], [48528, 0], [39978, 0], [0, 5184], [0, 481], [0, 11970], [-2402, 0], [0, -11961], [14796, 0], [0, 3438], [0, -2064], [19178, 0], [0, -5483], [-43074, 0], [4772, 0], [0, 11247], [0, -5033], [0, -7770], [0, -11539], [54288, 0], [0, -14832], [9054, 0], [0, 2412], [0, 17127], [0, -7240], [-22996, 0], [35522, 0], [0, 696], [-6094, 0], [2052, 0], [61820, 0], [0, -1965], [-10332, 0], [2718, 0], [-1394, 0], [0, -3184], [24534, 0], [0, 16068], [0, -4053], [0, 9367], [0, 19636], [-45674, 0], [-25848, 0], [0, -23127], [0, 13723], [55224, 0], [27918, 0], [3052, 0], [34658, 0], [0, -6501], [0, 11983], [32724, 0], [0, 18450], [-5930, 0], [0, 4605], [-18702, 0], [0, 17460], [0, -11757], [0, 9772], [0, -12033], [162, 0], [0, 16419], [-49680, 0], [0, 9286], [-4842, 0], [0, 16758], [0, -2017], [-35460, 0], [0, -6668], [39364, 0], [0, -17949], [90126, 0], [-104228, 0], [0, -16698], [-11762, 0], [0, 6807], [-64368, 0], [0, -16326], [97704, 0], [-23140, 0], [0, 12749], [0, 10534], [-39402, 0], [0, -16734], [0, -1339], [21996, 0], [-40084, 0], [0, 28116], [0, 9036], [-31914, 0], [0, 3594], [3770, 0], [0, -19503], [-105300, 0], [0, -9716], [-102364, 0], [0, 3453], [-99146, 0], [0, 1883], [72684, 0], [0, -11236], [0, 13958], [63810, 0], [-28924, 0], [0, 25563], [-48978, 0], [113956, 0], [0, -19065], [0, -2710], [30716, 0], [-5110, 0], [0, 15593], [34274, 0], [0, -16033], [14184, 0], [0, 31434], [42550, 0], [-114660, 0], [0, 35190], [0, 23655], [0, 30798], [0, -4630], [-3356, 0], [0, -31788], [-35254, 0], [0, 15351], [0, -26303], [-120762, 0], [0, -31209], [-100836, 0], [20646, 0], [26388, 0], [0, 42318], [0, 27963], [0, 31439], [0, -26955], [-76392, 0], [-94148, 0], [-73558, 0], [0, -20229], [0, 37149], [-60588, 0], [-7748, 0], [-73654, 0], [-52992, 0], [0, -50648], [0, 42474], [0, 506], [0, -20148], [0, -24867], [-136350, 0], [-15812, 0], [0, 2364], [-27862, 0], [22500, 0], [0, 20202], [95398, 0], [-100098, 0], [-171028, 0], [-81766, 0], [0, -20235], [0, -38463], [-17766, 0], [62110, 0], [37852, 0], [-54884, 0], [0, -28584], [0, 18687], [0, 28516], [0, -35565], [0, 34471], [-71316, 0], [78140, 0], [62856, 0], [0, 48262], [99198, 0], [165742, 0], [0, 23031], [0, -52666], [-92574, 0], [0, -20991], [0, -48401], [0, 5709], [-73944, 0], [0, -22824], [-54196, 0], [0, 40314], [0, 36381], [-47924, 0], [-163466, 0], [0, -14271], [0, 11907], [0, 41126], [20070, 0], [0, 6096], [-5508, 0], [115506, 0], [0, -59268], [0, 26854], [-84042, 0], [0, 5652], [-130680, 0], [93644, 0], [163990, 0], [0, -10599], [0, -14915], [61606, 0], [-202752, 0], [113140, 0], [0, 4608], [0, -51099], [0, -17291], [0, -54200], [40248, 0], [0, 3684], [-146062, 0], [82386, 0], [-76798, 0], [0, 2679], [42210, 0], [0, -65431], [22158, 0], [220708, 0], [0, -2940], [0, 1161], [0, 42004], [73772, 0], [0, -17454], [-130606, 0], [0, 54207], [129132, 0], [-225620, 0], [0, 2064], [-249002, 0], [0, -2213], [243666, 0], [-26876, 0], [0, -25713], [0, -64806], [185634, 0], [0, -19185], [62298, 0], [0, -54135], [0, 10725], [0, 58772], [-245862, 0], [-252404, 0], [69192, 0], [-50834, 0], [0, -14025], [73440, 0], [-52316, 0], [-176066, 0], [0, 60321], [0, 44484], [0, 48701], [194346, 0], [0, -7758], [0, 57063], [0, -49170], [0, 26724], [-73584, 0], [75818, 0], [0, -64431], [264888, 0], [127350, 0], [217132, 0], [0, 22314]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2304_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2304_4_a_be();".
// 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_2304_4_a_be(:prec:=2)
    chi := MakeCharacter_2304_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_2304_4_a_be();".
// 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_2304_4_a_be( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2304_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-108, 0, 1]>,<7,R![-12, 0, 1]>,<11,R![0, 1]>,<13,R![-3072, 0, 1]>,<17,R![-90, 1]>,<19,R![116, 1]>],Snew);
    return Vf;
end function;