
// Make newform 504.4.a.i in Magma, downloaded from the LMFDB on 14 September 2025.
// 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_4_a_i();".
// 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_4_a_i();".
// 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 := [-14, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    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 := 4;
    raw_aps := [[0, 0], [0, 0], [-11, -1], [7, 0], [-18, -6], [21, -5], [-4, 6], [-59, 13], [52, -4], [28, -22], [10, -14], [252, -10], [272, 18], [206, -14], [250, -14], [-134, 72], [99, -13], [-173, -31], [504, -68], [612, 44], [358, -36], [292, 36], [615, 47], [-298, -160], [-428, -70], [-1755, 15], [294, 38], [1380, 40], [352, -14], [228, 286], [1616, 0], [-485, 3], [1042, -228], [1371, 19], [518, 68], [-1496, -208], [-3219, 3], [-626, 42], [438, -250], [-2369, 73], [-452, 344], [-547, 331], [-148, -292], [1320, 270], [-642, -244], [-2566, -214], [656, -252], [1356, 124], [187, 611], [-871, -25], [-1442, 376], [-2564, 300], [-2756, -238], [4781, -59], [2262, -136], [4356, -308], [1455, 153], [368, 32], [1822, 432], [3078, 272], [-955, -107], [-2535, 275], [1861, 397], [-4752, 536], [-1264, 990], [-4026, -452], [3902, 130], [3536, -218], [-2214, 550], [3617, 199], [150, -1096], [-4416, -664], [2372, 1316], [1274, -1124], [-654, 1142], [-5094, 386], [-1588, -238], [2209, 823], [5040, -6], [-6612, 1130], [-11, -1115], [13222, 424], [12012, -452], [4336, -778], [7248, -824], [-3824, 1876], [17078, 88], [2080, 238], [-3645, 1341], [5528, -952], [4503, 1663], [134, 734], [1132, -204], [-4152, 316], [2320, 2244], [8636, 756], [-6609, -1175], [8112, 242], [-7039, 2193], [-7382, 500], [12898, 1102], [4430, -1996], [-9751, -1927], [17328, 1042], [16346, 1086], [594, 48], [9929, -351], [-1878, -308], [4640, 2024], [4954, 1872], [10720, 704], [-16724, -762], [-1560, -870], [-14667, 1557], [5948, 772], [-1384, 2962], [-11321, 903], [-234, -1114], [-13640, 1414], [-2426, -2102], [-9841, 1381], [6670, -1828], [-16629, 141], [13080, -468], [-16867, -1147], [20288, -194], [-15980, -178], [22470, -1458], [13958, -810], [-10613, 1241], [7918, -438], [-12968, -672], [-8140, -732], [6484, -738], [4164, 710], [-416, -746], [-6487, 1475], [-17999, -1751], [-31977, 785], [-2424, -2950], [8193, 145], [-21462, -552], [31016, 1856], [-18828, 744], [5579, -1863], [-8622, -4206], [-43655, 247], [2628, 2374], [5491, -133], [-9692, 3220], [9236, 950], [-17374, -2524], [-8060, -2552], [-8382, 50], [-1972, -3960], [6536, 4040], [-28856, -1280], [21716, -914], [2454, 3948], [-7851, -5577], [12590, 1522], [-7474, 472], [-1308, -1684], [2651, -3269], [-10710, -2036], [16866, 1298], [5112, 3608], [-3137, 5669], [10248, -1570], [1919, 4353], [-10552, 44], [-2499, -3661], [-42300, -1652], [-47198, -280], [42978, 1978], [-33998, 1772], [27284, -3744], [37764, 3242], [-5756, 1052], [25435, -775], [23284, -4044], [18433, 3809], [23680, 426], [-8914, -7096], [8520, -824], [-8757, 1693], [11318, 4880], [40517, -2915], [11118, 3396], [-15150, -4742], [5906, -3920], [-64464, -508], [16244, -3176], [40371, -2659], [21476, -368], [5658, -1500], [44896, -234], [11684, 4406], [-42622, 3828], [-50488, -1440], [-12398, 488], [19950, 3158], [31535, 3205], [21502, -724], [27159, 4615], [31365, 4631], [-44866, -3882], [-12966, 670], [-15380, 5166], [-20753, 791], [18792, 2046], [51957, -785], [4648, 6448], [-23493, -1749], [-16136, -1872], [23004, -4598], [-2136, -7368], [-10712, -6782], [-21216, 7912], [1544, -9466], [49152, -4886], [15016, 4928], [37750, 6168], [-8700, 10420], [-4309, -1117], [-37840, 8714], [23934, -344], [-53804, -1164], [-41492, 6148], [44838, 3762], [-14456, 7834], [22691, -5085], [-37952, 3328], [8846, 4616], [-49463, 2073], [-15048, 10408], [-42652, 4314], [-14322, -1492], [-45760, 5028], [58020, 4588], [-23666, -5326], [-21319, 1049], [-71284, -5820], [21262, 1464], [37698, -5916], [40862, -5186], [-22472, -8328], [68227, -5525], [-43050, -1158], [-92744, 776], [-3094, -1644], [-58034, -2000], [-37012, -1740], [-34734, -6504], [-51043, -833], [54324, 1360], [-34840, 8802], [54767, 7], [20613, 5295], [84996, 962], [-11260, -5852], [43602, 7350], [101595, -1967], [6523, -9591], [-39876, -810], [26051, 3219], [4262, -6132], [16262, 5552], [-83748, 2344], [61848, 4238], [99889, 391], [21730, 10462], [-2458, 3788], [15720, 728], [-16110, 512], [-4516, -17564], [72202, -2090], [26194, -12676], [109940, 1842], [39999, 4071], [58692, 3476], [-8848, 6168], [-46374, 10730], [-23793, 11861], [77369, -9335], [-41016, -4024], [-10806, -11784], [-100282, -2652], [-15930, 470], [-84330, 2808], [19770, -6192], [89615, 279], [-46616, -8502], [-29089, -7185], [-115666, -3208], [100871, 1153], [66624, -10176], [2923, -1251], [-4155, 10429], [-2713, -10617], [-18748, 2706], [-128040, -186], [123888, 1984], [-19062, -4290], [19518, 6002], [22718, -6388], [-25110, -602], [94375, 9845], [45044, -1732], [-43090, -17616], [19156, 4724], [21052, 5234], [78026, -10532], [-16154, 11074], [-92060, 8492], [-73166, -424], [-12247, -775], [119144, -2040], [-41234, -19332], [-40410, 5112], [57995, -1909], [-57370, 524], [74949, 439], [2500, 12180], [-152432, -2910], [59312, 11190], [-11102, -7378], [-22319, 5969], [139392, -5616], [17424, 10726], [-2934, -4796], [-13200, 14510], [44422, -3362], [83405, -4195], [-26236, -20032], [-33857, -5665], [-67016, -7846], [58454, 6264], [62810, -15936], [2374, 12974], [66810, -196], [-45432, -9206], [33435, -11331], [-100372, -1084], [616, 22822], [-84954, -2118], [4741, 22019], [105802, 15198], [-36820, -17652], [-137927, -4061], [-42217, -73], [54130, 4024], [-6366, -392], [-153042, 470], [67770, 17180], [118458, -9836], [-84474, 11486], [-143741, 10851], [-54978, -3184], [2844, 17764], [78842, -11092], [3882, 10100], [78888, -19512], [-27228, -6632], [-16755, -29115], [-4432, 16094], [11151, 8025], [-193380, 260], [4288, -18658], [-167108, 2120], [-46813, 5019], [108504, 12456], [111902, -2916], [-120680, 5520], [-125766, 4196], [11027, 491], [15276, -27092], [-62962, -1028], [-50924, -26242], [-53012, 14090], [29423, 25001], [-161480, 6346], [92488, 18880], [-33786, -3960], [110903, 12951], [-195120, 1256], [91508, -6892], [50339, -2263], [-31936, -21444], [148082, 4634], [112352, 5606], [-38227, -14249], [-52596, 9936], [-54933, 2475], [-10528, -8072], [-29794, -14108], [-142238, 10794], [103928, -2822], [112996, 6528], [156300, -10814], [72891, -13079], [-42650, 6472], [-25800, 22568], [-12924, 32902], [-178073, -5799], [-39754, -15306], [129854, -3480], [144056, -13278], [-159573, 15243], [24369, -23023], [60054, -364], [87048, -6386], [-142490, -6558], [91168, -7164], [-63654, 8288], [-26061, 27853], [82724, 24532], [-231794, 366], [185940, 9694], [-169588, 7844], [121824, 11102], [-89449, 8925], [110472, -1768], [-108327, -15519], [82608, 7566], [-164247, 5819], [254990, -5550], [-81666, -23448], [2855, 22527], [-298378, -970]];
    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_4_a_i();".
// 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_4_a_i(:prec:=2)
    chi := MakeCharacter_504_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_4_a_i();".
// 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_4_a_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_504_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![64, 22, 1]>,<11,R![-1728, 36, 1]>],Snew);
    return Vf;
end function;