
// Make newform 2304.4.a.bk in Magma, downloaded from the LMFDB on 24 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_bk();".
// 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_bk();".
// 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, 1], [0, -7], [48, 0], [0, -12], [-54, 0], [4, 0], [0, 50], [0, 47], [0, 17], [0, 94], [-294, 0], [-188, 0], [0, -146], [0, 215], [252, 0], [0, 26], [-628, 0], [0, -2], [1006, 0], [0, -387], [-720, 0], [-1482, 0], [1822, 0], [0, 263], [0, 131], [-1188, 0], [0, -136], [390, 0], [0, 175], [-1380, 0], [-1158, 0], [-1180, 0], [0, -627], [0, 41], [0, -386], [-1748, 0], [0, 4], [0, 173], [-3228, 0], [0, 584], [0, 1004], [-766, 0], [0, -837], [0, -501], [1100, 0], [0, -113], [3336, 0], [0, -1732], [318, 0], [0, 248], [-2710, 0], [-5136, 0], [4398, 0], [0, -1968], [0, 1335], [0, -1121], [0, 440], [4398, 0], [-4372, 0], [0, 1031], [4172, 0], [0, -1868], [74, 0], [0, 567], [7556, 0], [-4106, 0], [-5256, 0], [0, -2998], [3942, 0], [0, 1918], [0, -839], [0, -2958], [-13844, 0], [0, -2068], [0, -3751], [0, 34], [5418, 0], [-11450, 0], [1176, 0], [0, 2896], [0, 242], [4318, 0], [0, -465], [-1032, 0], [-726, 0], [-8666, 0], [0, -4239], [0, 1443], [-16824, 0], [0, -3162], [0, 3093], [852, 0], [11156, 0], [0, -4330], [0, -2681], [-2766, 0], [18988, 0], [0, 3752], [-21188, 0], [0, -3531], [504, 0], [-20358, 0], [-13300, 0], [4606, 0], [-13980, 0], [12486, 0], [0, 2534], [-6986, 0], [0, 1327], [0, 3202], [-2850, 0], [-20116, 0], [0, -2099], [-7230, 0], [-2948, 0], [0, 4954], [0, 2997], [-10308, 0], [0, -4562], [30910, 0], [0, 4273], [528, 0], [9052, 0], [0, 9411], [0, 7860], [0, -198], [0, 5829], [0, 10172], [13940, 0], [0, -3176], [0, 9625], [0, 5036], [-30222, 0], [-11758, 0], [0, -541], [31012, 0], [0, -2047], [40650, 0], [-8372, 0], [0, -2705], [0, -6255], [6684, 0], [0, -7032], [0, -5662], [0, -5938], [-27222, 0], [-3548, 0], [0, 13004], [0, 8378], [48318, 0], [14380, 0], [0, -9840], [31252, 0], [0, -3776], [0, 2553], [-29622, 0], [23210, 0], [0, -5695], [1236, 0], [18402, 0], [0, -12077], [-8832, 0], [23034, 0], [0, 5136], [0, -887], [0, 15090], [29374, 0], [0, 9501], [43476, 0], [0, 10278], [0, -1360], [30314, 0], [0, 12189], [-11394, 0], [-9124, 0], [0, -2203], [0, 8223], [0, -10274], [0, 949], [6240, 0], [0, 7956], [16926, 0], [0, -14436], [0, -15555], [0, -13876], [-11500, 0], [4898, 0], [0, -14696], [-14350, 0], [19452, 0], [-1276, 0], [0, 833], [-37860, 0], [54750, 0], [-28850, 0], [0, 2964], [7254, 0], [0, -3020], [0, 10169], [0, -12561], [0, 20688], [-48554, 0], [69576, 0], [0, -14501], [0, -1197], [-66888, 0], [47406, 0], [48292, 0], [22754, 0], [0, 15545], [0, -17609], [-20436, 0], [0, -2478], [-7274, 0], [0, -1691], [10146, 0], [0, 9012], [0, 25841], [0, -3624], [0, 25767], [8370, 0], [0, -5797], [100800, 0], [0, -11922], [-93642, 0], [0, 12870], [0, 29287], [10596, 0], [0, 8960], [14092, 0], [0, 18811], [93198, 0], [-100172, 0], [0, -21994], [52654, 0], [0, -8963], [-78144, 0], [0, -16278], [10248, 0], [76484, 0], [0, -20443], [0, -12146], [-37482, 0], [0, -30814], [0, 5613], [-79500, 0], [-79756, 0], [0, 6420], [0, -20520], [-66762, 0], [0, 18586], [89594, 0], [0, 11331], [71412, 0], [0, -344], [-86020, 0], [0, -13417], [62326, 0], [0, 22803], [-133932, 0], [0, 17528], [0, -7154], [-62382, 0], [-101860, 0], [0, 19801], [106446, 0], [15436, 0], [0, -32851], [0, -4262], [6500, 0], [-96118, 0], [0, -37039], [54242, 0], [0, -16057], [-20952, 0], [0, 29818], [-49610, 0], [-71676, 0], [0, -36474], [0, -10993], [0, -1602], [0, -8950], [52300, 0], [0, 28692], [36842, 0], [0, 7373], [0, -29927], [-34842, 0], [0, 19501], [-136668, 0], [3270, 0], [-118740, 0], [0, 678], [0, -41751], [0, 10119], [0, 12015], [-103176, 0], [-124364, 0], [-35158, 0], [0, -30983], [0, 10405], [-37908, 0], [40564, 0], [38954, 0], [78192, 0], [0, -2132], [0, -11318], [0, 5610], [0, 29692], [0, -441], [49170, 0], [-94892, 0], [0, 48332], [7658, 0], [-27204, 0], [0, 27386], [-26138, 0], [77406, 0], [-162988, 0], [-71782, 0], [0, -15985], [0, 32105], [107370, 0], [-3458, 0], [97972, 0], [-154028, 0], [0, -46824], [0, -44171], [0, 9952], [0, -11663], [0, 38783], [-16716, 0], [47300, 0], [14088, 0], [0, 43822], [-81378, 0], [-112274, 0], [0, -35313], [0, 22686], [26034, 0], [0, -14317], [0, -20041], [0, -21401], [53448, 0], [0, 47628], [-59884, 0], [0, -38006], [0, 2263], [-109532, 0], [52054, 0], [0, 12931], [0, 32475], [0, -58978], [139110, 0], [0, 27904], [65892, 0], [-127134, 0], [0, -21652], [0, -46482], [-57258, 0], [0, -9852], [-31224, 0], [-97708, 0], [-47594, 0], [0, -55205], [0, 3477], [13990, 0], [220176, 0], [99100, 0], [0, -23136], [0, -38369], [0, 44109], [0, -19860], [-102408, 0], [0, 51124], [-198670, 0], [38946, 0], [156962, 0], [0, 21533], [-175470, 0], [0, -55775], [-227442, 0], [77740, 0], [0, -12092], [0, -26991], [0, -3328], [206996, 0], [0, 44882], [13970, 0], [0, -57243], [-194604, 0], [77092, 0], [0, 50032], [142390, 0], [0, -38317], [33570, 0], [83212, 0], [0, -23451], [0, 35642], [137394, 0], [0, -11449], [-164310, 0], [0, 34827], [0, -43619], [0, 8880], [40170, 0], [141316, 0], [-81240, 0], [108334, 0], [0, 17261], [191568, 0], [-75572, 0], [139966, 0], [0, 23539], [0, 57812], [0, 10965], [-183174, 0], [0, -38286], [0, 79117], [0, 61654], [0, 2788], [80256, 0], [-83926, 0], [0, -45021], [44568, 0], [107862, 0], [218596, 0], [0, 52954]];
    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_bk();".
// 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_bk(: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_bk();".
// 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_bk( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2304_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-12, 0, 1]>,<7,R![-588, 0, 1]>,<11,R![-48, 1]>,<13,R![-1728, 0, 1]>,<17,R![54, 1]>,<19,R![-4, 1]>],Snew);
    return Vf;
end function;