
// Make newform 840.4.a.i in Magma, downloaded from the LMFDB on 03 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_840_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_840_4_a_i();".
// 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_840_4_a_i();".
// 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 := [-6, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 4]];
    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_840_a();"
function MakeCharacter_840_a()
    N := 840;
    order := 1;
    char_gens := [631, 421, 281, 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_840_a_Hecke( : Kf := Kf)
    return MakeCharacter_840_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], [8, 4], [-6, -5], [-62, 5], [16, -14], [136, 1], [-66, 23], [-140, -15], [-146, 21], [-254, -4], [228, 13], [528, -3], [26, -46], [-220, 6], [-378, -35], [-124, 45], [-244, -15], [-546, -51], [-616, -36], [-388, 86], [-78, -28], [78, 91], [-690, 30], [8, 88], [-228, 5], [-1306, -68], [-1810, 24], [-568, -216], [-2348, 40], [-546, 86], [-152, -122], [-1634, 121], [-328, 324], [-94, -163], [-68, -245], [-784, 85], [-1154, 8], [1824, 28], [-442, -387], [-84, 131], [-542, -190], [450, -408], [524, 429], [-1276, -70], [-1912, 4], [1036, 542], [3854, 165], [2246, -454], [-4188, -307], [-2806, 396], [3764, -76], [-3366, 263], [2096, -387], [1830, 276], [2956, -137], [6686, 47], [-2430, 232], [-196, -24], [246, 270], [5148, 162], [-616, -752], [-2714, 297], [6146, 150], [-3732, -42], [2242, -178], [4628, -137], [2582, -305], [818, -521], [-972, 561], [-1016, 38], [-202, 631], [948, 876], [3048, 269], [3038, 995], [-2838, 281], [-3950, 182], [2922, 1138], [12628, 196], [-2178, -928], [-7372, -647], [2430, -499], [-9652, -297], [2116, -1133], [-3758, -414], [6626, -86], [-8362, 530], [-120, -1934], [16316, 352], [-928, 636], [-2336, -942], [-3800, 1596], [17740, -340], [-8144, 491], [-8490, -692], [-6510, -426], [-9020, 678], [18854, -414], [12100, -35], [-11550, -666], [4260, 388], [2746, -314], [2692, 744], [24206, 77], [-3588, -2120], [2706, -383], [2356, -1657], [-12446, 1226], [-18840, -416], [1246, -203], [-22506, 366], [-6424, -416], [-13616, 526], [-7510, 618], [-11380, 508], [4592, 1839], [2778, 1734], [-4072, -618], [1470, 917], [7914, -1424], [-13578, 2208], [25812, -267], [-10504, 62], [-18882, -161], [-4098, -2258], [-9624, 1684], [22832, 798], [-1526, -1633], [3580, -70], [-25392, -1283], [-9000, 148], [-9210, 1959], [4962, 86], [19450, 136], [102, 4174], [2988, -3732], [10670, 140], [19810, -578], [-3752, -1546], [6486, 549], [-26816, 498], [1516, -1789], [29102, 27], [13888, 2648], [-20974, 749], [12114, 3039], [-38768, -420], [8624, 2587], [-11178, -829], [3194, 1004], [-3004, -1097], [-27240, -349], [18796, -725], [-26916, -1201], [-20496, -880], [-11974, 2910], [9598, -2881], [10806, -3600], [34076, -1953], [19030, -116], [20776, 726], [19972, 1618], [-18498, 302], [18792, -625], [-16216, -2656], [-7070, -2199], [-18734, 744], [31366, 600], [21240, -1000], [-6146, 2523], [4604, -169], [-18742, 2974], [-21204, -903], [-12510, 1440], [11916, 1786], [-21042, 1947], [-23216, 254], [25518, -1171], [25168, 328], [34508, 3000], [-56538, 155], [-42246, -947], [19080, 2377], [43966, -1126], [-7274, 2797], [-26324, 2158], [10666, -2352], [-28584, 92], [-20450, 4935], [27804, -543], [51180, 100], [470, -6914], [43452, 1247], [-15702, 13], [58194, -1308], [14830, -131], [-12598, -1041], [12272, -765], [18702, 2507], [7604, -2779], [30106, -3225], [33370, 1950], [47572, 970], [3918, 5374], [-55380, 2241], [62612, 2507], [-15486, 3340], [23152, 6556], [-294, 4796], [-17106, 2576], [37400, -4528], [56548, -1778], [-21776, -3320], [-35470, -1928], [23512, 774], [28730, -6850], [31616, -2375], [-45702, -1890], [-11842, -6802], [524, 9323], [35898, -3614], [-16208, -7830], [8324, -618], [-31778, -4438], [45330, -121], [2492, -3923], [-49976, -1250], [-38376, 1116], [13310, -643], [-30864, -1682], [73344, -2270], [26306, 1368], [-59180, -842], [-27072, 3801], [58962, 5022], [22290, 156], [-42472, -2132], [-25872, -5994], [2292, 2303], [18040, 1160], [22024, 1424], [-10970, 4046], [-35174, 3469], [-25008, 3958], [-74392, 2018], [-42156, -150], [39356, 4724], [-5104, 3331], [-46010, -641], [35418, -2302], [-5640, -1319], [-15174, -1520], [23758, 5266], [42624, 6994], [-2242, 3996], [15308, -8032], [-64410, -2230], [-81674, 2913], [-35336, 8646], [-19636, -4009], [18958, 2495], [-47774, -4491], [10578, -537], [2584, -5302], [-58290, -5849], [63986, 2234], [-8196, 11711], [-71422, 4350], [93182, 851], [26348, -1301], [-1498, 1147], [-696, -2638], [41326, 4055], [-13968, -12260], [-95604, 1093], [-2346, -2338], [26266, 1560], [-2500, -6206], [-55584, -7633], [-21520, 8120], [108088, 3009], [-54618, 5], [33044, -10126], [-125460, -1795], [9258, -1538], [-104406, 4370], [4732, 3809], [-46934, -5330], [21518, -13173], [-42452, 4864], [78390, -5118], [-62724, -3114], [-105634, 5477], [-45018, -3198], [93596, -663], [60222, 4970], [77780, 1288], [14540, -736], [32750, -11121], [-60102, -170], [-5072, -2552], [12108, -6569], [123028, -3700], [-8494, -4640], [-44020, 2443], [-90250, -2569], [-44244, -5195], [-75498, -933], [19840, -8397], [-32234, -717], [111218, -1462], [66340, -3465], [-17928, -629], [-49086, -13142], [-13804, -12138], [-94740, 3099], [-110146, -97], [-35806, 7816], [-3736, 6552], [-66094, -7512], [-8538, -2410], [65408, 5040], [-121362, 2156], [64490, 3988], [67292, -2784], [-23780, -10598], [-78768, -8251], [100106, -3328], [-35658, 1712], [-23014, 6002], [27596, 5041], [-51420, -738], [123084, 7054], [55964, 11066], [130582, -2622], [180378, 3121], [-95598, 2522], [-2920, 12704], [-117034, 4567], [-115098, -4474], [68814, -13928], [81992, -14038], [78202, -5758], [-81368, 748], [-5858, -14259], [-6244, 17685], [12072, 13994], [83750, -2746], [113904, -1104], [45602, -4434], [-42834, -8939], [-19232, -1400], [-117890, 8346], [18378, -3777], [144440, -6904], [-6180, -7742], [132942, 3744], [16400, 7115], [124134, 5471], [73362, 8938], [-181096, 2267], [-80656, -6234], [35324, 18108], [-54126, 994], [199830, -2330], [53272, 1000], [59210, 1708], [-94304, -7610], [-62720, 5132], [-35176, 3959], [-164994, -5081], [59940, -4397], [-94778, -3221], [-78300, 11720], [-43428, 12247], [-11042, 3077], [-4790, -14786], [120062, 13], [-107098, -978], [-153210, -7692], [174688, 1274], [-105082, -9828], [116768, 3842], [32880, 225], [-23464, -198], [214498, 3547], [-17364, -3347], [13056, -3201], [-101230, 4312], [69006, 11892], [180976, -4178], [-109572, 8394], [-47076, 8357], [-39430, -7572], [-42292, 6559], [-53390, -12484], [178148, 4050], [77190, 11441], [-38930, -16563], [-104818, -16468], [25376, 3296], [-201102, -739], [-128658, -10400], [-134204, -13905], [-172170, 6659], [-68318, -3690], [-33516, -14766], [88092, -15894], [54998, -2429], [97338, -1292], [21988, 7139], [692, 14852], [4154, 11238], [122694, -3868], [134916, -11255], [-29008, 12888], [-31134, 4447], [-52008, 21027], [177286, 391], [108546, 7165], [79752, 1981], [-9468, 8738], [-82442, 12189], [-18290, -13302], [63028, 8497], [-142454, -13384], [-210112, 5008], [-84528, -21956]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_840_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_840_4_a_i();".
// 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_840_4_a_i(:prec:=2)
    chi := MakeCharacter_840_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_840_4_a_i();".
// 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_840_4_a_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_840_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<11,R![-1472, -16, 1]>],Snew);
    return Vf;
end function;