
// Make newform 1080.4.a.g in Magma, downloaded from the LMFDB on 17 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_g();".
// 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_g();".
// 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 := [1, -6, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-4, 12, 0], [-24, -6, 6]];
    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], [2, 0, -1], [-4, 1, 1], [6, -1, -1], [7, 2, 3], [19, -3, 3], [-29, -3, 2], [-46, -8, 1], [39, 8, -5], [50, 8, 4], [0, 12, 5], [60, -4, 21], [-228, -1, -16], [-29, 1, -19], [-238, 3, -15], [-171, -10, -22], [-58, -12, 14], [-256, -19, 11], [-84, 15, 7], [69, 21, 17], [-563, 17, 10], [-104, -14, -33], [-360, -4, 60], [-996, -6, -40], [-308, 0, -60], [-556, 47, 22], [-435, -53, 14], [-566, -41, 12], [1102, -14, -2], [-894, -36, -4], [-1179, 23, 71], [-396, 24, 72], [-1160, 74, 15], [920, -87, -94], [-504, 29, 47], [1834, -30, 32], [-713, -50, -100], [-2087, 14, 23], [-1324, -18, 94], [189, 43, 22], [50, 72, -88], [-1654, -83, 51], [-1759, -29, 37], [2080, 62, -30], [-291, -14, 53], [1534, 2, -72], [593, -82, -238], [-3917, 27, 8], [-326, 22, -244], [-1682, 28, 50], [-2213, -19, -184], [-1944, 18, 14], [465, 3, 13], [1544, -37, 244], [-270, -104, -70], [3375, 132, 91], [-1844, 53, -101], [990, -100, -21], [-2120, 20, 47], [-755, 129, 11], [8182, -24, -92], [-98, 137, 317], [-3352, 84, 258], [-1385, -20, -143], [916, 94, 366], [-1138, 13, -533], [956, 102, 24], [-7435, -124, -48], [86, -84, 410], [-1490, 238, -114], [6066, 40, -13], [-8584, 118, -146], [4785, -298, -311], [2351, -328, -382], [2724, 120, -215], [7698, 5, 199], [1214, 26, -464], [-8911, -119, 42], [2396, -499, 5], [-4077, 18, 416], [946, -271, 113], [5090, 261, -199], [-961, 388, 13], [8253, 99, 308], [11130, -6, 77], [8548, 54, 558], [326, 74, -662], [-4562, 334, 342], [1177, 332, -242], [788, 1, -307], [12664, 126, -223], [3206, 188, -366], [-8353, 60, 157], [9163, 367, -462], [8708, 4, 416], [6008, -356, 317], [5962, 192, 33], [2022, 431, -854], [5204, -522, -579], [10466, -282, -338], [8004, 173, 634], [-4134, -524, 83], [-6389, 210, -543], [20752, 125, 83], [1595, -715, -182], [1045, -11, 349], [1430, 329, -461], [5229, 425, -884], [3044, 308, 1197], [-3424, -790, 556], [1571, -235, -843], [-18072, -38, -542], [797, -665, -159], [-6992, 646, 436], [-9826, -442, -187], [-3429, -738, 46], [-373, -126, 787], [5014, 805, -55], [-10522, -451, 698], [5094, 363, -29], [-10918, 205, -448], [-8963, -392, 512], [-13579, 522, 9], [3226, 776, -776], [-10214, -373, 742], [-16294, -176, 132], [12592, 98, -110], [-15848, 406, -408], [-7503, 816, 175], [2536, -302, -920], [-2243, 229, -979], [15162, 448, 242], [-12626, 34, 371], [6893, -443, -22], [-2877, -36, -525], [4584, -1142, 63], [8641, 217, -637], [7144, 58, 249], [-460, -819, -102], [-8854, -1040, 840], [-13796, -408, -299], [-21693, -120, 682], [-10610, 309, -396], [-9744, -1262, 330], [-5292, 1240, 882], [-33841, 224, -103], [-17503, -216, -465], [-10749, 663, 316], [19568, -371, -151], [-1362, -1050, -1145], [-9798, 154, -97], [-7309, -197, -108], [9892, 580, -296], [12178, 345, 499], [-21488, 374, -992], [-7504, 742, 237], [39392, -380, -194], [-32442, 404, 100], [-831, 227, 1814], [-11702, 364, 1088], [22186, 1426, -984], [-25118, -490, -1176], [9182, -78, 1758], [22431, -153, -1420], [-22591, 789, 13], [-920, 499, 569], [-4197, -509, 640], [-17403, -854, -473], [-18532, 678, 320], [-1049, -462, -302], [-27646, 357, -911], [12508, -994, 484], [-31143, -17, -1371], [18370, -860, 67], [-18129, -823, 1051], [6, -812, -345], [-14432, 360, 521], [-20270, 849, 1390], [23220, 580, -1013], [48856, -500, 474], [14098, 836, -608], [2022, 1871, -576], [-3819, 1066, -1048], [-7556, 422, -2952], [-10434, -251, -2007], [-19016, -592, 1122], [40833, -101, 864], [18830, 805, 1125], [5526, -536, -2000], [25115, -1828, -1284], [-15995, 803, 873], [-14976, 388, -152], [-15675, -163, -3366], [-10839, 1072, 89], [40317, -135, 288], [-11792, -1520, -1434], [-36686, -1648, 1278], [25592, -1431, -1742], [45304, -872, -411], [2668, -120, -486], [8774, -1560, 588], [17659, 1882, -1376], [-31486, 1079, 627], [7686, -866, 2092], [-20236, -800, -710], [45853, 156, 2894], [6036, 966, 2128], [26820, 172, 1472], [27590, 307, 2655], [-43572, -776, -1913], [27864, 1672, 260], [452, 1283, -2746], [-16916, 1548, 2832], [17445, -1704, 998], [6712, -2586, -259], [21968, -414, -356], [31027, -320, 1082], [2163, 1868, -2019], [-5366, 752, -1188], [42951, -307, 2349], [56934, -772, 11], [-5232, -1410, 35], [75825, 681, -1182], [-27185, -2103, 2934], [-17103, -191, -2281], [-12496, -1203, -1297], [-866, -784, 1822], [54724, -412, -820], [-4540, -659, 2577], [-22573, -553, 285], [17152, -160, -80], [-6362, -2934, 800], [4306, 370, -1679], [-26535, -1632, 186], [18641, 1379, 2148], [6913, -110, -1809], [18986, 322, 744], [45340, 37, -2729], [44772, 497, 1522], [-1849, -1403, -3879], [23222, 778, -2074], [-55979, -387, 1090], [6494, -1458, 410], [-30078, -128, 570], [-51968, 2280, 1894], [-6610, 2727, -1717], [28284, -3106, -1972], [51557, -1080, 428], [-78638, 400, 734], [45642, -298, 414], [48493, 1597, -1820], [33449, -1248, -2126], [-32849, -1582, 1123], [-44600, 586, 2692], [-77559, -1004, 776], [34398, 198, 3973], [3031, 1915, -659], [-39950, -1631, -2251], [-11208, 374, 2615], [-9529, -1398, -586], [12027, 2001, -1582], [-15468, -806, -1932], [31793, 2019, 2973], [-7868, 612, 1680], [49552, 1932, 1752], [75574, 1804, -776], [55398, -2682, 184], [-3726, -2188, -1726], [-8769, 1918, -1100], [-64658, 2862, 2310], [10672, 2653, 4291], [21751, 3710, -1461], [-53980, -1683, 3171], [25342, 638, 737], [53487, -1957, 2452], [15213, 874, 4548], [34753, 1451, -2162], [51040, -251, -2107], [13784, -1231, 598], [73211, 1673, 2137], [-35865, -524, 1514], [-32469, 824, 216], [35508, 2450, -824], [38446, -1521, 4193], [-4366, 240, -402], [35790, -1266, 892], [34785, -138, 903], [-11696, -1772, 1280], [26768, -1742, -2652], [-72409, -2245, 2984], [-20626, 1418, 5456], [-5266, 1634, 2550], [272, 739, -2167], [35868, -2208, 990], [17423, -3879, 1157], [-20926, 974, 1412], [-87272, -1518, 480], [-29638, 1844, -5831], [27888, 3801, -5233], [-31237, 1304, -6879], [59200, -70, 3292], [60669, 3907, -3218], [39585, -105, 1625], [47760, 1235, -1491], [-66220, 3473, 1982], [-5653, 2095, 6376], [-62284, -1039, -6597], [-47176, 1413, 897], [-46539, -2116, 2914], [-6836, 304, -3566], [73784, 2252, -1566], [-47782, -488, -2513], [34025, 4593, 294], [-31589, -3348, 2634], [-65664, -1420, -1924], [-106312, -1291, -1173], [27086, 313, 6205], [14670, -3202, 764], [-45223, 567, -3189], [-117944, -580, -3038], [-69268, 2168, 3450], [35584, 534, -4002], [-20113, -3377, 1959], [-14258, 709, 2466], [90033, 1241, -1819], [47888, 546, -2434], [-103512, -116, -5256], [-32195, 3193, 165], [4938, -2336, 5764], [123558, -3346, -2472], [-41728, 1285, 758], [-81452, -3609, 832], [69784, 2106, 590], [-22452, -1371, 2474], [27127, 1943, -2484], [-100145, -488, -5669], [31102, 1179, 3640], [-55300, -772, -6883], [-22840, -3786, -5354], [-95957, -1112, -1811], [26894, 3022, 6809], [8313, 5224, -2335], [-51438, 6965, 5892], [-36680, 2985, -4517], [34079, -3134, -3324], [-41468, -4128, 3782], [5340, -2466, -4674], [19661, -1180, 8905], [-53420, 2595, 4602], [-8762, 4906, -2814], [-134662, -2, -139], [5928, 82, -2826], [130970, -3243, -1300], [-113337, -4300, 4319], [-10646, 2287, 4605], [-41130, 5831, 3363], [-14054, 1128, -6702], [-50521, -957, 5804], [-9522, 1147, -4319], [68906, -2132, 4150], [49336, -2329, 1020], [-140710, 368, -3574], [-110572, -2872, 4202], [8766, 4319, 3119], [35235, -1011, -6857], [161114, -96, -1068], [11682, 1840, -5500], [30582, -1590, 8306], [121899, -2204, 3969], [-69263, 7127, 4304], [47908, -332, -4455], [-29913, -1350, -7493], [186360, -1148, 190], [45858, -948, 7748], [185034, 790, -916], [48412, -3661, -1755], [-51782, -2000, -98], [-122010, 3706, 958], [29540, -5346, -3390], [-9303, 1841, -2021], [-92510, 2398, -31], [-46693, 2336, 7787], [-12684, 6306, 4366], [67196, 1525, -5128], [-83667, -19, -1101], [-149170, -1, 2031], [55428, -3390, 149], [123072, 1832, 352], [37082, -5519, 4326], [61775, -226, -7541], [-1670, -1490, 1240], [-38066, 5550, 3860], [21110, 4866, -4598], [37112, 3405, 3937], [148945, 860, 4541], [20506, -1478, -9067], [-72555, -701, -2827], [-107452, 4970, 4238], [106746, -1944, -4708], [-37214, 3808, -1198], [-102666, 1118, -231], [68538, -4860, -5368], [-9230, -2120, 1631], [82315, 2542, 3419], [-25546, -1322, 8636], [241138, -824, 1402], [-129724, 622, -7006], [-59390, 2065, 8175], [-73130, -4530, 2908], [93217, 1972, 11311], [21515, -5637, 3840], [-93405, -2608, 4579], [-75534, -4054, 26], [-60234, -684, 5365], [192170, -1844, -742], [-48576, -2980, 2360], [-97343, 1483, 2535], [-7255, -7186, 4744], [133924, -170, 1370], [82826, -7766, -3146], [-14943, -2794, 884], [213238, 3042, 202], [-40074, 360, -10522], [73485, -1779, -4193], [-10313, 5266, 5738], [-29486, -1202, 5980], [42185, 8265, -993], [-82368, -2873, -975]];
    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_g();".
// 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_g(: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_g();".
// 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_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1080_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![-2744, -456, -6, 1]>,<11,R![-20920, -1260, 12, 1]>],Snew);
    return Vf;
end function;