
// Make newform 1080.4.a.e in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1080_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_1080_4_a_e();".
// 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_1080_4_a_e();".
// 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 := [15, -12, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [15, 6, -2], [-71, 12, 8]];
    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_1080_a();"
function MakeCharacter_1080_a()
    N := 1080;
    order := 1;
    char_gens := [271, 541, 1001, 217];
    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_1080_a_Hecke(Kf)
    return MakeCharacter_1080_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], [0, 0, 0], [-5, 0, 0], [-3, 1, 0], [4, -1, 1], [16, -1, -1], [-12, -1, 0], [9, 1, -1], [4, -2, -1], [-9, -3, -2], [14, 1, 2], [80, -8, 2], [-125, 1, -4], [-45, 11, 6], [23, -4, 9], [-271, 9, 1], [-202, 19, -11], [-91, 22, 6], [2, -18, 2], [-414, 9, 5], [-134, 3, -1], [-111, -5, -17], [-242, 26, -13], [-791, 15, 0], [190, -8, -14], [-204, -28, -12], [-238, -40, 10], [-619, -42, -15], [-240, -10, 27], [-699, -36, 9], [-388, -66, 8], [-996, 8, 10], [-961, -5, -9], [-616, 16, -4], [-315, -93, -16], [65, -50, 41], [2416, -9, 17], [-1306, -12, 20], [-1777, 0, 38], [-1218, 75, 8], [-1936, 50, 58], [104, 54, -69], [-1340, -12, 14], [2036, 43, -37], [-311, 145, -41], [-2920, -26, -14], [-716, 119, -28], [-246, -84, -52], [-493, -74, -66], [2428, 56, 67], [316, -108, 58], [-568, 94, -44], [1302, -124, 73], [-1356, 98, -14], [-1855, 217, -109], [-929, 128, 65], [1620, -102, 36], [-4830, -127, 30], [4326, 7, -65], [-2235, -221, 14], [-1985, 93, 28], [2945, -177, -43], [-3478, 164, 132], [798, 23, -91], [-762, 130, 112], [-380, -3, 166], [-1624, -238, -54], [6262, 159, -23], [3334, -280, 134], [2785, -60, -236], [-1036, 178, -144], [2040, 190, -60], [1731, 433, -86], [6546, -118, 76], [-7940, -165, -12], [1379, -166, -8], [-2489, 185, -268], [4248, 131, 47], [3986, 364, 56], [-206, 270, -119], [4264, 3, -55], [4133, 460, 78], [244, 415, 19], [-6040, -139, 85], [-5516, 63, 174], [3742, 560, 61], [2105, 149, -140], [9178, -30, 184], [-416, 150, -32], [3598, -54, 10], [-3687, 434, 140], [13992, -9, 61], [-2081, 95, -294], [5894, -142, 34], [832, -377, 246], [-3638, -346, 1], [872, -32, 140], [9107, -111, -44], [-8073, -189, -124], [137, -354, 175], [8259, -305, 234], [4434, -34, 258], [-3009, 138, -221], [-3071, -29, 206], [1606, 843, -64], [1162, -453, -293], [15800, -62, -189], [13495, -119, 65], [-1780, 41, -51], [-9136, 504, -339], [15699, 39, 34], [-8594, 4, -114], [7409, -303, -435], [-11732, -194, 70], [-9873, 379, 521], [-4758, -156, 114], [3919, -37, -192], [-8311, 502, 10], [3628, -241, 88], [14026, -225, 321], [3603, 310, -99], [-5196, -985, -53], [-8637, 552, -145], [-14257, 376, -4], [-2604, 235, -416], [6504, 332, 54], [-2599, -718, 255], [3774, -636, 348], [24072, -274, 10], [172, 100, 360], [-2028, -203, 146], [-16006, -296, 270], [10097, 247, 291], [19062, -66, 46], [7031, -37, 132], [-18202, -74, 73], [-738, 1247, 6], [31289, -347, -22], [-14211, -601, -83], [-7099, 613, 334], [11805, -306, -487], [-31146, 400, -124], [-4251, -397, -36], [-12517, -738, -188], [-10955, 64, -471], [16124, -586, -274], [-4242, 1258, -148], [-4664, -651, 46], [-7608, -627, -554], [-12056, -500, -203], [18688, 189, -429], [4077, -245, -562], [4867, 165, 774], [-28196, 356, 233], [12082, 1236, 246], [-13278, 1229, -201], [5682, -560, -178], [-34101, -147, -264], [-4188, 1274, 66], [20022, -388, 340], [7156, -290, 293], [15822, 360, 484], [19586, -804, -200], [-20262, -1396, 72], [-23582, 334, 942], [-12176, -1204, -527], [6069, -745, 259], [13380, 369, 291], [-24792, -628, -137], [-422, 515, -232], [28852, 1084, -204], [1011, -1762, -446], [-9514, 1355, -827], [-44002, 548, -390], [-27453, -433, 597], [-21935, 467, -890], [-959, -247, 891], [18409, -901, 882], [19793, -761, -696], [-9845, -302, 453], [24295, 1053, -104], [-23876, 354, 1114], [3058, 120, -1056], [7993, 872, -235], [-21691, -140, -634], [-26374, -256, 802], [40776, -535, 373], [-2196, 434, -742], [-38542, 404, 315], [-23700, 315, -445], [-24384, 148, 754], [1625, 292, 832], [44095, -597, -643], [-16834, 1372, -1114], [-9650, -1110, 35], [19794, -275, -1130], [-31968, -428, -31], [29348, -1366, 402], [13036, 2894, 424], [-30197, 1330, 659], [-33039, 1273, 382], [18838, -1034, -344], [-9756, 1792, -374], [-52331, 1360, -826], [6666, -11, 111], [29204, -956, -690], [39214, -650, 1032], [-15803, 322, 620], [-4156, 76, -476], [-36180, 952, 784], [46380, -901, 703], [63717, 79, 72], [-12156, -236, 752], [50653, -162, 177], [-354, -524, 1122], [-3345, -986, 480], [8807, -253, 846], [-33168, -88, 1544], [11723, -198, -980], [40692, 1305, 198], [14734, 1132, 688], [-38929, 327, 515], [-14409, -3465, 64], [31573, -1595, 102], [-17170, 66, -897], [34260, 70, -855], [25373, 1531, -923], [58196, 289, -149], [-24836, -2190, 372], [-6974, 344, -1726], [-12340, 1725, 1083], [51677, -1401, 765], [-29848, 720, -1560], [60622, -92, -516], [-27199, 859, 618], [42345, 450, 384], [-1674, -680, -1693], [43542, -789, 680], [53284, 760, 394], [13680, 1697, -125], [25843, 578, -1769], [-17549, -317, 159], [-21958, 250, -282], [46786, 1306, -587], [16146, 26, 1394], [54468, 1206, 732], [13472, -1714, 818], [37090, 3029, 779], [-58246, -1820, -322], [42923, -2392, -204], [-2608, -4114, 172], [-2532, 690, -1836], [-22928, -1244, -469], [27139, 130, 1548], [15164, 2007, 1452], [13680, 2040, 1008], [46261, 1356, -116], [-44017, -1957, -816], [8719, 3881, 255], [-4070, 1429, 99], [-20333, -267, -1104], [58369, -2550, 566], [38512, -2046, 1077], [57352, -1880, 1124], [-32683, 65, -329], [18532, -936, -840], [-9702, -212, -150], [-37634, -2264, 1064], [-36792, -1688, 242], [23776, -870, -760], [3901, 1816, 998], [-77698, -2006, 386], [39712, -945, 561], [30756, -359, -452], [-75460, -1577, 305], [-1223, 3599, 970], [-23232, 2016, -111], [43763, -1520, -378], [18488, -1286, 623], [-63870, -3345, -177], [-69829, 1270, -689], [-30909, -821, -769], [30895, -2318, 428], [84831, -1628, -1780], [5468, -316, -2116], [6484, -1645, -189], [34224, 942, -1740], [-53880, -2996, -534], [-42010, 701, 2236], [-19194, 2604, -2290], [-33668, -728, -2132], [-40536, 1764, 541], [21236, -2480, 1210], [71716, 502, -1816], [36982, 5085, -179], [-94928, 2106, 386], [-31797, 3055, -2417], [39376, 44, 1238], [-5098, -2624, -782], [-29153, -821, 1044], [10508, 1475, -1759], [-37008, -3467, 1014], [92810, 68, 754], [5136, -2202, 21], [-35285, -2365, 717], [-12350, 421, -39], [-11525, 5166, -989], [101492, 2344, -597], [-50956, 2421, -1709], [32294, -951, -2967], [-54271, 3026, -1964], [-48334, -2054, 1760], [-69084, 70, -1778], [41333, -523, 2132], [16390, 5178, -1541], [-10479, -3110, 2664], [-3006, 56, 918], [21822, -1671, 257], [10046, -2219, 2699], [-50900, -1012, 2046], [34637, -807, 229], [-33344, 2318, -2326], [5708, 934, -262], [49604, 610, -918], [14953, 5443, -937], [1347, 222, 2269], [29593, -609, -3557], [21898, -2234, 240], [-52708, 1456, -2364], [-30425, 249, -2707], [-54662, 3804, 1252], [-125668, -2200, -494], [63017, -2038, -915], [-57153, -5060, -687], [-26776, -4558, -538], [-20173, -2494, -1937], [-2008, 4780, -585], [13990, -2353, -2242], [48647, 1628, -725], [-128225, -1201, -826], [23020, 5862, 1654], [131552, -1367, 782], [-97129, -2535, 478], [-8682, -2557, -570], [27283, -1388, 1835], [-15200, 193, 1831], [-86991, -4384, -958], [10702, -3078, -412], [-127010, 358, -688], [-104446, 1525, -610], [17275, 118, 1955], [2628, -1394, -2188], [132777, -495, 16], [-8862, 350, -328], [106025, -456, 1769], [12982, -4301, 2506], [-98814, -3789, -1239], [-97380, -2519, -747], [-96396, 3722, -2980], [-68464, 1428, 3449], [-128982, 3713, -2261], [-102076, 214, 1768], [143119, -592, 161], [19230, -4910, 1606], [-113312, 1794, -374], [50246, -3681, -3911], [53175, -4245, 1273], [-67246, -84, 2696], [-66298, 1140, -584], [-65732, -1054, -1716], [62684, -1077, 1434], [-29862, -1720, 1169], [34647, 2849, -52], [-12848, -647, -1320], [-78950, 174, 1744], [38072, 3784, -2594], [57706, -1576, -148], [2132, 4393, 2079], [-23188, -6458, 592], [3190, -2426, 4186], [710, -1058, 3824], [-1527, 3407, 2005], [-119875, -3473, 306], [166418, 415, -298], [95916, -3934, 2870], [63529, 9492, 399], [112763, 3033, 1287], [-12630, -5373, 1673], [-12577, 3431, 6], [-100792, -5752, 632], [42167, 5506, -2367], [53980, 1831, -1932], [18410, 2100, -2232], [-14646, 4840, -824], [-56580, -5350, -2164], [112722, -5787, 2209], [73070, -2041, 242], [166759, -1911, -478], [66215, 2535, -1319], [128602, -3662, -232], [42926, -1300, -4000], [-58696, 1906, 1608], [65599, -973, -4440], [22082, -808, 1264], [-2145, -5889, -3708], [-33180, 2065, -640], [-107036, 540, -738], [-9048, -2790, 552], [49586, 50, -2136], [39110, 4645, -189], [42780, -2628, 1774], [38828, 9187, 1058], [-25800, -1996, -1639], [84290, 5825, 1166], [-74264, -2354, 3596], [12189, -1627, 3236], [111530, 2386, -686], [15744, 4160, -3536], [127543, 4859, -981], [-21435, 4356, -1742], [27716, 6650, -730], [-42074, -4986, -2410], [111453, -5688, 1030], [-12618, -482, -1770], [-95384, 6942, -3504], [-104955, -6405, 741], [10213, -8474, 966], [61266, -696, -176], [45655, -1947, -3641], [-69222, -6909, -301]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1080_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1080_4_a_e();".
// 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_1080_4_a_e(:prec:=3)
    chi := MakeCharacter_1080_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_1080_4_a_e();".
// 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_1080_4_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1080_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![5832, -756, 8, 1]>,<11,R![59400, -2864, -10, 1]>],Snew);
    return Vf;
end function;