
// Make newform 1216.4.a.l in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1216_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_1216_4_a_l();".
// 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_1216_4_a_l();".
// 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 := [-44, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_1216_a();"
function MakeCharacter_1216_a()
    N := 1216;
    order := 1;
    char_gens := [191, 837, 705];
    v := [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_1216_a_Hecke(Kf)
    return MakeCharacter_1216_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+1)]];
    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, 1], [-6, 2], [-28, -1], [4, 2], [-10, 7], [-18, -15], [-19, 0], [84, -13], [54, -29], [0, 16], [-198, 16], [-398, 6], [124, 48], [120, -40], [-194, -9], [136, -71], [362, -44], [-448, -43], [-192, -22], [62, -1], [-24, -58], [1116, -6], [-430, -10], [-894, -76], [34, -60], [16, -182], [352, 119], [-18, 189], [-222, 148], [200, 26], [708, 144], [6, 5], [2252, -100], [-1814, 22], [-272, 138], [490, -304], [788, -12], [-776, 148], [706, -404], [-2140, -148], [2666, -72], [2812, 227], [2034, 96], [-3414, 302], [-572, -501], [704, -187], [1208, 502], [1264, -87], [-2030, 456], [570, -48], [1436, -541], [-86, -114], [-3516, -302], [2794, -106], [-3984, 288], [-830, 232], [-3204, 619], [-550, -150], [658, 414], [-1116, 450], [3174, 309], [2148, 216], [916, 491], [-2114, -733], [-1906, 41], [-768, -209], [2554, -642], [2404, -594], [10586, -60], [-90, 279], [5436, -411], [7976, 108], [-3642, 305], [4280, 881], [6952, -562], [-3950, 1060], [6082, -570], [810, -1258], [-7054, -1190], [3796, -788], [6878, -1613], [-7784, 694], [9010, -4], [-8152, -836], [644, 142], [-10414, -464], [3774, -1265], [-12526, -542], [1720, 500], [-6356, 1374], [2248, 1964], [-944, 446], [-9524, 272], [-11388, 116], [6596, -109], [-9726, -1164], [6050, -846], [-2048, 2651], [-2006, 1524], [3012, 1952], [2098, 2090], [10420, -2432], [-12990, -1210], [-2276, -1624], [10366, -1783], [6268, -992], [11506, -240], [3816, 2760], [-10094, 3126], [952, -198], [-2686, -1236], [21466, -536], [-7164, 3314], [3904, 696], [2834, 2744], [12204, 1046], [2980, 1227], [402, -2622], [-3256, 2499], [-14154, 2389], [7754, 1890], [12502, 2849], [-11204, 480], [380, 458], [7938, 2834], [-20254, -2260], [-1988, -3529], [-28012, 51], [-3406, 4970], [12420, 532], [7976, -4256], [-19552, 1432], [-19438, -1296], [-1946, -2639], [13014, 2099], [7558, 1237], [-4960, -3287], [-16490, 1291], [6878, 527], [-11936, -2117], [-6758, 682], [-24324, -1759], [3736, -3751], [9598, 829], [-28184, 348], [-7166, 1636], [18930, 4170], [-24876, 1838], [-12296, 334], [12126, -5015], [-15198, -1284], [25276, -3486], [-34592, 110], [-37120, 1491], [22768, -3140], [-3460, 2905], [-35322, -161], [9534, -665], [-18314, -1825], [33076, -920], [11130, -3224], [21072, 5208], [-28900, 192], [-2422, -4722], [13152, 6282], [3840, -8216], [35530, -214], [-10198, 2830], [50458, 202], [-3904, -7897], [18918, -5905], [23632, 4840], [-44410, 2109], [17248, -1784], [-29766, 3540], [-15860, 2744], [19698, 2280], [-31496, 3044], [31538, -3002], [-24204, -3827], [49192, 1647], [-14438, 1352], [16530, 1250], [36380, -2821], [-15278, 268], [-11746, -251], [-23660, -1836], [-35334, 1756], [11676, -2661], [-19198, 8152], [-24116, -496], [21652, 5268], [-75202, -355], [-12540, -2620], [-68126, -1754], [46870, 4679], [-35822, 2434], [-58466, -1423], [-30036, -6987], [-25198, -4828], [-13760, -292], [-37154, 2951], [-21286, 7218], [3268, 4778], [-36590, 4230], [-2036, 12447], [-23216, -95], [-12274, -7141], [29320, 53], [38982, -317], [-48214, -1286], [8624, -10828], [-44512, 2939], [-61160, 5128], [-4742, 604], [-10036, 455], [25442, 9968], [15344, 2466], [63978, -2052], [9418, 4180], [24592, -3630], [-10478, 5360], [-1076, -3045], [-19320, -173], [4914, 3840], [39242, 408], [952, -3326], [33024, -3778], [6340, -2162], [-49094, 8140], [33904, -2923], [17472, 1224], [34170, -1576], [13460, -11850], [292, -12167], [-9822, -9300], [-25638, 9422], [32420, 1962], [-10248, -9996], [-1676, 11592], [39204, -1498], [-41908, 8697], [69334, -6153], [-73782, -5334], [-69312, -4236], [-39272, -11536], [38068, -4792], [-17524, -6144], [-15812, -9353], [-67622, -5560], [2398, -8527], [6852, -2569], [-25190, -7624], [-62974, 970], [-27364, 2938], [62914, 3256], [-88532, -2344], [15546, 636], [-19910, 15972], [-15952, 11136], [12052, 88], [10, -11498], [80918, 2843], [-10334, 4096], [-87552, -1519], [-71378, 8869], [-58874, 4993], [61280, -10413], [-52654, -8668], [82710, -3897], [62712, -5593], [87438, -345], [-64940, -9747], [38018, -7116], [110428, -3467], [14260, 670], [-103834, -465], [30914, -6050], [20132, -13576], [32600, -8026], [49268, -8889], [8452, -8357], [-34626, -1917], [42332, -7556], [-6024, 15312], [-34378, -15481], [12506, -1960], [604, 6341], [32834, 4752], [2266, -10784], [-71756, -1736], [-29510, 2548], [13132, -2896], [-75246, 3320], [-50270, -6354], [-95496, 1826], [-17246, -12156], [-55280, 8043], [-22004, 10966], [-53430, -1972], [43454, 13033], [41292, -7505], [-130672, 1821], [90380, -5752], [28802, 2652], [-4040, -2495], [-16066, 10801], [83632, 2824], [26890, 7902], [-9128, 1904], [5314, 13132], [-5550, 14576], [-37292, 11680], [111920, 1328], [15554, 470], [-107780, 12838], [-98840, -3382], [46238, -15519], [57794, -17060], [31064, -13685], [69750, -3003], [114230, -1909], [1544, -8930], [34886, -13363], [-134558, 6064], [77504, 6625], [-95888, 5007], [-42304, 6072], [11850, -22078], [-109246, -366], [-69042, 9], [59852, -10097], [-121236, 2954], [22772, -24646], [-86996, 7496], [69326, -18199], [52442, 13370], [42214, 9485], [-107260, 12357], [133446, 4129], [7382, -4747], [18014, -6037], [100560, 10790], [-24826, 17239], [-69068, 9120], [161506, 5632], [74736, -12261], [-10392, 9434], [29098, -11930], [-107724, -5788], [-94918, -14580], [-33070, -2474], [-23376, -27012], [-123062, 3288], [-76814, -7530], [-170500, 4231], [-121428, 8448], [60350, 2101], [-89776, 19934], [168858, 4678], [100906, -9028], [-197144, 3742], [62376, 505], [-99540, 10534], [15250, 21434], [-195830, -2012], [-84624, 6570], [-91110, -15040], [153292, 6466], [95120, -6877], [14908, -32313], [-14098, 30363], [130912, -5124], [-42254, -1842], [-108936, 23467], [80456, 20032], [-34126, 16860], [144326, 5003], [149554, -3590], [-152174, -10760], [-31014, 22768], [136972, 7001], [60594, -34116], [178816, -4811], [159872, -1214], [-129884, -607], [47274, 7774], [87172, 18486], [92352, 24784], [8578, 1592], [17846, -22055], [-68524, 1214], [12364, -17958], [-73288, -20212], [227994, 3568], [-134408, 5246], [-73630, -24462], [210540, -3160], [-193894, -1090], [-11342, -11100], [128674, 16104], [56248, 16042], [85986, 5846], [-103542, -7164], [-116860, 20347], [215706, -1328], [120378, -2510], [-156344, 12855], [-64780, 24096], [-98870, 5706], [-2206, -26644], [-68376, -1123], [5788, 194], [17326, 17787], [40866, 6918], [9544, -8078], [82568, 664], [7022, -16159], [176872, -13192], [88018, -3920], [32390, -16235], [84900, 23537], [85312, -36957], [39594, 2552], [92702, -29431], [-51392, 36605], [-36538, -24359], [-18580, 11460], [169940, 9883]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1216_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1216_4_a_l();".
// 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_1216_4_a_l(:prec:=2)
    chi := MakeCharacter_1216_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_1216_4_a_l();".
// 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_1216_4_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1216_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-44, -1, 1]>,<5,R![-152, 10, 1]>],Snew);
    return Vf;
end function;