
// Make newform 882.4.a.v in Magma, downloaded from the LMFDB on 09 May 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_v();".
// 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_v();".
// 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 := [-336, -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], [-2, -1], [0, 0], [-34, 1], [21, -1], [44, 4], [23, -3], [-76, 4], [-44, 11], [-261, 2], [-1, 9], [210, 6], [-61, 15], [-282, -12], [120, 3], [16, -25], [114, -4], [349, -11], [-226, -20], [-443, -35], [-267, 8], [98, 25], [-408, 42], [994, -35], [-362, 20], [-1237, 21], [-132, 45], [-323, 49], [922, -82], [-1461, 68], [-86, -7], [1660, 50], [-749, -101], [-468, -6], [496, -59], [-646, 18], [1028, 132], [-1274, 8], [-212, -70], [-1266, -114], [-1407, 143], [414, -78], [-589, -222], [1580, -170], [-2872, -36], [2732, 102], [-4480, -9], [-3078, -57], [289, 211], [-1882, -62], [-2970, -54], [110, -39], [-84, 75], [2322, 48], [-5172, 102], [-1790, -55], [2256, -247], [-2983, 255], [-2368, -38], [2875, -17], [2016, -9], [3745, 175], [1066, 86], [2935, -38], [-3408, 63], [1385, 147], [-1083, 44], [3060, 168], [5362, 232], [1626, -162], [1660, 218], [4877, 354], [-9437, 157], [-5171, 307], [1328, -302], [11866, 68], [-2469, -319], [-7776, 264], [509, -366], [-1554, -174], [6477, 53], [-2358, -246], [-3913, -201], [8640, 41], [4544, 91], [10918, 38], [-3347, -518], [7756, -274], [877, -797], [-6134, -502], [12560, -218], [1301, -282], [-2004, -633], [-2045, -101], [2310, 606], [138, -423], [13932, -426], [-4807, 675], [7041, -583], [5028, -364], [-16862, -301], [-20662, -143], [7890, 690], [18339, 287], [-7793, 544], [-6832, -623], [-7506, -510], [-4164, -1014], [18767, 348], [-6627, -802], [-3438, -538], [-394, 472], [733, -1259], [-3568, -645], [-30652, 82], [-14245, 591], [-54, 420], [12006, 399], [-13624, 688], [11947, 211], [9599, 798], [4212, -1131], [18768, 21], [-3715, 627], [-3068, -493], [-10186, 744], [3750, -264], [-2975, 496], [-9651, -823], [-14337, 191], [-6918, -1128], [21951, 356], [-9966, -724], [-3124, -80], [16135, 910], [-7502, 1616], [-2928, -562], [-25788, 813], [-5522, -958], [5992, -674], [-3310, -1127], [-19664, -608], [-19434, -627], [-9011, 703], [3332, 1876], [-30625, 567], [12000, -1374], [-13312, 486], [19930, -196], [-7862, -458], [-11844, -1782], [-20347, 963], [-12210, -846], [6957, -637], [-38124, 450], [18493, -1613], [46422, -384], [13559, -204], [-11408, 977], [19342, -1822], [-11272, -962], [-22279, 804], [26472, -891], [-12942, -444], [3600, 1788], [-6301, -2394], [-17929, -873], [16445, -1758], [-19560, 537], [6112, -1135], [-8666, -1280], [-31044, 600], [-17739, -40], [19479, 2204], [4312, -340], [11517, 473], [-29014, 127], [-54208, 72], [18923, -1401], [-6609, 1646], [-27160, 1201], [10453, -2087], [-4496, 2306], [8674, 632], [56268, -255], [-3522, -544], [-4615, 2565], [11241, -2662], [-13494, -846], [45481, 472], [9294, -1221], [25360, 1852], [-28408, -410], [6504, 3123], [18440, -2714], [39731, -93], [-37850, -1520], [-25746, 2004], [-30312, 2514], [-4878, -381], [25053, 419], [6638, 3360], [9210, -3520], [33054, 1650], [-21810, -3159], [11216, -4152], [12174, -1965], [-10572, -1596], [-59236, -642], [16127, 3699], [-32648, 1961], [-44028, -1735], [19192, 3305], [-16224, 3468], [22535, -405], [-25040, -2969], [37508, 340], [-10912, 3226], [79994, -32], [-22247, -1985], [14287, -1871], [-81654, 1116], [-16136, 817], [-51702, -669], [-15958, 2934], [38624, -2714], [17914, 2210], [-47451, 260], [3270, 2070], [-52935, 569], [35404, 1756], [29437, -1064], [-34278, 4296], [24143, -4101], [-36762, 2766], [31453, -602], [103482, 183], [-64164, 1200], [-24122, 1850], [38186, 994], [-35761, -2991], [60359, 744], [-6378, 980], [30632, 3268], [23280, -804], [-27783, -916], [-23602, 1438], [85616, -960], [19080, 5400], [-79847, -599], [-3852, 2586], [47874, -780], [77413, 1837], [93704, 1267], [2864, -2225], [-18859, 4053], [-48519, -1789], [-44198, -4471], [-112978, -393], [7657, -1745], [-54224, -2509], [60625, -2579], [-131201, 373], [-48438, -2028], [-39401, 3127], [-69666, 987], [-39998, 626], [26980, -296], [-8574, -2265], [29703, 2873], [19676, -6474], [-46251, 776], [68669, -3186], [86674, -1085], [12084, 5396], [-119650, -653], [114099, 1445], [44323, -749], [-65004, 396], [-18744, -4398], [59709, 2708], [-15750, -198], [-53725, 345], [78612, -670], [55574, 2962], [-39159, 4070], [12038, -701], [-24649, 996], [49770, -3582], [27252, -534], [13932, 213], [45102, -1242], [57484, -5416], [-64825, -2739], [-91446, 471], [-96829, 1509], [-109872, -450], [-17838, 2658], [-47775, 3317], [-35642, 3184], [24606, -3237], [18892, 5479], [9588, 3543], [-65773, 5931], [-31939, 357], [11614, 2309], [128597, -759], [128024, 1054], [9911, 3735], [-63240, -2394], [57898, -208], [84190, -34], [-62392, -4776], [94456, 1208], [-1423, 6165], [73206, 3537], [-95780, -2140], [-679, 7716], [-45474, 5514], [-10117, -3147], [83719, 4219], [41202, -6291], [84541, 2107], [-32150, 5006], [-83263, 1290], [-51367, -7071], [2011, -8261], [-34348, -5306], [111998, -1697], [-87067, -3555], [134198, 3019], [32571, 77], [37130, -434], [32269, -9971], [-36386, 5510], [-37518, 3842], [53716, -178], [-64939, 3252], [45103, -3176], [-106765, 4371], [11520, 3564], [-9156, 3315], [55911, -3112], [27294, -3855], [144534, -2289], [93245, -1023], [9260, -1302], [-5250, 2820], [-50514, 3321], [124364, 3192], [-95278, 3153], [-71850, -7476], [-67272, -6253], [-33125, 5995], [-14518, -7796], [-2774, 656], [44592, -5337], [32348, 9016], [37406, 400], [120178, 3136], [-115642, -206], [-47690, 7316], [-79414, -6734], [-6281, 12361], [-14050, -6651], [140112, 1458], [-3165, -5779], [65326, -4877], [103832, -3263], [101635, 4381], [20910, -5760], [-45278, -1699], [-195827, 2731], [10765, -7493], [133044, 6660], [-218332, 1600], [-32762, 565], [215444, 754], [-37807, -675], [-225132, 2010], [-66404, 7214], [148528, 1480], [5832, -1596], [184492, -3542], [61420, 5990], [-16171, -1677], [16462, -2786], [178765, 1279], [143402, -1286], [-62599, -6720], [-16830, 6924], [218156, 2959], [12665, -7743], [274, 10244], [-92478, -5539], [191812, 847], [-61474, -7712], [157425, 2327], [16766, 3091], [249734, 414], [-75144, 7584], [-106352, -8372], [-33434, -2416], [56814, -315], [-112117, 2748], [79414, -6968], [40836, 12066], [-205, 2355], [102044, -1145], [-74366, 6469], [115844, 3001], [-80992, -2387], [95556, -2062], [-58567, 5457], [-41890, -4307], [63554, 9490], [84691, 1933], [-115836, 9060], [251788, 326], [-112636, 7681], [-168901, -93], [50552, 2482], [182406, -5691], [-97426, 2028], [2914, 6536], [-174698, 4811], [37392, -1968], [169692, -2818], [21296, 11620]];
    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_v();".
// 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_v(: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_v();".
// 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_v( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_882_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-330, 5, 1]>,<11,R![786, 67, 1]>,<13,R![84, -41, 1]>],Snew);
    return Vf;
end function;