
// Make newform 975.4.a.l in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_975_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_975_4_a_l();".
// 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_975_4_a_l();".
// 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 := [-8, -16, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-10, -2, 1]];
    Rf_basisdens := [1, 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_975_a();"
function MakeCharacter_975_a()
    N := 975;
    order := 1;
    char_gens := [326, 352, 301];
    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_975_a_Hecke(Kf)
    return MakeCharacter_975_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, 0], [-3, 0, 0], [0, 0, 0], [-8, -6, 0], [-8, 2, 6], [-13, 0, 0], [46, 8, 0], [28, -6, 16], [24, -32, 8], [-10, 20, 8], [120, -54, -4], [-150, 48, 28], [150, -4, 34], [68, 60, -4], [12, -54, 42], [186, 108, 12], [-624, 82, 2], [78, 24, -28], [-36, -42, 76], [-276, -134, 14], [-2, 240, -12], [-16, 48, -24], [272, -30, 10], [430, 116, 30], [-1098, 48, 4], [414, -340, -128], [752, -84, -76], [636, 304, -40], [54, 288, -64], [-330, -232, -68], [448, -108, -72], [364, -192, 152], [-918, -268, -146], [-308, 552, -116], [810, -176, -94], [1392, -234, 20], [-478, 480, -172], [-332, -222, 288], [356, -230, 234], [1818, -4, -248], [148, 452, 300], [-1594, -456, 348], [1256, -92, -12], [1742, 72, -280], [3534, -176, 26], [584, -108, 480], [252, 264, 272], [-840, -282, 316], [776, 506, -490], [-2818, -216, 192], [638, 552, -380], [468, -1086, -138], [4890, 96, -196], [-2532, -20, -580], [1222, -1256, 124], [-1296, 28, 188], [2902, 436, -512], [160, 918, -272], [2050, -24, 552], [2822, -612, -14], [-1156, 636, -40], [-858, -40, -290], [-3620, -102, 420], [792, 720, 0], [-3466, 48, -64], [-1754, 120, -166], [284, 2034, 420], [3470, -1248, 272], [-132, 512, 232], [-2610, 2184, 716], [-1966, -788, 342], [5196, -1074, -738], [4248, 552, 148], [3186, 312, 1456], [2212, -942, -728], [1684, -970, -210], [-2426, -156, 44], [-62, 1224, -588], [-1082, -1396, -474], [-2190, 1704, 428], [-5828, 2576, 624], [-3970, -72, -1248], [-11364, -214, -446], [-7722, 120, 148], [2432, -756, -1620], [9004, -624, 296], [6406, 76, 718], [-2, -1080, -1980], [4858, 952, 238], [-7248, -126, 760], [7788, 876, 444], [6492, 1526, 1018], [3392, -282, 1100], [-324, 2948, 868], [-2636, 1362, 196], [-2656, 3452, 428], [-566, 3560, -978], [6210, 1392, 2316], [-5612, -2232, 516], [5206, 528, 2104], [8652, -1728, 628], [4398, 2944, -466], [-3108, 212, 844], [14098, -1648, -1380], [2324, -4668, 912], [-7874, 2832, -528], [56, 2314, 1986], [9578, -2316, -350], [11744, -3396, 148], [7530, 4800, -544], [1144, -504, 348], [-13350, -2976, 340], [-18694, 1940, 950], [7372, -6954, -596], [-5200, 918, -2124], [4754, 2920, 1704], [13852, -1602, 636], [-9832, 376, -552], [7290, 3076, -1240], [1804, 1648, -104], [-2762, -792, 364], [20502, -2184, -500], [5978, -3804, -428], [216, 878, -1310], [-188, 2442, 700], [542, 5532, 676], [19854, 120, -952], [7296, -1952, -2464], [2824, -6060, -2496], [18938, -3624, 896], [-556, -1146, 492], [-13068, 886, -670], [-15016, -2268, -2460], [-1302, 1344, -548], [8678, 3964, -2670], [-3998, -4056, 2080], [-9274, 1376, -2722], [8364, 5466, 460], [-12958, -772, -1876], [-30414, 1424, 388], [-3196, -870, 3984], [15578, -5104, 506], [896, 996, 2228], [6536, -2970, 34], [11678, 720, 636], [852, 2014, 554], [13754, 2472, -1108], [-1634, -1824, 1532], [17364, -2352, 704], [-4012, -4290, -4658], [-4334, 1800, -708], [8938, 3080, -3036], [-2364, 2556, -4016], [-18288, 6172, 524], [-12052, -4476, 1208], [18152, 1596, -308], [8536, -1080, -3392], [14670, 724, -1030], [21598, 2328, 1068], [19810, -7464, -2518], [4248, 7342, 4070], [-5202, 6704, -1340], [-12800, 10950, -804], [15444, 2248, 2216], [13434, -12236, 26], [-36964, 6522, 1894], [840, -12216, 3044], [-510, 3072, 4240], [-28838, 912, 460], [-9054, 9804, -1992], [-34992, 8622, 882], [4974, 1200, 140], [-8200, -1352, -888], [-226, 1392, 1748], [26776, 2652, -1772], [-16086, -11552, 3104], [-2708, -1626, -1964], [-13638, -6984, -4686], [5664, 3588, 4396], [-8618, 3576, 6016], [-9968, -5142, -6624], [-3564, 7668, -2124], [5530, 3696, -468], [12306, 5532, -3078], [-2084, 10450, 5026], [9510, -2876, -5068], [9378, -3768, -1292], [19636, 3174, 3120], [-10222, 5256, -5148], [-3564, -11330, 4670], [10566, -10200, -4124], [6872, -1006, -2590], [-42780, 4848, 188], [33746, 992, 2810], [45084, 404, -3404], [-21282, -10952, 4676], [-22734, 8160, 3776], [-14694, 1680, -6512], [-28214, 6804, 2474], [-35088, -4956, 5268], [-16710, -1136, 2798], [-41128, -4728, -6060], [-27438, -192, 2128], [19994, 11352, 828], [-55632, -238, 3562], [-36926, -8084, -2708], [5640, 3042, -3724], [-36268, 1256, 3224], [-35410, -10684, 6278], [18228, 5100, -376], [-15818, 9624, 2004], [20982, 1932, 6588], [-43304, 1368, 984], [20168, 5582, 8018], [14260, 16474, -6038], [-50614, -528, -3768], [-6944, -13224, 288], [10658, -8840, 2664], [45924, -10778, -1918], [-35538, -7104, -1818], [23822, -12792, -7416], [32136, 270, 2504], [-9530, -6900, 2606], [-10296, -2994, -3812], [54492, -6860, -1084], [-24834, -3168, 7256], [-24522, 3472, 5840], [45320, 8764, 3516], [9480, 6612, 4936], [1040, -2550, -10982], [70322, -3576, 1940], [-25468, 13104, 8892], [-71440, 1050, 3696], [43290, -17280, -5328], [-1596, -13056, -1028], [26844, 2502, 5394], [71594, 4704, 1764], [31862, -5432, -5586], [-61348, -2996, 4260], [32368, 5060, 9084], [16640, -18038, -1662], [-13500, 5100, -6376], [-46520, 4248, -4152], [-33314, 9720, 604], [-966, -1468, -5414], [-7656, -15312, 576], [51936, 10266, 1000], [24840, 10514, 5938], [81188, 522, -816], [32112, 10096, -3256], [13498, 4392, -7056], [44654, 6644, -6694], [-8004, -15102, -3714], [39546, 15216, -6016], [-35814, -5268, 4776], [-32720, 5722, -6266], [-36466, 22608, 1152], [8284, -5010, 1464], [-16806, -17724, 2004], [-6714, 1680, -11432], [39248, -1860, 8144], [9332, 4000, 1824], [-19714, -8592, 10944], [48570, 6288, 6976], [-33606, -8140, -7358], [-37092, 4344, 872], [2474, -8312, -4602], [43302, -21396, 882], [-86252, -11238, 4236], [14786, 11036, 5984], [-56674, -13896, -636], [-54004, -9690, 1964], [-20130, 7872, 9724], [-5032, 6516, 2460], [-26338, -2928, -3496], [11304, 5358, -608], [60512, 866, 38], [7278, 3120, -9460], [-51414, -13944, 4808], [-12396, -3764, -1084], [38040, -7676, 4412], [39848, -24330, -3552], [-38176, 2676, -14972], [74870, 4560, -1548], [-107564, 4362, -108], [-113888, -3864, -760], [33558, -1608, -13052], [-17034, -24144, 1614], [-16912, -25074, 4116], [20474, 5176, -7740], [33582, 5612, -8972], [-19980, -1360, 1288], [-6798, -1700, 2306], [15216, -5366, 3146], [-10446, 17328, -5372], [814, 23988, -1060], [21976, -17400, -7844], [119738, 964, 5100], [-61756, -16840, -5752], [66652, -34398, -9396], [-2138, -15648, -7104], [-41674, 27744, 7450], [55560, -14172, -7876], [38164, -19296, -10408], [-32644, 17304, 11916], [-56122, 21408, 9692], [-7772, 5724, -6700], [14694, -13464, -1240], [44148, -14482, 9826], [144626, 6744, 1784], [77944, -7708, -5652], [-1758, 27152, 8518], [50746, -32880, -8092], [-52188, 38352, 568], [-668, 11234, 15498], [33290, -31536, -9528], [-14280, -38786, 3458], [13900, -6342, -3742], [-23034, -10536, 6172], [29634, 20912, 13624], [51284, -24732, -10332], [-38970, -23712, 8536], [-37746, -29708, 13724], [-22648, -30198, 6404], [-28590, -27108, -1398], [-44726, -16152, 7708], [-86836, 14646, 8784], [23124, 29598, 10012], [35600, -23168, -4008], [-24702, 5764, -12976], [69830, 4536, -2616], [12906, 1956, -6024], [-67968, 2784, -15496], [24016, -29458, -1902], [-31116, 29778, -10648], [117032, 14466, -9998], [414, 19176, 1796], [72898, 18172, 3646], [146, 20832, 10500], [26328, 38340, -5420], [41402, -17592, -12100], [-44578, 704, 10700], [-48166, -9768, 3826], [-90304, -7380, -7884], [110566, 4568, -2166], [8340, 17796, -20268], [24798, -3888, -8752], [12012, 2274, -18152], [1556, -14026, 14198], [-56902, 11012, -6148], [-52412, 23082, 9988], [33182, -25320, -4588], [99762, -7720, 8434], [4528, 2484, 4920], [-16426, -4104, 84], [61198, -20136, 13316], [25892, -40442, 6630], [-26688, 13510, -8350], [-47322, 19536, 16068], [89228, 14646, -11714], [-21622, -6312, -22468], [40410, 41744, -12368], [-70392, -3380, -3196], [133872, -6106, 9826], [5244, -21228, -16868], [-118098, -13944, 8548], [-12138, 6272, -20198], [19536, -9798, 19780], [114514, 15000, 7924], [69468, 6520, -3808], [-22964, -16260, 22540], [-18580, 32034, 20170], [-110394, -12396, -3228], [-38072, -12552, 8920], [-13942, 19752, -14488], [-38736, -6426, -14202], [-34416, 18472, -19624], [-32898, 15168, 4768], [-35054, 16024, -11264], [-78274, 18792, -4540], [83778, 2304, 27570], [-24582, 19268, 11110], [-27176, 49650, 17640], [74490, -38844, -20094], [79212, -20778, -4960], [-47380, -26390, 22614], [-26960, 31770, 24904], [-20998, 18768, 8324], [-107300, -26154, 17208], [65560, -19012, 21636], [50522, 5784, 7716], [-78746, -39440, 6478], [-44440, 28362, -4946], [188020, -33768, -5880], [-154132, -17786, -13050], [4254, 50232, -3404], [82976, 7002, 8232], [35802, -19176, -11136], [-3564, 9888, -616], [-23118, -18952, -28850], [-1378, 31104, -23820], [61950, 17944, -16480], [22992, -222, 808], [-105678, 16956, -15822], [-69598, -12920, 7998], [-86152, 52488, 4632], [-55878, 24360, -20840], [-16762, 13324, 1206], [-42436, -7086, -5452], [124944, 25490, -4562], [-121874, -8832, -16848], [22954, 21700, 33988], [-59172, 68624, 1240], [74292, -1740, -3556], [-16618, -25536, -9832], [-109074, 73428, 9204], [-173260, 8026, 3486], [187912, 17784, -9192], [247050, -6332, 2930], [-76328, -1312, -15096], [-72794, 32564, -12384], [-173062, 20784, -5356], [-16244, -7034, -2102], [105284, 22968, 12256], [-41354, 23904, 14424], [138926, -35512, 446], [4044, -22452, 30972], [50862, -46524, -6786], [-31132, 198, -744], [35232, -23492, 1724]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_975_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_975_4_a_l();".
// 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_975_4_a_l(:prec:=3)
    chi := MakeCharacter_975_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_975_4_a_l();".
// 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_975_4_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_975_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-24, -15, 2, 1]>,<7,R![-1984, -288, 30, 1]>],Snew);
    return Vf;
end function;