
// Make newform 1080.4.a.j in Magma, downloaded from the LMFDB on 25 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_j();".
// 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_j();".
// 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 := [9, -8, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [11, 2, -2], [-25, 8, 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_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], [-4, 1, 1], [11, -5, 0], [-27, 3, 0], [5, -1, -3], [-24, 3, -2], [-10, 12, -7], [-32, -23, 1], [-31, -3, -11], [-142, 4, 12], [-202, 13, 1], [22, -21, 7], [-201, 30, -7], [-52, -17, 4], [87, -41, 14], [-233, 26, 0], [126, 34, -26], [-1, -3, 22], [-325, 91, -8], [394, 53, 28], [-588, -68, 17], [-592, 11, -35], [-292, -12, 48], [-778, 20, 6], [452, -28, 36], [-149, -12, -33], [-266, -4, -7], [-423, -110, 5], [-552, 38, 108], [-678, -100, -64], [-1384, 5, 68], [524, 56, 32], [-256, -101, -3], [863, 52, -9], [-871, 135, 38], [600, -108, -46], [-1005, -200, -54], [371, 91, -159], [-1394, 26, 128], [-2698, -108, -15], [-1562, 96, 136], [323, 123, 106], [16, -229, 82], [-1122, 418, -28], [2109, -33, 33], [3076, 28, -62], [-1543, -66, 4], [1024, 162, 71], [-2196, 72, 134], [-774, 298, 62], [-1398, 494, 21], [-1314, 98, -148], [-1700, 355, -74], [-345, -534, -135], [-3654, 442, -190], [1405, -571, 113], [-2987, -525, -126], [2268, 123, 215], [6054, -167, -51], [750, -163, 50], [-3522, 380, -244], [-743, 119, 52], [1216, 38, 82], [4023, -207, 5], [498, 822, -80], [15, -373, 50], [3546, -268, 10], [-531, 280, -96], [3722, 34, -258], [5044, -158, -120], [-1460, 357, 237], [1014, 174, -568], [4381, -845, 137], [5833, -446, 150], [3006, 41, 1], [-14389, -57, 30], [364, -804, -106], [9456, -156, -209], [3727, 583, 168], [-1475, -708, 614], [7645, -317, 80], [-5377, 189, -148], [9289, -77, 47], [-862, 314, -103], [4330, -1159, 539], [-3918, -34, -568], [10416, 598, -104], [8844, 206, -40], [4015, 998, -350], [307, -1193, 292], [-13624, -477, -227], [1954, 146, -250], [9021, -205, 339], [5216, -176, -129], [-3728, -120, 476], [302, 1509, -295], [5680, -673, 351], [-11201, 936, -419], [-13156, 327, 401], [3584, -86, -752], [-7583, 212, 237], [632, 1811, -9], [10475, 1603, 349], [-5079, -581, 714], [-10006, -1100, 141], [8450, -505, -108], [11853, 749, -678], [11912, -366, -531], [-5746, 1347, -545], [-6522, 1168, -194], [8020, 463, -1012], [4538, 618, -96], [-2904, -687, -914], [11814, -688, 622], [7838, 599, -343], [-5781, -38, 1076], [677, 1263, 769], [-6907, 187, -604], [6401, -484, -765], [21153, -505, 72], [2015, -1534, -493], [5011, -640, 816], [-3059, -2357, -211], [-5890, -1600, 840], [6303, -1820, -579], [9606, 2708, 364], [-14670, 2266, -128], [1890, 292, 1006], [9279, 1625, -259], [-12526, 940, -954], [-7742, -2103, 680], [-14074, -1738, -586], [-12198, -241, 825], [20208, 1628, 331], [-11089, 1299, -1129], [-9784, -2067, 163], [-1398, -1691, 954], [-32580, 525, -9], [-3521, 1204, -533], [16662, 1720, -728], [-5198, -1109, 771], [8369, 586, 922], [7605, -1598, 1273], [-4978, -1170, 792], [-10680, 4142, -778], [-6129, 1585, -683], [4439, 633, -1211], [-16028, -550, -1151], [-23963, -731, -244], [-13866, 2179, -863], [-13118, 1533, -69], [-3504, 730, 365], [-28928, -408, 948], [185, 325, -998], [13482, -668, 462], [-2856, -2255, 503], [9496, 1026, -1370], [-35850, 2860, -864], [-34414, -260, -485], [-8678, -2504, 28], [-14624, -2340, -686], [-76, 1820, -78], [2184, 2962, 348], [-24016, -2974, 353], [-4386, -343, 1152], [-5577, -1503, -78], [29940, 266, -357], [5139, -1261, -347], [-5862, 2596, -1494], [-9891, -1894, 612], [-26951, -1613, 1740], [13086, 112, -822], [-24020, 2893, -1158], [-17680, 387, -89], [-4600, 3155, -670], [-2204, -2745, 2843], [21742, -1881, 1343], [1689, 3728, -1941], [-12414, -3107, -183], [-16992, 346, -1010], [9046, -3320, -436], [1869, -666, 609], [2161, -1076, 994], [-18014, -1452, 658], [4827, 2445, -388], [12260, -3162, -90], [19242, -54, -53], [-6739, 207, 2656], [44854, 2392, -40], [-28431, -124, 3256], [1856, -479, 142], [50692, -1576, 204], [21376, -1164, -1235], [14261, 1137, 1557], [16488, -1714, 1697], [-18276, -3150, 2938], [19154, -3298, -586], [-271, -1404, -2959], [6530, 173, -2459], [-10408, 214, -442], [-51242, -36, -828], [7561, 572, 986], [40663, 5257, 924], [-8824, -600, 1486], [41856, -890, 118], [-37309, 742, 922], [-2934, -6316, -638], [3400, -4744, 1564], [38817, 267, 1604], [21874, -2025, -641], [-20088, 3308, -700], [-30745, -1988, -1741], [56104, -304, 932], [15281, 4010, -2286], [4872, -953, 2073], [30514, 4408, -1486], [1973, -2022, -2098], [45699, 861, -1887], [-33478, -92, 332], [-23676, -3079, 3024], [-9980, 4387, -305], [-21348, 7057, -965], [43816, -4236, 1905], [12458, -5608, -153], [17862, 3961, -2014], [42831, -2839, 1882], [34114, -3150, 1698], [46656, -4420, -536], [-50983, -3683, -844], [34802, 5749, 1262], [-65680, 3952, -1792], [-54828, -2628, 2854], [11950, 4459, 721], [-129, -4854, -1362], [21354, -1258, -2257], [10151, 7883, 1469], [36880, -3780, 2070], [-32853, 5633, -1750], [-26539, 3188, 401], [13944, -771, -688], [39256, 166, -2828], [-34516, 9412, -2809], [50140, 1990, 44], [7626, 9738, 978], [14572, -238, 1978], [-80277, 3601, 116], [-1402, 680, 890], [-32169, 4124, 2928], [-49090, 2642, -342], [-3432, -1630, -1400], [86624, 3294, 779], [-9963, 478, 3166], [44569, -9073, 2425], [83610, -656, -2278], [6921, -6080, -288], [33054, 4887, 3049], [-16406, -877, 1386], [68355, -4031, 1372], [-14828, -3851, 983], [-2801, -1910, 3636], [-45962, -3908, 2435], [-27998, -5264, -2922], [51652, 3299, 1982], [-10256, -5832, 4452], [-23732, -984, 2452], [74126, -8288, 2548], [-22272, -548, 3510], [28366, 2842, -1242], [-35171, -2976, -3194], [-30844, 5342, 416], [-23135, 12595, -1798], [-18221, -3039, -1845], [-48907, -3277, 218], [69742, -4125, 701], [2520, 4026, -4095], [-90809, -312, 842], [-75634, 6060, -899], [38475, 4607, 3040], [-40023, -1624, 1765], [20580, 3285, -4112], [-50947, 1090, 1618], [-3561, -6088, 4676], [109594, 3148, 242], [-545, -7497, 434], [-19914, -30, 3090], [55912, 4232, -298], [-25411, 10005, -4009], [-13468, -7120, -988], [49810, 9904, 2810], [-64520, 3646, -2219], [8316, 3332, 286], [-100000, -5806, -684], [807, -9239, -606], [-15920, -7706, 5862], [-81560, 4169, 2476], [-2940, -2976, -210], [5778, 4596, 2574], [50988, -433, -5013], [2797, -4513, 586], [-23945, -3223, -1279], [-15874, 3104, -858], [-89538, -620, -2869], [29552, -6439, 1274], [73959, 1301, -5130], [-50595, 11088, -2707], [-23564, -1814, -4373], [29543, -7347, -958], [-56035, 5317, -3892], [-15161, 2250, -6014], [-56888, -3118, -2286], [6152, -11006, 2510], [-19988, 6529, -3751], [-47628, 1144, -1727], [-55549, -12786, -3526], [28052, -11460, 4568], [-82465, -6307, -2674], [-36937, -10615, -244], [33496, -5128, -138], [41164, -9625, 5408], [68064, -6610, -3110], [35104, 8242, -2438], [29302, -2474, -4280], [-40738, 11477, -252], [31505, 1300, -2061], [-87906, -8855, -528], [33882, -2618, -2420], [-91924, -2192, 3540], [24874, 13191, -2588], [-41598, -3348, -2996], [-22712, 8164, -5742], [11715, -10040, 2607], [-40721, -6578, -1959], [20746, -5634, 1836], [-23207, -4668, 5725], [-68648, -474, 5639], [6843, -11261, 4319], [12551, 3186, 3971], [-51570, -6477, -3945], [32094, 1662, -3200], [-47717, -13547, -5063], [-7678, 6293, -7029], [19975, -2489, 3759], [-65641, 1478, -4257], [64051, -1107, -3534], [-69487, 11848, -2782], [105560, 6634, -614], [119006, -3550, -288], [-12647, -13511, 2101], [-30239, 9224, -2959], [39720, 9282, -344], [-44450, -12391, 927], [-122110, 1870, 212], [60345, -982, 489], [-17777, 4031, 2815], [75795, 4827, -7314], [-22325, 12033, -3716], [81826, 4850, 4762], [36996, -11774, 4749], [2061, 14217, -2950], [-47370, 7454, -4670], [-52317, -7398, -27], [-40798, 6674, -3830], [-114552, -6610, -1018], [12325, -5845, 2864], [-69716, -14047, -4494], [-42414, -6004, 2124], [-70718, -5060, 4452], [150328, 1838, -1800], [61241, 3439, -5785], [63166, -2050, 4645], [-137174, 385, 1733], [-33633, -9671, 2143], [101736, -12822, 2374], [-65190, 12980, -7448], [-46884, 3504, -6834], [-42773, -14139, 782], [41322, 2654, 790], [80936, -6066, 6636], [2038, 9574, -1028], [50934, 6237, -6650], [-15518, 9155, 4269], [-47057, -2173, 927], [-162202, -8850, -1668], [-174763, 1058, -581], [36974, 6051, -2406], [159781, 8907, 2336], [-40032, 3255, -5339], [72176, 3664, -544], [-42815, 2648, 8835], [-111507, 543, -4115], [56932, -8868, -1830], [11800, -15448, 490], [134632, -17066, 4736], [76301, 5173, -3540], [-112997, -4701, 543], [20986, -5383, 9947], [114136, -2075, -5550], [19946, 4858, 7372], [23554, 16916, -1004], [48794, 8946, -4166], [5174, 7171, 3261], [41602, 17568, -5300], [-85140, 1695, -3273], [11247, -7295, -525], [2872, 10680, 1506], [26466, -5622, -870], [-102630, -16518, -4460], [-16615, -447, 7342], [122936, -1848, -9422], [-188735, 4655, 651], [171556, -1434, -4515], [-90839, 24597, -6663], [-11420, 11530, -6096], [174256, 1117, 1697], [-188922, -2406, 6246], [110580, 5184, 5828], [29104, 15149, -2112], [101257, 2100, -7114], [29438, -922, -6284], [126404, 8806, 2380], [62905, 3552, -10510], [81832, -21650, 3384], [-123902, 13546, -2542], [3858, 9433, 9002], [47991, 13710, -3224], [163252, 1760, -9570], [12762, -1569, -2162], [-6451, 11831, -6286]];
    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_j();".
// 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_j(: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_j();".
// 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_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1080_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![-2808, -704, 10, 1]>,<11,R![8424, -2772, -28, 1]>],Snew);
    return Vf;
end function;