
// Make newform 1344.4.a.bu in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1344_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_1344_4_a_bu();".
// 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_1344_4_a_bu();".
// 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 := [-148, -57, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 2, 0], [-152, -16, 4]];
    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_1344_a();"
function MakeCharacter_1344_a()
    N := 1344;
    order := 1;
    char_gens := [127, 1093, 449, 577];
    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_1344_a_Hecke(Kf)
    return MakeCharacter_1344_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], [3, 0, 0], [-2, 1, 0], [-7, 0, 0], [16, 1, -1], [-2, 4, 1], [18, -1, 1], [28, 2, 1], [-16, -3, -1], [-6, 10, -3], [-24, -2, -3], [-70, 4, 1], [138, 5, -3], [56, -8, -2], [-24, -26, 0], [-134, -12, -3], [180, 38, 0], [-266, -30, 7], [16, -38, 2], [152, -21, 1], [410, 18, 16], [456, 26, -8], [20, 40, 10], [914, -31, 3], [650, -26, -12], [-82, 43, 20], [936, -74, 3], [-184, -39, -21], [-22, 16, 4], [1330, -4, 10], [496, -162, -14], [-60, 120, -12], [874, -122, 2], [-676, 20, 22], [42, -20, -47], [1440, -36, 14], [158, -158, -7], [-792, -98, -18], [-1704, -14, -40], [846, -97, -4], [-248, -129, 53], [3030, 100, -17], [-3016, 135, 13], [-678, 216, 17], [890, 152, 69], [848, 204, -28], [544, 56, -28], [-552, -256, 62], [1956, 162, -76], [3174, 176, -11], [730, 162, 26], [-3008, -171, -49], [-2102, 18, -26], [124, -282, -86], [330, 201, -65], [2680, -99, 3], [1918, 257, -8], [3760, 234, -47], [3938, 16, 9], [2458, -318, 20], [-2132, 494, 63], [6094, 111, 34], [-372, -406, 79], [-4208, -242, -72], [4210, 88, -20], [-1598, -240, 79], [-2664, 696, 48], [-2942, -76, 124], [-6496, -49, -111], [574, -398, 115], [-3158, -273, 101], [-592, -349, 61], [1976, 240, 60], [234, -560, 28], [4568, -432, -108], [-3208, 248, 88], [738, -534, -99], [-3170, 330, 81], [-5886, -14, -102], [-1278, 506, -114], [5788, 130, 6], [-334, -808, 33], [1616, -601, -131], [186, -412, 12], [3160, 812, -50], [-10104, 215, 65], [-2878, -588, 136], [-726, -200, 200], [-8210, -17, 94], [5256, -526, -94], [-7260, -294, 54], [-6632, 798, -22], [11392, -40, -14], [9528, -449, -3], [-3648, 52, -294], [-10640, 264, 66], [-674, -499, -18], [5626, 75, -27], [-4588, -704, -8], [-7142, -672, -211], [12936, 374, 256], [-17582, 456, 53], [428, -1054, 40], [-934, 550, 152], [-12152, 882, 144], [-4366, 540, -136], [-1668, 174, 48], [-6134, 355, 15], [7800, 239, 221], [11114, -92, 52], [5176, -1764, 62], [-7422, -676, 414], [8378, 374, -364], [18772, 144, 162], [-632, 662, -354], [3202, 842, 476], [-860, 58, 313], [-2312, -554, -360], [-14038, -6, -247], [992, 829, -385], [-5010, 66, 381], [-1814, 192, 107], [6582, -1345, -148], [-26248, -237, 37], [-12268, 84, -316], [-1526, -794, -171], [15506, -1016, -84], [1528, -2084, -240], [-24472, 358, 123], [-20362, -844, 109], [-1992, -1786, -122], [3296, 499, 253], [-11776, -816, -20], [4082, -192, 204], [-2854, -623, 191], [1562, -756, -284], [-1730, -1313, -324], [28196, -1144, -2], [-11458, -689, 40], [5258, -1280, -26], [30980, 76, -140], [6506, 1712, -47], [12952, 926, -408], [11784, 937, 343], [9766, -244, 103], [-13128, 490, -82], [5462, 106, 95], [-4278, -1127, -461], [-2108, 406, 269], [2824, 337, 483], [21594, -236, 318], [-806, 999, -401], [23776, 724, 298], [-6584, -1014, -8], [18768, 1512, -206], [14912, 351, -171], [-10264, 600, 486], [-26046, 529, 37], [8810, 376, 10], [-5226, -1019, 30], [-14400, -303, -25], [154, 1224, 432], [-1488, -226, 390], [-20588, -1700, -690], [722, 358, 114], [25928, 504, 718], [15752, 984, -90], [36606, 1378, -211], [-19238, -424, -517], [13222, 1455, -14], [-37688, 1005, 155], [-2722, -582, 637], [-9336, -569, -479], [706, 684, -427], [12288, 1940, -612], [-18494, -2661, 255], [28768, 134, 176], [29042, 1382, 693], [-10592, -138, -471], [-12650, -414, -383], [352, 1518, -420], [-25876, -1452, 172], [-23942, 920, -375], [818, -2929, 35], [10064, 993, -785], [20438, -741, -2], [22130, -536, -638], [8116, 616, -864], [6402, -1972, -75], [-18344, -2004, 278], [44450, 946, 382], [10200, -1047, 243], [-19456, 2908, 640], [4190, 1175, -674], [20040, -3883, 31], [21234, -1261, -241], [-9558, -720, 435], [9810, -3128, 437], [21722, -4023, -11], [-7008, 3474, -220], [19570, 228, 683], [-36928, 1072, 478], [-42386, -704, -289], [13186, 78, -920], [-14700, -3452, 448], [-20170, -1133, -174], [-16704, -1288, -198], [39056, 113, -297], [18826, 2076, -226], [-1452, 1070, 1141], [-670, -1352, 1344], [17502, -823, 1162], [30256, 1376, -642], [-35548, -2032, 264], [23360, 1290, 6], [76610, 648, 146], [-2216, 2616, 234], [13954, 735, -493], [7704, -2475, 243], [-12454, -2862, 245], [2034, -2792, -700], [15248, 3958, -1329], [17890, -3792, -460], [2400, -120, -156], [37428, 956, 586], [-44022, -3124, -983], [-7998, 597, -995], [-7536, -1771, 1255], [-35408, 674, -527], [-29936, 5555, 225], [-21030, -416, 1072], [-11916, 6194, 359], [17160, -1352, 858], [36010, -2132, 700], [-17556, -2518, -1137], [40832, 1656, -300], [938, -5210, -472], [-77974, 1748, 201], [55624, -2333, 85], [32576, 1312, 370], [63888, 51, -459], [-45724, -3988, -660], [41240, 2072, 1074], [61018, 2088, -279], [-5574, -1307, 959], [17640, 2494, -562], [39440, -690, 1373], [40612, 890, 484], [-13848, -4926, 1140], [48392, -3967, -57], [-42350, 5616, -242], [-18278, -3277, 495], [-22904, 871, 709], [-37894, 4378, -728], [-57994, 2391, 560], [50872, -555, 1071], [50330, 1360, -1103], [-17932, -1858, -1019], [26846, 3891, -298], [29794, 4336, 354], [5888, 850, 764], [53040, 3547, 525], [68286, 3624, -583], [-64778, 1154, -21], [-2462, 4167, 1279], [-31428, 5912, 594], [68450, -2004, -207], [-32478, 803, -1639], [9072, -3338, -776], [-58670, -3786, 989], [-34946, -4098, -955], [60008, 2276, 1508], [-49350, -4974, 784], [2544, 3116, 220], [3394, 822, -1122], [-13072, -2658, 195], [20416, -4579, -989], [61370, 2232, -267], [-20750, -8, -503], [22420, -950, -940], [-34912, 5992, -858], [-56584, -1698, -850], [108424, 1360, 446], [-23170, 3218, -871], [-2364, 4072, -328], [-29312, 2967, -79], [-66014, 3936, -716], [14922, 2584, -225], [30104, 3378, 1341], [23514, 3433, -377], [-6862, -8580, -1045], [8244, -4992, 1020], [-34806, -82, -736], [18772, -6966, -320], [-53774, -3736, -1404], [-20962, 1719, 1820], [-2312, -2028, 796], [-21066, 1597, 712], [11180, 4130, 776], [-83860, -468, 522], [44882, -6860, 162], [35594, -4890, -389], [-8, -1310, -62], [114336, 1205, 1107], [-32680, 354, -616], [40674, 3340, -1996], [10432, -5445, -1071], [-4810, 176, -1963], [-37360, 1219, 493], [-52030, 11864, 153], [-40656, -5168, 1522], [18226, 1542, -481], [38322, 730, 1512], [32152, -5532, 606], [92936, 1949, 1711], [-65222, 2354, 600], [-41332, -2768, -714], [-91800, 2709, -465], [92290, -982, 1020], [-58318, -6438, -984], [-90460, 1038, -557], [-91870, -3144, 475], [9174, -4273, -542], [81176, 1568, 1526], [52154, -5360, -1420], [93322, 2534, 26], [888, 2122, -1818], [22812, 4866, 2645], [65024, 43, 765], [-36046, 6650, -421], [71122, -3336, 934], [19450, 8170, -1203], [-25608, -1694, 2113], [-89572, -4102, 118], [34800, -4438, -2190], [-70268, 4818, -774], [45818, 6452, 34], [56090, 8889, -1169], [55274, 4094, -2384], [23112, 3674, -2043], [-73062, 200, -2544], [53114, 7170, 400], [48902, -9435, -1584], [29288, 7180, -1240], [-66502, -7730, 607], [-37216, 1501, 443], [14182, -10952, -325], [21848, 8368, 674], [42576, 100, -260], [44526, -4269, 1640], [1492, -2618, -403], [-20734, -616, -13], [102818, 2508, 187], [16192, 1016, 34], [33562, 8256, 1392], [21314, -93, 871], [-68584, 2652, 88], [-65596, -1060, -1170], [-40158, 1804, -98], [86480, -9609, -1187], [-48550, -5664, -1332], [57298, 6177, -775], [48080, 2223, 649], [-35512, -4107, -1289], [25876, -10452, -1148], [-17502, 12248, -381], [-16610, -659, 3104], [-134192, 2122, 1216], [63314, -8888, 441], [648, 7035, 2821], [69412, 850, -1969], [-80776, -5997, 1377], [56026, 9764, -1023], [-27648, 146, -223], [26938, 8904, 1597], [96804, 4440, -2704], [-16480, 1117, -3377], [139170, 6444, 496], [-27758, 8987, -2157], [1682, 12498, 2668], [-168546, -389, -204], [79466, -11424, -1618], [-60424, 8308, 660], [177026, -2420, 1228], [-29556, -328, 1984], [46928, -452, 1934], [21432, -4748, 1974], [148334, 2924, 529], [178208, -4346, -560], [-78584, 12742, 50], [48106, 1012, 17], [-53058, -7663, 564], [-110904, 1577, -589], [108724, -14478, -173], [67472, -12133, -723], [-57862, -5364, 356], [104320, 2516, 1548], [-9366, -4725, 2511], [26416, 9126, -1064], [34594, 6478, -511], [32646, -11826, 2085], [75346, 4516, -270], [-40824, -12818, 1666], [-44678, -2635, 2609], [-4682, 2913, 2052], [-18256, 992, -1600], [19770, -1480, 45], [57426, -9572, 2194], [-69284, 3188, 26], [-13156, -10598, 3022], [86498, -18140, -1246], [-57134, -8830, 477], [-69072, -2301, -2407], [-11024, -6160, -994], [154946, 6420, -831], [90574, 4869, -1048], [-45448, -2991, 2107], [-74264, -10262, -369], [-30350, -3609, -1477], [-125968, -11342, 2282], [157466, -426, 795], [24590, 1686, 827], [22968, 8615, 2093], [73948, 2592, 2432], [-24878, 7756, -1158], [-7402, -10157, -1202], [-21776, -1901, -1175], [39882, 5438, -2834], [197660, 2592, 1636], [97736, -1686, 2236]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1344_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1344_4_a_bu();".
// 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_1344_4_a_bu(:prec:=3)
    chi := MakeCharacter_1344_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_1344_4_a_bu();".
// 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_1344_4_a_bu( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1344_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-1632, -216, 6, 1]>,<11,R![95488, -3060, -48, 1]>],Snew);
    return Vf;
end function;