
// Make newform 280.4.a.f in Magma, downloaded from the LMFDB on 05 January 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_280_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_280_4_a_f();".
// 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_280_4_a_f();".
// 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 := [-54, -31, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-20, -3, 1], [39, 10, -2]];
    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_280_a();"
function MakeCharacter_280_a()
    N := 280;
    order := 1;
    char_gens := [71, 141, 57, 241];
    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_280_a_Hecke(Kf)
    return MakeCharacter_280_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]];
    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], [-2, 1, 0], [-5, 0, 0], [7, 0, 0], [-1, -1, -3], [2, -7, 2], [-16, -5, -4], [-53, 12, 7], [-17, -20, 3], [-153, 13, -9], [-91, 10, 5], [83, -22, 13], [-29, 12, 13], [-227, -24, -11], [-256, 25, -6], [16, 22, 14], [-364, 40, 4], [69, -68, -33], [64, 64, 20], [-360, -96, 24], [-60, 92, -14], [137, -67, -49], [-558, -40, -22], [27, -12, 77], [552, 207, -36], [-339, 78, 51], [484, -147, -2], [868, 82, 36], [371, 135, 7], [553, 30, -65], [-212, 208, -108], [295, 252, -61], [1355, 372, -51], [-798, 202, 22], [-2144, 104, -38], [839, -103, 93], [54, -12, 76], [-150, -478, 66], [728, -19, 114], [-1120, 131, -132], [344, -224, -164], [-972, -430, -90], [-299, 271, 79], [1247, 652, 9], [-917, 188, 81], [-946, -364, 46], [-2313, -139, 145], [-1354, 57, -192], [-544, -319, 2], [-2813, -84, -27], [-1612, 142, -18], [-2809, 277, 157], [-331, -66, 51], [-590, -466, 62], [356, -392, -142], [102, 178, -38], [-7416, -108, 22], [-527, -306, -79], [4496, -28, -134], [-1751, 601, -339], [-5004, 23, 170], [-3096, -1001, 124], [540, -641, -38], [-1161, -1076, -45], [3898, -83, 154], [-868, 204, 174], [984, -280, -148], [7466, -556, -160], [2017, 632, -23], [-3385, -1370, 101], [5346, -237, -370], [1580, 1576, -44], [-1260, -1055, 38], [4773, -868, -493], [2844, -912, -544], [-3674, 1032, 262], [-3305, -69, 331], [1058, 111, 574], [5441, -917, 225], [368, 1624, -58], [-476, -484, 76], [4957, 739, 209], [1855, -769, -839], [10866, -880, -272], [2846, 1494, -166], [-2991, -1648, -191], [7693, 509, 497], [-3003, 1020, 111], [-7560, 542, -438], [-2315, -1274, 597], [-2656, -21, -602], [515, 1012, -65], [-9734, 722, 646], [-1367, -1379, 259], [6407, -629, 573], [-2290, 663, -20], [-358, 256, -488], [6325, -1050, 731], [9372, -1164, -36], [-9381, 757, -29], [-19089, 118, 307], [-6628, -1206, -118], [-3556, -1484, 300], [-4342, 664, -1264], [-6202, -1148, 250], [-10786, 577, 198], [-4794, 2220, 262], [-15838, 697, 634], [-14525, 1143, 173], [7430, 1340, 500], [-3970, -1329, -156], [9466, 1212, -636], [6712, -2076, 574], [-4975, -176, -779], [-21583, 555, -405], [-5838, 1424, -368], [13574, 1337, -136], [2402, 916, 34], [-6255, 1278, 1315], [8669, 1031, 379], [506, -2078, -1476], [7459, 1740, -467], [-5160, -1563, 768], [181, 2346, 1081], [-2710, -1832, 90], [10855, -2871, -801], [11077, -383, 781], [16409, -664, 181], [-6394, 332, -906], [-5030, -779, -1446], [-14793, -409, -1443], [-3774, 192, -870], [705, 1085, 911], [6930, 3334, 544], [-5725, 754, -407], [-12226, 3572, 1548], [5422, 5097, -98], [-4858, -787, 904], [13676, -1773, -280], [-16027, -573, -915], [11572, -1262, -1368], [-15735, 1239, 997], [-679, -1374, 1225], [11670, -2498, -202], [-197, 1660, -1459], [1043, -3088, 415], [32930, 1244, 256], [5362, 1288, 1288], [1772, 2124, -20], [-1387, -1522, -779], [3137, 2022, -1117], [6548, -2674, -298], [-5347, -498, 2273], [-15796, 2944, 908], [-4817, 5648, 311], [25922, 3476, 146], [-20401, 2957, 805], [1318, -2066, 2136], [11854, -1893, -1102], [4061, 2404, 1015], [-5435, 1730, 825], [-12241, -4880, -247], [-8876, 2482, -2024], [581, -122, 37], [-16731, 438, 2107], [938, 119, -1488], [-29712, 528, -1880], [12372, -1585, -344], [12835, -2077, -2037], [-12512, -9076, 1014], [5884, -4980, 2528], [11296, -3668, -130], [107, -4421, 1613], [424, -1748, -82], [-7163, -4928, 1857], [-39104, 1626, -478], [-42443, -3769, 275], [-13613, -3613, -1673], [48710, -2328, -426], [26619, 2240, -475], [-5957, -714, 363], [19047, -2978, 2767], [-21493, -690, 413], [19794, -4996, -1656], [-20767, 2050, 1217], [30481, 2362, 1351], [4490, -5018, -824], [-17614, -5919, -196], [15001, -965, -223], [35505, -762, 409], [-1642, -2560, 812], [28479, -1756, 303], [-11133, -7615, -1227], [9827, 1344, 853], [37390, 3308, 1138], [-1826, -1311, -3538], [-4875, 6677, 265], [9207, 152, -811], [9180, -5525, 3248], [-15720, 4501, 3434], [19918, 768, 2072], [-27310, 3502, -738], [39432, 1180, 2326], [-33505, 2726, 1197], [-66749, -2856, -225], [53750, 3987, -382], [30162, -3402, 1358], [-22919, -6562, -1083], [18406, 636, 1220], [18429, 7790, -1771], [-5663, 5192, 4443], [10350, 2128, -596], [4991, 1974, -665], [-8980, 3553, -2378], [-7540, -5246, -1336], [3615, 11188, -199], [2131, 4460, 55], [2509, 4376, 2943], [3935, 1812, -677], [-5434, -1928, 3152], [-26484, -5240, 382], [-37582, -8834, 110], [41739, 4555, 451], [-32560, 6746, -2772], [-29260, -10431, 502], [-39660, -1508, -1138], [-39142, -10373, -66], [11883, -8337, 2437], [-15788, 1773, -1370], [26766, 2364, 2002], [43993, 956, 1927], [-7320, -530, -1820], [-23110, 572, -2270], [25707, 7167, 2035], [20752, 9697, 1610], [29806, -2887, -3912], [39275, -5448, -139], [-27842, 9510, 5364], [37183, -2031, -2199], [1545, 7168, -3531], [21644, 11020, -2688], [-29662, -1612, 2290], [69202, 4693, -1604], [2954, 7648, -3612], [-30582, 6017, 3266], [-47453, -7552, 223], [122, -4524, 5466], [33460, -5622, -976], [70945, 769, -1477], [60939, -5544, -1113], [-64749, -7414, 653], [11780, 5412, 4162], [-19358, 3168, 3506], [-22538, -278, 2528], [-17460, -4600, -4566], [46087, 1571, 3549], [-61880, -6172, 674], [-2700, -20, 4188], [19714, -207, 1090], [-10176, 8053, 3784], [5205, -5564, -951], [-61900, 446, -1044], [-50286, 10342, 2908], [-14452, 3401, -3620], [-64376, 1524, -1098], [9775, 9868, -2541], [60219, -7229, 2239], [29534, -1288, -3980], [43052, -4464, -4456], [46153, -2194, 4067], [-20961, 10512, -5215], [31343, 11274, -453], [24006, -173, 250], [72252, 676, -732], [40516, -15648, -3854], [67446, -5467, -3136], [-61192, 6016, 3212], [-57138, -7668, 1680], [14317, 3811, 2773], [-22020, -3750, -4456], [3280, -1411, 3658], [10101, 1109, -445], [-70292, -12280, -900], [-21548, -320, 4554], [80180, -5831, -1698], [-6925, -7433, 189], [99909, 6502, -1541], [47757, -13338, -929], [17280, 6628, -1496], [-48956, -7390, -1282], [2249, -4009, -5331], [-18896, -7853, 1286], [-38153, -5976, -1423], [-64049, -2282, -3321], [-31129, -4262, -4271], [-5903, 3476, -3021], [-89024, 1162, 1908], [14586, 21257, -574], [22082, 768, 6914], [-54934, -8927, 604], [58286, 14567, -2574], [14638, 5408, 6248], [31387, 5003, 2437], [-44644, 12644, 96], [12653, 16965, 559], [-10117, -12562, 3817], [3975, -140, -2801], [14748, -6986, 5670], [-95250, -7268, -682], [56870, 16454, 1516], [-93942, 676, -3238], [35489, 2389, -4111], [-38438, -5020, -3632], [111270, -1122, 5302], [87705, 1100, -931], [-47571, -7808, -1745], [-64382, 8150, 2182], [15549, 4091, 5391], [95256, -4117, 732], [48989, -13073, -6603], [-101964, 4302, -6672], [1261, 5684, 5703], [-43212, 4244, 2778], [7369, 13762, 705], [91606, -4844, -4652], [99330, -2762, -988], [49611, -967, -2731], [79998, 15544, -626], [-35517, 1162, 4571], [-50213, 808, -2383], [-65230, 4208, -708], [49541, -4364, 739], [47444, -2674, -7816], [-90940, -11193, 1242], [7174, 14164, -3662], [-90314, 5609, 4744], [-76063, -2317, -7595], [-131538, -2544, -204], [101789, 2678, 3643], [-125018, 6781, -7520], [-470, 2124, -4484], [40944, 4830, 3354], [-41935, -3062, -4265], [-56753, -14317, -5423], [28307, -16586, -2147], [48072, 16000, 3780], [-19400, 6544, -474], [-94435, 4438, 5697], [-14899, -4616, -3759], [-3574, 3543, -4330], [-41776, 576, 5296], [-91351, 14396, -1869], [56911, 1811, 7459], [34526, -16867, 360], [-279, -20377, -3451], [-80992, 232, -7130], [-134540, -8298, -1976], [51727, -8880, -2981], [-48981, 4902, -8263], [-7250, -1890, 7266], [-83277, 11196, 1705], [1760, 13374, 538], [-72701, 12802, -10949], [31447, -12677, -2987], [20448, 1916, -1704], [120723, -16634, -2263], [23858, 4031, 7054], [-60883, -13520, -1375], [-31443, 19991, -4275], [-38349, 6803, 5401], [14309, -2082, -10195], [-90936, -31776, 2248], [54397, -1243, 8933], [5650, 3930, -1034], [14518, -25820, 1200], [14698, -6388, -3310], [142265, -2321, 6171], [-31176, 18565, -7008], [-32814, -29628, -4544], [-1552, -7479, 5216], [51828, -6768, -8262], [-19160, 5184, -9498], [30212, -9476, 3012], [6856, -14856, 654], [118925, 17166, -3219], [16102, 9633, -8424], [-3375, -29157, -1517], [-83876, 12005, -3876], [-53670, -3604, -5770], [-6436, 9463, -11438], [-77683, -10357, -1571], [-138638, 5171, -1930], [-53233, -13619, -2303], [110500, 16044, 2596], [112189, -7021, -2049], [20150, 10938, 544], [105713, 9242, -6095], [-28377, 5856, -2119], [-78437, 11215, 5665], [7750, -24676, 11432], [-43887, -4960, 3171], [38584, -27350, 2514], [107459, -13092, 8423], [64788, -11321, 15296], [-41632, 17602, 898], [3014, -1010, -4422], [-159722, 11276, 2944], [35207, 1505, -4037], [71060, -13692, -9324], [95096, 5580, -4448], [-100486, -8709, -810], [-12, 20460, 9542], [96769, 18808, -3383], [-80388, -4080, -480], [134161, -4394, -1905], [3328, 3006, -7886], [41825, 13059, -957], [162014, 648, 7398], [53476, -17932, -3246], [-86780, 21645, -7994], [57125, 10459, -7143], [-63330, 21980, -7788], [34702, -12250, 5810], [-184622, -3496, -830], [73288, -19479, 10408], [248772, 3075, 296], [-68458, 22456, 5914], [29148, 21564, -686], [-46815, 2278, 9353], [-23497, 9362, 5799]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_280_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_280_4_a_f();".
// 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_280_4_a_f(:prec:=3)
    chi := MakeCharacter_280_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_280_4_a_f();".
// 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_280_4_a_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_280_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![8, -35, 6, 1]>],Snew);
    return Vf;
end function;