
// Make newform 1344.4.a.bq in Magma, downloaded from the LMFDB on 24 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_bq();".
// 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_bq();".
// 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 := [-84, -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_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], [3, 0], [3, 1], [-7, 0], [-13, -1], [-48, -2], [39, -3], [-20, 0], [11, -5], [-102, 0], [48, -16], [-252, 2], [-51, 11], [-148, -16], [-390, 10], [-96, -18], [-106, -14], [50, 16], [-106, 2], [-267, -11], [564, 10], [234, 58], [412, 48], [-1059, 27], [200, 70], [181, -93], [-812, 28], [-829, 31], [-326, 96], [782, -36], [1194, -38], [-1720, -52], [1012, 74], [-492, 32], [2592, -18], [-1048, 64], [-2170, -44], [-982, 70], [1602, 106], [1057, -73], [-1483, -7], [3052, -14], [-15, -151], [-1348, -22], [-928, -2], [-1980, -180], [456, 84], [-4924, 52], [670, 82], [-548, -110], [-3620, 82], [3307, 115], [2616, -122], [1654, -190], [4845, -13], [-1565, -109], [-357, -31], [-6556, 100], [-1152, 350], [936, 174], [-812, -128], [-2867, -37], [-4176, 260], [-6062, 154], [3482, -64], [2336, -410], [-4368, 148], [-4826, -44], [-1723, 241], [-862, -272], [7663, -27], [1989, 213], [9048, 88], [-5326, 96], [-1160, -84], [884, 292], [-6838, 168], [-5938, 12], [2128, -82], [2680, -498], [-3658, 122], [4048, 94], [-12439, -127], [-6098, 204], [2136, -576], [-1043, -247], [-7590, 568], [826, -288], [8037, -165], [-6370, 366], [-1966, -426], [-8778, -234], [5700, -244], [7965, -87], [-2016, 748], [-8272, -280], [-2117, -431], [-17037, 129], [-8564, 232], [3888, -314], [11326, -358], [12644, 314], [5810, -250], [-116, -686], [9842, -906], [542, -292], [-3078, 54], [18743, 221], [12897, 465], [-3802, -324], [14760, 440], [-454, 40], [-1192, -658], [-4544, -1412], [-10510, 106], [13388, -902], [16772, 312], [4686, 1078], [-194, 340], [-7233, 99], [-4562, 1428], [-1200, 94], [7073, -449], [14833, -163], [10768, -572], [9538, -1048], [-25830, -408], [4656, 1616], [1260, 1444], [16144, -642], [10562, 1278], [19109, 21], [-12952, 920], [-21318, -328], [-11355, 723], [6438, -844], [12049, 927], [-22328, 348], [3777, -1113], [4170, -400], [2040, -268], [15356, 74], [8614, 1598], [-18533, 39], [-1484, 1314], [-32562, -618], [-3590, -2064], [-22819, -629], [5664, -1028], [-1617, -233], [802, 1928], [-4317, 105], [-2080, -276], [12754, -1430], [-26180, -624], [27489, 1401], [5156, 2220], [9161, -289], [-5210, 588], [6907, 2417], [-28925, -1049], [-19982, 1448], [45586, -470], [15260, 1240], [-22344, -682], [10916, -404], [23788, -1892], [-40642, -300], [8032, -2210], [18813, 459], [2671, 1307], [25942, 388], [-29855, 545], [-7832, -2978], [-6740, -1572], [39791, 637], [-40818, 1346], [-19598, -2096], [-11304, -528], [1118, 812], [-58914, -530], [28296, -1764], [-39240, 886], [-42421, -407], [-9753, -1009], [-39871, -785], [13270, 188], [40636, -608], [22704, 1894], [-14476, -60], [7544, 102], [-16349, 703], [4148, 2208], [8669, -1085], [-2833, 3859], [-7977, -1035], [-2808, -58], [-3672, -1074], [-11271, -2401], [6158, 742], [-25312, 1494], [3924, 1508], [38304, -1386], [-1960, -506], [21592, -1548], [-36647, -209], [-24852, 1644], [1691, 3791], [-48622, 952], [-24712, -572], [-23046, -88], [-14969, 1877], [-31060, -1212], [21332, 2176], [-7862, 3842], [33526, -2420], [-29932, 1396], [-7021, -2807], [7347, -2061], [-36270, 1976], [-13742, -1728], [29364, 2044], [3414, -2540], [-19408, 256], [-29216, 532], [-32780, 2], [52109, 523], [3155, -597], [4316, -1420], [-2087, 4405], [38138, -1408], [48832, 1508], [39388, -2516], [26498, 296], [44024, -876], [57208, 328], [-592, -258], [-28132, 2570], [56465, -1619], [-15288, -2224], [-42223, 2117], [-73272, -524], [-62548, 132], [28744, 270], [-25647, -441], [41274, -2094], [68928, -1168], [20398, -1502], [-13830, 2318], [34439, 1855], [1734, 3020], [66759, -2595], [-107071, 257], [71260, 1522], [-343, -3857], [-28689, -1725], [-29024, 2734], [2248, -1980], [-34919, 3687], [-31826, 116], [-19478, -1830], [-19191, -339], [64804, -1046], [71962, 1368], [-96845, 153], [32280, -1012], [-35588, -2574], [-5381, 4009], [81014, 2410], [17722, 2808], [-6710, 40], [60788, 2032], [-65628, 170], [-13540, -3652], [37852, 3770], [4980, -4], [59055, -4853], [-100464, -2554], [41564, -1678], [-16786, -302], [91124, 2452], [69586, -4518], [-45868, -2308], [-68698, -1828], [15932, 4216], [72377, 2001], [-100014, -1504], [100108, -422], [-85252, 3828], [19205, 1355], [-79432, -3890], [9976, 2348], [2792, 5582], [-1406, 2030], [-105982, -936], [28225, 6439], [15156, 2500], [121799, -59], [-35314, -3430], [52812, -2144], [121410, 312], [10202, -1872], [55398, 2966], [42111, -3357], [-90270, -2330], [20830, -1668], [112945, -2003], [7836, 1658], [15837, 2301], [29304, -890], [80364, -4452], [-130538, -1244], [24888, -730], [50392, 2596], [24331, -3973], [64980, -4598], [58936, 4156], [-102573, -1413], [-54964, -4870], [-78988, 1842], [-77436, 520], [-77912, -4914], [-17491, 4995], [3988, -5532], [-15802, -628], [-20060, -366], [101646, 970], [137268, -1568], [23005, 4517], [23210, -9304], [-10162, -316], [130702, 244], [-46228, -628], [49590, -7718], [-31362, -1534], [-103482, -3454], [19330, -4264], [-4979, 4307], [-8896, -5386], [-125052, 2036], [11218, -8928], [26088, 1230], [83031, -2619], [-21460, -9340], [-23454, 4712], [-91289, 3451], [-14952, 1934], [-11564, -3304], [-102668, -1628], [117421, 5035], [-52664, 4796], [-71496, 174], [-76616, 8014], [-3300, 5484], [92226, -2192], [13535, -9811], [-78688, -5104], [68, -7040], [-124458, -1212], [32089, -2919], [-11670, 1608], [131761, 3583], [67697, 2729], [-46817, 4971], [-21040, 84], [-40240, 3238], [166247, 3757], [159898, 3090], [-18660, 834], [-25383, -2739], [-138872, 2100], [-2931, -3947], [-121860, 1066], [31172, 396], [-184448, -3786], [45040, -7516], [-60469, -4349], [-1122, 348], [-127393, -5003], [194812, -1710], [66885, 9195], [100578, -5016], [-47332, 2404], [20142, 8364], [40140, -7776], [-11540, -844], [-4568, 13608], [-136040, 4814], [13782, -10774], [109142, -7690], [45792, -11026], [-193549, 1457], [-87189, -1305], [-66936, 4108], [-101555, -1395], [-30322, -8252], [145748, 3348], [-121273, 3413], [-122490, -2998], [-23650, -11764], [-35470, 12432], [18366, -6084], [-105326, 4418], [-14659, -2581], [51459, -4463], [84424, 4560], [159600, 1686], [63586, 2864], [11852, 8016], [-208866, -126], [47946, 1688], [-113046, 8184], [-1399, -10571], [-185588, -3928], [158424, 1262], [132503, 1085], [-4033, 7079], [7872, -11576], [119451, -4815], [46146, -5046], [90298, -5056], [-68426, 2956], [-9695, -1591], [-68304, 8588], [70250, 352], [24905, 2159], [120881, -5947], [744, -8082], [-152844, 3600], [-187598, -3958]];
    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_bq();".
// 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_bq(:prec:=2)
    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_bq();".
// 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_bq( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1344_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-328, -6, 1]>,<11,R![-168, 26, 1]>],Snew);
    return Vf;
end function;