
// Make newform 525.4.a.m in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_525_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_525_4_a_m();".
// 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_525_4_a_m();".
// 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 := [-4, -1, 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_525_a();"
function MakeCharacter_525_a()
    N := 525;
    order := 1;
    char_gens := [176, 127, 451];
    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_525_a_Hecke(Kf)
    return MakeCharacter_525_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 := [[1, 1], [-3, 0], [0, 0], [-7, 0], [-18, 5], [11, 17], [-53, 27], [-56, 56], [115, 24], [-73, 84], [-61, -13], [66, -19], [95, 45], [373, 58], [120, -88], [119, -89], [-325, 209], [25, -273], [640, -123], [192, 235], [90, 88], [-162, -103], [821, -431], [494, -522], [-266, 704], [116, -666], [-111, -21], [390, 310], [-1196, 597], [342, 601], [1918, -109], [32, -246], [4, -394], [-876, -390], [1187, -874], [410, -453], [-834, -242], [427, 341], [-2342, 90], [448, -44], [3270, -370], [-2458, 364], [901, -237], [-2566, -429], [595, -2224], [1952, 1200], [-2041, -479], [957, 1757], [-2529, 1097], [3166, -152], [-236, 2349], [4744, -1232], [-5370, 406], [983, 163], [711, 1403], [-4609, 1126], [4142, 1508], [1684, -1424], [1230, -1760], [-2948, 2267], [-2160, -1278], [6360, 868], [-2114, -1232], [-2538, -868], [-5774, -714], [759, 2852], [-2727, 3782], [-3263, 3121], [9082, 279], [179, 4889], [-390, -3740], [4629, -94], [2411, -4627], [6348, -3735], [-4257, -3808], [2956, 924], [6102, -3883], [1521, -3735], [7580, 63], [2350, -4418], [-6791, -2195], [-2894, 477], [13053, 1159], [4238, 2594], [-4201, 4661], [-2576, 4428], [-2272, 2097], [-1215, -1916], [-9572, -328], [4972, -6344], [14521, 157], [-11324, 2596], [18698, -631], [19062, -335], [-1587, 3395], [3410, -7344], [3628, 1084], [-7659, -491], [-3292, -1420], [2756, -3781], [-12757, 1658], [8126, -4751], [-5487, 8341], [5738, 2293], [16535, 336], [-5690, -2258], [21653, -3819], [-8522, 1078], [-1327, -7952], [-21184, 3428], [-516, 6864], [-5574, 3233], [3898, -10589], [-5818, 1374], [-9386, 3405], [7846, 2877], [24682, -4598], [-8862, -220], [-29034, -336], [-21558, 3890], [-23302, 2402], [-7215, -3615], [6880, -4466], [-28170, 107], [-150, -10942], [-16997, 8163], [18340, -10198], [-26378, -582], [-28047, -2403], [-26415, 5415], [6095, -598], [3077, 2847], [9136, -17936], [-12222, -115], [8246, 1366], [13228, 9084], [-31728, 730], [-8318, 4484], [-16002, 17692], [6388, 4009], [12030, -2688], [19302, -9572], [20146, 8659], [8994, -15877], [-20129, 6503], [2504, -9162], [-8831, 3871], [-2318, -4038], [9416, -19166], [-6052, -13883], [-5016, -12510], [5375, -12041], [6615, 10858], [17642, 9234], [-661, -20719], [10695, 5310], [13812, -3721], [-20109, -4597], [-5234, -15338], [11256, 13710], [2132, -8776], [-14036, -12093], [-4608, -13936], [44156, -3968], [-5962, -4785], [-392, 3150], [41428, 3575], [-31190, -8538], [11887, -20536], [60872, -1242], [-26466, 8523], [31399, -1923], [-21615, 13264], [22333, -6323], [-26772, -1222], [6395, -1689], [-20328, 9147], [417, -19239], [21449, -3229], [-19879, 7989], [-20470, 16329], [38607, -8927], [5870, -24047], [42465, -11523], [1724, 5607], [43138, -16112], [-29884, 14053], [49570, -532], [-38599, 8596], [18544, -17450], [-43932, 2630], [51612, 3731], [34540, -3463], [-3734, -15208], [-28052, 24337], [-53895, 63], [-39803, 24660], [30046, 5049], [39178, -6554], [41280, -21370], [27242, -14124], [8941, 2933], [36509, -6467], [-16642, -18146], [2695, 6013], [1180, -21704], [-37009, -14517], [32274, 13442], [-3486, -4993], [10950, -11470], [38078, -4607], [37966, -7544], [-7690, -18695], [10093, 1523], [15618, -27028], [-60400, -1414], [3532, -8541], [-9998, 39270], [-8059, -21402], [3363, 686], [-5116, -5739], [64615, -17597], [83238, -7177], [18880, 27629], [43412, 7036], [42002, -31180], [44502, -10796], [-16044, 25801], [-66364, 17970], [-6782, 41193], [-14648, 21115], [2884, 21710], [29404, 124], [-81046, 12411], [29888, 22088], [35544, 6022], [-1626, 42382], [-25598, 21593], [35890, -32779], [9558, -5626], [25196, -28781], [-90210, -10358], [12411, 7191], [50794, 1089], [29823, -16767], [-65984, 22754], [68225, 453], [-5876, -2678], [-46460, 24332], [8896, -14768], [53108, -982], [-11061, 2873], [-10175, -9509], [45826, -13132], [-78144, -8764], [14270, -23426], [1682, -4317], [38190, 14640], [-28566, 17702], [65038, 5410], [63496, -28608], [15356, -51747], [-8481, 34239], [-31978, -24732], [55831, -19677], [34578, -12138], [66351, 11234], [28223, 20515], [-49199, 39598], [7199, 26450], [-15061, -7563], [64455, 16385], [-14432, 32136], [61796, -13293], [55356, -1282], [18868, -13322], [80452, 20837], [-6614, -23764], [32439, 17864], [33687, -51273], [-39972, 6498], [-564, -15516], [97220, -34780], [-50735, -423], [5608, -5914], [43161, -13058], [11245, -65404], [54122, -9663], [-95563, -16381], [94078, -35744], [-98786, 28275], [43324, 30214], [7664, 18005], [-33512, -33314], [78966, -21897], [-52680, 45962], [-55163, 20691], [79006, 6130], [-127421, 7221], [2438, 48948], [55028, -8626], [-22113, 26911], [-1214, 4957], [43932, -25875], [36552, -2385], [11663, 20587], [74622, 19245], [-15725, -59427], [36671, 16186], [54678, 6264], [71962, -3536], [-72241, 14783], [-74986, -9239], [125560, -25692], [-48289, -33564], [20250, -52648], [13828, -1794], [-149167, -14985], [46788, -45384], [-69084, 58047], [-171142, 11296], [-75278, -17812], [65354, 15086], [-19724, 39821], [-56294, 27349], [-10580, 10634], [104211, -14516], [-51958, 72132], [-54188, -23373], [28047, 29654], [-6550, 7592], [-105689, 1254], [-40939, 4229], [-40469, 23647], [73643, -59327], [96092, -59336], [109424, 31545], [-13917, 29237], [-106678, 11238], [-45731, -29975], [-85254, 18876], [69762, -149], [64396, 31188], [-8716, 71727], [8645, -43884], [-16628, -41221], [59214, -74776], [-5313, -46272], [-63660, 28936], [52070, -24944], [84804, 2690], [72157, -34420], [-27079, 38369], [69851, 29513], [137526, 14437], [50013, -1621], [-154746, 6900], [-85699, 12717], [-127218, 2056], [-23053, 19841], [7280, -25915], [-111246, 18164], [44296, 15012], [90028, 22715], [83246, -53830], [83067, -93661], [-116734, -17300], [-153996, 34495], [68569, -61022], [-19516, 86411], [79044, 17134], [-184989, -804], [60609, -89767], [25795, -105], [61280, -60351], [-115977, 30993], [-102676, -16145], [-15308, 9378], [-74547, -19697], [-204576, -14506], [23978, 15592], [95244, -61381], [-64328, 92365], [5500, -94649], [111736, -63966], [-29528, 78792], [-29038, -97], [-104322, 102448], [-164616, 38811], [-153950, -12834], [-35929, -21818], [45196, 28378], [30642, -51059], [98206, -83556], [111473, -24874], [-147662, -6739], [-124975, -1733], [-58627, 84811], [-21324, -27984], [13954, -43255], [-61103, 711], [14306, 73541], [-75676, -49251], [84769, 50339], [113932, -76148], [231789, 1047], [-51018, 115503], [-28806, -30088], [86902, -55718], [-151768, -49710], [52988, 21080], [-93266, -33345], [24608, -52416], [-56237, -21956], [-29611, 35374], [71760, 20528], [-101179, -57009], [21647, -41009], [24767, 11657], [-148746, 8012], [28157, -16535], [153167, -17345], [-82331, -50553], [-47351, 1459], [87308, -101926], [-113188, 57434], [47678, -64369], [89538, 2388], [-134052, -1770], [-161990, 64748]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_525_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_525_4_a_m();".
// 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_525_4_a_m(:prec:=2)
    chi := MakeCharacter_525_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_525_4_a_m();".
// 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_525_4_a_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_525_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-2, -3, 1]>,<11,R![134, 31, 1]>],Snew);
    return Vf;
end function;