
// Make newform 108.5.g.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_108_g();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_108_g_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_108_5_g_a();".
// 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_108_5_g_a();".
// 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 := [440076, 85254, 6529, -1647, 1104, 121, 6, -3, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [307232328, -8283339, -3500708, -988763, 527797, -34123, -3472, 35], [-10751676, 1909485, 13645, -65600, -26525, 4562, -175, -115], [416903721, 49979736, 17133464, 681581, 612635, -8318, 21007, -95], [-2489799, 10634175, -4310506, 549521, -3580, 12583, -3659, 574], [9836232, 736731, -102856, 11840, 16298, -509, -164, 28], [201354, -20592, -18628, 1460, 419, 43, -35, 4], [323067342, 80817471, -4541909, 837436, 631207, 137138, -30661, 5003]];
    Rf_basisdens := [1, 2814669, 5629338, 2814669, 2814669, 72171, 6561, 5629338];
    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_108_g();"
function MakeCharacter_108_g()
    N := 108;
    order := 6;
    char_gens := [55, 29];
    v := [6, 5];
    // 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_108_g_Hecke();"
function MakeCharacter_108_g_Hecke(Kf)
    N := 108;
    order := 6;
    char_gens := [55, 29];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 0, -1, 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 := 5;
    raw_aps := [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 1, 0, 1, 0, 0, 1], [3, -1, 3, 0, -2, 0, 1, -1], [2, 1, -1, 1, 0, 0, 2, -2], [0, -3, 5, 1, 2, 1, 0, -3], [-53, -3, -106, 0, -2, 5, -1, 0], [76, -4, 8, 8, 5, -4, 10, 2], [292, -8, 141, -5, -10, 5, 16, -5], [-172, 0, 181, 9, 0, 0, 9, -1], [0, -14, -39, 7, -6, 7, 0, -1], [-21, -1, 2, 2, -29, -1, -1, -60], [1328, 5, 675, 11, 37, -11, -10, 26], [-17, 3, -23, -6, 0, 12, -9, 6], [-1143, 11, 1127, -16, 0, 0, -5, 1], [-961, -45, -1922, 0, -61, -45, 45, 0], [3286, 41, 1627, -16, -46, 16, -82, -30], [-530, 122, -519, 11, 48, -22, -111, 13], [0, 108, -25, -3, 93, -3, 0, -90], [-2747, 105, -5494, 0, 31, -19, -43, 0], [-1003, 31, -62, -62, 42, 31, -165, 146], [-604, -57, -635, -31, -244, 62, 26, -91], [-3015, 47, 2999, -16, 0, 0, 31, 217], [-1259, -39, -2518, 0, 241, -31, 35, 0], [1874, -34, 1911, 37, 122, -74, 71, 24], [-227, -44, 327, 100, 0, 0, 56, -231], [0, -145, -2111, 98, -87, 98, 0, -11], [-4054, -36, -8108, 0, -445, 204, -84, 0], [-973, -85, 170, 170, -3, -85, -9, -176], [-1218, -118, -595, 14, -291, -14, 236, -305], [920, -90, 180, 180, 72, -90, 252, -36], [1166, 3, 433, -150, -209, 150, -6, -59], [6818, -124, -6789, 29, 0, 0, -95, 744], [0, -103, -905, 52, -140, 52, 0, 88], [-17936, -57, -8791, 177, 734, -177, 114, 557], [4144, 179, 4065, -79, -576, 158, -258, -209], [0, -40, -3299, -124, 393, -124, 0, -269], [-7896, 122, -244, -244, -38, 122, -352, 168], [-8970, 43, -4331, 154, -519, -154, -86, -673], [14619, -96, -14661, -42, 0, 0, -138, -495], [4532, -252, 9064, 0, -256, -372, 312, 0], [-5331, 121, -242, -242, 151, 121, -247, 544], [2563, -149, -2865, -302, 0, 0, -451, 495], [0, 835, -4161, -5, 27, -5, 0, -22], [22648, -816, 45296, 0, -632, 40, 388, 0], [10579, 111, -222, -222, 239, 111, -905, 700], [0, 292, -16875, -175, -394, -175, 0, 569], [-6215, -457, -6069, 146, -1434, -292, 603, -863], [-6018, -635, 6607, 589, 0, 0, -46, 338], [0, -1586, 23769, 334, -915, 334, 0, 581], [12452, 1626, 24904, 0, 1199, 434, -1030, 0], [19656, -642, 10293, 465, 720, -465, 1284, 255], [-21087, -184, -21663, -576, 352, 1152, -392, 752], [-18352, 402, -36704, 0, 545, 218, -310, 0], [-30798, -218, -16289, -890, -1578, 890, 436, -688], [-16604, -503, 17217, 613, 0, 0, 110, 537], [7847, -1365, 15694, 0, 623, 1027, 169, 0], [-24496, -90, 180, 180, 1452, -90, 384, 2724], [-6503, -2224, -5937, 566, -390, -1132, 2790, -761], [7034, 1112, -8235, -1201, 0, 0, -89, 1893], [0, -835, 54901, -64, 141, -64, 0, -77], [14446, -950, 7257, 34, -529, -34, 1900, -563], [56600, -100, 200, 200, 663, -100, -1314, 1126], [54452, 1216, 27185, -41, -1244, 41, -2432, -1203], [57987, 1332, 57277, -710, 676, 1420, -2042, 1048], [-3272, -1204, 4561, 1289, 0, 0, 85, -175], [-43498, 1811, -44223, -725, -784, 1450, -2536, 333], [0, 936, 73715, -604, -734, -604, 0, 1338], [130056, -468, 66063, 1035, 2055, -1035, 936, 1020], [-45201, -356, -44485, 716, -1202, -1432, 1072, -1317], [-35290, -492, 33835, -1455, 0, 0, -1947, 2084], [-35238, -42, -70476, 0, -1692, -602, 322, 0], [115486, -69, 116017, 531, 960, -1062, 600, -51], [0, -1153, -79019, -705, 1208, -705, 0, -503], [-88401, -95, 190, 190, 1150, -95, -1651, 2110], [72578, -307, 35421, -868, -2993, 868, 614, -2125], [2755, -2380, -581, 2174, 0, 0, -206, -343], [-45967, -1391, 2782, 2782, 3225, -1391, -2403, 3668], [-51832, 3289, -27673, -1757, -305, 1757, -6578, 1452], [0, 52, 7443, -348, 1714, -348, 0, -1366], [71208, -730, 34493, -1111, -1500, 1111, 1460, -389], [158796, 766, 159353, 557, -3680, -1114, -209, -2397], [18658, 5022, 37316, 0, 244, 1662, -3342, 0], [-109897, -195, 390, 390, 2808, -195, 1089, 5226], [-45302, -3229, -45435, -133, 1788, 266, 3096, 1027], [-21267, 1859, 22649, 1382, 0, 0, 3241, 2086], [38973, -4317, 77946, 0, -1254, -29, 2173, 0], [-86522, -4762, -85929, 593, -12486, -1186, 5355, -6836], [57080, 616, -56959, 121, 0, 0, 737, 985], [0, -4258, -23795, 807, -1384, 807, 0, 577], [-2470, 108, -4940, 0, 5927, 2820, -1464, 0], [92172, -623, -90023, 2149, 0, 0, 1526, 4205], [-142298, -1236, 2472, 2472, -2212, -1236, 178, -6896], [-124934, 1627, -64689, -2222, -5410, 2222, -3254, -3188], [0, 1665, 223943, 504, 4752, 504, 0, -5256], [70911, 2415, 141822, 0, -1761, 1291, -1853, 0], [-62608, -3977, -30031, 1273, -11174, -1273, 7954, -12447], [68464, 6114, 136928, 0, -2075, -3374, -1370, 0], [241331, -521, 1042, 1042, -453, -521, 4263, -1948], [-223128, 1930, -3860, -3860, 1450, 1930, -250, 6760], [-88988, 3999, -87005, 1983, -3978, -3966, -2016, -3972], [81625, -6015, 163250, 0, 5707, -1375, 3695, 0], [23724, 2222, 13847, 1985, 3009, -1985, -4444, 1024], [26245, -1096, -26963, -718, 0, 0, -1814, 15212], [0, 8306, -63065, -905, 4375, -905, 0, -3470], [316391, 653, -1306, -1306, -3144, 653, -5859, -4982], [60571, 347, -58631, 1940, 0, 0, 2287, -8236], [-63293, 2559, -126586, 0, -7301, -1121, -719, 0], [-348794, 507, -170587, 3810, -2551, -3810, -1014, -6361], [-250490, 2362, -254689, -4199, -12174, 8398, -6561, -1888], [0, -7507, 392641, 568, -4721, 568, 0, 4153], [-128305, 667, -1334, -1334, -4977, 667, 39, -8620], [18368, -4367, 14423, 5239, -2789, -5239, 8734, -8028], [-260336, 1463, -257865, 2471, -3342, -4942, 1008, -4142], [244980, 2894, -5788, -5788, 6454, 2894, -11488, 18696], [-28321, 2592, 23821, -4500, 0, 0, -1908, 5654], [0, 2106, -297949, -81, 8505, -81, 0, -8424], [167538, -12594, 335076, 0, -3276, -1906, 7250, 0], [342142, 374, 166681, -4390, -5209, 4390, -748, -819], [-45398, -10383, 49145, 3747, 0, 0, -6636, -2453], [0, 3008, 206953, 1316, -7125, 1316, 0, 5809], [-145690, 1462, -143803, 1887, 19796, -3774, 425, 8011], [-38345, 3564, 41567, 3222, 0, 0, 6786, 10399], [-135198, -9528, -270396, 0, 3045, 3496, 3016, 0], [352441, 2955, 350311, -2130, 10746, 4260, -5085, 7503], [-107383, 4173, -214766, 0, -8683, 149, -2161, 0], [-179269, -12784, -180453, -1184, -2002, 2368, 11600, 183], [79986, 1950, 159972, 0, 8280, 5750, -3850, 0], [-247418, -3201, -245435, 1983, 5436, -3966, 5184, 735], [0, 4727, -44279, 5039, -858, 5039, 0, -4181], [265787, 65, -130, -130, -3792, 65, -8163, -7454], [45282, -1499, 31909, 9268, 19515, -9268, 2998, 10247], [0, 1777, -419691, 1680, 1429, 1680, 0, -3109], [-328786, -476, 952, 952, -1644, -476, -8748, -4240], [169692, 5413, 77545, -7301, 16416, 7301, -10826, 23717], [0, -10588, 281185, 2664, -4261, 2664, 0, 1597], [-362739, -4935, -725478, 0, -9843, -3439, 4187, 0], [0, -307, -61547, -5404, 2049, -5404, 0, 3355], [267900, 4913, 129149, -4801, 2598, 4801, -9826, 7399], [-119717, -5511, -239434, 0, 15712, -919, 3215, 0], [-184174, 1686, -3372, -3372, -81, 1686, 11808, 3210], [-128018, 11312, 114769, -13249, 0, 0, -1937, -1321], [0, 5754, 490133, -4793, -3388, -4793, 0, 8181], [-21410, -18258, -42820, 0, -5702, -4418, 11338, 0], [-267335, 2505, -5010, -5010, 9137, 2505, -7643, 23284], [159207, -4241, -165149, -5942, 0, 0, -10183, 6557], [205084, 10534, 200597, -4487, -2220, 8974, -15021, 3377], [-135474, -15788, 141997, 6523, 0, 0, -9265, 3125], [0, 788, -406085, 1873, -8369, 1873, 0, 6496], [-14744, 9300, -29488, 0, 9730, 2572, -5936, 0], [0, 16117, 109773, -435, 18154, -435, 0, -17719], [66269, 6441, 132538, 0, 13661, -1903, -2269, 0], [-163070, 4686, -9372, -9372, 83, 4686, -31736, 9538], [-649960, 7150, -329743, -4763, 7666, 4763, -14300, 12429], [420659, -6973, 422265, 1606, 16784, -3212, 8579, 6786], [495522, -5735, -493031, 2491, 0, 0, -3244, -541], [-66052, 2786, -5572, -5572, 4596, 2786, -3636, 14764], [54378, -2388, -44571, 9807, 0, 0, 7419, 22989], [-82257, -3989, 7978, 7978, -12353, -3989, 12239, -32684], [-282230, 9136, -138195, 2920, 32735, -2920, -18272, 29815], [-22056, 9217, 19195, -2861, 0, 0, 6356, -37630], [20163, -28587, 40326, 0, -11718, -4603, 16595, 0], [0, 5518, -127467, -5945, 10164, -5945, 0, -4219], [53739, 6147, 107478, 0, 22599, 16239, -11193, 0], [-317234, -13128, -148021, 10596, 170, -10596, 26256, -10426], [97696, 4797, -96535, 1161, 0, 0, 5958, -17063], [154058, -8388, 16776, 16776, 19338, -8388, 11226, 21900], [157243, 7100, 158907, 1664, 47598, -3328, -5436, 22135]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_108_g_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_108_5_g_a();".
// 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_108_5_g_a(:prec:=8)
    chi := MakeCharacter_108_g();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 5));
    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_108_5_g_a();".
// 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_108_5_g_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_108_g();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,5,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;