
// Make newform 504.6.a.o in Magma, downloaded from the LMFDB on 13 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_504_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_504_6_a_o();".
// 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_504_6_a_o();".
// 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 := [-282, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-2, 4]];
    Rf_basisdens := [1, 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_504_a();"
function MakeCharacter_504_a()
    N := 504;
    order := 1;
    char_gens := [127, 253, 281, 73];
    v := [1, 1, 1, 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;

function MakeCharacter_504_a_Hecke( : Kf := Kf)
    return MakeCharacter_504_a();
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, -1], [-49, 0], [-50, 1], [270, 8], [-576, -3], [1472, -18], [-1342, 49], [-498, 30], [1308, 62], [-1746, 124], [-8508, 83], [6820, -116], [-5916, -254], [-18774, 240], [3160, -382], [19882, -154], [-13688, -806], [-17730, 415], [32094, 418], [-55044, 406], [2948, 156], [-83580, -549], [-5938, -338], [-11692, -879], [-110876, -242], [134854, 1421], [-140914, -1032], [-66706, 1200], [-76860, -1406], [75652, 2404], [-85910, 482], [-118812, 3532], [-19158, 1872], [-177088, 3724], [-76118, -6250], [-10304, -730], [185340, -1382], [-231580, -6323], [-162734, -2753], [-518746, -4624], [33126, 11711], [31850, -412], [-473030, -4672], [-35904, -12444], [853404, 612], [108944, 1840], [-67072, -13606], [-427282, -13204], [-290630, 11146], [-613286, -455], [419574, 17098], [-368320, 6358], [783852, -2701], [-454358, 11741], [-1644552, 2815], [-916444, 4522], [259446, -14648], [-292326, 31410], [1495280, -11710], [1492964, 10777], [282240, -30482], [1689964, -19526], [-1810966, 12488], [1198810, -2740], [1526292, 21188], [1190122, 3292], [396994, 16043], [-443990, 31190], [-919616, -44523], [2180982, -23877], [-1894896, 35032], [60022, -58968], [5011364, -3036], [4593320, -3356], [-4371866, -12066], [1123738, -52842], [1405258, -4906], [3252238, -17454], [107320, -51578], [4722182, 5288], [4803686, -12217], [1243786, 17340], [-784896, -2676], [-2678158, 9043], [-6171618, 9568], [-3116438, 15072], [2483676, -80055], [2659148, 17646], [745456, 12618], [2489268, 67362], [-1351368, 57584], [-3252006, -56001], [1925604, -37240], [-2716576, 908], [-3140344, 101759], [531264, -41991], [-470308, 56264], [-12966018, 1016], [3970640, -68882], [1308250, -38540], [-4477928, -136706], [4135474, -158258], [-1198016, 131994], [-5095846, 147260], [-5523360, -133026], [-2593600, -39859], [3934422, -116253], [-5328430, -150660], [-4541400, -15028], [1770910, -29932], [10925594, -13606], [-13388260, 50792], [-6143908, -73118], [7037738, 139870], [-300032, -23178], [-8696604, -33410], [13367414, -75670], [7580598, 53577], [-14834974, 66822], [-3093414, -131252], [-7730756, -113467], [-9264502, 153991], [-13439620, -81772], [5476046, 105646], [-7024266, -80304], [-12141696, -48040], [19347972, 114070], [2421518, -41952], [1758304, 67590], [-1872922, -155709], [5078384, 244136], [2434278, 147088], [8659188, -120045], [17747898, -111412], [-23709460, 55101], [-14098732, -24960], [5702820, 246021], [4939806, -252364], [4446708, -58412], [-10635470, 122212], [6063580, -337054], [4093646, -196503], [2939294, -474888], [-19396500, -19182], [10237778, 297726], [-3673036, -120893], [-19660992, 264698], [-22902678, -54503], [-8417626, 12676], [9692184, -349095], [-18544940, 65616], [-8828228, -86846], [15260420, -216852], [26332902, 339879], [-11765176, 98112], [-20325340, 230495], [32728378, 239448], [9753464, -418241], [2544806, -285103], [34950694, 157424], [40367356, -53606], [23514316, -151396], [20556282, 261230], [22139528, 31792], [-7457888, 21832], [-2474366, -127986], [27198538, -303140], [-22965324, 61593], [35561246, -34415], [-4650214, -755650], [31684006, 417779], [-1088054, 465040], [-37230440, 197532], [56207096, -168323], [-19031016, 632614], [-12085018, 522734], [26812500, -241914], [-13635830, 498814], [42822420, 246778], [982596, 165780], [7212150, -816304], [-44883184, 127249], [25021410, -97315], [-41434772, -541483], [2012942, -455264], [-19804924, 840320], [-11555718, -49544], [-37803520, -248640], [26512454, -284694], [-406354, 543617], [-13420844, -877872], [24228172, -192919], [-71046338, -84379], [12204264, 386205], [14521434, 575300], [-80925330, -64032], [-18934044, 613631], [-57649852, 15742], [-4437062, -352044], [19347504, 1147496], [-26964402, 114564], [-259330, -249914], [-5788756, -970404], [-64646476, -337171], [11330880, -812040], [41963830, -691919], [-7708162, 262852], [-27277376, -317758], [30645570, 198488], [27310280, 347803], [30289064, 1298304], [25319284, 180728], [-3385148, 96542], [-96165830, -300008], [19533968, 1170904], [10924184, 1404985], [-11530422, 462261], [-36599922, 665518], [-79479514, 69336], [-114978540, -204194], [-68506266, -958892], [-84736000, -114992], [12947132, 417224], [105291422, -192356], [58533092, 438955], [-15085390, 154653], [-23799412, -295438], [77405354, -426457], [28588126, 1582048], [-3412768, 1422574], [-39457712, -946016], [105390950, -459256], [159832, -1268130], [-90537536, -331496], [-31675906, 1311726], [-119278622, -322628], [57890362, -430729], [14718576, -1101940], [-37985486, -1461761], [-76170684, 1404164], [-9178888, -2109312], [31149998, 1112232], [13483236, -1863897], [59912724, 462462], [-63259380, -96298], [-55192912, 176066], [13532736, 2441794], [-36022990, 1290805], [80452254, -620552], [-29369280, 304965], [11581886, 1492127], [28041454, 694090], [-40682300, -907939], [451830, -624759], [42943382, 557432], [79444304, 1386738], [-23398516, 620157], [-5548598, -1040488], [54695692, -445386], [-6190614, -1477053], [129224750, 1193564], [171515354, 112974], [99376888, -569871], [163553652, -652712], [-195141190, 250980], [98680720, 790825], [45588760, 2066630], [-40217002, 121302], [-45060622, -745006], [73239844, 1051544], [-49370274, 2294042], [-11891848, 3329252], [154791406, 243542], [35203140, 2183126], [56330814, 280721], [13518846, -3475304], [39418178, 771836], [-91407728, 2598602], [71948624, -506744], [-62524676, 1263018], [-145998472, 1515464], [-7986302, 558814], [164708764, 1068584], [214283318, -429297], [112097442, -739384], [-73690870, 2940800], [123715292, -1276110], [-66622516, 2858099], [119303242, -1593172], [-73475452, 33724], [-26448886, 3438746], [-186076336, -335498], [-100173410, 1803648], [147187028, 653597], [37070376, -4032404], [231763240, -1235893], [-157394360, -1987286], [55607340, 3061604], [133533762, -1454244], [146537734, 2048370], [-120435540, 1828334], [231836142, -344619], [-35880480, -2738518], [-224778614, 62148], [-213301246, 15347], [-120699738, -452972], [-1239354, 2562699], [137167638, 318320], [141695616, 1729320], [133345094, -1909402], [-214331166, 1675706], [-51971452, 4804976], [87698746, 867893], [68173230, 407482], [-51789700, -976216], [-189991158, -2892567], [317768822, -624574], [50766170, 2741358], [-81053016, 2663042], [43087858, 4965516], [27894556, 4414593], [-210082880, -2123784], [-78157330, 4317884], [278346478, -647370], [-90201096, -2143390], [62675736, 2376470], [-8942234, 3120431], [-162442322, -3786206], [33646558, -1475744], [126558710, 1979042], [-124315948, 1463402], [265370472, -928930], [-201773376, -567086], [-154323504, -4442162], [-54419482, 469900], [-266493716, 673859], [-49343098, -2185354], [10275300, -2706694], [138320198, -2905008], [84626778, 4273938], [94866792, -412653], [-192248848, 1521980], [122642838, -4546094], [235446830, 2368877], [370723374, -917396], [131833508, 1579132], [-266430680, 307564], [62115332, 4455953], [-3467416, 2566138], [-225474654, -1801428], [-256610758, 2647556], [313833456, 173160], [82548294, -5025376], [-78616504, 2581157], [203552864, 2691776], [-49139444, 1768988], [-191026578, -2995392], [210858022, -886197], [-353829642, -213888], [-385567604, -500537], [-34243546, -3531481], [197848622, -2356935], [-28378580, -2725788], [100092530, 2060452], [120122560, -2863357], [-103366844, -5612034], [-425972718, -1800612], [80581602, 4077999], [-38026888, 526302], [133884462, -5731157], [-283836222, -5060404], [72766220, 631770], [-367141570, 1907208], [458354036, -535724], [-45142270, 2923381], [207363018, 5786724], [-356584000, 1471405], [-196643090, -2949774], [3288156, 1872129], [166295454, -299772], [-75832048, 6044980], [-45008538, 3836724], [-301820508, -4352160], [399449464, 4799024], [-45202520, -3195276], [177950534, -2507360], [9361368, -7236458], [-87941548, 3733058], [-444029166, -1308376], [92543296, 1921279], [451983510, 2935365], [74856192, -5067634], [-124948226, -4652361], [-111825070, 4551676], [9934424, -1703004], [25654184, 1645709], [-228290520, 1901110], [-159170738, 4042234], [153658690, 3363042], [230886510, -4945464], [559456180, -2337646], [-364555564, -770989], [381176352, 3332303], [-208190168, 1274664], [-226179282, 5298120], [158399062, 1323236], [266822332, 4981236], [277204104, 1022814], [120531258, 4339268], [330253878, 2073102], [159558082, -2977909], [644374460, -173348], [-216290694, -2327176], [54062464, 1864291], [211185026, -3953659], [652572636, -3050246], [271923768, -4740759], [-266676444, 2713350], [-375720970, -7096718], [-150437590, 2741522], [-94578482, 5679707], [104983356, -1042772], [319468850, -3751724], [60969220, -10842083], [127898194, 5743231], [-338226222, -6173922], [61400748, -3871128], [203572588, 5061962]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_504_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_504_6_a_o();".
// 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_504_6_a_o(:prec:=2)
    chi := MakeCharacter_504_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_504_6_a_o();".
// 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_504_6_a_o( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_504_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![-4516, 0, 1]>,<11,R![-2016, 100, 1]>],Snew);
    return Vf;
end function;