
// Make newform 315.4.d.b in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_315_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_315_d_Hecke();"
// 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_d_b();".
// 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_d_b();".
// 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 := [100, 0, 1040, 0, 1149, 0, 398, 0, 37, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [880, 0, 8248, 0, 5285, 0, 561, 0, 16, 0], [0, 790, 0, 28813, 0, 18816, 0, 1999, 0, 57], [6535, 0, 41065, 0, 24563, 0, 2574, 0, 73, 0], [5995, 210, 48052, 0, 29414, 0, 3096, 0, 88, 0], [-5575, 0, -67876, 0, -43148, 0, -4566, 0, -130, 0], [0, 7690, 0, 82603, 0, 52136, 0, 5514, 0, 157], [0, 134830, 0, 548881, 0, 320432, 0, 33483, 0, 949], [-34200, -139610, -350940, -706907, -220080, -413224, -23220, -43161, -660, -1223], [0, -228710, 0, -838937, 0, -468664, 0, -48591, 0, -1373]];
    Rf_basisdens := [1, 105, 700, 105, 105, 105, 525, 2100, 2100, 2100];
    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_d();"
function MakeCharacter_315_d()
    N := 315;
    order := 2;
    char_gens := [281, 127, 136];
    v := [2, 1, 2];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_315_d_Hecke();"
