
// Make newform 1472.4.a.q in Magma, downloaded from the LMFDB on 03 January 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1472_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_1472_4_a_q();".
// 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_1472_4_a_q();".
// 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 := [-1, -6, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-1, 4, 0], [-8, -2, 2]];
    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_1472_a();"
function MakeCharacter_1472_a()
    N := 1472;
    order := 1;
    char_gens := [1151, 645, 833];
    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_1472_a_Hecke(Kf)
    return MakeCharacter_1472_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]];
    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 := [[0, 0, 0], [-1, 0, 1], [-1, 1, 1], [10, -2, 1], [-8, 2, -3], [9, 0, 4], [-33, -9, 5], [-72, -2, 8], [-23, 0, 0], [70, -1, -14], [118, 5, -23], [-69, -23, -9], [26, -25, 12], [-94, 34, -44], [216, 19, 1], [-252, 14, -10], [130, 10, -94], [-196, 26, -96], [56, 22, -57], [207, -46, -59], [199, 74, -46], [-22, -72, -104], [-98, -114, 199], [-468, 88, 10], [343, -85, 53], [191, 13, 48], [-184, 184, -73], [102, 48, -142], [-1056, 32, 48], [-681, -25, 37], [212, -95, 217], [114, 91, 199], [-2024, 52, -112], [548, 91, -275], [1422, -28, 240], [313, 324, -127], [-706, -18, 358], [389, 124, -1], [246, 86, 242], [833, 259, -254], [-414, 113, -541], [307, -87, -485], [-452, -286, 167], [414, 273, -530], [1126, -25, -516], [-264, 186, 535], [-228, -32, -362], [-2043, -47, -282], [-1028, -588, 437], [-3258, -22, 124], [-1497, 20, -646], [-1005, 558, 243], [-1755, 299, -719], [-1984, -104, 471], [-2753, -472, 206], [928, -214, 100], [-1029, -36, 408], [1988, -100, 272], [-5696, 261, 76], [861, 381, -697], [-1406, -480, 785], [-922, -538, -418], [-4044, 332, -398], [5386, -167, 27], [3670, -74, 1282], [-687, -953, 552], [-3490, 297, 549], [3900, 416, 586], [483, -637, -1158], [-2879, -374, 1090], [-6583, 664, 122], [4504, 642, -1184], [-402, 254, 1335], [-8071, -429, 899], [-10326, 154, 158], [-326, -42, 616], [4302, -410, -230], [4101, -68, 122], [-5737, -415, -11], [-565, -762, 766], [4920, 360, 1238], [-5175, 1017, -149], [-6288, -208, -330], [8209, -197, 889], [-1261, -568, -595], [407, 544, 2055], [-2054, 1212, -1532], [-3091, 481, -2147], [7687, -752, -538], [-451, 353, -266], [8568, 246, 1092], [-10814, 98, -1341], [14677, -282, 321], [4498, -1303, -483], [2224, -779, 1297], [-2062, 192, -1584], [7324, 177, 1340], [3098, -170, -570], [10772, -1348, -153], [12523, -688, 426], [8114, -603, 109], [-6996, 1424, -1526], [166, 466, 320], [6569, -149, -1423], [536, -316, 2433], [166, 1385, 2098], [-6927, -2670, 2295], [10179, -631, 3254], [-3652, -524, -2192], [-8301, 118, 900], [8698, -1378, -946], [-15593, 631, -257], [18718, -12, 1382], [-18546, -394, 258], [16780, 328, 1654], [-7256, -316, -1570], [6590, 232, 4123], [12313, -992, 3051], [-7698, 2561, -268], [-3740, 908, -881], [11520, 1278, 1328], [10425, -2746, -124], [7884, -2618, 228], [11206, 2605, -2405], [7914, -1394, 1200], [13409, 457, 81], [-2567, -2979, 2919], [-9882, 1174, 960], [19946, 1232, -607], [8519, 735, -813], [-13705, -1734, -1239], [-2246, 1538, -939], [2246, -210, 3250], [-1623, 115, 1287], [8718, 1661, -1720], [14047, -347, 949], [-12766, 1070, 3278], [-17496, -1540, -6], [-15300, 2298, -1790], [25721, 1155, -1362], [6549, -2450, -1275], [12427, 1033, -314], [3219, -2682, 749], [4430, -1538, 2546], [8667, 3193, -3960], [13876, 1548, 3511], [-37265, 33, 20], [487, 1756, 5514], [-17597, 3372, -1029], [-11261, -1796, 2345], [-1073, -95, 3548], [8893, 1445, -509], [14398, 130, 1260], [-7015, -1528, 1925], [-12322, -224, 570], [-27012, 1634, -3126], [-6482, 4086, -1771], [-1360, -3403, 5790], [8723, -2507, -2293], [21197, -2575, -1493], [-14372, -2935, -1935], [9970, 524, 7342], [-14162, 343, -647], [-3330, -952, -3682], [3079, 3297, -6955], [10182, -1968, -1314], [-2658, -2698, -420], [13099, 813, 294], [-27936, -2770, -762], [5275, -4078, 2580], [-7464, -606, -2661], [7276, 2105, -3290], [13356, 164, -3829], [4654, -1714, -2948], [39567, -644, -113], [5747, 3975, 3295], [23620, 771, 1993], [19647, 3478, -6408], [15530, -656, -1184], [-28979, -4367, 5381], [-24300, -4327, 1119], [-16252, 3264, 1180], [-4738, 51, -7084], [-21571, -745, -806], [-25626, 1464, 3015], [6617, 145, -3979], [11019, -5979, -200], [9152, -3630, -5602], [-27331, -2184, -3568], [24654, -3898, -2260], [-42416, 1345, 3064], [-7694, 3878, 7182], [-14232, 1174, 545], [3407, 181, 8154], [-24322, -1380, 5243], [-40376, 1388, -4398], [-14049, 3153, -291], [-21016, -1592, -4550], [24310, 558, -110], [22272, -2643, 6827], [-12988, 1896, -5224], [-29718, -2142, -2528], [-23162, 6207, 3156], [-13213, -2075, 3697], [-13346, 346, -3954], [-23937, 3420, -1912], [-9638, -828, 7923], [625, 886, 9101], [-1380, 3465, -3804], [26879, 1566, 1557], [-14000, 3401, 4996], [-5588, 667, -12040], [-9584, 5248, -4202], [-17692, 2270, -11630], [-18333, -3073, 658], [7396, -2380, 10492], [-13251, 2360, -11347], [15382, 829, 658], [40564, -4938, -5049], [11309, 5592, -3886], [3514, -1143, -868], [13428, -4658, 14841], [-25869, 6606, -5050], [-38492, 1472, 5083], [-9596, 1213, 10353], [-53631, 1172, 298], [-6875, 2163, -1771], [27451, 7828, -5249], [-6188, -638, 2244], [-34523, -6739, 9694], [-52746, 3200, 2232], [-14696, 2444, -941], [-29330, 1012, -7017], [9539, 885, 910], [49336, 1932, 532], [81284, -2188, 1413], [-25336, 5768, -4226], [-13465, -9111, 2985], [-10536, -2839, -6475], [-23084, -6691, 6721], [-80758, 538, -2000], [-18636, 2501, -6369], [54339, -4642, 2043], [18242, -5663, 15006], [-18123, -2573, 266], [75891, -2362, -1665], [40081, 3048, -2283], [2338, 2772, -6290], [15620, -3106, -8800], [29636, -6654, 2033], [-68495, -2159, 1007], [-51611, 1315, 7231], [-18834, 632, -382], [40937, -5579, -7489], [-2202, 1872, 10384], [-20913, -6246, 5353], [-27091, 875, -12171], [12090, -6260, -9999], [-67300, 193, -11484], [-53722, 121, -8212], [52530, -6890, 186], [30644, 8080, -13048], [32930, 9524, -6560], [-30539, 11013, -2901], [-35439, 1935, 10154], [46014, -7276, 3238], [37375, -5379, -5377], [-24618, 9162, 2016], [-29686, -5272, 3424], [52376, -6119, -3224], [43430, -3205, 12050], [20576, 12718, -18430], [-23452, 3308, -19908], [-34056, 2444, -351], [-33776, -8101, 16354], [-12497, 4910, -3143], [-22930, 7874, -8322], [-60919, -2385, -474], [-94573, -4803, 2359], [-10722, 4606, -4994], [-8547, 11442, -7379], [-22806, 4448, -9061], [-4966, 3020, -7901], [-59604, 6458, 1742], [90402, 1762, 3110], [-70644, 5980, -2018], [9256, 1462, 4040], [18238, -4308, 14824], [-83340, -6716, 5730], [117485, -101, -5600], [-54452, 3454, 11400], [10728, -5788, -15233], [8534, -8444, 15608], [49808, -10578, -4702], [865, -10050, 6386], [34112, -5494, 19154], [16332, 10320, -16633], [-21717, 770, -16696], [40708, -3817, 9195], [19528, -3633, 20493], [2483, 12519, -1895], [16412, -2530, -7104], [6618, -13210, 79], [-51694, -4395, 7481], [22424, -2740, -4226], [-81470, -3697, 12396], [79780, -2256, -3128], [49614, 9426, -7818], [-35754, 3500, 3713], [2234, -2108, 14916], [49603, 1606, 6527], [56538, -1448, -10220], [85177, 2733, -3071], [-60077, -13918, 11557], [-98092, 6310, -7118], [-44205, 10171, -1147], [-18892, -357, -3693], [-1278, 1793, 23667], [16518, 1830, -18360], [50719, 3344, -5712], [-14770, 398, -25846], [-71089, 6419, -1141], [52227, -2246, 1986], [92406, -7906, 5122], [-29367, -3433, 7817], [-68654, -3518, 16406], [-117002, 3608, -575], [29955, -5214, 27599], [37152, -9206, 9715], [37811, -4273, 11937], [-9468, -3271, -12672], [2727, -934, -10234], [-16272, 6777, 10171], [-12739, 16676, 19], [-21746, -948, 10958], [-112219, 3700, -3229], [101105, 1743, 809], [-60283, -7691, -3005], [33566, -8477, 204], [1490, 2494, -14906], [-32230, 2585, 16904], [14046, -18066, 4304], [12065, -9893, 9536], [-69406, 1516, 1328], [4515, -11619, 7419], [31740, -11448, 10726], [-98020, 3847, 4858], [83028, -1656, 19448], [-4136, -2958, -22592], [20435, -12423, -12197], [-41015, 7126, -16451], [69672, -10929, 16700], [53985, 5035, -10326], [-64958, -6496, 9446], [-9591, 2901, -4575], [34157, 1079, -398], [17132, 4200, 5451], [105626, 7128, 6239], [4959, -9838, 22926], [19224, -6236, -2086], [-18853, -16179, 12123], [107509, 2032, 13280], [20504, -3955, -2485], [-52152, 10374, -15665], [-113439, -10648, 7875], [-28413, -10870, 27290], [-69713, -12734, 814], [79518, -4148, 34973], [-31644, -11678, 12960], [-15505, 6502, -5077], [155336, 10892, -9824], [-126038, -8543, 2097], [-16207, 11313, 21865], [-54694, 5250, 11738], [118992, 7963, 8738], [-10159, 15376, -13397], [-44986, -12500, 14793], [-28876, -8746, -5678], [-77512, -3804, 1908], [116075, 3420, -7560], [-28447, -10897, -10967], [-53446, -2940, -27970], [-6123, 25709, -7394], [43345, 8778, -5796], [-69290, -22142, 25877], [82663, 5004, -11721], [80649, -1850, -20443], [-79941, 8997, 12110], [16098, -8988, 21895], [-25206, -1078, 26677], [-30489, 263, -23795], [90258, -16992, -5936], [-16504, 14881, 4623], [-104982, 10630, -13732], [30992, 12896, -7497], [-15159, -441, -237], [92014, -7422, -19362], [-41387, -4075, 13299], [24458, 18966, -10099], [23515, 8557, -2236], [-56654, -14123, 6672], [-86292, -6941, 17140], [99100, -10404, 8975], [-119535, -2559, -4987], [-19680, 8335, 11424], [92316, -15113, 12437], [26578, -11512, -17378], [-13542, 1145, -36256], [-50926, -2682, -14957], [51205, -21435, 1918], [-115988, -10399, -6202], [-12676, 4831, -25534], [-106708, -14662, 6529], [-8346, -9516, -14932], [-60498, 16284, -10758], [79111, 15692, -29210], [-40021, 9135, 5162], [-101440, 7972, -1270], [31792, 15400, 14290], [-138676, 5040, 6130], [117981, -3239, 37621], [-104904, -7928, 5672], [43227, -3833, 11422], [-58052, 6160, -14804], [-948, 1035, -41694], [-15596, 10139, 13850], [114696, -2998, 8324], [43749, 17003, -28200], [-115774, -8049, 25265], [112662, -11335, -5977]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1472_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1472_4_a_q();".
// 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_1472_4_a_q(:prec:=3)
    chi := MakeCharacter_1472_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_1472_4_a_q();".
// 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_1472_4_a_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1472_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![61, -41, 3, 1]>],Snew);
    return Vf;
end function;