
// Make newform 1216.4.a.o in Magma, downloaded from the LMFDB on 24 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_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_1216_4_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 := [-8, -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], [3, -1], [0, 5], [-17, 4], [38, -5], [23, -11], [3, -6], [19, 0], [27, -59], [-45, -65], [-84, 80], [-186, -8], [-56, -30], [-136, 117], [-216, -23], [199, -123], [419, 35], [-310, 175], [-353, 61], [-846, -20], [-463, -64], [-642, 10], [102, -114], [-484, 80], [126, 458], [-1178, 300], [950, 80], [317, 421], [777, -225], [-1074, -152], [898, 424], [-480, -45], [-1377, 734], [-596, -275], [2368, 235], [902, -840], [-1562, -76], [2716, -432], [1268, -766], [-1166, -368], [1312, -710], [134, -1320], [443, 820], [-4146, -18], [-5160, 110], [-469, -900], [-2177, 1555], [-4046, 572], [-1165, -1575], [-3434, -75], [1170, -15], [-4733, -560], [3088, -90], [5058, -115], [4372, 236], [-816, -723], [-914, 730], [-1749, -955], [-1504, 363], [-32, 630], [-1170, 1515], [-2271, 387], [492, 2736], [4427, -290], [1261, -367], [-2851, 677], [2661, -625], [4, 2172], [1454, -1863], [1202, 2685], [5049, -903], [-2139, 2070], [6964, 12], [8565, 935], [-4685, 2815], [218, 1714], [-4226, -965], [2020, 2475], [-480, 380], [-3664, -1700], [3428, 680], [-2989, 685], [-8314, -2350], [-11606, -328], [292, 4490], [1138, 3869], [-9778, 1810], [-3495, 370], [7844, -4205], [-1708, -3719], [1910, -2655], [-12364, -200], [16010, 880], [-2908, -80], [8388, 235], [451, 2953], [-4854, 3270], [1268, -180], [4265, -7055], [4150, 1515], [-3180, -2600], [3928, -181], [-9892, -3466], [-7440, 5480], [12140, 2200], [-4661, 152], [13700, 2915], [11554, -4428], [-2664, 5460], [23140, -1530], [1250, -1650], [-874, 1413], [10834, -1433], [-4494, -3470], [-13960, -4665], [12110, 2210], [-11250, -2645], [-22069, 828], [22224, -1473], [11209, 1365], [441, 6175], [14276, -1182], [10957, -2299], [-9268, -3984], [-14630, 145], [1044, 2270], [-5950, 7580], [11087, -2180], [-3221, -258], [-14536, -1978], [-5112, -1135], [16924, 2732], [12544, -7120], [15806, -2037], [-1709, -2450], [2325, 6890], [-12695, 8485], [-15245, 7865], [-2381, 7777], [-10303, 6830], [8777, -865], [-29960, 5095], [-14007, -446], [13307, -239], [2233, -65], [34712, -5310], [17566, -272], [-3708, 4686], [21690, -9485], [-9202, 10844], [22269, 2257], [-4410, -7185], [34514, -5373], [-9418, -1964], [6937, 1191], [-15352, 8330], [17665, -8365], [-1047, -8195], [-26463, -3944], [10855, -11485], [8408, -18676], [-7290, -230], [-10800, 7440], [13588, 240], [-29068, -3804], [6930, 3690], [-21108, 2330], [-28160, 9575], [-11500, 11920], [-12080, -8105], [12397, -7835], [-3657, 10505], [2912, -6160], [-1345, 7635], [15608, -12460], [8454, -12315], [-7240, -3380], [-23550, 1605], [30440, 8080], [-20488, -13295], [-7971, -14308], [28253, -1245], [-16418, -484], [-22440, 350], [16891, 6928], [11518, -8495], [6737, 6601], [20120, 12630], [24006, 11260], [-21525, -5415], [5150, -21200], [32756, 4633], [-4168, -6720], [41153, -8215], [16908, 7204], [28636, -8312], [26281, 620], [28444, 2362], [2731, 10043], [38709, -2148], [18698, -2590], [6848, 13630], [-36017, -12271], [-1132, -4830], [17270, -5090], [26032, -11589], [2279, -8370], [-56653, 11381], [341, -1420], [53183, 6595], [67653, 5749], [-24400, -7370], [-3092, 12679], [6937, 9331], [-74092, 1970], [41458, -13820], [-16793, -4679], [-64258, -3370], [4954, 3042], [19158, -20541], [-68030, 5440], [-3610, -5520], [-16094, -26080], [18635, -22470], [19521, -28327], [-3798, -16185], [-34942, -1176], [-30010, 26450], [5982, 5176], [-19954, 21995], [6994, 19987], [1703, 11125], [-3552, -12540], [-46230, -4600], [-24386, -4443], [-29983, 12806], [-40146, 22155], [53280, 7805], [34702, -5670], [9684, 4560], [33692, -15054], [-12090, -17555], [-28967, 9519], [1255, 12555], [-1932, -5346], [-20388, -24555], [61496, 2953], [100460, -2300], [46132, -4740], [48047, -31054], [52714, -5668], [-67685, 11120], [-42753, -5219], [59590, 650], [-25564, -4787], [8014, 26630], [41446, -30875], [-40900, -18830], [-65550, -1680], [76102, -12924], [6748, 23454], [-86860, 5450], [49264, -23675], [56339, 5867], [36922, 26221], [-38301, 19765], [-88991, -2285], [-32261, 19060], [-7199, -3627], [74774, 5207], [-37977, -29295], [-37923, 22501], [-77583, 2256], [57245, 19230], [72902, -12294], [-56299, 3203], [-5110, -32425], [6119, 4725], [-52948, 20290], [9496, -17315], [47734, -10628], [-43505, 13725], [27179, -8518], [40035, -13185], [-8468, 33881], [52512, 15015], [9377, -10954], [-16594, -21562], [-116179, -2570], [-81802, -10830], [39310, 27460], [92660, 9245], [-71390, 30310], [-48220, 41170], [-16650, -25360], [-55220, -11430], [-34782, 26230], [-142910, -4545], [-93871, -7785], [-58, -10399], [-78282, -8341], [67469, -7883], [81807, 17900], [-20225, -38655], [-113444, -17165], [118382, -17994], [-4069, 33353], [8957, 11005], [-62800, -18625], [-1820, -25110], [56, 36463], [-118262, 15100], [35418, -39370], [10292, -15394], [39400, 2320], [-9376, -35440], [-18970, -34495], [123518, -10430], [-89029, -3252], [-99802, 35695], [35425, -65215], [39759, -19278], [121283, -5485], [84298, -2026], [-22777, -28681], [-13310, 36970], [-41669, -18295], [-19219, 27153], [119872, 10626], [-152700, -6565], [7568, 33465], [-31011, 55377], [-70625, 19025], [-85494, 24823], [-53402, 33715], [-88984, 40303], [-82315, 15455], [-16960, -36790], [-98681, -340], [65509, -34293], [-78699, 23203], [-15073, 9566], [11747, -24625], [20214, -11030], [-139369, -22997], [39980, 18300], [-30890, 33040], [116745, -6195], [51462, 39730], [93400, -905], [30216, 36790], [-10246, 23202], [-106360, 5245], [-18048, -13674], [15166, -32550], [205360, 3000], [104119, -34855], [-40560, -27780], [-15985, -57830], [-134990, 19300], [77040, 23335], [-1418, -52540], [-153142, 18044], [-933, -29875], [-63954, -21427], [-41516, -26338], [-103886, 9892], [56826, -20472], [-52242, 68450], [18686, -11410], [-134495, 37285], [-81841, -6258], [-17941, -53805], [-38908, -11325], [8680, -10665], [-22791, 37235], [61384, -1240], [89006, -4707], [-29779, 60470], [-205220, 20140], [116614, -2120], [25338, -75911], [-29695, -5240], [-142794, 16173], [58847, -31465], [-48746, 26522], [-44383, -4145], [-79860, 370], [8954, -8343], [-148680, 5510], [-19922, 21620], [73013, -57671], [-105218, 4450], [117626, 23553], [-174548, -290], [10374, 34612], [84506, 17290], [-82096, 59670], [-68628, 19690], [112016, -54490], [-225638, -9390], [-27206, -3723], [-46270, -42250], [-15192, -59686], [-139182, 23550], [173611, -20650], [-35070, -47135], [-184524, -770], [41813, 37389], [111424, 6375], [-135392, -5736], [-25750, 39635], [220791, 1303], [-149134, 23365], [115837, 11421], [28212, -38850], [160046, -52990], [-129500, -13360], [-19141, 29567], [185192, -19214], [17230, -34310], [-142711, 34237], [123753, -75956], [-217831, -7275], [32586, 74498], [98045, 54515], [-72577, 12619], [95003, -24440], [-222632, 13065], [-87413, -16450]];
    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_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_1216_4_a_o(: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_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_1216_4_a_o( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1216_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-2, -5, 1]>,<5,R![-200, -5, 1]>],Snew);
    return Vf;
end function;