
// Make newform 882.4.a.ba in Magma, downloaded from the LMFDB on 24 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_ba();".
// 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_ba();".
// 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], [4, -1], [0, 0], [-16, 7], [-27, 5], [44, 10], [-61, 3], [68, -14], [40, -7], [63, -28], [155, -21], [168, 0], [143, 21], [324, 24], [-156, -63], [412, -61], [-186, -34], [-503, -35], [812, 28], [-143, 97], [213, 98], [188, -89], [1224, -54], [46, -155], [352, 206], [-121, 81], [-636, -147], [-467, 217], [1540, -28], [-309, -70], [2248, -37], [-1424, 182], [1723, 19], [-1584, 210], [244, -245], [1910, 198], [8, 210], [940, 206], [2260, 254], [-1716, -336], [1725, 239], [732, 168], [1799, 42], [284, 490], [2396, -396], [-2032, 504], [4364, 57], [1608, 333], [349, -593], [908, -98], [696, -378], [2510, -15], [-2556, 135], [636, -810], [1080, 336], [-3536, 317], [-180, 59], [-3019, 231], [-4420, -14], [2539, 529], [-456, -327], [-911, -299], [-8600, 92], [-53, 1030], [2856, -651], [3005, -21], [-1227, -616], [7188, -504], [-2618, -56], [-804, -996], [4168, 770], [9509, 204], [6271, -1211], [1393, -749], [-7156, 550], [-20, -658], [-12585, -79], [-1716, 588], [-5263, -1038], [-3216, -540], [1569, 287], [2004, 588], [-3277, -537], [10572, -109], [6932, -161], [-2972, -1834], [961, 2170], [3904, 410], [913, 763], [2452, -2272], [8156, -548], [-3127, 1008], [-6456, -21], [-13385, 259], [5304, -1746], [-5004, 1293], [-2232, 768], [3113, -1011], [3321, -1897], [5544, 1778], [1816, -49], [-11740, -677], [24, 1974], [387, 1253], [-7709, -1676], [4736, 2281], [10008, 1278], [-8784, -378], [7463, -2256], [16521, -184], [19998, 644], [27488, -308], [3373, -1265], [10820, -2331], [-1324, -1064], [803, -129], [9936, 372], [-15072, -273], [11684, 112], [-14885, 1357], [-613, -3738], [20592, -633], [3660, -819], [18533, 531], [8020, -1603], [-16030, -924], [20160, 42], [12385, -158], [-9339, -3505], [-57, -2401], [9336, 1302], [-16593, 1862], [-18606, 1610], [4508, -686], [-11873, -2210], [26056, -298], [18168, -2512], [-9684, 111], [-19748, -280], [-17912, -2690], [15836, 301], [-13868, 1204], [11604, 1071], [-38027, 13], [8000, -1874], [-30865, 627], [42864, -804], [-2872, 5016], [-18440, 2702], [5110, -350], [18132, 2250], [29861, 735], [3912, 3054], [-24111, -2947], [-1092, -1764], [-17759, 3283], [-1740, 2052], [-17557, 744], [-32804, -3013], [21928, 3500], [-17212, 4984], [-1987, 210], [-3420, 225], [-1968, 756], [18348, 1188], [-2281, -1512], [1307, 2895], [2861, 1806], [-5352, -4017], [-11792, 3269], [1702, -254], [-36624, 210], [19629, 4088], [-4689, -4846], [-59192, 728], [40917, -301], [17420, 4291], [-3892, -3864], [-39469, 4101], [-11553, -2800], [4040, -107], [-12059, -3731], [-7820, 1430], [13840, 4046], [-7800, 4743], [-29574, 770], [26993, -2991], [1845, 2030], [-6888, -2058], [-26375, -1388], [-36588, -5019], [-24896, 1918], [-6604, -4922], [10788, -6657], [-50944, 2782], [43883, -1533], [18250, 910], [31728, -5412], [-30756, -1824], [7032, 63], [50793, 3239], [5762, 5724], [-57090, 3860], [-33288, 2316], [-11808, -975], [46796, -1164], [-22968, -4011], [-24624, 9366], [12200, 9186], [24407, 2583], [-8480, 1091], [-34644, 1799], [-20108, 8009], [-29484, -7686], [-2809, -4161], [33124, 1561], [1952, 5350], [23252, 5866], [-35836, -4718], [-18647, 3283], [45751, -3743], [-23892, -5964], [23116, -5621], [6504, -12315], [-42130, -4578], [9848, -1118], [-20672, 13244], [35325, -3058], [3324, -11172], [-6183, -5173], [39112, -4976], [39577, 742], [7704, 3990], [-24217, -2001], [13500, -1422], [11053, -5390], [33624, -7497], [72168, -672], [27700, -9130], [46076, -4676], [9947, 693], [2435, 9942], [-18570, 11312], [14624, 4366], [18084, -11220], [23973, 7046], [-18292, 4216], [12608, -168], [33264, 840], [-35027, -2975], [14892, -1980], [74592, -3234], [-28571, -587], [72920, -4559], [-36760, 7903], [-67927, -3213], [22653, 5003], [17188, -13663], [-30982, -777], [28801, -10745], [-9080, 9527], [637, -4739], [-73289, -947], [3912, -12276], [-55169, -6317], [43920, 7119], [66316, 3182], [-60440, 364], [81984, -6405], [7779, 3797], [-120304, -546], [-50091, 9140], [-77179, -6552], [60814, -353], [22716, 6116], [7844, 2653], [10335, 7763], [40855, -13181], [79452, 2040], [-12336, 16440], [72117, 5138], [47952, 4770], [-21925, -9903], [45048, -6838], [-32536, -5894], [67377, -6370], [24068, -413], [-41053, -18], [-50484, -10668], [26568, 12558], [35952, 8673], [-80412, -504], [59104, 4460], [51611, -17493], [17808, 3171], [18587, 12645], [66660, -306], [-52524, -11208], [-13371, 20855], [14746, -10256], [3312, -11949], [-7964, -7427], [-13512, 8883], [-21961, 16317], [20729, -4011], [32068, 9023], [49193, -1023], [36872, -2534], [-24577, -5397], [52212, -4086], [-61124, -15274], [72136, -2254], [54488, -14112], [46000, 4886], [-58099, 3561], [-4692, -22473], [11884, -13090], [-739, 372], [3768, 1680], [-28105, -19467], [20515, -16121], [20064, 2061], [-67619, 11683], [77488, 8036], [28805, -10626], [-36115, -9597], [-94313, 6451], [-59992, -7322], [-77068, 6475], [-44827, -5397], [-8116, -9653], [26211, 19349], [-75688, -15644], [-100235, -5159], [26932, 15464], [20214, 644], [25600, -3544], [22529, 13140], [-14765, -10538], [-9637, -1827], [-16560, -22722], [-103332, 8025], [-57897, -16702], [-106524, 14805], [-61296, 4641], [-51463, 15237], [-30496, 3822], [-41976, -17478], [-140784, -5859], [-10360, -2058], [-112858, -7119], [45552, 378], [-111636, -5467], [-70181, 12817], [79436, 10276], [-153356, 8456], [6348, -13725], [132380, -6860], [-108832, -7238], [74638, -6734], [-19492, -4052], [96352, 14546], [124184, 7084], [-122201, 4939], [-99622, 19929], [-95496, 16818], [75771, 12173], [212650, -413], [5348, 27349], [-202481, 4009], [38460, -16926], [-61664, -16387], [-187967, 9967], [-48635, -3143], [-13476, -3288], [26972, -3542], [-8990, -24419], [-159112, -1970], [-64867, -5079], [-60060, 17934], [-246056, 1820], [-107036, -308], [30420, 7938], [-201080, 4924], [46504, -16876], [35261, 315], [132082, -12122], [140317, -3227], [5804, 10582], [197033, -2856], [23232, 28002], [-173944, 9919], [-122539, -12921], [4000, 10010], [85686, -12943], [-112916, 14257], [-213760, 6610], [4473, -36883], [67196, -21581], [-1882, 11100], [-27180, 12054], [-255476, -728], [72880, -29434], [-126888, -20631], [-92437, 19422], [-36758, -26180], [-31512, 14784], [-134509, -16155], [-174736, 11743], [86722, 6085], [-152464, -16457], [-58960, -15743], [99864, 1148], [52553, -17535], [179360, -8615], [-88936, 25816], [18907, 33817], [62640, -15030], [130060, -6496], [32780, 3199], [36767, 4635], [-91792, 20860], [-156108, -5241], [-65830, 10140], [151996, 74], [-60644, -1939], [167928, 5922], [48552, -9730], [-146392, 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_ba();".
// 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_ba(: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_ba();".
// 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_ba( : 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;