
// Make newform 126.6.g.e in Magma, downloaded from the LMFDB on 08 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_126_g();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_126_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_126_6_g_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_126_6_g_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 := [16900, 0, 130, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 0, 1, 0], [0, 260, 0, 1], [0, 130, 0, -1]];
    Rf_basisdens := [1, 130, 65, 65];
    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_126_g();"
function MakeCharacter_126_g()
    N := 126;
    order := 3;
    char_gens := [29, 73];
    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_126_g_Hecke();"
function MakeCharacter_126_g_Hecke( : Kf := false)
    N := 126;
    order := 3;
    char_gens := [29, 73];
    char_values := [[1, 0, 0, 0], [0, 1, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), 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, 4, 0, 0], [0, 0, 0, 0], [0, 21, 0, 0], [29, -58, 1, 2], [-147, -147, -7, -7], [-70, 0, 2, -4], [651, 651, 6, 6], [0, -721, -34, 17], [0, -1323, -70, 35], [-834, 0, -14, 28], [7399, 7399, 25, 25], [0, 2591, -252, 126], [2562, 0, -214, 428], [-2260, 0, -112, 224], [0, 7497, -274, 137], [12003, 12003, 98, 98], [19425, 19425, -321, -321], [0, -11809, 284, -142], [-16001, -16001, -623, -623], [44688, 0, 196, -392], [23569, 23569, -240, -240], [0, -20485, 686, -343], [-34188, 0, 172, -344], [0, -61551, -1096, 548], [-21826, 0, 1370, -2740], [-2457, -2457, 196, 196], [0, -149149, 334, -167], [0, 64737, -4102, 2051], [34009, 34009, -1148, -1148], [13938, 0, 1526, -3052], [-28744, 0, -3164, 6328], [0, -112203, -1234, 617], [-39213, -39213, 2170, 2170], [-141484, 0, 924, -1848], [0, 249237, 4592, -2296], [181711, 181711, 3437, 3437], [80605, 80605, -2922, -2922], [0, 337091, -8470, 4235], [-31164, 0, -3842, 7684], [0, -424263, 8476, -4238], [313317, 313317, -3899, -3899], [260582, 0, -8312, 16624], [0, 337353, 3934, -1967], [-647171, -647171, -602, -602], [-155802, 0, 2282, -4564], [348439, 348439, -895, -895], [-450916, 0, 140, -280], [-466312, 0, 10692, -21384], [-267939, -267939, 16993, 16993], [0, -758653, 14600, -7300], [0, -218019, 196, -98], [-641196, 0, -9366, 18732], [144865, 144865, -6304, -6304], [990360, 0, -5574, 11148], [0, -135723, 26164, -13082], [-991515, -991515, -1183, -1183], [-172557, -172557, -23294, -23294], [0, -1174621, -25642, 12821], [-860147, -860147, -154, -154], [-1173222, 0, 17262, -34524], [1587859, 1587859, 8807, 8807], [1488522, 0, 9952, -19904], [-589708, 0, -11712, 23424], [873117, 873117, -17027, -17027], [0, -1582777, -12080, 6040], [0, 1004217, 52780, -26390], [0, 2015003, -18550, 9275], [-1417066, 0, -28994, 57988], [-38751, -38751, 8463, 8463], [2221730, 0, 7070, -14140], [-1053213, -1053213, 31098, 31098], [0, 2169249, -66962, 33481], [46291, 46291, 7419, 7419], [0, 1459031, -57316, 28658], [507680, 0, -7182, 14364], [0, 1391985, -59770, 29885], [-2444889, -2444889, 34580, 34580], [0, 355187, 106816, -53408], [0, -405291, -7868, 3934], [52717, 52717, 40950, 40950], [3268860, 0, -20416, 40832], [-1538974, 0, 32074, -64148], [3670785, 3670785, -39557, -39557], [-690466, 0, 80258, -160516], [0, -2905105, 78642, -39321], [0, 1529289, 165746, -82873], [-1807782, 0, 30898, -61796], [0, 1107143, 6272, -3136], [1545054, 0, 21482, -42964], [83696, 0, 49280, -98560], [0, -1097187, 50886, -25443], [-6065451, -6065451, -19895, -19895], [2251, 2251, 60935, 60935], [1078992, 0, -38850, 77700], [0, 5132867, 104538, -52269], [-1044624, 0, 32732, -65464], [0, 3134229, 184264, -92132], [2450343, 2450343, 50532, 50532], [0, 4722095, -118922, 59461], [0, -2205877, 39256, -19628], [-387568, 0, 74102, -148204], [8486343, 8486343, 39340, 39340], [-3358383, -3358383, 61959, 61959], [0, 5683353, -120848, 60424], [2855635, 2855635, 118615, 118615], [1976065, 1976065, 155104, 155104], [-4338012, 0, 111944, -223888], [0, 538461, -171364, 85682], [7526877, 7526877, 413, 413], [2110262, 0, -34166, 68332], [0, 10938431, -156854, 78427], [10766353, 10766353, 5264, 5264], [3001986, 0, -113190, 226380], [-1361129, -1361129, -178547, -178547], [14348192, 0, 22652, -45304], [5148975, 5148975, -88200, -88200], [4111268, 0, -37296, 74592], [-16200051, -16200051, -10491, -10491], [0, -5053911, -129780, 64890], [9122676, 0, 60620, -121240], [-13094459, -13094459, -117798, -117798], [4349126, 0, 57470, -114940], [0, 6313293, -261304, 130652], [-428907, -428907, -121555, -121555], [0, 1367387, 88562, -44281], [3711522, 0, 149464, -298928], [0, -10326241, -4060, 2030], [0, 1449021, 449226, -224613], [-6886096, 0, 150660, -301320], [0, 4710167, 439300, -219650], [-1241453, -1241453, -170009, -170009], [-7043424, 0, 256060, -512120], [0, -4865209, 132706, -66353], [2549066, 0, -232666, 465332], [0, 8568021, -400356, 200178], [5646326, 0, 58646, -117292], [-4696041, -4696041, 6044, 6044], [-8664761, -8664761, 241109, 241109], [3521070, 0, -2358, 4716], [-4443441, -4443441, 369264, 369264], [21496412, 0, -129480, 258960], [0, -631347, -783720, 391860], [-4307069, -4307069, -169645, -169645], [-12975276, 0, 16184, -32368], [-5727239, -5727239, -236236, -236236], [24505656, 0, 67808, -135616], [17527874, 0, 128274, -256548], [740607, 740607, -39400, -39400], [0, 7949207, -86674, 43337], [0, -2456379, 568610, -284305], [0, 12332603, 171416, -85708], [-19080978, 0, -19256, 38512], [8976428, 0, 106148, -212296], [0, 15516921, 255126, -127563], [-7585505, -7585505, 389249, 389249], [18173520, 0, -200256, 400512], [0, -15011857, -423150, 211575], [0, 13731417, -116728, 58364], [-3285478, 0, -437928, 875856], [15538299, 15538299, -179938, -179938], [0, 13824645, -269906, 134953], [-29133078, 0, 8470, -16940], [-13443328, 0, -308252, 616504], [0, 18734373, 912950, -456475], [797715, 797715, 580930, 580930], [-20512863, -20512863, -303941, -303941], [-612965, -612965, 278047, 278047], [35654101, 35654101, -24606, -24606]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_126_g_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_126_6_g_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_126_6_g_e(:prec:=4)
    chi := MakeCharacter_126_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_126_6_g_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_126_6_g_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_126_g();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![441, 21, 1]>],Snew);
    return Vf;
end function;