
// Make newform 4882.2.a.c in Magma, downloaded from the LMFDB on 07 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4882_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_4882_2_a_c();".
// 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_4882_2_a_c();".
// 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 := [-1, -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_4882_a();"
function MakeCharacter_4882_a()
    N := 4882;
    order := 1;
    char_gens := [2447];
    v := [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_4882_a_Hecke(Kf)
    return MakeCharacter_4882_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 := 2;
    raw_aps := [[-1, 0], [0, 2], [3, 0], [-1, -2], [1, -2], [-6, 1], [-1, -4], [-4, -2], [-1, 0], [7, 1], [-7, 0], [4, -8], [7, -1], [-4, -2], [7, 0], [-7, 6], [2, -7], [-3, 5], [-7, 1], [3, 3], [-3, 11], [-7, -5], [-8, 3], [0, 1], [-2, 5], [9, -8], [-3, -6], [7, 4], [-4, 5], [-5, -3], [-3, -5], [-9, 13], [13, -3], [-7, 4], [1, -1], [-1, 7], [-7, 1], [-19, -4], [-4, 16], [5, -8], [1, 1], [-6, 2], [18, -4], [-13, 6], [-3, -12], [-14, 3], [-9, -7], [-10, -2], [9, -2], [5, -20], [-16, 19], [-19, 3], [17, -18], [0, 13], [6, 5], [-6, 4], [1, 5], [1, -8], [-5, 7], [17, -5], [-12, 21], [17, -2], [-7, -3], [16, 0], [11, -4], [-19, 10], [11, 8], [1, -5], [-10, 5], [14, 12], [5, 0], [-2, -7], [-17, 20], [-4, 23], [5, 4], [-5, -12], [-15, -2], [-5, -6], [-6, 25], [11, -19], [5, 10], [32, -3], [-9, 18], [10, -17], [-23, 2], [-3, 11], [0, -14], [-22, 11], [-25, 4], [-12, -1], [16, -12], [-25, -6], [-9, 0], [13, -4], [-5, 8], [-18, -2], [3, -24], [8, 3], [-4, 0], [-3, 22], [-7, -14], [-23, 2], [-18, 26], [26, -2], [21, 10], [-11, -11], [-26, -2], [9, -5], [-30, 6], [24, -12], [-25, -3], [0, -26], [8, -31], [23, -2], [-31, 28], [-14, -10], [-29, 16], [44, -2], [-3, -10], [0, 3], [-18, -13], [-2, -16], [31, 8], [-12, -6], [-9, 11], [12, 15], [24, -18], [6, -2], [17, -23], [-32, 3], [25, -19], [17, -42], [5, -17], [-8, -6], [0, -4], [20, -9], [11, -26], [-15, 30], [29, -11], [-15, 18], [31, -29], [-19, -1], [10, -16], [-9, -9], [27, -1], [-21, 7], [7, -21], [-19, -8], [-29, 30], [15, -7], [-14, 26], [-3, -1], [12, 9], [0, 13], [34, 7], [-4, -1], [25, -27], [45, -5], [-7, 3], [39, 7], [-43, 18], [-41, 0], [11, 6], [42, 10], [-12, 25], [34, -11], [-1, 18], [5, -20], [-2, -6], [-23, -10], [-8, -21], [23, -1], [16, -35], [37, 1], [5, -12], [24, -5], [-12, -1], [14, -9], [-24, -12], [2, 24], [-24, 1], [23, -42], [6, -2], [25, -25], [12, 10], [-28, -16], [-33, 16], [-12, -32], [-22, 21], [-52, 14], [22, -5], [-31, 8], [4, 22], [18, 2], [33, -18], [22, 22], [25, -18], [-9, 27], [21, -25], [-34, 25], [-3, 1], [-7, -20], [-30, 18], [8, -19], [-50, 20], [-34, -2], [11, 4], [-33, 39], [-24, 25], [52, -24], [-8, 47], [-28, 15], [-48, -11], [0, -34], [-22, 40], [-21, 14], [-2, 28], [41, 0], [6, -37], [34, -54], [-19, -27], [-2, -41], [-11, -18], [20, -42], [-6, 29], [-39, 8], [-40, -4], [-48, 41], [36, -24], [-24, 0], [31, 26], [6, 15], [-35, -10], [0, 30], [-7, -16], [-1, -16], [-49, 24], [46, -29], [-9, 11], [14, 16], [27, 15], [20, -42], [-40, 14], [39, -32], [37, 24], [-21, 7], [12, 12], [33, -16], [-6, 29], [54, 6], [-66, -4], [24, -31], [19, 22], [-36, 36], [50, -36], [5, -15], [66, -14], [18, 33], [7, -15], [-20, 56], [0, 38], [-29, -15], [25, -49], [-57, 24], [-11, 6], [-21, 26], [36, -45], [34, -42], [-1, -34], [-3, 32], [13, -1], [5, -24], [-49, 36], [44, -37], [19, 4], [-1, -10], [18, -43], [-27, -6], [23, -20], [-24, 0], [6, 47], [8, -42], [-31, 61], [-43, 40], [36, 22], [21, 0], [-2, 11], [-11, 48], [-22, 50], [13, -10], [63, -36], [-53, 24], [63, -4], [17, -31], [-10, -11], [36, -68], [-1, 29], [42, -36], [42, 0], [45, -18], [9, -50], [-56, 18], [13, 31], [22, -7], [64, 14], [34, 32], [-22, 4], [-13, -38], [68, -24], [37, -23], [52, -51], [43, -12], [-1, -6], [53, -32], [17, -25], [-52, 16], [-16, 10], [-7, -20], [-7, 26], [44, -42], [-45, 25], [2, 33], [-58, 50], [-10, 1], [21, 17], [44, -69], [-59, -4], [52, -39], [-14, 25], [-29, -8], [24, -52], [63, -22], [-57, 19], [39, -81], [-36, 62], [-15, 18], [39, -5], [6, 44], [25, 32], [58, -41], [-31, 45], [-17, 14], [16, 44], [36, -50], [13, 37], [-28, -31], [-54, -17], [37, -25], [66, -22], [-62, -5], [25, -10], [-8, -2], [50, -7], [-27, 13], [-3, -8], [25, -30], [-21, 32], [-59, 14], [-74, 35], [13, -8], [68, -16], [-1, 0], [-14, -46], [29, -6], [-46, 32], [-61, -2], [18, 1], [-41, -12], [-48, -26], [-48, -4], [17, -45], [42, -81], [-50, 30], [-47, -17], [76, 4], [85, 1], [10, 17], [44, -38], [2, 5], [-14, 35], [-11, -22], [-7, 12], [-2, -5], [24, -21], [-38, -20], [38, 7], [28, -32], [-29, -41], [-37, 45], [19, -62], [45, 17], [-15, 17], [-16, -21], [37, -18], [57, -50], [-27, -15], [-19, 5], [-57, 64], [18, 20], [-40, 78], [-8, 10], [-49, 51], [-60, 56], [37, -68], [-23, -18], [40, 11], [39, -2], [-28, 31], [-7, -34], [-34, -19], [-53, 46], [-62, 67], [56, -61], [-39, 64], [-38, 43], [38, -34], [-45, 82], [-5, 20], [32, 32], [73, 3], [53, -1], [11, 0], [-57, 75], [78, -9], [-33, -46], [29, -12], [-2, 10], [-21, 32], [0, 44], [41, 6]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4882_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4882_2_a_c();".
// 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_4882_2_a_c(:prec:=2)
    chi := MakeCharacter_4882_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    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_4882_2_a_c();".
// 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_4882_2_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4882_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-4, -2, 1]>],Snew);
    return Vf;
end function;