
// Make newform 546.4.l.h in Magma, downloaded from the LMFDB on 15 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_546_l();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_546_l_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_546_4_l_h();".
// 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_546_4_l_h();".
// 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 := [1979894016, -452924784, 134848233, -12165606, 2657151, -176472, 37612, -1187, 218, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [9783021566002129488, -598994776703489760, 165693405718363410, -43023530436087069, 2711777331630600, -171971462149010, 10225419141385, -709244146510, 65004637490, 2087315101], [738682920836352769536, 825016138865442868707, -28162627521976377522, 17168362886971323189, -1153615233798737128, 289425733625121588, -8496992120212513, 1668062055190782, -11582967294587, 8143072008139], [-1680715624099735172592, 138364725229760961360, -38274328001283034635, 2831031190256138424, -626406673260689100, 39724526879116235, -3310369651390627, 163831764932485, -15015738291515, 608388106031], [-13213159721445699977472, -8647660162780597850157, 20619087547899343455, -173452961748351099354, -3433942819728269881, -2989818401764186536, 13280410647179012, -18471496053999366, -364874105326490, -93227252809367], [2041754492758086199017, -299960823351061688112, 82974897839092023117, -5306633302571383158, 1357986735071843220, -86118783310589837, 10782998698954108, -355170806855587, 32552612045213, -2788594780523], [-566374114687840270443, 78862683641779176480, -21814925847282650430, 882178915376975598, -357028218156223800, 22641484604439230, -3119609992674673, 93377937381730, -8558405450270, 953059197149], [419770633285416395718144, 59908955196242916411147, 11310368517950656759182, 2200586628404976038061, 396119569293756748120, 40813930983518597652, 3013365908869338343, 420541014912266718, 25759476066588797, 1663227306040451], [141268084374332443507200, 15010829743527616944177, 2852787277394986967082, 1004351204170549516263, 92250453510698022104, 18052355833923957180, 740339164298150357, 167520507089531514, 7539927197758807, 663219885876457]];
    Rf_basisdens := [1, 1, 2087220060201337659, 3439738659211804462032, 18784980541812038931, 644950998602213336631, 18784980541812038931, 6261660180604012977, 10319215977635413386096, 3439738659211804462032];
    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_546_l();"
function MakeCharacter_546_l()
    N := 546;
    order := 3;
    char_gens := [365, 157, 379];
    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_546_l_Hecke();"
