
// Make newform 882.4.a.u in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_882_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_882_4_a_u();".
// 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_882_4_a_u();".
// 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 := [-48, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_882_a();"
function MakeCharacter_882_a()
    N := 882;
    order := 1;
    char_gens := [785, 199];
    v := [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_882_a_Hecke(Kf)
    return MakeCharacter_882_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 := [[-2, 0], [0, 0], [-3, -1], [0, 0], [-9, -7], [22, 5], [-54, 10], [58, 3], [54, 14], [33, 7], [-35, -28], [134, 21], [-168, 0], [164, -21], [-348, 24], [-219, 63], [-351, -61], [220, -34], [-538, 35], [840, -28], [46, 97], [311, -98], [-99, -89], [-1170, -54], [109, -155], [-558, 206], [40, 81], [-783, 147], [-250, -217], [1512, 28], [-379, 70], [-2211, -37], [-1242, -182], [-1742, 19], [-1374, -210], [-1, 245], [-2108, 198], [218, -210], [-1146, 206], [-2514, 254], [-2052, 336], [-1964, 239], [900, -168], [1841, -42], [774, -490], [-2000, -396], [-1528, -504], [-4421, 57], [-1941, 333], [244, -593], [810, 98], [318, 378], [-2495, -15], [2421, 135], [174, -810], [1416, -336], [3219, 317], [121, 59], [-2788, -231], [-4434, 14], [-3068, 529], [783, -327], [1210, -299], [8508, 92], [-977, 1030], [2205, 651], [2984, 21], [-1843, 616], [6684, 504], [2674, -56], [1800, -996], [4938, -770], [-9713, 204], [5060, 1211], [644, 749], [6606, 550], [-678, 658], [12664, -79], [-1128, -588], [6301, -1038], [3756, -540], [1856, -287], [2592, -588], [3814, -537], [-10463, -109], [6771, 161], [-4806, 1834], [3131, -2170], [-4314, 410], [1676, -763], [-180, -2272], [-7608, -548], [-2119, -1008], [-6477, 21], [-13126, -259], [-3558, -1746], [3711, 1293], [1464, 768], [-2102, -1011], [1424, 1897], [7322, -1778], [1767, 49], [12417, -677], [1998, -1974], [1640, -1253], [9385, -1676], [-7017, 2281], [-11286, 1278], [-9162, 378], [-5207, -2256], [-16337, -184], [20642, -644], [27180, 308], [-2108, -1265], [8489, 2331], [-2388, 1064], [-674, -129], [-10308, 372], [-15345, 273], [11796, -112], [13528, 1357], [-4351, 3738], [-19959, -633], [2841, 819], [-19064, 531], [6417, 1603], [-16954, 924], [-20202, 42], [-12227, -158], [12844, -3505], [-2458, 2401], [10638, -1302], [-14731, -1862], [-16996, -1610], [-3822, -686], [14083, -2210], [-25758, -298], [-15656, -2512], [9573, 111], [-20028, 280], [20602, -2690], [16137, -301], [-12664, -1204], [12675, -1071], [38014, 13], [-6126, -1874], [30238, 627], [-42060, -804], [-2144, 5016], [-15738, -2702], [4760, 350], [-20382, 2250], [30596, -735], [-6966, 3054], [-27058, 2947], [-2856, 1764], [-14476, -3283], [-312, 2052], [16813, 744], [35817, -3013], [25428, -3500], [-12228, -4984], [-1777, -210], [3195, 225], [-1212, -756], [-19536, 1188], [-3793, 1512], [-4202, 2895], [4667, -1806], [9369, -4017], [-8523, -3269], [-1448, -254], [-36414, -210], [23717, -4088], [9535, -4846], [58464, 728], [40616, 301], [21711, -4291], [7756, -3864], [35368, 4101], [-14353, 2800], [-3933, -107], [-15790, 3731], [6390, 1430], [17886, -4046], [3057, 4743], [-28804, -770], [-24002, -2991], [3875, -2030], [8946, -2058], [27763, -1388], [-41607, 5019], [-22978, -1918], [11526, -4922], [4131, 6657], [48162, 2782], [42350, 1533], [19160, -910], [-26316, -5412], [32580, -1824], [7095, -63], [-54032, 3239], [-11486, 5724], [53230, 3860], [30972, 2316], [12783, -975], [-45632, -1164], [-26979, 4011], [-15258, -9366], [-21386, 9186], [26990, -2583], [7389, 1091], [-32845, -1799], [12099, 8009], [37170, -7686], [6970, -4161], [34685, -1561], [-7302, 5350], [29118, -5866], [-40554, 4718], [-15364, -3283], [-42008, -3743], [-29856, 5964], [17495, 5621], [5811, -12315], [-46708, 4578], [-8730, -1118], [-7428, -13244], [-32267, -3058], [-7848, 11172], [-11356, 5173], [-34136, -4976], [40319, -742], [11694, -3990], [26218, -2001], [-12078, -1422], [-5663, -5390], [26127, 7497], [71496, 672], [-18570, -9130], [41400, 4676], [-10640, 693], [-12377, 9942], [-7258, -11312], [-18990, 4366], [-6864, -11220], [-31019, 7046], [14076, 4216], [12440, 168], [34104, -840], [-38002, 2975], [-12912, -1980], [71358, 3234], [29158, -587], [-68361, -4559], [-28857, -7903], [-71140, 3213], [-27656, 5003], [-3525, -13663], [31759, -777], [18056, 10745], [447, -9527], [4102, -4739], [74236, -947], [8364, -12276], [61486, -6317], [51039, -7119], [-69498, 3182], [-60076, -364], [75579, 6405], [-11576, 3797], [-120850, 546], [40951, 9140], [-83731, 6552], [-60461, -353], [-28832, 6116], [10497, -2653], [18098, -7763], [27674, 13181], [-81492, 2040], [-4104, 16440], [77255, -5138], [-52722, 4770], [31828, -9903], [-38210, -6838], [-38430, 5894], [61007, 6370], [23655, 413], [41071, -18], [61152, -10668], [39126, -12558], [-44625, 8673], [-80916, 504], [-63564, 4460], [34118, 17493], [-20979, 3171], [-31232, 12645], [-66354, -306], [63732, -11208], [-7484, 20855], [-4490, -10256], [-8637, 11949], [-15391, 7427], [-4629, -8883], [-5644, -16317], [16718, 4011], [41091, -9023], [-48170, -1023], [34338, 2534], [-29974, 5397], [-48126, -4086], [-76398, 15274], [69882, 2254], [40376, 14112], [50886, -4886], [54538, 3561], [27165, -22473], [-1206, 13090], [367, 372], [5448, -1680], [47572, -19467], [4394, 16121], [-22125, 2061], [-55936, -11683], [85524, -8036], [-18179, -10626], [-45712, 9597], [87862, 6451], [-67314, 7322], [-70593, -6475], [-50224, 5397], [-17769, 9653], [-45560, 19349], [91332, -15644], [-105394, 5159], [-42396, 15464], [20858, -644], [-22056, -3544], [-35669, 13140], [25303, -10538], [-11464, 1827], [-39282, 22722], [95307, 8025], [-74599, 16702], [-91719, -14805], [-56655, -4641], [36226, 15237], [-26674, -3822], [59454, -17478], [146643, -5859], [12418, -2058], [-119977, 7119], [45930, -378], [117103, -5467], [-57364, -12817], [-89712, 10276], [144900, 8456], [7377, -13725], [125520, 6860], [-116070, 7238], [67904, 6734], [23544, -4052], [110898, -14546], [131268, -7084], [117262, 4939], [-79693, -19929], [78678, 16818], [87944, -12173], [212237, 413], [32697, -27349], [198472, 4009], [21534, 16926], [-78051, 16387], [178000, 9967], [-51778, 3143], [16764, -3288], [23430, 3542], [33409, -24419], [161082, -1970], [69946, -5079], [42126, 17934], [-244236, -1820], [-107344, 308], [38358, -7938], [196156, 4924], [-29628, -16876], [35576, -315], [-119960, -12122], [137090, 3227], [-16386, 10582], [194177, 2856], [-51234, 28002], [-164025, -9919], [135460, -12921], [14010, -10010], [72743, 12943], [98659, 14257], [207150, 6610], [-32410, 36883], [45615, 21581], [-9218, 11100], [-15126, -12054], [-256204, 728], [-43446, -29434], [147519, -20631], [73015, 19422], [-62938, 26180], [-16728, -14784], [150664, -16155], [162993, 11743], [-92807, 6085], [-168921, 16457], [-74703, 15743], [101012, -1148], [35018, 17535], [-170745, -8615], [-63120, -25816], [-52724, 33817], [-47610, -15030], [-123564, -6496], [35979, -3199], [-41402, 4635], [-70932, -20860], [161349, -5241], [55690, 10140], [-152070, 74], [-62583, 1939], [173850, -5922], [-38822, -9730], [128316, 18076]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_882_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_882_4_a_u();".
// 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_882_4_a_u(:prec:=2)
    chi := MakeCharacter_882_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_882_4_a_u();".
// 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_882_4_a_u( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_882_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-36, 7, 1]>,<11,R![-2208, 25, 1]>,<13,R![-606, -49, 1]>],Snew);
    return Vf;
end function;