
// Make newform 315.4.a.p in Magma, downloaded from the LMFDB on 31 December 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_315_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_315_4_a_p();".
// 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_315_4_a_p();".
// 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, -17, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-11, -1, 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_315_a();"
function MakeCharacter_315_a()
    N := 315;
    order := 1;
    char_gens := [281, 127, 136];
    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_315_a_Hecke(Kf)
    return MakeCharacter_315_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 := [[1, -1, 0], [0, 0, 0], [-5, 0, 0], [7, 0, 0], [25, -3, -1], [13, -13, 5], [21, -13, -11], [54, -10, 6], [42, 14, -2], [-105, -19, -17], [108, 24, -4], [-14, 16, -12], [-120, -10, -2], [6, 30, -34], [239, 51, 13], [-44, 130, 22], [76, 176, -48], [416, -34, -26], [32, -12, 108], [32, -72, 40], [78, 124, 76], [-315, -83, -89], [556, 160, -8], [-108, 98, 82], [55, -87, -65], [-510, -316, 40], [389, 313, -73], [1054, 138, -106], [323, 437, -17], [-326, 24, -4], [-236, -348, 28], [-834, 14, -26], [-820, 146, 122], [626, -2, -22], [598, -244, 60], [605, -363, 183], [282, 100, -356], [-206, 390, 178], [1515, -505, -71], [121, 371, -195], [-212, 792, 8], [1732, 246, -302], [-651, 277, 215], [-3292, 518, -2], [-28, 110, -178], [-772, 540, 252], [-2543, 285, 55], [3037, -383, -9], [-1165, -165, 109], [1504, 62, 302], [2244, -34, 202], [2879, 847, -363], [-254, -260, -504], [-1366, -1186, 26], [5822, 120, 112], [-1298, 262, -638], [-1706, -508, -588], [-812, 1760, 164], [4194, 796, -500], [-497, -1127, 739], [1403, -1181, 101], [4837, -681, -7], [3387, 843, 173], [-1622, 918, 14], [1805, -1545, 57], [914, -2016, -8], [-1524, 664, 328], [2178, -384, 656], [3150, -1930, 334], [666, 1224, -124], [5713, -201, 1097], [-2768, -1800, -232], [-7175, 5, 11], [3380, -1310, 602], [-10860, 400, -80], [3444, 1148, -1172], [-9119, 135, 149], [-505, -1643, -13], [117, 863, -755], [-254, 1808, 728], [-1600, 1516, 468], [2867, 485, 1495], [6257, -1239, 619], [742, 548, -196], [-6666, 222, -358], [-5166, -262, -422], [-5109, -1267, 223], [-5436, -1082, -314], [6148, -758, 1726], [-10716, 120, 68], [-1607, 1481, -81], [-2650, 2890, 1290], [-8378, -34, 1082], [-4429, 1287, 253], [3, -1865, -83], [-13755, 49, 455], [-7426, 2452, 972], [-6742, 1128, -1196], [-788, 1256, 968], [7305, 2451, -655], [-380, -1756, -1072], [-5228, -1334, 910], [-5708, 1152, 32], [-778, -832, -928], [-3556, -1680, -2952], [-2679, -885, -475], [1320, -2636, 2276], [4807, -1483, 987], [-655, -895, 2195], [9594, -2592, -1168], [755, -5825, 281], [-12974, 2212, -228], [3730, -220, -1356], [-5134, 2274, 306], [1031, -337, 805], [2334, 1600, -2656], [9369, 2649, -505], [-664, 5400, 208], [22362, -756, -792], [-4739, 321, 1187], [9372, -2970, 170], [9500, -2354, -730], [4579, -2563, 531], [9524, -396, 496], [-348, 6880, 280], [12915, -311, 515], [-3231, -2341, 2913], [-23610, -3470, 650], [-5368, 6376, -208], [4457, -2945, 1385], [-6489, 2907, -2455], [7080, -152, 4112], [-1451, -1171, 215], [23812, -4610, -1086], [-5194, 2492, 1208], [-6046, -7504, 2944], [523, 3933, -421], [-3323, -651, 1051], [5353, -4989, 1949], [-331, 4039, -27], [9302, -6710, -730], [23009, 879, -779], [-3660, 4080, 1292], [-14326, -3234, 1018], [19080, 4574, 462], [-3894, -4618, -1250], [-1782, 1692, 20], [10194, -148, 1876], [-13100, -2832, 1264], [-7640, -4988, -176], [3926, -8732, -2296], [-6772, -4066, -3478], [4728, 5872, -2420], [576, -1400, -5032], [-26906, -490, 1742], [28488, 192, -2184], [6873, 1, 3115], [-20036, 2166, -2086], [6735, 5505, 5231], [2520, -5814, 5106], [13016, -2096, 900], [9396, -7798, -3422], [9478, 2902, 3594], [4448, 6440, 2180], [-18258, -2276, 3704], [23253, -6175, -1385], [-22848, 8288, -96], [34667, -759, 87], [23127, -4267, -153], [-24246, 736, -328], [11088, 1476, 1020], [5534, -8272, -4808], [15773, 1149, 5287], [11982, -2820, -1780], [19374, 8194, -2702], [-13080, 5426, 1798], [19139, -5417, -4363], [-10335, 3063, -2283], [-12164, -7732, -1060], [-16960, -186, 4422], [-19408, -8068, 2920], [1280, -7848, 5164], [27378, 6176, -2508], [30726, 4800, 2208], [-6648, 8884, 3488], [21362, 436, 5256], [10320, 13298, -2850], [29953, -7791, -2369], [-7469, 1953, -4877], [37028, 6088, -4236], [9430, 10276, 1020], [44714, -2070, 4354], [-14043, 13841, -1197], [33364, 3310, -986], [-26180, 12848, -72], [-13161, -9459, 2787], [28277, -1837, 6289], [53000, 2358, -2274], [23653, 5219, -6027], [-3181, -6417, -3887], [6018, 1592, -4472], [-9702, 6074, 1806], [33870, 8552, -3888], [-4214, -12612, -2432], [-20338, -6650, 1758], [7885, 911, 4377], [-11410, -2994, -102], [-27712, 3624, -7028], [36466, -7668, 2180], [14244, 2092, 8584], [1656, 8930, 570], [-24658, 28, -2220], [25956, -2728, -5268], [59531, 2507, 269], [17302, 18438, -5398], [17892, -2730, -2650], [-45130, 2682, 42], [-744, -2378, -442], [-55074, 10786, 506], [6374, 924, 4996], [22370, -1620, -1668], [48658, -7078, -3442], [17257, 3675, 233], [-35594, -3138, 2482], [1627, 2275, -7883], [-21642, -19872, 1736], [-52847, 303, -991], [-1159, -9711, -10349], [50741, 4457, 391], [37860, -7616, 440], [-29364, -7422, 5450], [20382, 7466, -4074], [6688, 4952, -880], [-54099, -841, -6371], [39397, 3077, 9011], [1963, -2217, 8465], [-39572, -6026, -3786], [15380, -2326, 4550], [-66413, 607, 4189], [11278, 2562, 506], [25624, -1484, -4628], [-3632, 5764, 2196], [-12055, 3253, 5651], [79478, -2128, 2368], [-21777, -2019, -1197], [-1922, -17174, 10], [-22432, 1304, -1520], [-29554, 1426, 4350], [-43815, -10603, 5031], [-58838, 1526, 3414], [8350, 7892, 512], [4858, -19740, 6500], [-41816, -20344, 2928], [-56772, 12362, 4518], [33974, 10404, -9644], [-21235, -12103, 2531], [-61858, -11208, 5856], [16460, 520, 2936], [-2053, 17133, 1291], [-24327, -3333, -10291], [68894, 23658, -8958], [-11298, 10402, -8242], [-24316, 16702, -2638], [9497, 10199, 8137], [-31614, -6148, 1084], [-31030, 1882, -814], [-39887, 1599, -691], [-22054, 4484, 3884], [-46608, 29772, 3716], [-61150, -12932, -1608], [12524, -10542, -5238], [2548, -1868, 4944], [-45673, -18663, -489], [-28516, 732, 1812], [-23054, -1304, -11472], [-13503, -12291, 7787], [-15460, 14000, -9376], [-9054, -10132, 948], [38259, -9887, -9293], [26718, -17262, -5346], [46635, -22257, 3057], [-17371, 16165, 1583], [47072, -2552, -1224], [-18298, 5456, -5432], [67693, -22707, -7733], [-10807, 12081, 6643], [-57038, 5604, -9368], [40050, -3380, 8984], [5856, 1272, 14600], [-23092, -17714, 9690], [17697, -16457, 12845], [-62375, -23383, 2415], [70460, 16690, -5382], [59132, 10972, 552], [21902, 6532, 5216], [-44108, -26538, 15254], [77702, -4882, 6034], [14611, 5861, -8445], [7308, 22408, -1984], [-44479, 2753, 7999], [-31685, -16051, 6899], [-98810, -2964, -6508], [93187, -9493, -1231], [-23376, -7572, -7212], [-58339, -10919, -8701], [-115422, -5092, -2088], [12882, 4146, 16410], [58388, -13666, 7114], [102752, 17168, -6808], [-20704, -13286, -13882], [38392, 20816, 10344], [-62645, 3233, -15021], [-54694, 14348, -11404], [10034, -3066, -8910], [-17814, -2906, 6110], [-32076, -12866, 2758], [-37914, 4978, -10042], [-6591, 37889, -2789], [7475, 13957, -10957], [3225, -5277, 6489], [30094, 24234, -4250], [-66116, 10734, 10654], [-14138, -4204, 7284], [-103532, -20328, 580], [47914, 24356, 4812], [-38028, -12934, 198], [-32459, 20161, -1293], [-5164, 20024, -2912], [-22176, -22876, 7432], [-40768, 22554, -10622], [25782, 22416, -14752], [-23952, 20282, 8122], [-18198, -3534, -514], [14533, -36955, 9315], [7636, 2520, -8624], [-104105, -17345, 3169], [115379, -9411, -4257], [-54742, -41652, 9604], [-59290, 48552, 5628], [36177, 28821, -1213], [21950, -27680, 9392], [19840, 37626, -16498], [43362, -11564, -17464], [80555, -4197, -2799], [-4590, -28916, 19280], [-62180, 10072, -3704], [-37842, -17912, 17728], [29528, -6584, -4684], [-62698, 11346, 5434], [85705, 31171, -7163], [74412, 21280, -3920], [-74768, -25470, 11914], [69073, 31295, -8115], [134473, -6019, -5653], [45631, -4079, 10827], [-40474, -600, 8512], [-16614, -2238, -2130], [27162, -12718, -9758], [-26150, 22992, 8780], [-98434, 15478, 1026], [-35528, -17842, 7718], [-48392, -1806, -6298], [-56976, -27580, 7720], [8629, 46393, -3485], [99772, -20704, 5312], [-26474, -9512, 13260], [96889, -37589, -5267], [52722, 28726, 5878], [-36545, -45043, 9863], [137749, 12209, -8949], [47332, 13324, 16680], [-7188, -27780, 756], [107155, -23847, -9301], [-7234, -34858, -6638], [62018, 19388, -4748], [38160, 26916, -15132], [46493, 701, 2543], [-138103, 2307, -19659], [-110014, 47748, 10108], [47053, -20513, -17271], [-141898, 16676, -8476], [-70114, 5184, -28616], [56304, 19848, -14824], [-6242, -22360, 2256], [114848, -112, 15076], [51699, 14279, 9601], [106071, 2967, 17117], [9069, -7901, 4429], [57716, -920, 34976], [-87615, 10733, 7603], [27211, 22881, 13027], [-154931, 28583, 5793], [192695, -10125, 5785], [-43132, -9624, -20664], [74905, -34975, -16197], [-70268, 19986, 8398], [41800, 35700, -14480], [3140, -29998, 2066], [130511, 32731, -12871], [-88562, 18508, -236], [-9100, 2738, -6206], [-23452, 28678, 834], [48278, 12314, 27370], [69977, 24287, -5047], [119912, 11686, 3906], [71786, 1330, 1286], [119054, -36680, -1528], [-102677, -31515, 8255], [18276, -15336, 11048], [77172, -32800, 17008], [12175, 36185, -19033], [77010, 22280, 4624], [-139914, 7390, 2822], [22204, -51568, 2144], [69366, -14224, -2532], [102364, 21282, -16090], [-118767, -26287, 13771], [-95916, -11116, -18396], [84866, -45620, 108], [20723, -19665, 6625], [78437, 4523, 18377], [7002, -42004, 9492], [-13758, 5762, -2522], [96884, -3440, -1224], [-54563, 15983, 4169], [-99799, 16675, 16173], [9668, 15352, -24864], [57318, 10440, 11712], [34400, -488, -16372], [58828, -22928, -4652]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_315_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_315_4_a_p();".
// 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_315_4_a_p(:prec:=3)
    chi := MakeCharacter_315_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_315_4_a_p();".
// 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_315_4_a_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_315_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![30, -14, -3, 1]>],Snew);
    return Vf;
end function;