function MakeCharacter_546_l_Hecke( : Kf := false)
    N := 546;
    order := 3;
    char_gens := [365, 157, 379];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 1, 0, 0, 0, 0, 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 := 4;
    raw_aps := [[0, 0, 0, -2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 3, 0, 0, 0, 0, 0, 0], [-2, 0, 1, 0, 0, 0, 0, 0, 0, 0], [7, 0, 0, -7, 0, 0, 0, 0, 0, 0], [0, -1, 0, -4, 0, 0, 0, 0, 0, 1], [0, -1, 1, -4, 0, -1, -1, 0, 0, 1], [-2, 2, -2, 2, 0, 0, 1, 0, -1, 0], [3, -6, 6, -3, 1, -1, 0, -2, 0, -2], [0, 3, 0, -11, 0, -3, 0, 0, 1, -2], [0, -8, 0, -27, 0, 2, 0, 0, -1, 3], [35, 0, 9, 0, -1, 0, 0, -5, 0, 0], [0, 5, 0, 36, 0, 2, 0, 0, 0, -2], [0, -4, 0, 72, 0, -4, 0, 0, -2, 3], [115, 21, -21, -115, 1, -1, 1, 12, -1, 12], [41, 0, -21, 0, 6, 0, 8, 2, 0, 0], [-3, 0, -2, 0, -6, 0, 12, -6, 0, 0], [-61, 1, -1, 61, 13, -13, 15, 10, -15, 10], [-47, -26, 26, 47, 16, -16, 2, 16, -2, 16], [0, -18, 0, 49, 0, -10, 0, 0, 5, -2], [0, -11, 11, 0, 13, -13, 9, 29, -9, 29], [-72, 0, 29, 0, -2, 0, 9, -15, 0, 0], [-27, 0, -51, 0, 6, 0, 6, 26, 0, 0], [42, 0, -11, 0, -1, 0, 18, 8, 0, 0], [0, 4, 0, 205, 0, -23, 0, 0, 16, -16], [-293, -65, 65, 293, -27, 27, 0, -21, 0, -21], [0, 43, 0, -597, 0, -30, 0, 0, -11, 40], [155, 0, -62, 0, 2, 0, 14, 9, 0, 0], [0, -23, 0, 212, 0, -18, 0, 0, -7, 52], [-53, 0, -32, 0, 20, 0, -11, -6, 0, 0], [313, -51, 51, -313, 10, -10, 22, 27, -22, 27], [0, 147, 0, -114, 0, 5, 0, 0, -4, -18], [-298, 0, -21, 0, -3, 0, 22, -24, 0, 0], [-541, 126, -126, 541, 35, -35, 12, 15, -12, 15], [-319, 36, -36, 319, -43, 43, -7, -41, 7, -41], [328, -239, 239, -328, 4, -4, 22, 40, -22, 40], [302, 0, 138, 0, -55, 0, -12, 9, 0, 0], [-199, 0, -29, 0, -12, 0, -20, 1, 0, 0], [-1483, -138, 138, 1483, -6, 6, 10, -9, -10, -9], [0, 186, 0, 289, 0, 8, 0, 0, -22, -21], [931, -127, 127, -931, 69, -69, -5, 56, 5, 56], [0, -114, 0, -1189, 0, 60, 0, 0, 9, 2], [-3, 0, 37, 0, -35, 0, -81, -29, 0, 0], [1275, 161, -161, -1275, 63, -63, -5, 44, 5, 44], [0, -31, 0, 459, 0, -3, 0, 0, 15, -7], [0, 181, 0, 812, 0, -10, 0, 0, 53, 10], [1866, 141, -141, -1866, -49, 49, -35, 1, 35, 1], [0, -117, 0, 687, 0, 61, 0, 0, -9, -38], [0, 176, 0, -447, 0, 58, 0, 0, -44, -59], [631, -237, 237, -631, -13, 13, -72, -137, 72, -137], [155, 0, 55, 0, 94, 0, -27, -49, 0, 0], [269, 0, -120, 0, 62, 0, 80, 61, 0, 0], [-508, 0, -40, 0, 32, 0, 2, 158, 0, 0], [-3495, 99, -99, 3495, -34, 34, -50, -15, 50, -15], [1105, 69, -69, -1105, -93, 93, -22, -95, 22, -95], [0, 11, 0, -1730, 0, 75, 0, 0, 75, 22], [0, -223, 0, 2884, 0, 7, 0, 0, 17, 19], [253, -141, 141, -253, -33, 33, -48, -193, 48, -193], [0, -102, 0, 1672, 0, 120, 0, 0, 23, -93], [4014, 74, -74, -4014, -95, 95, 2, 78, -2, 78], [-2473, 0, -167, 0, 32, 0, 102, 131, 0, 0], [0, -410, 0, -781, 0, 40, 0, 0, 17, -102], [-2082, 265, -265, 2082, -58, 58, 74, 176, -74, 176], [-457, 0, -124, 0, -5, 0, -81, 157, 0, 0], [920, 0, -26, 0, -111, 0, -135, -80, 0, 0], [1328, 0, 157, 0, 25, 0, 60, 220, 0, 0], [-1390, 0, -288, 0, 9, 0, 73, -91, 0, 0], [2669, 332, -332, -2669, -180, 180, 55, 48, -55, 48], [-1929, 0, 317, 0, -1, 0, 88, 56, 0, 0], [853, 368, -368, -853, -93, 93, 49, 9, -49, 9], [0, 94, 0, -893, 0, 52, 0, 0, -19, 116], [0, 175, 0, 841, 0, -70, 0, 0, -104, -33], [-3826, 0, 152, 0, -118, 0, -40, -100, 0, 0], [0, 437, 0, 3075, 0, 15, 0, 0, -65, 94], [-347, -137, 137, 347, -102, 102, 89, -76, -89, -76], [0, -136, 0, 1482, 0, -28, 0, 0, 110, 24], [3420, -384, 384, -3420, -55, 55, -58, -149, 58, -149], [-400, 0, 80, 0, -223, 0, 78, -60, 0, 0], [-5642, 255, -255, 5642, 46, -46, -20, 59, 20, 59], [0, -412, 0, 1893, 0, -199, 0, 0, -167, 6], [5401, 110, -110, -5401, 137, -137, 75, 78, -75, 78], [0, -385, 0, 3212, 0, -227, 0, 0, -24, -164], [-4323, 0, -383, 0, -6, 0, 132, 121, 0, 0], [0, 303, 0, -807, 0, 7, 0, 0, -216, -19], [7097, 630, -630, -7097, 119, -119, 64, -171, -64, -171], [0, -172, 0, -269, 0, 198, 0, 0, 215, 4], [1013, 0, 428, 0, 35, 0, -64, -400, 0, 0], [-142, -325, 325, 142, 83, -83, 18, -86, -18, -86], [0, -137, 0, 531, 0, 2, 0, 0, -203, 172], [3749, -701, 701, -3749, -46, 46, 192, 111, -192, 111], [-2183, 0, 345, 0, -20, 0, 191, -39, 0, 0], [77, 0, 796, 0, 250, 0, -221, -14, 0, 0], [0, 81, 0, -1502, 0, 254, 0, 0, -91, 306], [6189, 130, -130, -6189, -177, 177, 99, -323, -99, -323], [0, 1246, 0, 3091, 0, -40, 0, 0, 19, -12], [-1570, 0, -692, 0, -66, 0, -105, 203, 0, 0], [-4151, 1138, -1138, 4151, -68, 68, 82, 101, -82, 101], [0, 310, 0, 296, 0, 27, 0, 0, 88, 216], [8843, 0, -910, 0, -274, 0, -109, -85, 0, 0], [0, -35, 0, 1673, 0, 254, 0, 0, 356, -464], [-4297, 0, 22, 0, -193, 0, -141, -292, 0, 0], [-64, 0, 40, 0, 260, 0, 97, 533, 0, 0], [0, 56, 0, 5909, 0, 30, 0, 0, -47, -203], [6594, -160, 160, -6594, -242, 242, -73, -277, 73, -277], [0, 221, 0, 2621, 0, -49, 0, 0, -7, 228], [812, 0, -176, 0, -120, 0, 37, -295, 0, 0], [-4433, 0, 703, 0, -46, 0, 131, -168, 0, 0], [0, -877, 0, -599, 0, -231, 0, 0, 212, -249], [-7293, 0, -1052, 0, 118, 0, 117, 287, 0, 0], [4753, 0, -936, 0, -204, 0, -136, 297, 0, 0], [0, 1075, 0, 1024, 0, 60, 0, 0, 196, 226], [-7150, 264, -264, 7150, -42, 42, -385, 147, 385, 147], [0, -901, 0, -6020, 0, -158, 0, 0, -92, 364], [11482, 39, -39, -11482, 156, -156, 104, -130, -104, -130], [1564, 0, -1332, 0, 425, 0, 124, 489, 0, 0], [-1820, 710, -710, 1820, 213, -213, 213, 592, -213, 592], [12111, -849, 849, -12111, 232, -232, 313, 324, -313, 324], [2483, -626, 626, -2483, 285, -285, -294, 308, 294, 308], [0, 260, 0, 7157, 0, 145, 0, 0, -235, -107], [0, 334, 0, -675, 0, -213, 0, 0, -192, 96], [3211, 473, -473, -3211, -292, 292, -100, -78, 100, -78], [0, 103, 0, 5817, 0, -66, 0, 0, -238, 297], [0, -1101, 0, 12691, 0, 89, 0, 0, 103, 587], [3619, 0, -828, 0, 236, 0, 157, 158, 0, 0], [3879, 1663, -1663, -3879, -295, 295, -119, 10, 119, 10], [0, -589, 0, -13183, 0, 399, 0, 0, 429, -672], [-7731, 0, 486, 0, -353, 0, -185, -169, 0, 0], [1106, -141, 141, -1106, -20, 20, -121, -631, 121, -631], [10928, -7, 7, -10928, -288, 288, -269, -182, 269, -182], [-2511, 0, 1044, 0, 390, 0, 25, 512, 0, 0], [1652, 0, -800, 0, 242, 0, -71, 96, 0, 0], [0, 2027, 0, 10085, 0, -295, 0, 0, -117, 348], [0, 198, 0, 14071, 0, 278, 0, 0, -359, 72], [0, -1110, 0, 11401, 0, 79, 0, 0, -313, -65], [0, 925, 0, 1799, 0, -701, 0, 0, 5, -82], [-3601, -1239, 1239, 3601, -5, 5, 74, -107, -74, -107], [0, -2214, 0, -6196, 0, 246, 0, 0, 244, 94], [838, 50, -50, -838, -670, 670, 105, 501, -105, 501], [-8663, -808, 808, 8663, -347, 347, -83, 527, 83, 527], [19362, 183, -183, -19362, 161, -161, 425, 343, -425, 343], [0, 778, 0, -6910, 0, 267, 0, 0, 249, 305], [9538, 0, 1057, 0, 467, 0, 479, 665, 0, 0], [0, -386, 0, 3554, 0, -163, 0, 0, -310, 731], [17833, -438, 438, -17833, -28, 28, 432, 523, -432, 523], [-3956, 0, 560, 0, 268, 0, -681, -21, 0, 0], [0, -1044, 0, 11030, 0, -362, 0, 0, 222, -85], [3909, 602, -602, -3909, 588, -588, 5, -692, -5, -692], [-1656, 0, 3269, 0, -31, 0, 221, 128, 0, 0], [-12441, 0, -532, 0, 439, 0, -231, -456, 0, 0], [3035, 0, 2971, 0, 106, 0, -130, 258, 0, 0], [14133, 0, 1819, 0, -543, 0, -499, -626, 0, 0], [-7223, 1542, -1542, 7223, -67, 67, -293, -802, 293, -802], [0, 902, 0, 16305, 0, -209, 0, 0, 197, 714], [-9695, 0, -49, 0, 725, 0, 334, 15, 0, 0], [0, -2144, 0, -12294, 0, 483, 0, 0, 414, -247], [0, -157, 0, 13782, 0, 583, 0, 0, 352, -44], [2871, 0, -6, 0, -192, 0, -126, -645, 0, 0], [-1335, -659, 659, 1335, -208, 208, -206, 90, 206, 90], [10102, 1863, -1863, -10102, 691, -691, -185, 496, 185, 496], [7826, 0, -2436, 0, 587, 0, -118, 668, 0, 0], [14902, 0, -2575, 0, -235, 0, 20, 662, 0, 0], [0, -967, 0, -11299, 0, 494, 0, 0, 246, 306], [7496, -1680, 1680, -7496, 176, -176, -525, -1363, 525, -1363], [16027, 0, 1614, 0, 12, 0, 332, 189, 0, 0], [-8137, -220, 220, 8137, 8, -8, -532, -241, 532, -241], [0, 975, 0, 10725, 0, -108, 0, 0, 1197, 264], [3937, 0, 2032, 0, -450, 0, -412, -409, 0, 0], [0, -2062, 0, -3309, 0, -1171, 0, 0, -103, 1121], [15210, -1760, 1760, -15210, 64, -64, -390, -685, 390, -685]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_546_l_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_546_4_l_h();".
// 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_546_4_l_h(:prec:=10)
    chi := MakeCharacter_546_l();
    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_546_4_l_h();".
// 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_546_4_l_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_546_l();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-23050, 10431, -544, -185, 9, 1]>],Snew);
    return Vf;
end function;