
// Make newform 315.3.h.d in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_315_h();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_315_h_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_3_h_d();".
// 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_3_h_d();".
// 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 := [441, -1638, 4950, -5472, 5613, -1074, 1704, -372, 295, -26, 21, -2, 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, 0, 0], [2151653525805, -1028895680526, 2969181679896, 8663666606754, 1781364901824, 1552126862414, 213549867516, 315532034086, 16671982336, 20630949354, 179172244, 1163071964], [10342332760284, -4393836770841, 12643415740656, 27659028800376, 7155359090394, 7205061506889, 348399189483, 1489720495401, 27516350446, 102990651177, -2605315656, 5593516534], [-203704095121695, 198646121553516, -573525290759622, 221435259480507, -135085839058755, 76701806074920, -31274532528455, 12823809975400, -2156880862761, 936265293410, -136320072447, 42289552636], [-16499782051746, 83456511918192, -68365456465596, 91463612199264, -13714835477540, 27112135117560, -5194542247732, 4653112414112, -365904134124, 329223217160, -28994320136, 15660232032], [17534758495653, -12304269726462, 35493670736670, 13113600071907, 11901611179383, 2607856396482, 1718774236945, 668319319750, 122141383813, 43893742358, 4168730751, 2752740836], [86851646987175, -442224670054734, 346171354438782, -472028460969018, 65772299304051, -139385258261016, 25973059454509, -23655237895132, 1834614270589, -1671226017089, 146272115177, -79026253784], [-97210890476343, 506394799279488, -337263809399094, 498019460789280, -60428204598579, 144041638848258, -25332409851961, 24601833997390, -1784598323581, 1733118865151, -145734598445, 82515469676], [4306806, -18996579, 29629158, -30382920, 5419563, -9463719, 2055140, -1697439, 142983, -121362, 11357, -5888], [-2426520744774, 375544345114512, -534812214191700, 467993649961155, -101412405605496, 148372710389544, -36605150224288, 26419119629440, -2547333298184, 1900808184921, -196270735236, 91626156422], [207714123345456, -604632734322246, 678449825160384, -876196609907601, 105142657549572, -261085625853546, 46879197803692, -46725482453698, 3245165108972, -3313587375429, 275300339232, -161873480282], [-498205455783, 2124183465543, -3732659132112, 3676528796220, -659018133716, 1154612659597, -253771899971, 207844732437, -17611281862, 14880207305, -1406324924, 722764520]];
    Rf_basisdens := [1, 5604734688861, 2402029152369, 16814204066583, 5604734688861, 731052350721, 16814204066583, 16814204066583, 1130283, 16814204066583, 16814204066583, 72788762193];
    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_h();"
