
// Make newform 525.4.a.v in Magma, downloaded from the LMFDB on 24 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_v();".
// 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_v();".
// 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 := [44, 19, -18, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-10, -1, 1, 0], [2, -14, -1, 1]];
    Rf_basisdens := [1, 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_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, 0, 0], [3, 0, 0, 0], [0, 0, 0, 0], [-7, 0, 0, 0], [18, -3, 5, -1], [11, -3, -1, -3], [17, 17, 3, -3], [-16, 6, -20, 0], [39, 0, -4, 8], [85, 16, -2, -2], [-27, 3, 3, -15], [42, -51, -3, -9], [-125, -5, -33, 21], [43, -114, 4, 0], [172, 34, 4, 4], [251, -151, -15, 3], [31, 73, 19, 1], [-321, -33, -9, 21], [424, -63, 31, 21], [-320, -137, 91, -11], [114, 18, -28, 36], [374, -33, -95, -9], [71, -79, -79, -37], [-50, -356, 38, -10], [754, -204, -16, 24], [-488, 244, -54, -6], [-47, -93, -47, -33], [158, 218, -34, 14], [544, -117, 87, 33], [494, 47, -55, 35], [570, -9, 89, -45], [496, 64, 42, -18], [56, 254, 150, -42], [-504, -108, -62, -6], [-903, 138, 64, 16], [1654, -519, -85, 9], [1142, 210, 178, 6], [-235, 621, -35, 15], [1394, 128, -122, -14], [744, -342, 256, -44], [-698, 130, 310, -26], [514, -810, -184, 96], [-465, -417, 59, 101], [-314, -621, -81, 33], [-1009, 752, 34, 22], [-1328, 96, -176, 48], [-417, -189, 3, 21], [-1219, 849, 103, -39], [1877, -361, -355, 47], [650, -432, 220, -12], [-1244, -5, -411, -69], [-3576, 348, 212, -16], [2474, 72, 446, -126], [-909, 783, 461, -73], [-1787, -209, 527, -139], [2155, -758, 162, 150], [-3694, 884, 464, 104], [-1108, 186, -708, -144], [-1734, 0, -220, -144], [820, -125, 189, 75], [1760, 66, 966, 42], [-1496, 850, -80, 196], [4122, 150, -192, 180], [-5182, -370, -204, 252], [3706, 1080, -310, 54], [371, 152, 250, 418], [2721, -1182, -108, 60], [1135, -903, -715, 171], [-10, 665, 1189, 7], [-1331, -1245, 521, 147], [926, -1132, -452, 244], [823, 610, 58, -482], [1043, -1857, -117, -135], [3056, 1125, -891, 147], [-73, -456, -482, 414], [960, -1794, 16, 472], [-22, -787, -377, 253], [-1015, 1023, -341, -15], [4368, 711, 73, -77], [3162, -252, 1310, -342], [2125, -281, 299, -223], [-1474, -333, -921, 345], [2295, 711, -365, 553], [-2170, 2322, -386, -318], [1641, -1209, -519, -177], [8964, 156, -180, -96], [-4896, -591, -1205, 841], [3679, 1176, 1024, -468], [-3752, 3778, 848, -220], [1968, 1272, -700, 612], [7467, 585, 293, 263], [1204, 370, -1300, -76], [-2334, 1497, 763, 501], [-3558, 2025, 949, -485], [1677, 4425, -883, 135], [-7810, 2504, 36, -36], [-132, -522, 1048, -620], [-7663, 2315, 983, 245], [14056, -456, -40, 312], [1188, 2541, -1259, 483], [133, -642, -1648, 300], [-10610, 2167, -1171, -337], [-4181, -1355, -251, -305], [9102, -1755, 71, -103], [-2561, -4284, -1582, 438], [7454, -1344, 1410, -426], [8495, -109, 637, 55], [-7366, 6770, 454, -350], [7867, -2648, -1468, -136], [2448, -504, -124, 84], [-13348, 726, -1212, -504], [-6962, 417, -1167, 543], [1150, -5183, 551, 269], [1642, 2904, -1254, 66], [-2026, -3789, 1609, -573], [9574, -1103, -857, -587], [-1182, 2622, -1298, 858], [11910, 1608, 104, 272], [-11578, -2848, -372, 468], [2522, 1862, 2494, 418], [4030, -2532, 1642, -186], [-5321, -5379, 1253, -45], [-6864, 3186, -1058, 34], [-1182, 549, -2451, 315], [7746, 210, -146, 1242], [-183, -4557, 391, 265], [-6464, -2238, -346, 462], [-9090, -246, -3106, 1274], [553, -3219, 1607, 537], [2729, -363, 1137, -597], [-5673, -270, 700, -1476], [-23287, -571, 625, -497], [11812, -216, 2276, -1188], [-16890, -3363, 441, -717], [10998, -4770, -278, 382], [-144, -5580, 1144, 648], [-4028, 1582, -586, 26], [-6830, -2394, 256, 276], [4442, 2774, 848, -1156], [1888, 1789, -345, -51], [-6758, 1344, 112, 960], [-18614, 3232, -800, 1096], [8070, -1761, 2209, -1413], [10214, -1603, -379, -133], [-17023, 4437, -293, 1377], [6356, 260, -1430, 454], [-5327, 4233, -663, -1101], [-13202, 1270, -2830, -1042], [2360, 1638, 322, -138], [8684, -637, 1503, 189], [-4288, 5946, -1810, 966], [-5005, -4147, -2691, -225], [-1079, -9510, 964, 564], [3730, 2650, 4470, -318], [-8339, -1119, 3801, -621], [-17531, -806, -3286, 1682], [28484, -147, -353, -1059], [-14553, -3837, 237, -1701], [-2894, -5814, -3322, 210], [-32848, 26, 82, -770], [9140, 4208, -2848, 296], [-28356, 1953, -1985, 61], [-5168, -2256, 556, -1824], [-1308, -3426, 4608, 672], [-470, -395, -2913, 2097], [29816, -3922, 2690, 470], [-10920, 909, 1907, -591], [-30886, -252, -3246, -570], [6399, 420, -1976, -96], [-36452, 1864, -362, -698], [9498, 6159, -3461, 241], [-3359, 2739, 1165, -1713], [-18197, 5524, 504, -768], [-11133, 2289, -387, 1911], [21268, 528, 2318, 1206], [-12353, 6775, 2257, 1159], [-2448, -1371, -3037, 669], [-24805, -4015, 3437, -85], [17657, -2385, 2481, -2097], [3343, -2907, -3983, -813], [-20838, 2649, 1731, -1491], [11467, 1291, 2883, -1695], [-10410, -4923, -875, -1125], [-18317, 6565, -1575, -1605], [24916, -4187, -1875, 1095], [-40626, -3396, -4908, 2076], [16336, 261, -747, -921], [26094, -6996, -5576, -696], [20457, -3120, -240, -204], [-32820, -552, 1650, -306], [-15400, -7518, -366, -978], [13460, 1085, 4585, -545], [-24716, 9243, 1913, -1713], [2466, 9540, -2536, -136], [4528, -8801, -1729, -1279], [11043, -1581, 1035, -639], [1581, -504, 1800, 2244], [-24794, 729, 1933, -45], [9078, -1548, 5970, -918], [-1788, 13530, 2102, 122], [-21426, -6204, 2576, -1888], [51043, -159, -107, 927], [4949, -16245, 1847, 333], [-14070, -1626, -2698, -2286], [2339, 5471, 4063, -2507], [-24544, 1352, -292, 236], [18401, -3417, 147, -951], [-9498, -4110, -8362, 1598], [-18942, 5775, 2529, 2559], [-7202, 1746, -5634, 1362], [18778, -11787, -4447, -1293], [14458, 5326, -848, 4276], [27274, -519, -2237, -615], [-3953, 12751, 567, 501], [36590, -238, 2556, 2388], [-2432, 14508, 1214, -534], [-32112, -717, -7019, 987], [1018, -9332, -2274, -978], [27665, -46, -3254, -698], [3207, 198, 4912, 1936], [38708, 4755, -3545, 1845], [21233, -999, -4329, 57], [-20534, 10267, -5547, -621], [-43544, 11853, 159, -1023], [-24484, -5026, -4220, -908], [45190, 4968, 956, -216], [-65030, 3442, -728, 2140], [7676, 2669, -995, 271], [13652, 2400, 4314, 762], [16638, -1695, -907, 1883], [-54504, -1053, 643, -1731], [-25056, -4422, 5378, -1050], [-2784, -6924, 1592, 24], [-21218, 18007, -3783, -1425], [52944, -7374, 2316, 1248], [-33032, 7822, 5298, -234], [-14574, -15966, 2102, -102], [-2262, 15939, 901, -833], [-23738, 13873, -827, -1385], [10470, -9162, -10342, -1138], [25696, -2771, 4853, 875], [19162, 13344, 9726, -2346], [22771, -3675, 4433, 2619], [16058, 14055, 6451, -447], [-32627, 10351, 1785, 2631], [-62584, 11696, 410, 134], [14265, 13287, 5779, -2127], [24484, 11722, 3010, -506], [-39668, -2736, -7652, 1548], [-31704, 3744, -7032, 384], [-5568, -8598, 6482, 354], [14039, 167, -1437, -1599], [4805, -9643, 2437, -2645], [15722, -282, -9084, -1596], [46992, -15366, 2416, 2548], [60442, 8638, -1214, 2842], [-38782, 19353, 2905, 3147], [-48534, -4458, 5280, -2772], [-54282, 20652, 3882, 426], [47050, -9588, -3398, -3162], [-2820, -11172, 1688, 2748], [55208, 14639, -5353, 1277], [-35367, 8943, -3429, -807], [-56698, 6972, -400, -4536], [3341, 8117, -5373, -2691], [-54294, 12474, -798, 2070], [-40531, 11246, 3644, -2116], [-25493, -1721, 197, 1283], [51087, 6810, 5264, -1332], [66451, -1430, 6488, -3124], [-62083, 4377, 2213, 1431], [61921, -13707, -911, 987], [-6404, 1020, -4556, -588], [-45084, -5091, -2889, -495], [-4828, -2232, -4762, 6834], [60004, -7128, -1546, 3534], [80692, -1349, -305, 1225], [-49978, 4092, -2476, -2808], [12567, 4260, 2544, 960], [55723, -7217, 1601, 2579], [4984, -19412, -11134, 422], [-89976, -5352, 3452, -216], [35176, -3830, 5296, -1376], [66095, -9597, 2341, -1281], [28924, -18420, -4910, -702], [-45293, 12550, -4490, 5578], [-47773, 12984, 6760, -1428], [-43382, -17345, -2139, -1281], [11315, -18465, 9051, -2391], [36334, -5576, 3744, 1392], [-28622, 13123, 2793, -5949], [4284, 690, 138, 2238], [23680, -17165, 3173, -2821], [51176, -1000, 910, -62], [77746, -32013, -7937, -807], [-34716, -11976, 9078, -2754], [23363, -8337, 1163, -3255], [44046, 18084, -2294, 202], [-16337, -25889, 9407, -4939], [35074, 10188, 4936, -4512], [46188, 17736, -3346, -1830], [39787, -19499, -4487, -1037], [-51402, 19587, 705, -2769], [26240, -13249, 6351, -483], [-19688, 11157, -15569, 249], [78825, 12015, 4995, -2391], [64162, 11131, 1191, -1395], [24845, -27693, -2403, 2559], [114197, 494, -1406, -2066], [-53710, 1800, -4468, 5496], [5534, 24062, 668, -1156], [10581, -11397, -7201, 3965], [50238, 1593, -985, -1087], [36072, -14580, -3076, -3732], [59419, 6580, 12104, -2428], [-23886, 25770, -5224, 96], [74700, -9030, 758, 5402], [-51949, -19249, 8299, 25], [22028, -28032, -5256, 4992], [672, 3399, -20419, -301], [24270, 7518, -7572, -120], [62430, 15948, 7400, -1764], [44606, 8204, 15098, -1558], [-22432, 3765, -7645, -987], [34170, -17229, 457, 3535], [-45056, 22494, 1354, 1398], [43219, -3000, -1650, 1074], [69586, -20460, -3756, -5244], [-1860, 3357, -9531, -2685], [40891, -17954, 2248, -5792], [1422, -18120, -3416, -420], [-90685, 758, -3116, -7088], [-23189, 12417, -2331, -585], [-45367, 10625, 8087, 3869], [-79677, 11127, -4545, 141], [69684, 3606, 856, -2216], [42456, -27681, -4557, -1767], [-16831, 11219, 4277, -4093], [40074, -11352, 3978, -1242], [-28395, 429, -11469, 9669], [67386, -14688, -3396, 2520], [11138, 11477, 9451, -2471], [-12824, 6148, -3344, -3368], [-66436, -18591, -7853, 477], [7569, -28020, 1118, 5966], [-43724, -1109, -15833, 5185], [26194, 31482, 7132, -6852], [-14767, 11268, 14266, 4290], [73840, -19730, 7132, -3812], [-105170, 32782, -1208, -2852], [27100, -12, 20982, 654], [33715, 24264, 3224, -3948], [20187, -11703, -6079, 7355], [-5173, 29469, 9571, -4323], [46530, 4503, 21947, -1839], [-49817, -24227, 22963, -1883], [-38174, 16972, -6932, -2612], [-11439, -27543, -9597, -1743], [61078, -20288, 1148, 4580], [-69457, 28547, 1535, 6353], [-37704, -2031, -12243, -5157], [-40694, -6668, -11188, -652], [8184, -12792, 2632, 1156], [69644, -3661, -4249, -3031], [40770, 36360, 3302, -3570], [-13763, 23403, 8495, -2007], [-57774, -16512, -7872, 1272], [-48408, 15243, 5525, 1359], [-91191, 13038, -4502, -5622], [145408, -6137, 779, -355], [-46608, -24270, 18322, -2250], [-121497, 8940, 5264, 2900], [29003, -8215, 1557, 7611], [-31595, 37791, -2945, -1227], [7676, -42039, -4123, -717], [-18733, 16499, -16125, 2841], [2892, 37251, 4815, -303], [-8804, 26640, 7546, -8874], [-54935, 1399, 12817, -4889], [64336, 20628, -7274, -3174], [-67242, 15318, -4576, 6452], [57136, 43633, 7455, -6543], [57760, 2001, 21071, 1137], [-49576, 46289, 16051, -875], [-82656, 20796, 6350, 1158], [-59856, -21228, -528, 24], [77754, -43995, 2183, 489], [-43754, -17772, -8356, 4740], [-77176, -8385, -13011, 5667], [-158706, -25554, 8198, -3286], [76087, -19242, 5542, 5838], [-8704, 3014, -29642, -1526], [4314, -34899, -3047, 3859], [-14538, 6204, 18572, -2220], [38611, 18274, 3478, 6850], [47390, 1545, -3727, 9231], [15543, -4221, -7773, -6807], [98945, -18493, 5397, -957], [-63244, -46524, 5096, 1104], [59494, 1525, -18393, 2865], [87743, 22245, 17063, -8955], [23750, -42985, -367, 6899], [-68552, -19299, 13511, -7659], [-102341, -37955, 11987, -403], [-30688, -20650, 15052, -7112], [-60005, -5463, -15877, 5589], [4086, 5871, -2165, 7917], [39186, 50964, -1108, -5536], [49762, 26346, 17658, -4026], [52176, 13002, -3486, -2034], [69656, 3222, 7988, -6372], [-84618, -1827, -1985, 553], [-20736, 12156, 10356, -24], [105219, -13716, 1862, 7842], [-5693, 30942, 1758, 10650], [10084, -6254, 13376, -7804], [112687, 23815, 2527, -3239], [-130593, -27789, -11995, 2955], [-26635, -53287, 13949, -1153], [-87866, -23120, -9412, 5012], [-35465, -46091, 3497, -1477], [-14017, -15573, -6931, 10575], [67449, -17031, 3669, 6927], [45437, 14453, 4297, -1109], [-92368, 12954, 6150, 474], [-50084, 26752, 15086, -442], [15742, -30863, 8865, 2211], [-29034, -30852, 6960, -3936], [-119456, 27948, 13806, 4854], [-37702, -2032, 15768, -2112]];
    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_v();".
// 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_v(:prec:=4)
    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_v();".
// 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_v( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_525_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![10, 45, -6, -6, 1]>,<11,R![99334, 44829, -1323, -57, 1]>],Snew);
    return Vf;
end function;