function MakeCharacter_315_d_Hecke(Kf)
    N := 315;
    order := 2;
    char_gens := [281, 127, 136];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := [[0, 0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0, -1, 0, -1, 0], [0, 0, 7, 0, 0, 0, 0, 0, 0, 0], [-14, -8, 0, 2, 0, 0, 0, 0, 0, 0], [-1, -1, 1, 1, -1, -1, 7, 1, 3, 1], [1, 1, -19, -1, 1, 1, 5, -9, -3, -3], [-31, 1, -1, 3, -3, 7, -1, 1, -1, 1], [-3, -3, -31, 3, -3, -3, -9, 5, 9, -5], [74, -10, -2, 2, -6, -4, -2, 2, -2, 2], [67, -27, -1, 3, -3, 9, -1, 1, -1, 1], [-2, -2, -84, 2, -2, -2, 26, -8, 6, -18], [-161, -35, -3, 17, -9, -17, -3, 3, -3, 3], [2, 2, 116, -2, 2, 2, 14, 0, -6, -14], [-6, -6, -136, 6, -6, -6, 42, -4, 18, 10], [-11, -11, 5, 11, -11, -11, -3, -3, 33, -9], [164, -40, -12, 28, -36, 40, -12, 12, -12, 12], [112, -20, 16, 4, 48, 2, 16, -16, 16, -16], [12, 12, 70, -12, 12, 12, 52, -10, -36, 24], [-316, 24, 8, -42, 24, -10, 8, -8, 8, -8], [13, 13, 99, -13, 13, 13, -115, 11, -39, 11], [194, 82, -14, 10, -42, -22, -14, 14, -14, 14], [4, 4, 312, -4, 4, 4, 44, 16, -12, -4], [71, 57, -15, -35, -45, 7, -15, 15, -15, 15], [1, 1, 91, -1, 1, 1, 161, 19, -3, 15], [-473, -23, 1, 69, 3, -41, 1, -1, 1, -1], [-2, -2, 346, 2, -2, -2, -146, -58, 6, 18], [7, 7, -293, -7, 7, 7, -31, -73, -21, -71], [-782, 48, -40, -16, -120, 92, -40, 40, -40, 40], [27, 27, 7, -27, 27, 27, 367, -129, -81, 41], [2, 2, -530, -2, 2, 2, 334, -38, -6, -74], [-284, -12, -56, -36, -168, 44, -56, 56, -56, 56], [-19, -19, 1345, 19, -19, -19, -167, 53, 57, -21], [-1055, -159, -41, 55, -123, -65, -41, 41, -41, 41], [-588, 152, -48, 36, -144, 102, -48, 48, -48, 48], [86, -218, -50, -62, -150, 50, -50, 50, -50, 50], [61, 61, 423, -61, 61, 61, 5, 35, -183, 71], [-40, -40, 794, 40, -40, -40, 416, 70, 120, 60], [22, 22, -688, -22, 22, 22, -346, 184, -66, 78], [-19, -19, 979, 19, -19, -19, 169, 17, 57, 21], [1794, -160, -32, -26, -96, 124, -32, 32, -32, 32], [-890, 314, -82, 58, -246, 168, -82, 82, -82, 82], [-428, -780, 12, -58, 36, 50, 12, -12, 12, -12], [2, 2, 1862, -2, 2, 2, 514, -70, -6, -138], [53, 53, -931, -53, 53, 53, -395, 133, -159, 23], [257, 87, -27, 5, -81, -37, -27, 27, -27, 27], [-396, 208, 20, -8, 60, -88, 20, -20, 20, -20], [-16, -16, 212, 16, -16, -16, -376, 20, 48, 224], [54, 54, -2610, -54, 54, 54, -390, 22, -162, -54], [-510, 398, -14, -34, -42, 28, -14, 14, -14, 14], [-11, -11, 3165, 11, -11, -11, 265, 73, 33, 35], [1724, -524, 60, -242, 180, -382, 60, -60, 60, -60], [-116, -22, 138, -126, 414, -262, 138, -138, 138, -138], [-1644, -144, 76, -92, 228, 304, 76, -76, 76, -76], [-129, -129, -969, 129, -129, -129, 259, 145, 387, 15], [27, 27, 1551, -27, 27, 27, -775, -101, -81, 21], [23, -983, -39, 205, -117, 219, -39, 39, -39, 39], [745, -41, -11, 25, -33, -325, -11, 11, -11, 11], [2, 2, -3844, -2, 2, 2, -610, 376, -6, -6], [1836, 522, 82, 34, 246, 30, 82, -82, 82, -82], [-22, -22, -1326, 22, -22, -22, -414, 330, 66, -42], [-89, -89, 1541, 89, -89, -89, -77, -337, 267, -129], [30, 30, 4178, -30, 30, 30, 702, -78, -90, 210], [-1318, 1390, -102, 22, -306, -70, -102, 102, -102, 102], [29, 29, 1427, -29, 29, 29, -251, -153, -87, 95], [-81, -81, -277, 81, -81, -81, 7, -173, 243, 133], [3240, 2092, -96, 228, -288, 220, -96, 96, -96, 96], [84, 84, -3312, -84, 84, 84, -68, -328, -252, -300], [191, 191, 1791, -191, 191, 191, 529, -533, -573, 217], [-176, -1472, 4, -376, 12, -282, 4, -4, 4, -4], [-95, -95, 2589, 95, -95, -95, 133, 47, 285, -283], [2120, 956, -148, -30, -444, 498, -148, 148, -148, 148], [140, 140, 3500, -140, 140, 140, -36, 52, -420, 20], [-66, -66, 4508, 66, -66, -66, 50, 156, 198, -194], [-3522, 186, 178, -442, 534, -538, 178, -178, 178, -178], [216, 216, 1474, -216, 216, 216, 812, -438, -648, 404], [734, -474, 246, -62, 738, -660, 246, -246, 246, -246], [35, 35, -3687, -35, 35, 35, -2037, 21, -105, 465], [-3164, 538, -142, -230, -426, 2, -142, 142, -142, 142], [-5284, -294, 122, 178, 366, 346, 122, -122, 122, -122], [2562, -362, 14, -298, 42, -102, 14, -14, 14, -14], [-450, 732, 32, -16, 96, 632, 32, -32, 32, -32], [-2072, -980, -44, 426, -132, -942, -44, 44, -44, 44], [-143, -143, -29, 143, -143, -143, -1927, 535, 429, -405], [-5151, -469, -55, -151, -165, 211, -55, 55, -55, 55], [-79, -79, -3919, 79, -79, -79, 615, -147, 237, -145], [1502, -1392, -120, -248, -360, 260, -120, 120, -120, 120], [-302, -302, -8186, 302, -302, -302, -62, -10, 906, -690], [657, 1631, 279, 123, 837, -55, 279, -279, 279, -279], [254, 254, -1242, -254, 254, 254, 898, -38, -762, 226], [206, 206, -1030, -206, 206, 206, -878, -414, -618, 314], [3542, 306, 110, 378, 330, 270, 110, -110, 110, -110], [156, 156, -3184, -156, 156, 156, 228, 740, -468, 76], [-4738, 840, -232, -174, -696, 668, -232, 232, -232, 232], [-2554, -1014, -94, 62, -282, 110, -94, 94, -94, 94], [-176, -176, -946, 176, -176, -176, -2668, -74, 528, -156], [669, 475, -237, 111, -711, -359, -237, 237, -237, 237], [-937, -2183, 65, -435, 195, -37, 65, -65, 65, -65], [-84, -84, -1012, 84, -84, -84, 444, 168, 252, 372], [-3158, 2588, 328, -408, 984, -232, 328, -328, 328, -328], [-24, -24, 4082, 24, -24, -24, -1248, -134, 72, -532], [-229, -229, -329, 229, -229, -229, 1915, -633, 687, -591], [106, 106, -1142, -106, 106, 106, -3042, -106, -318, 358], [-1944, 114, 50, 314, 150, 1274, 50, -50, 50, -50], [-1176, 496, -300, 636, -900, -368, -300, 300, -300, 300], [-269, -269, -1859, 269, -269, -269, -2965, -607, 807, -175], [-122, -122, -5010, 122, -122, -122, 874, 306, 366, -1006], [-37, -37, -9593, 37, -37, -37, -193, 645, 111, -441], [-84, -2892, -324, 930, -972, -194, -324, 324, -324, 324], [-10230, 148, 300, 148, 900, -556, 300, -300, 300, -300], [-40, -40, -908, 40, -40, -40, -1488, -108, 120, -432], [-344, -344, 794, 344, -344, -344, -1396, 666, 1032, 844], [419, 419, -281, -419, 419, 419, -1473, -997, -1257, -675], [-3567, -1211, -469, 475, -1407, 599, -469, 469, -469, 469], [-702, -646, 442, -262, 1326, 202, 442, -442, 442, -442], [2828, -586, 342, 478, 1026, -106, 342, -342, 342, -342], [-258, -258, 2246, 258, -258, -258, -3330, 598, 774, -598], [-66, -66, -6836, 66, -66, -66, -1962, 876, 198, 446], [173, 173, 3165, -173, 173, 173, -491, 1281, -519, -77], [-2010, -2588, -52, 62, -156, -300, -52, 52, -52, 52], [-5372, -56, -4, 1000, -12, -514, -4, 4, -4, 4], [-480, -480, 3728, 480, -480, -480, 1264, 28, 1440, -1040], [447, 447, 4177, -447, 447, 447, -837, -1117, -1341, 959], [-51, -51, -3031, 51, -51, -51, 3075, 93, 153, -773], [8749, -379, -77, 1435, -231, -885, -77, 77, -77, 77], [13902, -1638, -318, 294, -954, 1732, -318, 318, -318, 318], [5082, 1596, 20, 996, 60, -36, 20, -20, 20, -20], [7322, 4222, -454, -30, -1362, -506, -454, 454, -454, 454], [522, 522, -6282, -522, 522, 522, -1982, 274, -1566, 622], [-277, -277, -10871, 277, -277, -277, 827, -639, 831, -1235], [5544, 3968, 188, -212, 564, -96, 188, -188, 188, -188], [-375, -375, -10775, 375, -375, -375, 3139, 205, 1125, 1199], [-10412, -4856, 332, -1112, 996, -220, 332, -332, 332, -332], [50, 50, 13716, -50, 50, 50, 310, -396, -150, 914], [27863, 985, -55, 381, -165, 47, -55, 55, -55, 55], [1970, -124, 4, -868, 12, 1696, 4, -4, 4, -4], [587, 587, 7137, -587, 587, 587, -121, 147, -1761, 1339], [544, 544, 4252, -544, 544, 544, 4752, -1184, -1632, 440], [371, 371, -16947, -371, 371, 371, -1945, -689, -1113, 331], [-7006, 2792, 424, 296, 1272, -1748, 424, -424, 424, -424], [13583, 191, 105, -1135, 315, -47, 105, -105, 105, -105], [6472, 6232, -24, -700, -72, 698, -24, 24, -24, 24], [-346, -346, -1442, 346, -346, -346, -3806, 1266, 1038, -934], [-37, -37, -3653, 37, -37, -37, 997, 815, 111, 933], [1350, 5142, 658, -458, 1974, -644, 658, -658, 658, -658], [1116, 1148, -756, 96, -2268, 1112, -756, 756, -756, 756], [-35, -35, -377, 35, -35, -35, -4859, 1747, 105, 703], [231, 231, -20689, -231, 231, 231, -3781, 33, -693, 319], [9743, -3869, -827, -623, -2481, 41, -827, 827, -827, 827], [-271, -271, -7031, 271, -271, -271, 5531, 829, 813, 399], [-556, -556, -610, 556, -556, -556, 1688, 742, 1668, -1200], [3623, -3747, 365, -1455, 1095, -581, 365, -365, 365, -365], [74, 74, 9112, -74, 74, 74, -1282, 2656, -222, 1650], [-878, -878, -12212, 878, -878, -878, -1358, 536, 2634, -1070], [-266, -266, -6200, 266, -266, -266, 4370, -464, 798, 654], [4820, 6028, -92, 62, -276, -822, -92, 92, -92, 92], [11448, -6948, -528, -1108, -1584, 608, -528, 528, -528, 528], [-14267, 3907, 507, 287, 1521, -491, 507, -507, 507, -507], [813, 813, 5591, -813, 813, 813, 4277, -829, -2439, 359], [-2809, 769, -271, 333, -813, -461, -271, 271, -271, 271], [461, 461, 18401, -461, 461, 461, -869, 165, -1383, -805], [155, 155, 5947, -155, 155, 155, -5177, -1045, -465, -207], [114, 114, -15542, -114, 114, 114, -1946, -614, -342, 1390], [10282, -9206, 18, 902, 54, 1502, 18, -18, 18, -18], [-349, -349, -389, 349, -349, -349, 5127, 735, 1047, 717], [-804, -804, -666, 804, -804, -804, 4944, 858, 2412, -1032], [4204, 1272, -260, 88, -780, -692, -260, 260, -260, 260], [211, 211, -10199, -211, 211, 211, -5365, -451, -633, -607]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_315_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_315_4_d_b();".
// 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_d_b(:prec:=10)
    chi := MakeCharacter_315_d();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_d_b();".
// 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_d_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_315_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![6400, 0, 37280, 0, 13329, 0, 1523, 0, 67, 0, 1]>],Snew);
    return Vf;
end function;