function MakeCharacter_315_h()
    N := 315;
    order := 2;
    char_gens := [281, 127, 136];
    v := [2, 2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_315_h_Hecke();"
function MakeCharacter_315_h_Hecke(Kf)
    N := 315;
    order := 2;
    char_gens := [281, 127, 136];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 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 := 3;
    raw_aps := [[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0], [-1, 0, 0, 0, 0, 0, 0, 0, -1, 1, 0, 0], [1, 1, -2, -1, 0, 1, 1, 0, -1, 0, 0, 1], [0, 0, 0, 0, 1, 0, 0, 0, 4, 1, -1, 2], [0, 0, 0, 0, 0, 0, -1, -1, 2, -1, 1, -2], [0, 0, 0, 0, 4, 0, 2, -1, -1, 2, -2, 1], [3, 3, 0, 1, 2, 1, 0, 0, 0, 2, 2, 0], [-5, -5, -2, -1, -2, -1, 0, 0, 0, -2, -2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 10, -2, 2, 2], [5, -5, -2, -4, -2, 0, 2, 0, -2, -2, -2, 2], [0, 0, 0, 0, -8, 0, 3, 0, 3, 0, 0, 5], [13, 3, -6, 2, 3, -2, -2, 0, 2, 3, 3, -2], [0, 0, 0, 0, 0, 0, -1, -7, 2, -1, 1, 4], [-15, 9, -12, -3, 2, -3, 0, 0, 0, 2, 2, 0], [0, 0, 0, 0, -4, 0, -7, 2, -7, -4, 4, 5], [0, 0, 0, 0, -6, 0, 0, -9, -1, 2, -2, 1], [17, -9, 6, 8, -1, 4, -2, 0, 2, -1, -1, -2], [-2, 4, 4, -2, -6, 0, 1, 0, -1, -6, -6, 1], [0, 0, 0, 0, -12, 0, -10, 2, 14, 2, -2, -6], [12, 10, -20, 6, 4, 2, -2, 0, 2, 4, 4, -2], [0, 0, 0, 0, -6, 0, 12, 0, -8, 4, -4, 0], [0, 0, 0, 0, -4, 0, -1, -4, 31, 4, -4, -7], [0, 0, 0, 0, -2, 0, 0, -6, -4, -10, 10, 4], [0, 0, 0, 0, 12, 0, -8, 4, 6, 6, -6, 8], [0, 0, 0, 0, 1, 0, -6, 0, 20, 5, -5, -2], [-29, -17, 0, -5, -2, -1, 2, 0, -2, -2, -2, 2], [-42, -4, 24, -10, 2, -2, 4, 0, -4, 2, 2, 4], [41, -19, -4, 7, 4, -1, -4, 0, 4, 4, 4, -4], [-8, 2, 16, -6, -1, 2, 4, 0, -4, -1, -1, 4], [0, 0, 0, 0, -16, 0, 13, 10, -7, 2, -2, -15], [-15, -3, -20, 3, 8, 11, 4, 0, -4, 8, 8, 4], [0, 0, 0, 0, -34, 0, 12, 9, -17, 4, -4, -3], [63, -9, 10, -9, -6, -21, -6, 0, 6, -6, -6, -6], [66, -16, -8, 4, -8, -8, -6, 0, 6, -8, -8, -6], [0, 0, 0, 0, 43, 0, 0, -18, -42, 3, -3, 24], [-41, -7, 10, 8, 7, 12, 2, 0, -2, 7, 7, 2], [0, 0, 0, 0, -18, 0, -5, 7, 0, -9, 9, -10], [0, 0, 0, 0, 22, 0, 22, -8, 36, 6, -6, 10], [-41, -5, -2, 1, 4, -5, -3, 0, 3, 4, 4, -3], [0, 0, 0, 0, 4, 0, -16, -13, 11, 8, -8, -3], [-44, 22, 4, -20, -2, -2, 9, 0, -9, -2, -2, 9], [-58, 4, -44, -14, -6, 10, 12, 0, -12, -6, -6, 12], [19, -17, 24, -1, -12, 11, 6, 0, -6, -12, -12, 6], [0, 0, 0, 0, 12, 0, -20, -8, -2, 22, -22, -22], [-32, 30, -20, -18, 10, -34, -8, 0, 8, 10, 10, -8], [0, 0, 0, 0, 59, 0, -10, 2, 10, -5, 5, 24], [0, 0, 0, 0, -10, 0, -2, 4, 38, -4, 4, -30], [0, 0, 0, 0, -14, 0, -20, -11, 33, 18, -18, 11], [105, -3, 8, -25, 8, -21, 2, 0, -2, 8, 8, 2], [-142, 8, 0, 14, -6, 28, 7, 0, -7, -6, -6, 7], [0, 0, 0, 0, -28, 0, 2, 2, -44, 16, -16, -4], [0, 0, 0, 0, 16, 0, -9, 30, 67, -2, 2, 35], [0, 0, 0, 0, 32, 0, 13, 19, 28, 7, -7, 12], [-99, 9, 40, -5, -2, -1, 2, 0, -2, -2, -2, 2], [0, 0, 0, 0, -48, 0, -10, 8, -56, 34, -34, 22], [0, 0, 0, 0, 62, 0, 20, 14, 12, 12, -12, 12], [177, -5, 10, -26, -4, -14, 6, 0, -6, -4, -4, 6], [-212, 10, 32, -14, 0, -22, -4, 0, 4, 0, 0, -4], [0, 0, 0, 0, -40, 0, 4, 10, -14, -26, 26, -34], [0, 0, 0, 0, -36, 0, -10, 8, 0, -24, 24, -50], [0, 0, 0, 0, 24, 0, -4, 32, 0, -18, 18, -24], [0, 0, 0, 0, 8, 0, -32, -8, 12, -24, 24, -36], [0, 0, 0, 0, -12, 0, 26, -4, 28, 10, -10, -32], [-39, -3, -52, -25, 2, -9, 8, 0, -8, 2, 2, 8], [-146, 48, 64, 42, 10, 38, -2, 0, 2, 10, 10, -2], [-114, -16, 100, 26, -16, -6, -16, 0, 16, -16, -16, -16], [151, 31, -40, 1, -12, -31, -16, 0, 16, -12, -12, -16], [0, 0, 0, 0, -26, 0, -20, 25, 69, 6, -6, 3], [0, 0, 0, 0, -4, 0, -31, -1, 84, -45, 45, 8], [-80, 58, -68, -12, 2, -2, 5, 0, -5, 2, 2, 5], [0, 0, 0, 0, -11, 0, 8, 44, 50, -25, 25, 0], [83, 33, -66, 38, 14, 10, -14, 0, 14, 14, 14, -14], [162, 8, 48, -14, -32, -46, -16, 0, 16, -32, -32, -16], [0, 0, 0, 0, -8, 0, -3, 21, -40, -25, 25, 62], [13, -23, -10, -3, -14, -7, -2, 0, 2, -14, -14, -2], [0, 0, 0, 0, 15, 0, 28, -8, -40, 11, -11, 54], [6, 0, 32, 20, 0, 16, -2, 0, 2, 0, 0, -2], [0, 0, 0, 0, 22, 0, -40, 8, -72, -18, 18, 48], [0, 0, 0, 0, 20, 0, -29, 16, 25, -2, 2, 9], [-12, -74, -60, -16, -30, -8, 4, 0, -4, -30, -30, 4], [-140, -50, -8, -20, 10, -26, -3, 0, 3, 10, 10, -3], [0, 0, 0, 0, 60, 0, -60, -24, 74, -4, 4, 22], [0, 0, 0, 0, -56, 0, 36, 0, -10, -22, 22, -54], [-157, -13, -32, 53, 12, -3, -28, 0, 28, 12, 12, -28], [4, 58, -52, -14, 8, -38, -12, 0, 12, 8, 8, -12], [40, -30, -88, -34, -6, -10, 12, 0, -12, -6, -6, 12], [0, 0, 0, 0, 40, 0, -16, -22, -32, 16, -16, 30], [-86, -28, 36, -10, 1, -50, -20, 0, 20, 1, 1, -20], [0, 0, 0, 0, 30, 0, 66, -6, 72, -6, 6, -48], [0, 0, 0, 0, -120, 0, 6, 48, 26, -4, 4, -42], [68, 34, -4, 44, -5, 44, 0, 0, 0, -5, -5, 0], [73, 1, -126, 47, 28, 45, -1, 0, 1, 28, 28, -1], [-212, 54, -44, -42, -8, -22, 10, 0, -10, -8, -8, 10], [0, 0, 0, 0, -48, 0, -13, 47, 224, 5, -5, -2], [0, 0, 0, 0, 56, 0, 26, -34, -6, -18, 18, 44], [0, 0, 0, 0, 120, 0, -15, -30, -153, -6, 6, -27], [0, 0, 0, 0, -76, 0, -20, -2, -42, -30, 30, -130], [110, -48, 104, -8, -14, 48, 28, 0, -28, -14, -14, 28], [-11, 35, 54, -24, -19, 36, 30, 0, -30, -19, -19, 30], [255, 15, 52, -19, -24, 41, 30, 0, -30, -24, -24, 30], [0, 0, 0, 0, 78, 0, -16, -4, 52, 52, -52, 4], [190, 40, 16, 12, -16, 4, -4, 0, 4, -16, -16, -4], [-136, 18, 36, 48, 24, 60, 6, 0, -6, 24, 24, 6], [0, 0, 0, 0, 54, 0, 6, -24, -84, 12, -12, -68], [0, 0, 0, 0, 46, 0, 68, 2, -106, 62, -62, 18], [0, 0, 0, 0, 60, 0, 11, -13, 86, 11, -11, 106], [-28, -82, -4, -28, -62, 6, 17, 0, -17, -62, -62, 17], [0, 0, 0, 0, 34, 0, 38, 32, 122, 26, -26, -26], [0, 0, 0, 0, 35, 0, -50, 58, -50, -41, 41, 100], [199, -115, -58, -62, -6, -66, -2, 0, 2, -6, -6, -2], [103, 31, 76, -79, 28, -31, 24, 0, -24, 28, 28, 24], [0, 0, 0, 0, 126, 0, -16, -43, -185, 16, -16, 21], [-2, -52, -8, -16, 22, 0, 8, 0, -8, 22, 22, 8], [94, 40, -28, 52, -4, 16, -18, 0, 18, -4, -4, -18], [0, 0, 0, 0, -26, 0, 28, -44, 200, -4, 4, 52], [0, 0, 0, 0, -60, 0, -47, -35, -300, -21, 21, 50], [413, 65, 60, -13, 30, -5, 4, 0, -4, 30, 30, 4], [3, -57, -10, 69, -40, 19, -25, 0, 25, -40, -40, -25], [0, 0, 0, 0, -62, 0, -60, -3, -83, 46, -46, 99], [40, 78, 200, 30, -2, 22, -4, 0, 4, -2, -2, -4], [0, 0, 0, 0, -104, 0, -46, 8, 64, -8, 8, -54], [287, -13, -132, -13, 50, 15, 14, 0, -14, 50, 50, 14], [0, 0, 0, 0, -14, 0, 54, 15, -37, -28, 28, 101], [413, -79, -54, -79, -6, -47, 16, 0, -16, -6, -6, 16], [18, -52, -112, 14, -4, 38, 12, 0, -12, -4, -4, 12], [0, 0, 0, 0, -100, 0, -50, 10, -36, 54, -54, -12], [0, 0, 0, 0, 25, 0, 2, 32, 148, 73, -73, -10], [0, 0, 0, 0, 59, 0, -36, 18, 94, -41, 41, -68], [-98, -64, 168, -80, -66, -4, 38, 0, -38, -66, -66, 38], [-805, 35, 48, 17, 0, 37, 10, 0, -10, 0, 0, 10], [-84, 2, 84, 2, -4, -38, -20, 0, 20, -4, -4, -20], [325, -33, 38, 36, 46, 16, -10, 0, 10, 46, 46, -10], [0, 0, 0, 0, -164, 0, 23, 26, -75, -6, 6, -69], [0, 0, 0, 0, 46, 0, 38, -28, 194, 38, -38, 6], [0, 0, 0, 0, -52, 0, -4, 56, -194, -20, 20, 68], [0, 0, 0, 0, 36, 0, -80, 34, -10, 2, -2, -26], [0, 0, 0, 0, 82, 0, 24, -6, 232, 76, -76, 62], [-126, -84, 268, 60, 16, 4, -28, 0, 28, 16, 16, -28], [0, 0, 0, 0, -78, 0, -76, -37, 337, 28, -28, -109], [-83, -23, 58, -71, -38, -59, 6, 0, -6, -38, -38, 6], [272, -54, -128, 18, -15, 2, -8, 0, 8, -15, -15, -8], [819, -45, 68, 13, -32, 13, 0, 0, 0, -32, -32, 0], [0, 0, 0, 0, -8, 0, 64, 7, -181, 8, -8, 5], [0, 0, 0, 0, -208, 0, 20, 38, 38, -46, 46, -82], [0, 0, 0, 0, -113, 0, 40, 4, 136, -17, 17, 94], [0, 0, 0, 0, -104, 0, -35, 31, 0, -69, 69, -92], [0, 0, 0, 0, 124, 0, -36, -21, -255, -30, 30, 51], [143, -1, 0, -87, -58, 73, 80, 0, -80, -58, -58, 80], [179, -15, -82, -30, 96, 22, 26, 0, -26, 96, 96, 26], [0, 0, 0, 0, 16, 0, 45, 48, -87, 12, -12, 71], [-177, -7, 214, -6, -15, -10, -2, 0, 2, -15, -15, -2], [0, 0, 0, 0, 138, 0, -13, -55, -290, 25, -25, -56], [-73, 73, -266, -26, -3, 10, 18, 0, -18, -3, -3, 18], [-28, -10, 188, 52, 78, -14, -33, 0, 33, 78, 78, -33], [1144, 54, -140, -2, 8, 22, 12, 0, -12, 8, 8, 12], [0, 0, 0, 0, 132, 0, 57, 90, -17, -26, 26, 9], [0, 0, 0, 0, -30, 0, -76, 8, 34, -50, 50, -94], [0, 0, 0, 0, 192, 0, 110, -22, 110, 104, -104, 88], [-373, -49, -132, 71, -6, -17, -44, 0, 44, -6, -6, -44], [-601, -25, 216, -63, -24, -115, -26, 0, 26, -24, -24, -26], [-242, 212, -148, -22, 67, 2, 12, 0, -12, 67, 67, 12], [0, 0, 0, 0, -36, 0, -43, -88, 247, 124, -124, 127], [461, 209, -232, 79, 72, 43, -18, 0, 18, 72, 72, -18], [0, 0, 0, 0, 0, 0, 147, 69, -86, -41, 41, 12], [16, 6, -84, 10, 26, 26, 8, 0, -8, 26, 26, 8], [0, 0, 0, 0, 135, 0, -24, -12, -244, 23, -23, 90]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_315_h_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_315_3_h_d();".
// 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_3_h_d(:prec:=12)
    chi := MakeCharacter_315_h();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    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_3_h_d();".
// 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_3_h_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_315_h();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<2,R![21, -198, 103, 40, -21, -2, 1]>],Snew);
    return Vf;
end function;