
// Make newform 2352.4.a.cf in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2352_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_2352_4_a_cf();".
// 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_2352_4_a_cf();".
// 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 := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_2352_a();"
function MakeCharacter_2352_a()
    N := 2352;
    order := 1;
    char_gens := [1471, 1765, 785, 2257];
    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_2352_a_Hecke(Kf)
    return MakeCharacter_2352_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], [3, 0], [10, 7], [0, 0], [10, -24], [52, 25], [58, -45], [-96, 22], [-14, 28], [148, -62], [52, 50], [-124, 48], [10, -219], [360, 100], [48, -250], [134, -360], [308, 226], [8, -3], [72, 524], [-494, 232], [52, 401], [472, -236], [-508, -80], [-194, 339], [244, -599], [914, -323], [-1100, 222], [270, -52], [-312, 4], [1398, 424], [620, 1196], [-1180, 944], [384, 94], [-36, -652], [-594, -832], [2676, -96], [304, -981], [-1464, -1064], [2496, -286], [838, -925], [-1130, 52], [1292, -1201], [1314, -1056], [474, -2024], [-3446, 552], [2864, -1076], [-1460, 588], [376, 420], [3292, 1030], [-3788, -717], [-2072, -766], [-1702, -1796], [-444, -2757], [1316, -3054], [3370, 777], [-3162, -2120], [5078, -63], [-3028, -994], [-1750, 2024], [344, 1746], [-288, -2022], [6234, 2057], [2768, 1330], [5464, 674], [4792, 761], [1490, -3864], [9388, -336], [-984, 3508], [-3998, -2000], [-4992, 2959], [1334, -6543], [102, 6164], [1432, 6880], [-1198, 2776], [-1292, -1976], [-1080, -8452], [2212, -1702], [-2288, -8411], [-248, 7250], [-3716, 5905], [684, -4018], [-2718, 1424], [3290, 4980], [11408, -213], [11112, -2696], [-3786, -8700], [3798, 6904], [-1506, 8736], [-954, -569], [4, 3824], [-5908, -1558], [4288, -4514], [-7732, -1328], [3826, 5580], [2192, 4952], [-16560, 312], [9358, -3139], [8950, 3545], [-1852, 11036], [16782, -1640], [-14548, 612], [-14078, 4536], [-5164, -8702], [-4888, -6354], [3308, 332], [-792, 10375], [-5804, 5798], [6554, 35], [-2318, -10560], [10552, 1613], [-6216, -1700], [8248, -2200], [-10016, 5838], [-13020, 11724], [10068, 12200], [-11080, -7670], [3832, 1410], [-2808, -15134], [-27244, 1146], [26170, -2048], [-12008, -5677], [-9156, -6344], [-1434, 10783], [-6602, 7924], [1116, -13456], [4292, 4958], [-8336, -5452], [17384, 5520], [2732, -9906], [8612, 10683], [-4312, -2696], [-7294, -9660], [18856, 13684], [21992, 6340], [-32762, -5153], [-18528, 7443], [-6018, -5597], [-40116, 1792], [13682, -16363], [1586, -2472], [-27492, -11044], [10498, -4576], [-21832, -12612], [-8274, -15460], [-3684, 19065], [8496, 706], [-11520, -829], [11878, 7303], [-17504, -1638], [-38982, 1816], [23640, -2968], [-13886, -7989], [10216, -4360], [-9312, -22834], [13144, -6768], [-32190, 1932], [-4196, 5308], [-42282, 7647], [-28192, 7657], [12598, -12831], [10830, 19184], [-10766, 528], [-4828, -16268], [23276, -3536], [-28488, -10282], [-28568, -1408], [14348, 21636], [5096, 16907], [-19090, 18552], [-18734, -6299], [-53482, 3348], [-25936, -4691], [-18526, -10408], [10284, -15956], [128, 12256], [3822, 38441], [-24372, -23720], [22228, 28430], [-924, -10830], [-16408, -8321], [-10072, -7480], [4076, 17616], [4292, -25196], [-1194, 9617], [-59230, 4252], [16894, -12885], [20178, 11176], [-32020, -14924], [12916, 33540], [-6552, -3720], [-25396, 6111], [12010, -26476], [15748, -26036], [18226, -9359], [60726, 9084], [-57174, -5929], [828, 14032], [14516, -36556], [4350, -3973], [-20672, 25694], [-31890, -15200], [27696, 10764], [54660, 1717], [7140, 13251], [10396, -17884], [57254, -10357], [-47240, 8656], [442, 6680], [25126, -13376], [17088, -10082], [-49104, -7728], [18494, 35349], [-45740, 7816], [6268, 19188], [-19944, 2366], [-42312, -25117], [-25132, -28660], [-52434, -27743], [-57998, -8224], [-10780, 6794], [-25192, -43404], [-76484, 9526], [21682, 48064], [40800, 16468], [4732, 49660], [8548, 2568], [18598, 17831], [-31410, 45060], [-15644, 43674], [-54778, -12280], [-57120, 28620], [-24992, -15106], [24396, 996], [35518, -13864], [36768, 23150], [34040, -40604], [-17044, 58263], [-8666, -60272], [-65550, -15524], [34776, -3292], [19306, 26456], [20228, -1560], [16224, 7832], [-89954, 1704], [-82206, 5313], [9024, -15114], [70820, -19734], [18284, -22462], [38052, 43980], [-60770, -10360], [16818, -4192], [-49458, 50413], [-55126, -12256], [-10820, -76321], [100538, -14399], [3806, -38924], [-55012, 35268], [10576, 2538], [6098, -49143], [-43080, -40765], [43120, -13136], [70642, -18232], [111460, 6033], [3176, 27355], [31162, -34073], [-48364, -1216], [-24354, -60736], [-63926, -14197], [38116, -18552], [-13660, 80422], [7928, -30861], [50132, -34784], [-24532, 76143], [38224, 4956], [28996, 45239], [30316, 17586], [-12306, -24400], [-27318, -28480], [13010, 15880], [-83516, -13546], [8080, 69864], [-11012, -51032], [-18944, 37212], [22872, -11339], [58932, -15476], [-88126, 22292], [12954, -9936], [-27070, 56448], [85868, -54402], [88766, 22383], [61982, -1984], [14244, -66284], [5880, 2318], [28388, -28630], [-27434, 70728], [-6526, 8357], [95920, 35896], [-70966, -21525], [37060, 71366], [-61868, 48056], [-23648, 42285], [-108468, -42178], [120756, 23504], [67378, -2920], [-53236, -34972], [-93920, -76], [112890, 43200], [52340, -2147], [34406, -61212], [-58142, 14176], [58560, -50680], [36660, -36874], [-57992, 11378], [-37680, -2972], [51202, -50880], [-68604, -39943], [-13844, -56148], [56554, -82984], [108596, -16523], [-92800, 39866], [2432, -34558], [-10180, -98512], [50718, 57763], [-10180, -63468], [48202, -15232], [-11276, 21421], [-41192, -40776], [55504, 34150], [50298, 24340], [93804, -33022], [62654, 22472], [-86620, 7594], [11172, 31170], [44692, 62682], [-11976, -32308], [8836, -29462], [-72936, 13616], [-51618, -34849], [29940, 89703], [-55012, 32498], [-59570, 97240], [-109576, 50786], [116554, 12995], [49808, 69352], [-43308, -38666], [-142290, -46632], [46844, -26695], [-58384, 5972], [13736, 94680], [153126, 37627], [21992, -42638], [-121638, -67648], [-34906, -89400], [42088, 20952], [-9010, 3856], [36542, -51583], [-10096, -87748], [196852, -4908], [-55482, -42632], [14378, 91460], [29666, 108568], [121866, 5185], [39594, -55028], [-34590, 105324], [-104508, 78844], [-58452, 25896], [-49830, -96057], [-38512, 131360], [-8526, -44648], [-89750, 68916], [-70776, 28926], [-174170, -35968], [-107930, 41912], [-11572, -36678], [-114074, 77024], [65108, -13928], [-55610, -83348], [59128, 137393], [-66654, 84871], [45596, 56141], [-205042, -17669], [79754, -121592], [107472, -79280], [-87434, 65096], [4900, -2932], [-40448, 134928], [-50332, 39732], [-173228, 50335], [-183652, -488], [27408, 78070], [18044, 3684], [-16546, 41865], [196514, -1204], [-79048, -1630], [116842, -87620], [65752, -60620], [122584, -103784], [-80250, 6445], [174388, 28808], [129284, -17418], [-232448, 29535], [182974, -48384], [5412, 128264], [-78694, -89107], [28962, -20997], [-45912, 113948], [-92598, -4816], [92750, -56712], [68676, 41336], [-3940, 54094], [142664, 2467], [216612, 17906], [-47214, -141024], [111264, -41632], [40380, 32980], [41886, 32977], [64330, 136176], [-143124, 40370], [118778, 36807], [-124632, -95382], [-3204, 171374], [168960, 86679], [-114298, 35184], [269332, -9992], [-217136, 3563], [-67150, 83781], [75234, -136832], [13440, -61386], [66484, -167344], [-25008, 90150]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2352_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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