
// Make newform 525.4.a.i in Magma, downloaded from the LMFDB on 13 May 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_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_525_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 := [-10, -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], [32, -2], [-2, 10], [-26, 12], [-60, -2], [-32, 48], [170, 12], [52, -38], [134, -80], [62, -108], [248, -100], [164, -140], [-462, -58], [220, 76], [-398, -84], [64, 228], [112, 86], [-182, 38], [920, -8], [228, 224], [230, 336], [474, -278], [602, 348], [48, -192], [-356, -340], [1150, -252], [718, 254], [-816, 520], [452, -72], [534, -134], [-1260, 390], [-110, -344], [632, 36], [94, 614], [1968, 316], [964, -300], [3038, -436], [-880, 574], [-3198, -184], [2752, -318], [4598, 48], [1434, 370], [1460, 714], [1812, -712], [-832, 4], [-2116, -416], [-3310, 1148], [1318, -354], [1280, -586], [-2198, 1172], [372, -1924], [-2506, -152], [6288, -436], [-2750, 1396], [4652, 830], [3214, 368], [2802, -1124], [468, -1176], [-482, 1220], [4724, -28], [3152, 952], [2338, -1398], [794, -1298], [812, 2776], [-8506, -976], [1564, 1296], [-6950, 1036], [7678, 1148], [3680, -2654], [-5816, 2092], [-4722, -1548], [7940, -236], [-8012, 228], [2210, -2600], [-2946, 3210], [7202, -1464], [-7990, -208], [4220, -2008], [12382, 912], [-9608, 2486], [6298, 418], [10780, -2798], [7708, 2256], [410, 480], [-1826, 2060], [42, 2656], [-5752, 3224], [6884, -3520], [-2920, 3728], [4024, -3272], [-5768, -322], [13820, 1300], [6788, -3084], [3410, -3988], [3742, 4148], [10948, -2108], [3742, 1360], [11104, 700], [-12966, 1382], [-6452, 3080], [-150, -2152], [5612, 12], [5354, 1130], [15044, -528], [6038, -2788], [17640, -3766], [4642, -5924], [-8016, -1740], [-1162, -4544], [-12826, -1834], [-15460, 1350], [-4568, 7848], [-1598, 132], [-1492, -7732], [-16276, 5548], [738, 2658], [-640, 1090], [-10358, -6164], [5598, -1716], [-2506, -3556], [25268, -3704], [-4948, -3662], [682, 5916], [-27930, 136], [13120, 1692], [-3096, 4164], [12558, -3726], [2140, -4700], [7448, 7596], [15392, -304], [-4786, 5596], [-18498, 4304], [-14750, 7884], [17998, 3092], [3444, -8060], [-16946, 5588], [20210, 6212], [612, -8322], [-16718, -6364], [-24592, -160], [20804, 4900], [-9630, 352], [12560, -1020], [-6922, 4322], [-39506, 840], [22500, -3670], [20688, -3928], [17574, -888], [4422, -4792], [10528, -1420], [18404, -5676], [11224, -8060], [36672, 1194], [40520, -440], [36230, -4736], [-5926, -4210], [-2358, -2400], [5404, 8416], [-17402, 14598], [22664, 3472], [-9708, -8092], [734, -13794], [-34532, -4500], [-12288, -11576], [15094, -15318], [-26550, 892], [11318, -6276], [-23040, 5478], [1642, 240], [7192, -6610], [-24562, 5552], [13820, 7966], [27590, -6636], [-17388, 16248], [22002, 8760], [-27512, 796], [-52270, -2112], [13064, -10848], [12772, 7508], [37518, 6740], [32814, 1812], [-7912, -972], [28250, 5708], [14814, -10840], [16188, 14260], [-23070, 1844], [3152, -3940], [-13222, 18730], [13148, 9652], [18492, 1708], [16842, -1016], [6284, 6296], [28638, -13596], [13162, 3276], [32398, 7188], [-17866, -280], [-55252, -5492], [-39790, -852], [-26628, -5966], [-55866, 3806], [-20910, 7100], [29300, -5452], [-42346, 9116], [-59140, -1314], [-19492, -12716], [10730, -2108], [1172, 1882], [-13026, 2276], [28442, 3500], [-25512, -5560], [39564, -1496], [9920, 3220], [13162, -1460], [-27056, 10440], [-61058, -4752], [18704, -14460], [43298, 1978], [-8218, 18312], [20180, -22534], [-57670, -1484], [-34632, 2920], [-1476, 5120], [-46850, 8908], [36718, -6400], [-8480, 21146], [-37336, 8640], [90952, -1482], [-50962, 2780], [88500, 1462], [-9688, -5044], [-35158, -12588], [-12452, -1772], [-78596, 3116], [-20030, 23960], [2298, 1426], [23640, 8902], [4112, 14188], [-17532, 14780], [-36068, 5630], [-14712, 11880], [18070, -24300], [15678, -13032], [34920, 1924], [-19696, -25524], [86852, 6536], [-42900, 6760], [13568, -4456], [-53546, 760], [-59938, 2416], [-89176, 12368], [-17550, -10712], [46358, 6868], [-57840, 16646], [70022, -14604], [-106236, 8472], [-13906, -21956], [-83326, -8014], [-83192, -7200], [-19996, -16224], [-2310, -11532], [52718, -18594], [109774, 7788], [11340, 8154], [26450, -14348], [102222, -11212], [11408, 18068], [-5942, -15374], [-83158, -5256], [-28216, -260], [7618, -6438], [680, -8208], [-35686, 14026], [11408, -13876], [444, 23452], [-45570, 24184], [-4438, -5792], [-7548, -948], [57348, -8316], [41712, 22224], [57604, -15188], [-32918, 1920], [87924, -14252], [-76328, 17786], [-55482, -8276], [7874, -9762], [460, 8602], [9830, -400], [-14558, 29460], [-85636, 14168], [-111722, 5806], [21932, -14800], [14958, 11244], [-128710, -7088], [-37988, -23874], [-5002, 32120], [77140, -23484], [54164, 20028], [-11222, 18814], [109474, -6238], [-280, -22636], [-82692, -4008], [107292, -9060], [-43986, 3992], [8844, -42708], [21730, 18516], [19200, -3682], [92718, -12132], [-101692, 356], [-83150, 9100], [-14718, 26456], [99088, -6300], [75224, 12216], [157370, -5924], [53260, 4560], [-85048, 4026], [-77862, 14922], [23130, 23928], [-47988, -17326], [16134, -24908], [89482, -26168], [-24912, -27488], [53318, -33382], [17562, -8972], [19780, 36404], [31628, 31824], [-111536, -48], [-37342, -28154], [40702, -34796], [-87326, 2778], [-139580, -8666], [-67612, 21248], [-73308, 40928], [59484, -8128], [8030, 33792], [82718, -896], [-19318, 56052], [7064, 7052], [-89442, 12972], [2854, 11270], [38170, -3900], [67952, -42420], [-26062, -22086], [-50040, 10906], [-8158, -13892], [40944, -13884], [-77528, -13492], [-77106, -29164], [-7588, -24890], [-127746, -9716], [6922, -52172], [17968, -2336], [-79730, 5588], [30998, -2108], [129120, -3084], [10292, -20808], [-24866, 43022], [-85952, 5020], [-86066, 6604], [-13978, 6700], [-38456, -5652], [-39240, -8198], [-121436, -22652], [-97282, 47740], [88974, 31112], [126208, 20456], [-54118, 3920], [17512, -11234], [107380, -4270], [-84792, 5724], [89690, 13384], [-169868, -17058], [44534, 55632], [16500, -600], [-6408, -10678], [-45302, -31086], [-3290, -55180], [-1606, 63910], [-53598, 48620], [-109642, 17782], [101624, 2888], [14654, -28990], [-114020, 46206], [-52532, 6564], [-86168, 34216], [29014, -7942], [74808, -5460], [-197636, -10356], [-70950, -3004], [-122242, 42776], [67960, -20134], [154564, -22980], [-59168, 44878], [-182442, -20888], [-23820, 3398], [-193650, 29960], [65172, -32628], [-138678, -5300], [-120110, -38616], [-28562, 934], [-42856, 61440], [174294, -488], [-23230, -54880], [-178068, 7830], [149574, 288], [-16918, -14672], [16508, -30448], [-37420, 20676], [3298, -41570], [80434, -954], [-41572, -41400], [114812, -23872], [-1266, -60856], [65762, 6052], [-220720, 5670], [70464, -8260], [92014, -60068], [-38812, -41516], [72330, -67384], [-41466, 60890], [49024, -27660], [56900, -43204], [-84302, -7670], [154774, -5060], [-119972, -6236], [91170, -10056], [-129828, -24486], [-122640, -28172]];
    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_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_525_4_a_i(: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_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_525_4_a_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_525_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-8, 3, 1]>,<11,R![920, -62, 1]>],Snew);
    return Vf;
end function;