
// Make newform 570.4.a.i in Magma, downloaded from the LMFDB on 03 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_570_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_570_4_a_i();".
// 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_570_4_a_i();".
// 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 := [-6, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 3]];
    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_570_a();"
function MakeCharacter_570_a()
    N := 570;
    order := 1;
    char_gens := [191, 457, 211];
    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_570_a_Hecke(Kf)
    return MakeCharacter_570_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, 0], [-3, 0], [-5, 0], [2, 3], [-24, -1], [20, -5], [36, -10], [19, 0], [-30, 2], [-42, 19], [38, 14], [236, -1], [6, -33], [38, -17], [102, 14], [-72, -26], [-408, 62], [-484, -48], [-160, 20], [-504, -26], [74, -80], [-376, -52], [-258, 100], [-702, 77], [-52, 171], [-1050, -66], [-16, 4], [216, -52], [-34, -126], [96, 96], [-592, -252], [-2388, -41], [-2166, 44], [-412, -182], [-1146, -72], [326, 42], [-538, 142], [1010, -65], [-138, 136], [-60, 24], [-396, -162], [2018, 42], [1884, -163], [1100, 441], [-2700, -70], [344, -250], [-2068, 104], [-88, 308], [-1734, -348], [-1384, 208], [4482, -20], [240, 413], [3674, -268], [-2484, 645], [-48, 616], [-402, -928], [1494, -339], [2756, 210], [-1906, 756], [-870, 515], [2054, -705], [3048, -628], [-5884, -378], [-6960, 447], [3746, 666], [3252, -670], [-214, -946], [1100, -79], [-8310, -72], [-6622, 56], [4422, 384], [-1188, 661], [-7162, -77], [1640, -273], [-2590, 386], [2364, 320], [2334, 204], [-2086, -772], [2634, 453], [578, 1230], [-2784, 1443], [-1042, 1152], [-252, -466], [3980, -767], [776, -464], [3666, 1470], [8442, -517], [-970, 942], [-1734, -1604], [-5434, -1309], [-8442, 274], [3972, 51], [-6928, 906], [-588, -1699], [-11140, 1162], [-4122, 712], [-930, -155], [-378, 2451], [-4264, 1686], [-7882, -408], [-2716, -178], [2682, 3068], [9978, -972], [-1230, -533], [-12616, 726], [-19438, -90], [-6666, -654], [12006, -128], [8304, -2280], [9110, -1994], [5852, 1282], [-646, -174], [13092, 318], [9776, 42], [-1528, 3916], [8706, 565], [-8134, 2889], [14958, -392], [-3864, 3718], [1092, 84], [-16558, -570], [-14488, 2065], [17184, 330], [10800, -1456], [-6640, -1470], [-11178, 160], [22412, -1956], [-4068, 1757], [-3094, -3655], [-3166, -3624], [-8692, 3384], [15972, 1000], [-9574, -3178], [-5830, 1182], [24342, -504], [-574, 1252], [20556, -854], [14816, 2046], [4524, 3704], [21654, 1496], [4412, 972], [-12678, 3034], [26570, 399], [3510, 68], [-1150, 5242], [-32208, 698], [-38950, 386], [-19032, -306], [8408, 464], [-7956, -1744], [11576, 4245], [17586, -3802], [-21598, -1257], [-48, -2028], [6284, -1194], [-12732, -2920], [24716, -3292], [-5766, 1074], [12530, 18], [6486, -2795], [-9150, -548], [-26352, 2316], [-25234, 589], [46908, 592], [-19524, 690], [7410, -3640], [-5560, -4380], [18686, -90], [-7450, 900], [50442, 368], [-27672, 2354], [17318, 4096], [-9408, 7329], [-8206, -2316], [35624, -2128], [4074, -3742], [-7000, -4846], [29754, 138], [-3724, -1874], [-21382, 632], [-61486, -279], [-47148, 1140], [-50380, 437], [36540, 3048], [-4098, 1918], [-38598, -1488], [-46816, 2727], [-22696, 1930], [18974, -7098], [-1332, 5347], [33320, -3381], [-45330, 2146], [12692, -168], [33690, 1273], [31230, -442], [-3000, 508], [28388, -696], [-19618, -6560], [-9456, -7114], [27738, 1258], [-20766, 3653], [2072, -6552], [-2572, -4039], [18074, 1112], [-42804, -1165], [-38052, -3302], [18848, 1440], [28086, 3312], [-48426, -658], [-1996, 172], [-34954, -4634], [-5106, 2986], [-37978, 227], [-16998, 3716], [-50808, -986], [37118, -2402], [67646, 1215], [-5730, -9185], [-23202, 2324], [-12936, -690], [69410, 4296], [41474, 1766], [-60582, -2963], [-42442, -6663], [-2622, -4052], [-10726, -568], [-11508, -7792], [46116, -4602], [22916, 7992], [-37644, -8085], [20702, 3030], [-13714, 1230], [40592, -996], [-13566, -12987], [3278, -1995], [-28914, 418], [41312, 7948], [51462, -6428], [-44508, -3245], [-3600, 1994], [-30192, -1012], [29756, 6624], [-16450, -4209], [28442, 4478], [45528, 6750], [89328, -2409], [65126, -1899], [-22944, -688], [88814, 2150], [-5274, -9836], [34202, -11454], [62658, 7364], [31578, -5156], [44174, 4122], [-56616, 5450], [-5400, -3655], [46064, -2016], [-13768, -9744], [58068, 9134], [-50218, -5388], [-5128, -6408], [25860, -7780], [88706, 3376], [-15496, -5295], [48696, -5122], [87374, 1422], [-35550, 11205], [1434, -8538], [102404, -84], [36168, 4330], [68006, -4188], [-66760, 972], [-22246, 13698], [101432, -1026], [60068, -9515], [105086, 1833], [39102, -5620], [-54970, 2206], [-18358, -12326], [-20688, 14609], [66372, -6180], [-27628, -9312], [8274, 12450], [-70810, 9116], [9578, -11523], [-102672, 2763], [-31246, 9992], [-106032, -6730], [126992, 1496], [-63702, 7155], [8130, -742], [-16866, -14076], [7548, 15190], [-136776, 1718], [-10024, 12643], [-45066, -2246], [50600, -9072], [46596, -5974], [-36684, -14252], [-65194, 10201], [-114118, -240], [32112, 5918], [52580, -2600], [-34770, -18344], [79508, 3154], [-78244, -2287], [11028, 6012], [-8566, -18276], [-22728, -11689], [17426, 3982], [103098, 238], [4842, 15244], [-12462, 3961], [43652, 19218], [-21474, 6548], [-102526, -5424], [107796, 979], [65760, -15884], [7310, -18058], [-36210, 18116], [-98026, 11582], [-99106, 7226], [-113238, 157], [-69424, 5642], [17220, -1906], [-172150, 916], [61148, -1928], [-3328, -13718], [105690, -2216], [-2268, -19474], [-68182, 11896], [72384, -6186], [46028, 11034], [11802, 15124], [-142828, 546], [-62154, 11064], [75170, -3336], [126420, -254], [-33532, 17824], [93206, -5781], [19496, -16899], [40422, -8508], [143754, -2787], [-19330, -11430], [-13920, -26378], [-57456, 9236], [-100492, -6768], [-22876, 12816], [-64104, -15776], [43326, 18100], [3314, -2562], [-117520, 1897], [11022, -10962], [33428, 15918], [66386, 11478], [-13068, 8602], [66840, 16087], [-113724, 8051], [133440, 2842], [34716, 11776], [-104758, -5688], [-60270, -20940], [-48060, -10268], [159708, 2966], [46514, 807], [110108, -9573], [151122, 1112], [29360, -9794], [-54970, 18214], [85080, 655], [26732, -19428], [-90066, 14632], [25194, 13665], [107588, -12436], [-87478, 3918], [2508, 23276], [130932, 6835], [-43702, -10212], [-4734, -3754], [77276, 7221], [-112614, 2173], [97440, 13470], [144650, -3015], [-86190, 6244], [-119122, 8266], [133038, 9008], [-46096, 4954], [-59722, 20412], [55910, 25389], [1014, -19188], [-232018, -850], [203160, -2082], [53496, 6779], [-17890, 13705], [-98412, -5366], [74216, 19203], [-63034, 22570], [-42630, -2609], [-232990, 1154], [6846, -16284], [23402, -26808], [-61128, 2078], [164, -24186], [139416, 13740], [-103086, 24775], [-9124, 21120], [-14146, 3366], [-123054, 4879], [-25468, -21894], [66936, -4301], [55424, -27073], [149196, -11234], [-127692, -15292], [39656, -29582], [158834, -9420], [-100458, 7572], [147924, -15160], [-44116, 5040], [128646, 5388], [43548, -7832], [-95226, -1713], [-91384, 17545], [132762, -13166], [20004, -5880], [197372, 7377], [-90228, 7236], [224904, 6692], [-232614, -5552], [-19024, 27038], [-220668, -8533]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_570_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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