
// Make newform 117.4.b.d in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_117_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_117_b_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_4_b_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_117_4_b_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 := [48, 0, 29, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [0, 25, 0, 1], [15, 0, 1, 0]];
    Rf_basisdens := [1, 1, 2, 1];
    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_b();"
function MakeCharacter_117_b()
    N := 117;
    order := 2;
    char_gens := [92, 28];
    v := [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_117_b_Hecke();"
function MakeCharacter_117_b_Hecke(Kf)
    N := 117;
    order := 2;
    char_gens := [92, 28];
    char_values := [[1, 0, 0, 0], [-1, 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, 1, 0, 0], [0, 0, 0, 0], [0, 0, 1, 0], [0, -6, 0, 0], [0, 2, -1, 0], [-19, 0, 3, 2], [-54, 0, 0, 0], [0, -6, 6, 0], [-36, 0, 0, 12], [18, 0, 0, -12], [0, 18, 6, 0], [0, -48, -24, 0], [0, -4, -13, 0], [260, 0, 0, 12], [0, -122, -21, 0], [198, 0, 0, 36], [0, 34, -15, 0], [-566, 0, 0, -8], [0, -150, 12, 0], [0, 6, -23, 0], [0, 0, -54, 0], [88, 0, 0, -32], [0, 138, 25, 0], [0, 4, 15, 0], [0, 336, 54, 0], [-162, 0, 0, 60], [-712, 0, 0, -60], [792, 0, 0, 36], [0, -192, -6, 0], [-342, 0, 0, -24], [784, 0, 0, -80], [72, 0, 0, 84], [0, -172, -151, 0], [1340, 0, 0, -60], [0, -392, 123, 0], [0, -102, 186, 0], [-82, 0, 0, 84], [0, -150, -174, 0], [0, -114, -65, 0], [-1530, 0, 0, -12], [1440, 0, 0, -180], [-1594, 0, 0, 84], [-252, 0, 0, -300], [0, -312, 12, 0], [0, -416, 21, 0], [-1880, 0, 0, -80], [-548, 0, 0, -80], [0, -726, 54, 0], [0, -30, 283, 0], [0, 744, -234, 0], [-3690, 0, 0, -72], [0, -730, 497, 0], [0, -288, 174, 0], [828, 0, 0, 0], [-2610, 0, 0, 264], [6120, 0, 0, 168], [-2286, 0, 0, -36], [0, 162, -216, 0], [2726, 0, 0, -168], [0, 588, -479, 0], [5428, 0, 0, -80], [0, -880, -271, 0], [0, 882, 216, 0], [972, 0, 0, -636], [-2114, 0, 0, -332], [0, 176, -175, 0], [0, -1566, -132, 0], [550, 0, 0, -404], [-180, 0, 0, 264], [0, 2232, -168, 0], [0, -1020, -401, 0], [0, 2406, 619, 0], [992, 0, 0, 468], [-5318, 0, 0, 244], [0, 978, 174, 0], [0, -3010, -301, 0], [-2070, 0, 0, 60], [0, -840, 372, 0], [0, -836, 63, 0], [0, -2232, 114, 0], [360, 0, 0, -420], [0, 1272, -1026, 0], [0, -1106, 243, 0], [3238, 0, 0, 760], [-1144, 0, 0, 876], [-8064, 0, 0, 204], [0, -1572, 763, 0], [0, -504, -186, 0], [0, 3304, 693, 0], [0, -2118, 900, 0], [-1044, 0, 0, 1080], [0, 3958, 453, 0], [0, -3342, -582, 0], [-7092, 0, 0, 480], [0, -1662, 264, 0], [16632, 0, 0, 0], [0, -2936, -15, 0], [-918, 0, 0, 144], [-5788, 0, 0, -276], [0, 816, -978, 0], [6716, 0, 0, -828], [0, -112, -751, 0], [-12960, 0, 0, 228], [10998, 0, 0, -552], [-10412, 0, 0, 1216], [0, 3744, 180, 0], [0, -2854, 425, 0], [0, -1492, 35, 0], [-16848, 0, 0, -528], [-8018, 0, 0, 100], [11432, 0, 0, -612], [0, -3888, -540, 0], [0, 2796, -725, 0], [0, -1398, -1488, 0], [0, 4434, -402, 0], [-486, 0, 0, 456], [0, 642, 300, 0], [14256, 0, 0, -720], [10674, 0, 0, -1068], [5148, 0, 0, -192], [0, 1704, 1308, 0], [-478, 0, 0, 84], [-3330, 0, 0, -1596], [0, 4266, -1169, 0], [0, 234, 48, 0], [-27630, 0, 0, 252], [0, -2664, 2010, 0], [28332, 0, 0, 612], [-128, 0, 0, -32], [0, 2472, -1530, 0], [0, 1434, -2064, 0], [0, 6918, 985, 0], [-8872, 0, 0, -1044], [-17390, 0, 0, -1184], [0, -5844, 517, 0], [0, -1368, -1128, 0], [0, -4184, 2511, 0], [0, -1734, -816, 0], [-9126, 0, 0, 1668], [-3510, 0, 0, -360], [0, -5262, -1254, 0], [0, -5296, -1777, 0], [368, 0, 0, 1020], [0, -5638, 347, 0], [-4166, 0, 0, 784], [0, 2022, 121, 0], [0, -4008, 1140, 0], [-20970, 0, 0, -1056], [-8948, 0, 0, -968], [0, -2178, -1097, 0], [0, 1944, 1500, 0], [21366, 0, 0, 1008], [-6212, 0, 0, 760], [-19620, 0, 0, -996], [5212, 0, 0, 1288], [-12060, 0, 0, 1932], [-9512, 0, 0, 2728], [0, -3988, -1789, 0], [6094, 0, 0, -1160], [0, 7280, 155, 0], [0, -5438, -843, 0], [8262, 0, 0, -2160], [0, -366, 750, 0], [28116, 0, 0, 648], [0, 8868, 349, 0], [0, 998, 2405, 0], [42992, 0, 0, 660], [6830, 0, 0, -2544]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_117_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_117_4_b_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_117_4_b_d(:prec:=4)
    chi := MakeCharacter_117_b();
    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_b_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_117_4_b_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_117_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![48, 0, 29, 0, 1]>],Snew);
    return Vf;
end function;