
// Make newform 525.4.a.n in Magma, downloaded from the LMFDB on 18 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_n();".
// 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_n();".
// 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 := [-14, -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], [-8, 10], [-14, 12], [2, 2], [44, -24], [-20, 34], [-138, 24], [-16, 72], [106, 36], [-210, -30], [-212, 48], [40, -68], [554, -4], [460, -116], [-250, 72], [-20, -108], [492, -30], [-530, -12], [-232, -108], [-924, -96], [254, -142], [-266, -276], [586, -26], [1384, 144], [-440, -170], [-106, -288], [222, -264], [1048, 156], [1052, -136], [974, -124], [644, 240], [-778, 356], [-1240, 432], [-2294, -192], [-1028, -324], [-672, 300], [-1682, -494], [1000, -890], [182, 684], [356, -22], [-2666, -324], [-870, 876], [-1528, -360], [1724, -264], [3472, 72], [2396, -988], [1766, -612], [6574, 4], [-516, 78], [1370, 36], [3948, -372], [-2774, -2], [1436, -814], [-2438, 1378], [-2896, 1296], [-1910, -180], [-558, -108], [-740, 72], [630, 378], [-3164, 1488], [1552, -1148], [1846, 96], [274, 1372], [7748, -168], [-2018, -1944], [3872, -1366], [-7546, 744], [-2350, 1970], [3884, 1346], [3376, -912], [4978, -1920], [2228, 1032], [6256, 1864], [3982, -248], [2266, -720], [-1030, 788], [3890, -1548], [1764, 2700], [1766, -2988], [-5132, -326], [-4802, 3864], [-3736, -2544], [6784, 1978], [9858, 192], [4390, -2016], [4578, -858], [-7688, 756], [10876, -1508], [376, 556], [568, 24], [-5808, -570], [3548, 1080], [-7560, -144], [9578, -2446], [-1514, 3094], [-1892, 2160], [-6994, -2076], [-212, -492], [2066, 644], [9788, -2884], [-7582, -3892], [-10900, -204], [-13970, 792], [-5292, 3276], [10498, 1138], [17548, 1978], [-4774, 5928], [-2816, -3936], [2626, -2592], [-1122, 5916], [-10348, 1944], [10544, 420], [-6854, -788], [-1148, 552], [-11632, 3380], [-9974, -2576], [5952, -1950], [-2242, -1248], [-18650, 1620], [-11930, -4766], [-16960, -3838], [5420, -1512], [-4842, -1512], [9470, -5328], [13232, -592], [19768, -4128], [-2270, 5580], [15140, -5868], [-5868, 702], [4976, -3696], [15538, -240], [-32674, -94], [-1582, 1944], [422, 5570], [5812, 2664], [20958, -3918], [-9542, -3296], [-5740, 7992], [34502, 1148], [736, -3996], [25464, -5082], [-41554, -852], [16464, -132], [-41006, 1656], [3362, 7502], [4916, -2736], [5188, 5962], [-3926, -8640], [-33810, -2346], [-10460, -7992], [11632, 7564], [8044, 1296], [-36300, 4650], [-22408, -1656], [-1594, 1178], [-26474, 4872], [-38054, -1550], [34672, 3334], [-6666, -10608], [26752, 4764], [-124, -1888], [-5242, 140], [-19192, -5800], [12368, -2520], [-20270, -288], [41162, -2676], [-7898, 8698], [37624, 2578], [14294, 5472], [-26020, 8954], [-29042, 7332], [13088, -1512], [-16170, -10194], [-2308, -11748], [-19538, 5896], [1624, 5016], [1766, 10224], [49960, -156], [23772, 4008], [27130, -8772], [22090, -11318], [6644, -1798], [-28982, 5038], [20266, 8568], [-45260, 2688], [-30094, -6804], [2224, -7640], [56278, 1500], [-27288, -1674], [52940, -1728], [19826, 6902], [-9232, 3422], [5210, -9982], [-59158, 1020], [-32654, -2196], [7098, -11514], [-29360, 2500], [-44738, 10036], [-9184, -12072], [-11846, -2772], [32618, -4716], [72660, 3288], [35870, -15214], [51536, -3672], [37024, 3382], [64794, -1248], [41060, 8640], [28078, 2448], [47586, 6906], [-10040, -10680], [3148, -11072], [42208, 6532], [-36790, -9864], [6112, 5064], [6382, -21770], [32236, -2702], [37098, 4536], [17534, 12096], [-13720, 1968], [-2542, 24008], [-13040, -3936], [6132, 8616], [-53338, 11580], [-11678, 5854], [-50324, 12766], [28936, 8880], [-2752, 6158], [5482, 13920], [18044, -21840], [30704, -5016], [19354, 8896], [33628, 10128], [17264, 18992], [-57286, 14052], [20602, -7532], [10320, 2526], [28728, 3744], [39656, -2446], [-45820, 9912], [-19304, 3336], [-12706, 5364], [62538, -13242], [68336, -2476], [16240, -15432], [-89756, -6308], [34460, 2532], [25716, -2598], [18058, 16248], [75854, 6158], [-16540, -8314], [17906, 10428], [12686, 1346], [-55840, 10274], [36182, -12492], [54700, -2880], [17094, 12162], [-29402, 600], [-43784, 19212], [39576, -17502], [51014, -756], [59962, -19032], [-102814, 5258], [-54052, 18072], [-19794, -516], [41958, -18810], [72196, -6732], [45074, -11320], [110294, -5208], [17620, -20160], [-43202, -6444], [68816, -16488], [87766, 14148], [-5672, -10512], [-46808, 15022], [16526, 24516], [-49246, 6804], [-56908, -9028], [-14992, 3368], [13376, -5436], [-76440, -2280], [42350, -24528], [-1892, 22896], [106196, -4198], [-18290, -8064], [117402, -2748], [-11608, -8496], [-60522, -12174], [-13826, -21980], [44564, -2776], [46894, -4100], [14028, 30516], [34186, 27408], [4450, -17618], [-17008, -3384], [20286, 630], [60524, 12716], [5908, -24432], [-12602, -6336], [97882, -11144], [78056, 6492], [-85248, -7650], [117452, 7380], [-99122, -4488], [-110368, 5570], [3710, 28908], [123836, 6386], [62938, 19644], [-33728, -1256], [-49106, -16832], [15434, -3484], [98260, 10008], [-57444, 24546], [64370, -32148], [81228, -20904], [-46292, 22270], [43078, 14196], [-60534, -15588], [81548, -18744], [64702, -27372], [48594, 20406], [-91184, -10104], [-81514, 3464], [-46870, -756], [32276, -27396], [16252, -17928], [-9428, -31298], [69522, 10104], [67430, 2232], [-20614, 13424], [27776, 864], [99836, 10772], [-41812, 8748], [-67788, 16164], [91814, 22560], [-15542, 7102], [65282, -18732], [-1136, 20880], [7666, -3744], [45582, 2796], [-4494, 3498], [-40696, 49032], [-28790, -5624], [-12528, -3726], [-125386, -1116], [67852, 18528], [-171360, 13896], [14950, 46666], [33644, 10800], [-84818, 10260], [52446, 18084], [18496, -17832], [46766, -43488], [-95382, -16686], [-38176, -8080], [-82364, -17168], [98302, 616], [852, -46794], [-35870, 11280], [30494, 20954], [-47284, 37622], [100568, -34990], [8836, -51480], [-84818, -15516], [-54474, 20550], [47104, 36540], [113234, -31692], [-4376, 14686], [66404, 33264], [-83684, 33406], [-38106, -17172], [-19000, -28320], [116530, -23076], [-27092, 55528], [-213876, 6030], [142, -36072], [-129442, 23198], [91294, 324], [160018, 6262], [-45306, 53424], [-46328, 13080], [-47410, -18664], [82796, -18336], [-160648, 20792], [111152, 19008], [-16742, -11412], [124804, -12684], [185640, -18444], [84506, 14172], [63166, -32162], [100792, 25786], [-189884, 16704], [64028, -56014], [91078, 21096], [-209680, -4248], [25158, 26526], [-120244, 12876], [125614, -13040], [141542, -19464], [-164114, 23896], [37864, -42996], [9154, -16226], [25282, -12158], [-156616, -6048], [-35678, 16668], [-87246, -35568], [-180668, 7632], [-38428, -57220], [68878, 13920], [45634, 12280], [-182352, 10194], [174908, -2016], [104494, -45276], [90890, -57862], [-34084, 33686], [12952, -16104], [162162, -16038], [-145616, -18068], [65302, -15320], [127762, 8640], [77964, 15702], [-31836, -14376], [-276122, 10224], [61742, -18286], [76168, -27854], [-159822, 40068], [129428, -21120], [64720, 22708]];
    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_n();".
// 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_n(: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_n();".
// 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_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_525_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-12, -3, 1]>,<11,R![-1416, 6, 1]>],Snew);
    return Vf;
end function;