
// Make newform 1680.4.a.bg in Magma, downloaded from the LMFDB on 15 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_1680_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_1680_4_a_bg();".
// 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_1680_4_a_bg();".
// 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 := [-16, -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_1680_a();"
function MakeCharacter_1680_a()
    N := 1680;
    order := 1;
    char_gens := [1471, 421, 1121, 337, 241];
    v := [1, 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_1680_a_Hecke( : Kf := Kf)
    return MakeCharacter_1680_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], [-3, 0], [5, 0], [7, 0], [11, -1], [-11, -1], [58, 8], [-51, -7], [-130, -10], [-98, 24], [-75, 21], [-48, 18], [-88, -50], [172, -16], [-280, -24], [163, -43], [422, 42], [-102, -12], [52, 32], [-835, 21], [-193, 101], [444, -52], [-464, 108], [294, -4], [261, -157], [-16, -14], [-1064, 32], [-488, 156], [-152, -78], [263, -171], [1360, 64], [1216, -196], [-227, 227], [-343, -259], [584, 218], [282, 226], [-1569, 121], [-792, -172], [-864, 8], [-880, -70], [-949, -297], [204, 254], [623, 47], [-2894, -144], [-2391, -341], [1309, -235], [-1944, 372], [-3918, -94], [-896, -564], [-2310, 220], [-1933, 217], [-1651, 125], [-5288, -58], [1730, 422], [672, 542], [-7448, -16], [104, 114], [3679, -177], [-3616, -622], [-7312, -26], [-2240, 276], [7252, -42], [-918, 1062], [-7336, -32], [-1767, -913], [-681, -527], [1584, -348], [-3198, -688], [-2574, -250], [-378, -448], [-2550, 616], [4667, -237], [-9710, -174], [770, 660], [-1098, -358], [520, -104], [6804, -362], [9, 595], [6650, -376], [4502, -820], [4068, 352], [-11002, 168], [10189, 349], [3333, 499], [-7659, 93], [4122, 1326], [-3850, -844], [-7000, 142], [2850, 44], [2692, -380], [11948, 968], [13764, 868], [-12004, -700], [6355, -89], [17974, -62], [-9412, 244], [1340, -586], [2828, 18], [810, -434], [-5174, -1148], [-11328, -308], [-8589, 317], [14408, -924], [5050, -2288], [-1506, 1186], [-487, -2601], [1644, -2704], [2502, -236], [1083, 547], [5024, 2390], [-7238, 522], [-19388, 6], [-13137, 917], [1205, 873], [-10200, 1808], [19528, -954], [-4270, 350], [-9520, 2264], [-299, -2689], [22497, 653], [9002, -2180], [-2268, 3650], [9524, -1354], [15786, -882], [22595, -145], [25550, -88], [12654, -16], [-238, -3454], [-8490, 2830], [-4519, 1395], [-274, 458], [-8160, 8], [-16188, 340], [-18750, 2004], [6698, 2528], [21988, -2462], [22752, 386], [3718, 3554], [428, 198], [-11392, 2950], [301, -1855], [3958, 2472], [848, 392], [17344, 3444], [1476, 1822], [17682, 938], [2605, -4065], [-3348, -1246], [2619, -2689], [-7738, 2134], [10732, 3350], [26314, -40], [-8816, -3796], [-9596, -4516], [-6352, 1140], [-44301, 547], [-192, 104], [26034, 3120], [5559, 3005], [-7602, -4616], [-37718, -2106], [-26677, 2369], [-42620, -1012], [19038, -462], [25715, 2593], [15208, -1536], [2656, -2432], [27113, -405], [-8096, 1486], [19348, -858], [-8537, -3125], [-21580, 4174], [-35195, 1757], [2214, -1716], [-3333, 3403], [568, -306], [11812, 5512], [-26836, -498], [8122, 2370], [-27496, -2846], [17976, -3096], [-6590, 4670], [-4046, -5996], [-9082, -3860], [40588, 44], [29544, 1818], [-34004, -1338], [17498, -4474], [20700, 1698], [52842, -2358], [17333, -1101], [-8460, -2440], [6018, -4850], [11326, 1816], [-46986, 3298], [41274, -384], [-53280, 654], [-42370, -584], [-14472, 1590], [3248, -808], [-866, -7736], [-23087, -2431], [-8633, 8441], [29624, -6058], [36414, 1106], [17204, -210], [17827, 1155], [-6712, -6412], [44028, -414], [62027, -1089], [-82524, -910], [-24308, -2178], [-15212, -1300], [-9236, -352], [29450, -254], [43980, -622], [-29692, 5252], [-48598, 5848], [33804, 2660], [-16495, 6731], [40878, 4240], [-58463, 681], [-73552, 1774], [-32176, -6576], [44640, -964], [55440, 1634], [76708, -294], [30663, 5639], [-31556, -9180], [4127, -3277], [-26282, 64], [-10511, 3901], [16066, 10114], [-22420, -6254], [4698, 6078], [-41876, -820], [6842, -376], [27809, -205], [6191, 1011], [-31738, -6370], [-33180, 7264], [16961, -1851], [-9204, -2060], [49884, -7610], [-76072, -2330], [-16130, 7686], [-59326, 3218], [23000, 9204], [-10040, -580], [-11442, -10098], [-15688, -10702], [-31118, -5680], [-75378, -1546], [25142, 3804], [85616, -2182], [-12421, -8793], [-30720, -3758], [26136, -5748], [-47436, 1014], [35477, 1195], [-40736, -7568], [27394, -6066], [83010, -6204], [65323, 5381], [28666, 6488], [-17793, 9435], [-3334, 5508], [12348, 13874], [22336, 5812], [32445, 6911], [-82640, 3290], [28864, -6436], [50525, 2515], [90744, -5064], [25381, 8531], [-10338, 790], [70736, 6468], [-58970, 1664], [93330, -6216], [47622, -7694], [95412, 2212], [-21896, -5840], [-85900, 2892], [-26400, -11486], [-90878, 6086], [839, -1929], [41496, -13466], [-11713, 3793], [2101, -2403], [-38854, 5368], [-53422, 7132], [123696, 4908], [16683, 7265], [16260, -5224], [-55750, 5956], [36306, 684], [108275, -5549], [24422, -520], [-28722, -4142], [-42566, -8986], [-41377, 3461], [56269, 12279], [123270, -1962], [-74290, -1814], [41110, -7942], [-87678, -8928], [5164, -1168], [76370, 8988], [19905, -3319], [125002, -2260], [3004, 636], [91390, 4240], [4018, -5360], [-94664, 7972], [48942, -8330], [104504, -2626], [39728, 6236], [-27741, 6179], [4253, -10149], [-14066, -164], [86463, 1611], [41504, -2026], [-69274, -6528], [-19792, 11296], [-87799, 5039], [80144, 2686], [28514, 11358], [-24712, -6132], [55758, -17538], [-57497, -10551], [60760, 9634], [75345, -8789], [-87553, -2913], [27256, 14916], [-960, 21108], [-13280, 8020], [-2406, 5460], [50672, 9486], [112380, -8382], [110598, 3654], [-88602, 4728], [-4209, 7237], [35560, -11382], [60378, -3406], [-106367, -11909], [83393, 8541], [-21694, 20260], [62604, -6352], [-199018, 1734], [52492, -7650], [47213, -9975], [172812, -3982], [-76802, 8680], [82872, 2360], [-33652, -4834], [52126, -7020], [-48970, -20586], [-75132, -9288], [-105657, 4757], [-48116, 12132], [59742, -1536], [56568, 8510], [-6092, -11276], [59149, 1809], [-35114, 8098], [89952, -13210], [-14586, 15600], [98020, 9292], [65530, 688], [-67857, -10325], [36719, -12637], [185444, -7324], [139900, 7790], [-31121, -11881], [-56384, -262], [-92848, -5156], [59835, 2907], [95261, 12859], [132580, -4302], [198407, -1955], [-90272, -5414], [43523, 2377], [-59820, 1996], [-5091, -12581], [68845, -10871], [108936, 5712], [132988, -9140], [-166515, 2015], [26752, -3660], [10376, 1208], [-45004, -13838], [-70938, 4168], [-25139, 20833], [20446, 30970], [-106255, -2631], [28954, 8336], [44811, -2229], [49042, -18760], [18098, -23930], [-97462, 11452], [-185396, 4838], [7163, 4185], [99240, 6664], [238104, 2318], [160710, 2056], [-120237, 6091], [-118616, 658], [-83330, 2092], [-11992, -32892], [-78486, 10374], [-94865, 14141], [-42193, -895], [-158106, 5274], [-34472, -5036], [151522, 4392], [2976, -15094], [-26779, 16965], [-16394, 11518], [64310, 4356], [118164, -10964], [77076, 14], [-58295, -15157], [88524, -7188], [-227190, 3854], [-40783, 11415], [104376, -2686], [9556, 16688], [-27186, -252], [1571, 5511], [-2734, -25478]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1680_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1680_4_a_bg();".
// 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_1680_4_a_bg(:prec:=2)
    chi := MakeCharacter_1680_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_1680_4_a_bg();".
// 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_1680_4_a_bg( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1680_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<11,R![56, -22, 1]>,<13,R![56, 22, 1]>,<17,R![-796, -116, 1]>],Snew);
    return Vf;
end function;