
// Make newform 117.6.g.b in Magma, downloaded from the LMFDB on 12 March 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_117_g();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_117_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_117_6_g_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_117_6_g_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 := [9216, 9696, 16825, -6777, 4766, -133, 70, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [3235111584, 87619296, 122871793, 1509169756, -9316963, 21464689, 174777, 319677], [318334817568, 555191312047, -373258954959, 161504238962, -6542587651, 2342156938, -64388071, 33699079], [192123818377, 223142688, 312921279, 3798492578, -23727789, 54664767, -737924, 814131], [1093886512128, -6958248787343, 1964498756691, -850012765738, 33519877559, -12327003362, 338880779, -163476431], [6608032024, 87619296, 122871793, 1424846745, -9316963, 21464689, 174777, 319677], [537815172096, -1534220097281, 965856352737, -417913336366, 17508240653, -6060637334, 166612553, -87076937]];
    Rf_basisdens := [1, 1, 5480995715, 526175588640, 5480995715, 263087794320, 337292044, 40475045280];
    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_117_g();"
function MakeCharacter_117_g()
    N := 117;
    order := 3;
    char_gens := [92, 28];
    v := [3, 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_117_g_Hecke();"
function MakeCharacter_117_g_Hecke(Kf)
    N := 117;
    order := 3;
    char_gens := [92, 28];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, -1, 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]];
    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 := 6;
    raw_aps := [[1, 1, 0, -1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [2, 0, -2, 0, -1, 0, 1, 0], [0, -4, -4, 16, -2, -1, 1, 2], [114, 24, 0, -114, 0, -19, 0, -8], [-65, 26, -26, 52, 13, 13, 13, -13], [0, 8, 8, -13, 8, 76, -76, -8], [0, -272, -272, 62, 8, 75, -75, -8], [-1544, -468, 0, 1544, 0, -15, 0, -26], [201, 432, 0, -201, 0, -56, 0, -94], [3224, 0, 544, 0, -68, 0, -12, 0], [-2913, -344, 0, 2913, 0, -492, 0, -62], [-6201, 376, 0, 6201, 0, -248, 0, -128], [0, 488, 488, 4198, 72, 523, -523, -72], [356, 0, 656, 0, 300, 0, -224, 0], [6826, 0, 2334, 0, -305, 0, 393, 0], [0, -3256, -3256, -13986, -320, 425, -425, 320], [0, -4528, -4528, 463, -394, -948, 948, 394], [19062, -992, 0, -19062, 0, -333, 0, 16], [0, -3540, -3540, 6940, 1042, -1539, 1539, -1042], [-10030, 0, -1562, 0, 497, 0, 1691, 0], [-444, 0, -7792, 0, -928, 0, -524, 0], [-9884, 0, -1160, 0, 908, 0, 2556, 0], [-1873, 7646, 0, 1873, 0, 1153, 0, 1379], [0, -10154, -10154, 31757, 1969, 1361, -1361, -1969], [30321, -18872, 0, -30321, 0, 832, 0, 1426], [42568, 0, 8152, 0, -64, 0, 5128, 0], [-4702, -560, 0, 4702, 0, -2099, 0, 3888], [-62606, 0, 16504, 0, 84, 0, 2928, 0], [0, -6376, -6376, -94357, 1788, -2320, 2320, -1788], [-96600, 12908, 0, 96600, 0, -8845, 0, 1054], [44724, 0, 1704, 0, -4120, 0, -1112, 0], [0, -11056, -11056, 208483, 668, 2960, -2960, -668], [0, -22304, -22304, 157434, 2292, 915, -915, -2292], [0, -29696, -29696, 1597, 5982, -8156, 8156, -5982], [-122304, 0, -11664, 0, 2940, 0, 8692, 0], [-58026, 0, -39606, 0, 5, 0, -7237, 0], [0, 2912, 2912, -127438, 3668, 12299, -12299, -3668], [11064, -8860, 0, -11064, 0, -11975, 0, 1830], [0, 4606, 4606, -202187, -555, -1109, 1109, 555], [-137442, 21640, 0, 137442, 0, 20529, 0, 2072], [-174802, 0, 57858, 0, -2787, 0, -6309, 0], [0, -18668, -18668, -274852, 4758, -15759, 15759, -4758], [-291699, 41560, 0, 291699, 0, -15628, 0, 4496], [-349207, 11658, 0, 349207, 0, -41511, 0, 12809], [0, -16532, -16532, 221020, -10318, 19807, -19807, 10318], [222186, -58680, 0, -222186, 0, -8125, 0, -5436], [690932, 99948, 0, -690932, 0, -7609, 0, 13814], [0, 22256, 22256, 394338, -15568, -1251, 1251, 15568], [-180286, 0, -36568, 0, 11836, 0, -8288, 0], [538162, 0, 88008, 0, 4236, 0, 24064, 0], [-313672, 0, 14136, 0, 20468, 0, 25380, 0], [0, -91000, -91000, 12533, 6528, -63660, 63660, -6528], [0, 29256, 29256, -792726, -6780, 7017, -7017, 6780], [225611, 59032, 0, -225611, 0, -24592, 0, -31732], [65520, -82260, 0, -65520, 0, -10371, 0, -9078], [0, -36090, -36090, -476975, 1025, 35083, -35083, -1025], [-315228, 111476, 0, 315228, 0, 53871, 0, -15786], [0, 41544, 41544, -748113, 23318, -49500, 49500, -23318], [-320578, 0, -75830, 0, -23185, 0, -23627, 0], [-332450, -130152, 0, 332450, 0, 667, 0, -28864], [0, 116288, 116288, 400781, 30330, 59768, -59768, -30330], [-282676, 0, -78424, 0, -40472, 0, -55064, 0], [360680, 0, -10312, 0, 192, 0, -94424, 0], [529190, 0, -141720, 0, 12460, 0, -8752, 0], [1698046, 0, 97998, 0, -4441, 0, -81811, 0], [0, -16136, -16136, 1423590, 12952, -53045, 53045, -12952], [1514090, 0, 176398, 0, 7125, 0, -9497, 0], [0, 22408, 22408, -594702, -39004, 84001, -84001, 39004], [-99937, -79498, 0, 99937, 0, -96905, 0, -14729], [1041207, 77904, 0, -1041207, 0, -8440, 0, -13280], [-416616, 0, 125424, 0, -66864, 0, 87360, 0], [212796, -97428, 0, -212796, 0, -57841, 0, 79878], [0, 207000, 207000, -1316225, -5654, -39536, 39536, 5654], [-793690, 55704, 0, 793690, 0, -4433, 0, -1716], [0, 321828, 321828, 1143684, 52370, 44093, -44093, -52370], [714550, 0, 309078, 0, 39627, 0, 120073, 0], [0, 72906, 72906, 1511575, 8103, 123957, -123957, -8103], [-2070597, 213160, 0, 2070597, 0, -190332, 0, 6608], [0, 104760, 104760, -251679, 82992, 136168, -136168, -82992], [313634, 548752, 0, -313634, 0, 90453, 0, 89392], [319302, 0, 140770, 0, 54501, 0, 10475, 0], [2466392, -45268, 0, -2466392, 0, 230261, 0, -2558], [0, 285304, 285304, -2532147, -16192, -64276, 64276, 16192], [3615836, 268332, 0, -3615836, 0, -12381, 0, -42158], [-1807836, 0, 424584, 0, -57404, 0, -9076, 0], [0, -714622, -714622, -3409401, -59437, -33105, 33105, 59437], [673541, -594272, 0, -673541, 0, 44368, 0, 78548], [0, 1928, 1928, 3346909, 126942, 21228, -21228, -126942], [-2385464, 0, 102144, 0, 64696, 0, -205616, 0], [5045848, 0, -356568, 0, 27244, 0, 2160, 0], [-4251088, -148060, 0, 4251088, 0, 171509, 0, 135778], [0, 651436, 651436, 1461500, -30082, -219213, 219213, 30082], [-5012850, 430792, 0, 5012850, 0, -36455, 0, -57848], [3435460, 0, -661888, 0, 17452, 0, 107916, 0], [0, 887180, 887180, -251872, -59090, -128595, 128595, 59090], [1290205, -237016, 0, -1290205, 0, -186908, 0, -8462], [2279926, 0, 402218, 0, 10619, 0, -459575, 0], [603554, 1286144, 0, -603554, 0, 69875, 0, 11724], [4824850, 0, -113982, 0, 24525, 0, 120743, 0], [3005884, 0, 189184, 0, -144396, 0, 18300, 0], [-5125567, -353840, 0, 5125567, 0, -32144, 0, -209694], [0, -822096, -822096, -5128222, 124148, 360249, -360249, -124148], [3031215, -600258, 0, -3031215, 0, 181649, 0, -3917], [3282060, 0, -500400, 0, 5872, 0, -281760, 0], [-3030118, 0, 126462, 0, 138837, 0, -389193, 0], [8515366, -804216, 0, -8515366, 0, -361087, 0, 49112], [-4126546, 0, -655038, 0, 119419, 0, -391823, 0], [-1835572, 0, -1300424, 0, -75304, 0, 459892, 0], [879489, 394312, 0, -879489, 0, -345348, 0, 80812], [0, 1747356, 1747356, -665048, -29094, -218085, 218085, 29094], [2572247, -475496, 0, -2572247, 0, 162828, 0, -228078], [0, 897056, 897056, 748235, 111472, -193116, 193116, -111472], [-3568468, 0, -1078976, 0, -282552, 0, 91768, 0], [0, -449588, -449588, -8666100, 145606, -479333, 479333, -145606], [0, -308264, -308264, 3410467, -158296, -605940, 605940, 158296], [0, -250456, -250456, 2459850, -107592, 369815, -369815, 107592], [-4969972, -142396, 0, 4969972, 0, -38687, 0, 213194], [7279417, -478886, 0, -7279417, 0, -188183, 0, -173935], [0, -702880, -702880, -3685170, -271852, -180051, 180051, 271852], [5391967, 424776, 0, -5391967, 0, -556232, 0, -237514], [-9954935, -1842256, 0, 9954935, 0, -185924, 0, -104988], [4385246, 0, 338968, 0, 194148, 0, 261024, 0], [0, 1375824, 1375824, -567338, -38240, 115833, -115833, 38240], [-6676734, -703648, 0, 6676734, 0, 117795, 0, 229524], [2208014, 0, -779928, 0, 227052, 0, -450304, 0], [0, 1594952, 1594952, 1364399, -222342, 365760, -365760, 222342], [0, 1370748, 1370748, -9741820, -83770, -56607, 56607, 83770], [-5890520, 0, -476296, 0, -262524, 0, -95588, 0], [680978, 0, -954590, 0, 137253, 0, -26273, 0], [-3317538, -578432, 0, 3317538, 0, 378079, 0, 339060], [-2482820, 1268964, 0, 2482820, 0, -47427, 0, -11018], [9555996, -2269284, 0, -9555996, 0, 182091, 0, 24626], [5325819, 1495422, 0, -5325819, 0, -692521, 0, -286773], [0, 1008858, 1008858, -9070429, 272263, -46057, 46057, -272263], [15468937, 884514, 0, -15468937, 0, -385745, 0, -184387], [0, -393634, -393634, 17807965, -256491, -395421, 395421, 256491], [0, 477424, 477424, -6022086, 440168, -383233, 383233, -440168], [0, -1936466, -1936466, 9180701, 215021, 498395, -498395, -215021], [389687, 2140504, 0, -389687, 0, -112136, 0, -222432], [8980800, 0, 1293712, 0, -359460, 0, 934880, 0], [-14819575, -769622, 0, 14819575, 0, -906391, 0, 223337], [0, 1434036, 1434036, 15462180, 247162, 222647, -222647, -247162], [12094716, 0, -608352, 0, -537520, 0, 420760, 0], [-8576505, 738896, 0, 8576505, 0, -896464, 0, 754726], [0, -638036, -638036, 3954012, 28082, 404509, -404509, -28082], [-1027194, 0, 1207682, 0, -315471, 0, -1283481, 0], [-2492002, 0, 1286570, 0, -501125, 0, -482943, 0], [-2409932, 0, -469832, 0, 86256, 0, -67776, 0], [-8195968, 0, -1543304, 0, -240612, 0, -620700, 0], [0, -2792896, -2792896, 1924863, -45378, -769468, 769468, 45378], [7281507, -3750664, 0, -7281507, 0, -123272, 0, 65580], [-3595468, 0, 4038800, 0, 11244, 0, 108908, 0], [-26230324, 24828, 0, 26230324, 0, -166647, 0, 139466], [6138518, 1187808, 0, -6138518, 0, 266215, 0, -292836], [15304608, 0, 1485336, 0, -177572, 0, -8428, 0], [0, 821708, 821708, 9735496, -920214, -396053, 396053, 920214], [0, -1631336, -1631336, 1616451, -205984, 245428, -245428, 205984], [-14976398, 0, -1984378, 0, 331377, 0, 1703419, 0], [8915714, 0, 1268512, 0, -442560, 0, -619488, 0], [14465726, 2583888, 0, -14465726, 0, -953031, 0, 194072], [0, 409570, 409570, 14503263, 8819, 781303, -781303, -8819], [1876112, 0, -2268328, 0, -318680, 0, -1372808, 0], [0, 483248, 483248, -19854678, -162176, 1428053, -1428053, 162176], [-9982049, 3571504, 0, 9982049, 0, 2368756, 0, -90220], [27159024, 0, -1709632, 0, 584148, 0, 491804, 0], [869624, -1764100, 0, -869624, 0, 1610803, 0, 284830], [0, -393680, -393680, 1571011, 1234986, 119492, -119492, -1234986]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_117_g_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_117_6_g_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_117_6_g_b(:prec:=8)
    chi := MakeCharacter_117_g();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_117_6_g_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_117_6_g_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_117_g();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![5184, -16704, 49504, -14640, 4832, -164, 85, -5, 1]>],Snew);
    return Vf;
end function;