
// Make newform 252.4.k.c in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_252_k();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_252_k_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_252_4_k_c();".
// 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_252_4_k_c();".
// 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, 10, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [81, -10, 10, -1], [-81, 190, -10, 1], [14, 0, 0, 1]];
    Rf_basisdens := [1, 90, 90, 5];
    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_252_k();"
function MakeCharacter_252_k()
    N := 252;
    order := 3;
    char_gens := [127, 29, 73];
    v := [3, 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_252_k_Hecke();"
function MakeCharacter_252_k_Hecke(Kf)
    N := 252;
    order := 3;
    char_gens := [127, 29, 73];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [0, -1, 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, 0, 0, 0], [0, 0, 0, 0], [0, -7, -2, 0], [10, -8, -2, 1], [16, -16, 7, 7], [-14, 0, 0, -4], [-77, 77, 4, 4], [0, 112, -3, 0], [0, 34, -7, 0], [118, 0, 0, 28], [98, -98, 7, 7], [0, -173, -42, 0], [210, 0, 0, 12], [-172, 0, 0, 0], [0, 42, -15, 0], [-219, 219, 42, 42], [-28, 28, -37, -37], [0, -49, 74, 0], [-168, 168, -7, -7], [-448, 0, 0, 56], [-483, 483, 20, 20], [0, 26, -133, 0], [-196, 0, 0, -88], [0, 147, 60, 0], [-210, 0, 0, 76], [-511, 511, -106, -106], [0, -1106, -9, 0], [0, -1692, 63, 0], [1131, -1131, 14, 14], [-734, 0, 0, -140], [-1448, 0, 0, 56], [0, -532, -233, 0], [791, -791, 224, 224], [252, 0, 0, -152], [0, -15, 294, 0], [-306, 306, -133, -133], [-329, 329, 330, 330], [0, 76, 273, 0], [-644, 0, 0, 4], [0, -2863, 118, 0], [1596, -1596, -357, -357], [-98, 0, 0, 272], [0, -606, -231, 0], [1069, -1069, -84, -84], [878, 0, 0, 140], [-2114, 2114, -357, -357], [-172, 0, 0, 168], [728, 0, 0, 600], [-4116, 4116, -165, -165], [0, -273, 922, 0], [0, -2513, -448, 0], [-4692, 0, 0, -84], [-4151, 4151, 216, 216], [5208, 0, 0, -84], [0, 4011, -492, 0], [-3498, 3498, 777, 777], [-2863, 2863, 494, 494], [0, -2926, -541, 0], [-1733, 1733, -42, -42], [-646, 0, 0, -700], [2184, -2184, -895, -895], [1890, 0, 0, -576], [2604, 0, 0, -896], [2534, -2534, 41, 41], [0, -2667, -932, 0], [0, -7095, -546, 0], [0, -2984, -651, 0], [694, 0, 0, -700], [3060, -3060, -693, -693], [-630, 0, 0, -668], [-3549, 3549, -1596, -1596], [0, 3110, 805, 0], [-3794, 3794, -429, -429], [0, -5613, 1078, 0], [-2736, 0, 0, 28], [0, -3878, 449, 0], [1649, -1649, 1190, 1190], [0, -6013, 470, 0], [0, -3837, -420, 0], [3745, -3745, 648, 648], [14532, 0, 0, -192], [-3158, 0, 0, 812], [1998, -1998, -1575, -1575], [686, 0, 0, 1308], [0, 9170, -829, 0], [0, -3980, 623, 0], [-4742, 0, 0, 2044], [0, 8445, -812, 0], [-266, 0, 0, 940], [432, 0, 0, -2240], [0, 10556, 1351, 0], [9394, -9394, 1501, 1501], [-9206, 9206, 567, 567], [-4224, 0, 0, 2436], [0, 10548, 1225, 0], [-6048, 0, 0, 1512], [0, -2163, 1146, 0], [-2709, 2709, -396, -396], [0, -3332, 417, 0], [0, 13475, 854, 0], [6784, 0, 0, 1652], [11957, -11957, -238, -238], [4816, -4816, -737, -737], [0, 17643, 420, 0], [5624, -5624, -623, -623], [-8127, 8127, -64, -64], [-20356, 0, 0, -592], [0, -21, -1932, 0], [-10314, 10314, 2457, 2457], [-12586, 0, 0, -2100], [0, -8890, -1441, 0], [9095, -9095, 1330, 1330], [8786, 0, 0, 2828], [6300, -6300, 2069, 2069], [4688, 0, 0, -1848], [-20177, 20177, -1232, -1232], [-14308, 0, 0, -2112], [25662, -25662, 273, 273], [0, 5265, 630, 0], [1052, 0, 0, -2296], [17283, -17283, -1186, -1186], [-154, 0, 0, -252], [0, -17535, 822, 0], [-1176, 1176, -4641, -4641], [0, 12796, 2145, 0], [17770, 0, 0, -1904], [0, -5213, 3654, 0], [0, 1134, 2205, 0], [16800, 0, 0, -1352], [0, 12887, 2, 0], [-2332, 2332, -2891, -2891], [-7344, 0, 0, -2520], [0, -5914, -4417, 0], [-14558, 0, 0, 308], [0, -33761, -16, 0], [-28266, 0, 0, 1300], [10241, -10241, -1738, -1738], [11480, -11480, -2999, -2999], [-15162, 0, 0, -1428], [-20173, 20173, 3164, 3164], [17220, 0, 0, -3536], [0, 29881, 350, 0], [-9414, 9414, 119, 119], [-19284, 0, 0, -1680], [483, -483, 3254, 3254], [-8344, 0, 0, 512], [-5110, 0, 0, -1860], [7707, -7707, 3828, 3828], [0, 22204, -1695, 0], [0, 2846, -2387, 0], [0, 11835, -1442, 0], [-7266, 0, 0, 1968], [-24316, 0, 0, 1848], [0, 33894, -1755, 0], [18260, -18260, -371, -371], [-14160, 0, 0, 672], [0, -8958, 5971, 0], [0, 17703, 4248, 0], [33866, 0, 0, 144], [10073, -10073, 4502, 4502], [0, -4444, 511, 0], [3434, 0, 0, 3668], [-4048, 0, 0, 5880], [0, 8232, -5109, 0], [9579, -9579, -2436, -2436], [3906, -3906, -4779, -4779], [-15842, 15842, -4557, -4557], [17227, -17227, 5526, 5526]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_252_k_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_252_4_k_c();".
// 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_252_4_k_c(:prec:=4)
    chi := MakeCharacter_252_k();
    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_252_4_k_c();".
// 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_252_4_k_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_252_k();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![9801, -1386, 295, 14, 1]>,<13,R![-396, 28, 1]>],Snew);
    return Vf;
end function;