
// Make newform 1088.4.a.v in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1088_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_1088_4_a_v();".
// 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_1088_4_a_v();".
// 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 := [-4, -14, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-9, 0, 1]];
    Rf_basisdens := [1, 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_1088_a();"
function MakeCharacter_1088_a()
    N := 1088;
    order := 1;
    char_gens := [511, 69, 513];
    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_1088_a_Hecke(Kf)
    return MakeCharacter_1088_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, 1, -1], [3, 0, -1], [8, -1, -2], [9, -11, 1], [-9, -8, -3], [-17, 0, 0], [-28, -22, 4], [48, -39, -2], [157, 16, -15], [74, 39, 8], [-127, 28, 25], [-88, -52, -30], [-176, -2, -28], [206, -48, 22], [-102, -116, 4], [-212, 130, 0], [41, 64, -39], [-358, -24, 66], [-146, 185, 36], [282, 16, -8], [-228, -267, 90], [820, -82, -64], [-75, -276, 55], [-110, 140, 60], [-437, -32, 49], [904, 76, -112], [485, 53, 49], [-373, -420, 31], [-404, 68, -94], [1684, 62, 120], [725, 185, 89], [651, 392, 161], [-381, 163, -285], [-238, -288, 272], [920, -354, -36], [744, -76, -194], [-21, -167, 223], [-296, -235, -270], [-227, -420, 337], [-652, 426, 4], [2929, 220, -55], [-570, 372, -226], [-504, -776, -6], [-325, -372, 67], [340, 1203, -210], [2991, 271, 203], [1522, -606, 254], [387, 21, 279], [-573, 528, 405], [-2908, -916, 210], [3586, -568, -174], [-3252, 708, -234], [1022, -1536, -458], [2577, 240, 303], [2520, -326, 444], [-1853, 480, -569], [1774, -736, 270], [1661, -652, -719], [164, -4, -354], [1589, 533, -731], [358, 2008, -156], [998, -1272, 250], [-3436, 257, -1178], [580, 528, -338], [-4573, -376, -269], [-3788, -138, 592], [2010, -1412, 248], [1035, -1579, 183], [1222, -228, -304], [196, 604, 654], [-4946, 10, -6], [-3326, 1607, -484], [4023, -496, -667], [259, 2353, 35], [-4332, -790, -280], [-1489, -816, 961], [-2803, -2132, 77], [4900, 316, 1270], [-2290, -3168, 840], [-919, -2025, -151], [5751, 1336, 237], [144, 309, 270], [-5025, 2876, 1], [1194, -703, -168], [774, -1152, -802], [9194, 1064, -740], [-3321, -3380, 1537], [2990, -1972, 1976], [3140, -2816, 1348], [-5916, 714, 276], [-11416, 1323, -614], [5522, -1473, -156], [-8044, -2662, -68], [-12021, -2525, 743], [-10310, -3045, 212], [-5410, 776, -1564], [9068, -1100, 478], [-5882, -2896, 934], [-4383, 324, 609], [-9247, -1083, 837], [-6457, 216, 1741], [-11304, 978, 52], [-12520, -5172, 1430], [6745, -1505, -415], [11039, -352, 541], [1176, -374, 2184], [-1516, 68, 930], [12196, -968, 876], [-322, 4812, -2620], [15262, -2165, -1108], [7790, -1680, 2724], [-1240, 2972, -2730], [3395, -515, -25], [-914, 3126, 2130], [-18, -5324, -104], [-981, 4481, -2421], [-1838, -2936, 1466], [-9907, 3672, 553], [3682, 1376, -714], [6020, 4760, 1126], [5998, -104, 1016], [14307, -2388, -789], [783, 837, -953], [12957, 2857, -1203], [-4257, -4896, -123], [7233, -3320, 2213], [-2142, -4167, 1048], [-4262, -2568, -726], [-2636, 3128, 2334], [17652, -5422, -1124], [18374, 1991, 276], [23618, -3651, -1704], [-17577, 6752, 769], [5639, -4120, -115], [-1893, 1568, -3831], [283, -5216, -3115], [23763, -77, -477], [8428, -504, 1558], [29518, 3016, -256], [12841, -605, -3067], [-6737, 3036, 1367], [5028, 9013, -1830], [-9081, 3999, 1203], [-1300, 1860, -3718], [-7940, -1973, 2570], [-3785, 3384, -2901], [-20428, 7040, 1966], [39760, 1762, -28], [5352, 10248, -2648], [-2233, -12380, 1835], [-15042, -6044, 564], [1494, 7668, 2910], [9628, 1335, -250], [11285, 1773, -1075], [4308, -461, 2658], [1398, 4692, 2382], [-3176, 2508, -5014], [30, -4904, 4472], [7527, -9636, 903], [22379, -2101, -2165], [13973, -8596, -2353], [7186, 3654, 566], [-33424, -3534, 796], [-11168, -5948, 3798], [-7034, 2089, -2052], [6498, -8103, -744], [-4593, 8540, 4375], [-11662, -4672, -44], [-4687, 13004, -1743], [18854, 2972, -2598], [10299, -6200, 449], [-16458, -6611, 2392], [-9619, -788, 3327], [19560, -3278, 1532], [-5838, 4576, 1416], [6877, -6057, 1809], [24865, 9252, -1375], [24650, -5774, 926], [-13065, 1448, -2015], [32808, 8832, -2592], [-32925, -12185, 2875], [-12687, -3464, -6415], [24738, -496, -952], [-452, -9614, 6488], [-12929, 4960, -6843], [17509, -2808, 4645], [20866, 1124, 6598], [28334, 2624, -3992], [818, 3315, 4504], [41906, -708, -3120], [6757, 19663, -1547], [11948, -6890, 892], [16231, 1408, -1511], [32617, -5045, 2349], [-50274, -908, -3180], [-27584, 9192, -354], [8819, 14228, -3197], [8098, 8836, 1848], [-22884, 1820, -4332], [-31071, 3956, -5583], [11752, 2441, 3790], [1610, -2416, -224], [22673, 14552, -6401], [12058, 2264, -6642], [-22321, 3224, 7201], [-29048, 468, -3336], [-24736, 8342, -5496], [-39590, 7816, 3360], [2606, -13800, 722], [-9086, -14084, 2948], [3647, 4416, 1609], [20886, -363, -1920], [5028, -7374, -492], [4418, 11513, -6212], [21244, 5744, -2314], [39212, -956, -3684], [-11602, 2192, 444], [5334, 11561, -3064], [15451, 7168, -7687], [-37124, 9036, -4470], [-3080, 2057, -8006], [-31082, -11432, 4440], [10080, 7901, 9802], [-1150, 2508, 9146], [-22049, 2928, -7475], [-12666, 13392, -3876], [14690, -16981, -732], [-34040, -17610, 1324], [-52367, 1443, -4327], [-3268, 17624, -2762], [25155, 12233, -4437], [3990, -5594, 2586], [-29873, -8484, 2297], [926, -2912, 4678], [1018, -5474, -8506], [-15324, -1432, -2738], [46429, 3668, -7339], [-19539, 4449, -6615], [2882, 13998, -3562], [-66743, -5957, 1145], [16662, 2468, 6258], [16530, 22140, -2934], [30083, -12488, 3077], [13416, 4716, -11394], [-55432, 15377, 3634], [-2118, -9281, 9384], [10765, -11965, -5331], [33140, 22762, -6728], [-55242, -9582, 4146], [18124, 9436, 3866], [-36468, -11152, -1494], [38324, 14014, 4128], [-18454, 7608, -7440], [-51577, -6448, 7713], [-44118, 5692, 1770], [-47193, 4756, 5631], [9943, 26641, -7537], [-42957, 15772, 4755], [-43023, -800, 6591], [63888, 10329, 930], [-59390, -20840, 2502], [25647, 10372, 135], [85997, -6176, -1791], [54586, -16364, -2828], [28098, -11548, 1706], [-25432, -520, 74], [45926, -2464, 6760], [-55225, -14463, -117], [96300, -3076, -3502], [33225, 23472, -4467], [4246, -12484, 16434], [396, 18316, -4318], [14318, -6886, -9542], [-97866, -968, 5528], [61098, -9610, -7898], [6792, -4642, -7708], [22815, -12832, 8485], [28585, -7396, -1765], [-8900, 17914, 3920], [12638, 12500, 4398], [-11004, -7775, -3098], [21994, 16981, -3716], [-38806, 19948, 3444], [53281, -5335, 10309], [-7776, -6420, -7680], [47354, -1616, 1964], [62089, -26928, -4087], [98732, 742, 6472], [-10953, 12468, -6215], [10229, 3392, -39], [80467, 20593, -4389], [-18779, 13072, -6277], [-96711, -1695, 1225], [-2211, -19428, -2091], [4471, 14092, 4275], [25404, -7316, -11732], [-94125, 4872, 4425], [15503, -32755, -4549], [103304, -598, 3892], [8625, 9276, -1557], [-30217, -26632, -615], [-4110, 24653, 2476], [85605, -22621, -7111], [-10213, -759, -14437], [-5758, -9512, 100], [17050, 28332, 358], [-25107, -23084, -4587], [106180, 6024, -1468], [-28180, 6732, 3962], [-86524, -4859, -582], [-43781, 12920, -5953], [-40946, 18208, 6144], [8072, 30998, 7840], [-103180, 10472, -9964], [19494, -26336, -8080], [31552, -16070, -9592], [-42916, 13265, -9362], [-58764, -5696, -11182], [-63138, -4080, 9432], [-10281, -1763, -9517], [1020, -5764, 230], [60174, -2064, 7252], [34532, 2320, 6180], [12960, -4172, 10906], [2640, 28380, -17034], [-39169, 12751, 9791], [-40319, 14721, -10991], [54374, 20133, -2540], [-10505, 6052, -10425], [95605, 3432, 3825], [23201, 22532, -9855], [52998, -15255, 24660], [24666, -35476, 10622], [-15863, 3575, 3785], [17023, -22793, 14739], [19462, 22156, -6400], [-14832, -11996, -15026], [115776, 1988, 10614], [47794, 56418, -12722], [-14232, -11736, -16062], [-13066, -15792, -15260], [74841, -10220, 2497], [81412, 41516, -11364], [38055, 5928, 18381], [1433, -15669, 4849], [-105345, -19096, 4351], [-39226, 29188, -4362], [70102, 1707, 2396], [27661, -22148, -9915], [-17996, -1110, -7936], [-33958, 37684, 17028], [36584, -32932, -12882], [10428, -41983, 1390], [-23917, -1416, 8261], [100575, 1664, -4507], [33434, -4238, 6118], [107293, 19399, -5095], [-56492, -840, 16646], [100956, 12438, 7200], [110593, 39672, -9007], [-14932, 22388, -2518], [68702, -19324, -2418], [-51215, 13531, -17751], [-49008, -30066, -6960], [14708, 20196, 10318], [26809, 26888, -17571], [63986, 34432, -8470], [69762, 32224, -10548], [-47980, 22594, 6240], [-5775, 2629, -5559], [35416, 11569, -1386], [-49265, 49240, 8541], [-39062, -46372, 15322], [170069, 13668, 4001], [44397, -12169, 27857], [-53092, 31571, -7510], [48629, 62024, -12893], [121556, -23324, 3334], [47202, -44272, 12808], [54395, -28480, 12375], [-112354, 35336, 12168], [104672, -21589, -14462], [143192, -6712, 19774], [9633, 50827, -2583], [-96874, -16675, -16824], [-198500, -242, -3808], [75127, -27464, -14215], [80993, -11577, 25069], [31912, -21396, 14248], [-88596, -43756, 9322], [-91305, -14988, 15031], [-57470, -7112, 2590], [57534, 9292, 5890], [32784, 5918, 31124], [66544, -15156, 10170], [94886, -3112, 4390], [-109578, -8528, -2640], [-147421, 20527, -4857], [12723, -1736, 11169], [99609, 25760, -15215], [22143, 36720, 17485], [-33864, -192, 7392], [-74344, -100, 3586], [66246, -28296, -5668], [-125690, -14061, -11676], [-48877, -37720, 15709], [82587, -16088, -551], [201964, -21522, -5128], [-14459, 3523, 3009], [74502, -36516, 3684], [-123113, 12288, -11623], [51830, -988, -14630], [-18535, -51711, 7085], [113198, 47760, -17856], [-187747, 29864, 1893], [-47986, 17011, 936], [3566, 3419, 6460], [-31594, 34856, 1632], [-63522, -8328, -20106], [20202, -15612, 13004], [-59567, -29228, -18019], [111266, -17275, 12792], [-79908, 41754, -8836], [-47812, -44632, -8138], [142008, 2100, -9434], [77927, -18397, 26415], [49794, 45384, -11840], [-130142, 7092, -7358], [160348, 21391, -4158]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1088_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1088_4_a_v();".
// 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_1088_4_a_v(:prec:=3)
    chi := MakeCharacter_1088_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_1088_4_a_v();".
// 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_1088_4_a_v( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1088_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-204, -62, 4, 1]>,<5,R![-32, -44, -8, 1]>],Snew);
    return Vf;
end function;