
// Make newform 117.4.a.g in Magma, downloaded from the LMFDB on 07 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_117_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_117_4_a_g();".
// 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_4_a_g();".
// 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 := [81, -9, -40, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-9, -31, -1, 1], [9, 49, 1, -1], [-171, 22, 10, -1]];
    Rf_basisdens := [1, 9, 9, 9];
    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_a();"
function MakeCharacter_117_a()
    N := 117;
    order := 1;
    char_gens := [92, 28];
    v := [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_117_a_Hecke(Kf)
    return MakeCharacter_117_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+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, 1, 0, 0], [0, 0, 0, 0], [0, 0, 0, -1], [8, 0, 2, 0], [0, 2, 0, -1], [-13, 0, 0, 0], [0, -8, 0, 0], [28, 0, -14, 0], [0, -32, 0, -2], [0, -20, 0, 10], [-152, 0, 2, 0], [30, 0, 32, 0], [0, 4, 0, 9], [216, 0, 8, 0], [0, 54, 0, -5], [0, -52, 0, 8], [0, 46, 0, -15], [142, 0, 44, 0], [780, 0, -34, 0], [0, -98, 0, -29], [-10, 0, -136, 0], [-236, 0, 112, 0], [0, 2, 0, -5], [0, 204, 0, 7], [-34, 0, -104, 0], [0, -92, 0, 54], [892, 0, -88, 0], [0, -72, 0, 86], [890, 0, -88, 0], [0, 216, 0, -70], [1156, 0, -92, 0], [0, 176, 0, 86], [0, -196, 0, 25], [8, 0, -188, 0], [0, 336, 0, 13], [720, 0, -90, 0], [686, 0, 84, 0], [756, 0, 110, 0], [0, -218, 0, 23], [0, -36, 0, -38], [0, 12, 0, 104], [-2662, 0, 180, 0], [0, -172, 0, -108], [-1726, 0, -352, 0], [0, -424, 0, -109], [-940, 0, 292, 0], [960, 0, -312, 0], [-928, 0, -270, 0], [0, -930, 0, 149], [-718, 0, -200, 0], [0, 1144, 0, -26], [0, -2, 0, -17], [-514, 0, 200, 0], [0, 252, 0, 150], [0, 184, 0, 258], [0, -852, 0, -18], [0, 60, 0, -114], [-64, 0, -302, 0], [-2462, 0, 0, 0], [0, 108, 0, 317], [4152, 0, -132, 0], [0, 912, 0, 257], [-3244, 0, 466, 0], [0, 864, 0, -122], [-7350, 0, -336, 0], [0, -1248, 0, -117], [8620, 0, 166, 0], [3534, 0, -832, 0], [0, 968, 0, 48], [-3274, 0, -824, 0], [0, 2084, 0, -43], [0, 1302, 0, -201], [2796, 0, 948, 0], [1966, 0, 480, 0], [-1988, 0, -558, 0], [0, -1070, 0, -83], [0, -1124, 0, -296], [-6490, 0, -120, 0], [0, -708, 0, 47], [3414, 0, 1104, 0], [0, -1216, 0, -482], [-4574, 0, -208, 0], [0, 178, 0, 605], [5946, 0, -116, 0], [3516, 0, 1248, 0], [0, 1384, 0, 226], [0, -2484, 0, 119], [-234, 0, -232, 0], [0, -2024, 0, -309], [5072, 0, -1902, 0], [0, 644, 0, 590], [0, -2390, 0, 17], [-344, 0, -566, 0], [0, -1436, 0, -462], [7372, 0, -1082, 0], [0, 1412, 0, 730], [0, -2608, 0, 483], [0, -2048, 0, -718], [-10608, 0, 1684, 0], [-9446, 0, 912, 0], [9296, 0, 1580, 0], [0, -1056, 0, -1231], [0, 1628, 0, -352], [0, 2768, 0, 758], [-5192, 0, -252, 0], [7634, 0, 480, 0], [0, -1326, 0, -633], [0, 3012, 0, -117], [0, 1020, 0, 1130], [-14598, 0, 1712, 0], [-3676, 0, -1044, 0], [-9202, 0, -1672, 0], [0, -844, 0, 445], [-11868, 0, 914, 0], [-21728, 0, 502, 0], [0, 664, 0, -364], [14980, 0, -658, 0], [0, -768, 0, -836], [0, -2188, 0, -590], [0, -120, 0, 1580], [318, 0, 24, 0], [3754, 0, 1012, 0], [0, 2692, 0, 504], [0, 1642, 0, -821], [6164, 0, -2642, 0], [0, 2372, 0, -964], [98, 0, -880, 0], [0, 3992, 0, -514], [8316, 0, 3388, 0], [17994, 0, 1208, 0], [3556, 0, -1318, 0], [0, -2978, 0, 271], [9844, 0, -192, 0], [-9846, 0, -1500, 0], [0, -3804, 0, 1077], [5922, 0, 1344, 0], [0, -1640, 0, 597], [-1620, 0, 2482, 0], [0, 300, 0, -488], [0, -384, 0, 782], [-24932, 0, 1178, 0], [0, -296, 0, 1029], [1940, 0, -288, 0], [0, -3694, 0, -1597], [10018, 0, -4052, 0], [0, -2902, 0, -1887], [-1042, 0, 5104, 0], [0, -7904, 0, 314], [6632, 0, -1600, 0], [0, 3322, 0, 1101], [34246, 0, 1064, 0], [0, 1000, 0, -514], [28480, 0, 580, 0], [0, 4028, 0, 560], [28240, 0, -444, 0], [0, -4796, 0, 1348], [11172, 0, -1552, 0], [0, 2204, 0, -399], [15186, 0, -1292, 0], [0, -2072, 0, -2535], [0, -3130, 0, 917], [0, -5440, 0, 390], [-10000, 0, 2626, 0], [0, -2768, 0, 864], [0, -2908, 0, -1793], [0, 5458, 0, -595], [-26644, 0, -980, 0], [19150, 0, 208, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_117_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_117_4_a_g();".
// 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_4_a_g(:prec:=4)
    chi := MakeCharacter_117_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(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_4_a_g();".
// 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_4_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_117_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![448, 0, -45, 0, 1]>],Snew);
    return Vf;
end function;