
// Make newform 882.3.n.b in Magma, downloaded from the LMFDB on 03 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_882_n();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_882_n_Hecke();"
// 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_3_n_b();".
// 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_3_n_b();".
// 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 := [4, 0, 2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]];
    Rf_basisdens := [1, 1, 2, 2];
    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_882_n();"
function MakeCharacter_882_n()
    N := 882;
    order := 6;
    char_gens := [785, 199];
    v := [6, 5];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_882_n_Hecke();"
function MakeCharacter_882_n_Hecke(Kf)
    N := 882;
    order := 6;
    char_gens := [785, 199];
    char_values := [[1, 0, 0, 0], [0, 0, -1, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 3;
    raw_aps := [[0, 1, 0, 1], [0, 0, 0, 0], [-2, 2, -1, -2], [0, 0, 0, 0], [-9, -3, -9, 0], [6, -4, 12, -2], [-5, 2, 5, 4], [-2, 1, -1, -1], [0, -9, 15, -9], [-12, 0, 0, 6], [7, 15, -7, 30], [0, 24, 31, 24], [2, -20, 4, -10], [-2, 0, 0, -6], [58, -1, 29, 1], [39, -12, 39, 0], [-13, 25, 13, 50], [14, -32, 7, 32], [-29, -45, -29, 0], [6, 0, 0, -30], [-53, 16, 53, 32], [0, -15, -55, -15], [68, -8, 136, -4], [-126, -24, -63, 24], [22, -52, 44, -26], [-9, -18, 9, -36], [-102, 13, -51, -13], [0, -57, 33, -57], [35, -78, 35, 0], [-60, 0, 0, 18], [-154, 0, 0, -66], [-162, 3, -81, -3], [-75, -30, -75, 0], [0, -56, 0, -28], [0, 42, -33, 42], [113, 15, 113, 0], [63, -48, -63, -96], [0, -111, 65, -111], [10, 152, 20, 76], [-54, 48, -27, -48], [147, -27, 147, 0], [-16, 104, -32, 52], [0, 63, -159, 63], [-61, 66, -61, 0], [-48, 0, 0, 162], [-149, -37, 149, -74], [118, 0, 0, 174], [156, 120, 312, 60], [45, -63, -45, -126], [-158, 90, -79, -90], [0, -174, 27, -174], [36, 0, 0, 162], [11, 28, -11, 56], [190, -136, 380, -68], [174, -102, 87, 102], [201, 165, 201, 0], [-115, -44, 115, -88], [34, -19, 17, 19], [61, 240, 61, 0], [72, 0, 0, -330], [47, -93, -47, -186], [8, 256, 16, 128], [-80, -96, -160, -48], [115, -7, -115, -14], [-34, -52, -17, 52], [0, -12, 465, -12], [0, -99, 85, -99], [-188, 0, 0, -54], [93, 201, 93, 0], [98, 28, 196, 14], [-221, 14, 221, 28], [0, 171, -63, 171], [209, -109, -209, -218], [0, -180, -1, -180], [364, 0, 0, 102], [266, -101, 133, 101], [9, -114, 9, 0], [74, 126, 37, -126], [0, -378, -117, -378], [-243, 46, 243, 92], [184, 176, 368, 88], [-4, 0, 0, -114], [183, -291, 183, 0], [2, 36, 4, 18], [-42, 45, -21, -45], [0, -45, -171, -45], [60, 0, 0, -138], [0, -108, 7, -108], [-346, -236, -692, -118], [-46, 0, 0, -198], [798, 39, 399, -39], [359, -47, -359, -94], [-241, -21, -241, 0], [12, 0, 0, 546], [0, 105, -23, 105], [-28, -56, -56, -28], [-658, -38, -329, 38], [233, 184, -233, 368], [54, -223, 27, 223], [0, -126, 677, -126], [68, 0, 0, 246], [-423, 114, -423, 0], [123, 285, -123, 570], [0, 408, -123, 408], [397, -117, 397, 0], [3, 268, -3, 536], [0, -672, 0, -336], [-826, -38, -413, 38], [9, 369, 9, 0], [-74, -660, -148, -330], [-370, -115, -185, 115], [-749, -246, -749, 0], [696, 0, 0, 186], [225, 251, -225, 502], [182, 0, 0, -402], [-1077, -60, -1077, 0], [308, -336, 616, -168], [-45, 33, 45, 66], [0, 24, 357, 24], [18, 0, 0, -222], [-193, 128, 193, 256], [364, 0, 0, 186], [366, 174, 183, -174], [399, -279, 399, 0], [458, 237, 229, -237], [942, 0, 0, 72], [0, 588, -149, 588], [-370, 187, -185, -187], [-136, 408, -272, 204], [-58, -216, -29, 216], [109, 63, 109, 0], [-510, 0, 0, 330], [0, -375, -305, -375], [520, 0, 0, 294], [494, -398, 247, 398], [-98, -140, -196, -70], [-77, 146, 77, 292], [-107, 47, 107, 94], [-270, 684, -540, 342], [627, -96, 627, 0], [396, -432, 792, -216], [0, -54, 507, -54], [-161, 615, -161, 0], [654, 0, 0, -570], [-103, -178, 103, -356], [508, -544, 1016, -272], [-682, 44, -1364, 22], [49, -484, -49, -968], [-194, 173, -97, -173], [0, -417, -525, -417], [0, -282, -703, -282], [-312, 264, -624, 132], [-542, 0, 0, -18], [-1166, -49, -583, 49], [-217, 111, -217, 0], [-1278, 0, 0, 102], [0, 429, 1063, 429], [10, 392, 5, -392], [-24, 1024, -48, 512], [-823, 28, 823, 56], [0, -525, -33, -525], [-996, 0, 0, 42], [1298, 0, 0, 54], [-322, -101, -161, 101], [-771, -162, -771, 0], [317, -215, -317, -430], [599, 903, 599, 0], [-421, -60, 421, -120]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_882_n_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_882_3_n_b();".
// 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_3_n_b(:prec:=4)
    chi := MakeCharacter_882_n();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_3_n_b();".
// 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_3_n_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_882_n();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![441, -126, -9, 6, 1]>,<23,R![3969, 1890, 837, 30, 1]>],Snew);
    return Vf;
end function;