
// Make newform 252.6.k.e in Magma, downloaded from the LMFDB on 10 March 2025.
// 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_6_k_e();".
// 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_6_k_e();".
// 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 := [3132900, 1770, 1771, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [3132900, -1771, 1771, -1], [3541, 0, 0, 1]];
    Rf_basisdens := [1, 1, 3134670, 1771];
    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, 0, -1, 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 := [[0, 0, 0, 0], [0, 0, 0, 0], [0, -1, 24, 0], [-73, -2, 59, 1], [-203, -1, 204, -1], [222, 0, 0, 5], [-932, -4, 936, -4], [0, -51, 757, 0], [0, 100, -72, 0], [-329, 0, 0, -109], [5547, 76, -5623, 76], [0, -21, 1567, 0], [3924, 0, 0, -6], [-6304, 0, 0, -21], [0, 36, 4770, 0], [6813, -231, -6582, -231], [-23431, -659, 24090, -659], [0, 440, 31606, 0], [-22168, -205, 22373, -205], [63170, 0, 0, -500], [-2644, -751, 3395, -751], [0, 1634, -9611, 0], [-18697, 0, 0, -1931], [0, 18, 41532, 0], [91825, 0, 0, 1135], [-52390, 1432, 50958, 1432], [0, -2403, -64643, 0], [0, 3513, -46578, 0], [8816, -3103, -5713, -3103], [51724, 0, 0, -1882], [-146397, 0, 0, 2330], [0, 1361, 136392, 0], [-44086, -986, 45072, -986], [145120, 0, 0, 2947], [0, -2142, -261600, 0], [-64567, 1937, 62630, 1937], [198688, -462, -198226, -462], [0, 1008, 279196, 0], [-311438, 0, 0, 9524], [0, -7834, 163020, 0], [191496, 14598, -206094, 14598], [-165090, 0, 0, -3943], [0, -7146, -441378, 0], [542359, 8274, -550633, 8274], [533642, 0, 0, 1546], [482452, 6948, -489400, 6948], [-551254, 0, 0, -6090], [14213, 0, 0, 4845], [-13533, 31881, -18348, 31881], [0, -23699, 57313, 0], [0, 1318, 687306, 0], [655032, 0, 0, 702], [678151, -15747, -662404, -15747], [-1446225, 0, 0, 8223], [0, -2448, 613146, 0], [-464958, -3090, 468048, -3090], [-247807, -41933, 289740, -41933], [0, 42443, -30014, 0], [-655142, 5439, 649703, 5439], [1385690, 0, 0, 5926], [599336, -7171, -592165, -7171], [1110399, 0, 0, -17697], [-307298, 0, 0, -40721], [2181188, -3158, -2178030, -3158], [0, 21478, 254389, 0], [0, -24537, 2478978, 0], [0, -8409, 2592187, 0], [2935041, 0, 0, -3676], [-1662276, 35004, 1627272, 35004], [-1608374, 0, 0, -53432], [1533444, -54126, -1479318, -54126], [0, 6914, 3427776, 0], [-1912895, 53520, 1859375, 53520], [0, -36821, -1376549, 0], [3511138, 0, 0, 12895], [0, 214, 2051928, 0], [8630, -50084, 41454, -50084], [0, -57457, 1274899, 0], [0, 37500, 1494948, 0], [1199269, -75750, -1123519, -75750], [-2767668, 0, 0, 8874], [4762368, 0, 0, -30385], [-1955640, 8250, 1947390, 8250], [-2481940, 0, 0, 75717], [0, 98843, 1241458, 0], [0, 69967, 2730534, 0], [-1350212, 0, 0, 96986], [0, 152158, -87521, 0], [-315134, 0, 0, 169094], [968194, 0, 0, 134755], [0, -51994, -5418342, 0], [9486982, -3022, -9483960, -3022], [-118691, 64548, 54143, 64548], [-58029, 0, 0, 114543], [0, -104429, -150587, 0], [-44700, 0, 0, 42234], [0, -124191, 455304, 0], [6892434, 98166, -6990600, 98166], [0, -61125, 5056651, 0], [0, -26053, 2267653, 0], [-2637132, 0, 0, -174952], [6840287, 157993, -6998280, 157993], [-250031, -87373, 337404, -87373], [0, 205554, 4371282, 0], [5540136, -220715, -5319421, -220715], [3074081, -19456, -3054625, -19456], [-5681527, 0, 0, -16895], [0, 49986, 13198758, 0], [-9843222, -77298, 9920520, -77298], [-4629541, 0, 0, -76476], [0, -137500, 1942873, 0], [1572480, 321058, -1893538, 321058], [-4376746, 0, 0, -216272], [-278164, -143185, 421349, -143185], [-4178791, 0, 0, -237111], [-5645930, -85114, 5731044, -85114], [4630340, 0, 0, 166935], [10055226, 4680, -10059906, 4680], [0, 20691, 9149988, 0], [17439968, 0, 0, 75940], [9841664, -235729, -9605935, -235729], [-10208071, 0, 0, -29022], [0, 52125, 11204442, 0], [-9581709, -37641, 9619350, -37641], [0, 354927, 9086551, 0], [1441903, 0, 0, -2905], [0, 330360, 5474146, 0], [0, -365736, 7469070, 0], [3229237, 0, 0, -530294], [0, -149533, -21075167, 0], [12042504, 132457, -12174961, 132457], [16580358, 0, 0, -194784], [0, -235990, 13325335, 0], [-7795278, 0, 0, -276040], [0, 156808, 14343840, 0], [-6189239, 0, 0, -48950], [-8566078, -241244, 8807322, -241244], [19293426, -21110, -19272316, -21110], [-12934287, 0, 0, 216849], [-5931028, 425662, 5505366, 425662], [-2689262, 0, 0, 3874], [0, -55031, -11788392, 0], [27533720, -115096, -27418624, -115096], [11578191, 0, 0, -527991], [21760106, 43499, -21803605, 43499], [-12028756, 0, 0, -345632], [-6606292, 0, 0, 272769], [-6604590, 727362, 5877228, 727362], [0, -641442, 3247804, 0], [0, 504908, -5019102, 0], [0, -601742, -4879550, 0], [6360102, 0, 0, 718254], [-11187046, 0, 0, 796023], [0, 3942, -15433998, 0], [-3984486, 548053, 3436433, 548053], [10882242, 0, 0, 647898], [0, 104299, -15247613, 0], [0, 126636, -7560810, 0], [991451, 0, 0, 108348], [10471127, 562867, -11033994, 562867], [0, -211054, -15880686, 0], [-35549662, 0, 0, -52994], [-5980351, 0, 0, 454374], [0, -1126767, 22218, 0], [17071242, 599484, -17670726, 599484], [11306868, 957168, -12264036, 957168], [-9152081, -469800, 9621881, -469800], [-12951044, 92967, 12858077, 92967]];
    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_6_k_e();".
// 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_6_k_e(:prec:=4)
    chi := MakeCharacter_252_k();
    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_252_6_k_e();".
// 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_6_k_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_252_k();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![1483524, 57246, 3427, -47, 1]>],Snew);
    return Vf;
end function;