
// Make newform 2842.2.a.n in Magma, downloaded from the LMFDB on 13 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2842_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_2842_2_a_n();".
// 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_2842_2_a_n();".
// 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 := [-2, -6, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-4, -2, 1]];
    Rf_basisdens := [1, 1, 1];
    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_2842_a();"
function MakeCharacter_2842_a()
    N := 2842;
    order := 1;
    char_gens := [1277, 785];
    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_2842_a_Hecke(Kf)
    return MakeCharacter_2842_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 := 2;
    raw_aps := [[-1, 0, 0], [0, 0, 1], [-2, 1, 0], [0, 0, 0], [0, 2, 1], [-2, -1, 0], [-2, -1, 1], [2, 0, -2], [2, 2, 2], [1, 0, 0], [-2, -1, -2], [4, -2, 0], [-6, -1, -3], [-6, 2, -1], [-2, 1, 0], [4, -2, -1], [-10, 1, -1], [4, -2, 0], [-4, -4, -2], [2, -2, -4], [6, -1, 1], [-2, 0, -3], [2, 5, -1], [2, -1, -5], [6, -5, -3], [-8, -2, 2], [-4, 2, -2], [-8, 4, 2], [4, 2, 7], [-2, -6, -4], [-12, -2, 2], [-6, 8, 2], [2, -6, -6], [-6, 5, 1], [-8, 4, -1], [-6, -2, -6], [8, 0, 4], [4, -2, 5], [-8, -4, 4], [-8, -3, -1], [0, 4, 0], [6, -9, 0], [-4, 2, -2], [-2, -2, 0], [-2, 2, -6], [8, 2, 6], [6, 2, 7], [4, -2, 2], [-10, 3, -1], [-8, 8, 2], [-8, -2, 7], [0, -4, 4], [4, -6, 5], [0, -6, -5], [12, -8, -1], [-6, -8, -5], [8, 2, 2], [-2, 7, 4], [14, 2, -2], [-2, -10, -3], [2, -3, 5], [-8, 0, -6], [4, 8, 3], [4, 1, 5], [-20, -2, 1], [2, 0, 4], [-6, -10, -5], [-2, 0, 4], [4, -2, -4], [-22, -1, 2], [2, -8, -8], [6, -4, 1], [-4, -3, -3], [-12, -4, -1], [-8, 4, -8], [-4, 0, 2], [4, 10, 2], [6, 9, -2], [4, -10, -1], [14, 3, 5], [-14, -5, 5], [20, 2, -4], [-16, 0, -4], [6, 7, -9], [-8, 8, 6], [6, 4, 6], [26, 0, 6], [-8, -4, -2], [0, 2, 2], [10, 2, 4], [4, 10, 1], [10, -5, -8], [16, 4, 0], [10, -6, -3], [-4, 4, 2], [6, -13, 4], [2, 1, 0], [0, 8, 13], [-10, 1, -7], [2, 4, 10], [-16, 10, 0], [-30, -4, 4], [16, 6, 13], [-2, 12, 0], [-20, -2, -8], [18, 7, 11], [-10, 17, 5], [16, 2, -5], [26, -4, 1], [2, -3, -1], [14, 9, 6], [12, -8, 1], [-22, 4, 2], [-4, 2, -7], [24, 4, -4], [2, 4, -2], [6, 5, 11], [-16, 2, -6], [-18, -4, 6], [-8, 6, -5], [12, 3, -7], [18, -2, 7], [12, -8, -8], [0, -4, 12], [22, -17, -7], [-4, -8, -1], [0, 6, 5], [24, 10, 4], [32, -5, -5], [-12, 6, 0], [-18, -2, -3], [4, 4, 4], [-20, 8, -4], [-8, 6, -10], [10, 8, 16], [-2, 7, -7], [0, -8, -4], [-18, -3, -9], [-16, -4, -4], [6, -10, 10], [-6, 5, -3], [4, -14, -7], [-12, 8, 12], [-16, -2, -3], [-32, 2, -6], [6, 9, -4], [-16, -2, 4], [4, -10, 5], [12, -12, 1], [-10, 6, 6], [4, -4, -15], [6, -5, 3], [36, 0, 2], [30, -3, 0], [-14, 4, 10], [-14, 12, 9], [-10, 6, -2], [30, 8, 12], [-14, -4, 0], [22, 11, 10], [18, 10, -1], [14, -14, 5], [-26, -10, 1], [-18, 8, 10], [10, 14, -9], [14, 1, 8], [-12, 12, 6], [-24, 14, 4], [-6, 2, 11], [12, -18, -12], [12, 4, 0], [26, 3, 6], [4, 8, 2], [-6, -6, -4], [0, -12, -10], [26, -16, 0], [0, 12, 10], [-4, 18, -4], [22, 11, 8], [-20, -3, -17], [18, -6, 11], [4, -12, 11], [18, 12, -8], [4, 0, 11], [24, -16, 4], [-2, -17, -8], [36, 6, 2], [30, 10, -4], [2, -14, 6], [-48, -2, -2], [-4, -4, -5], [-6, 2, -19], [-10, 10, 3], [-16, -10, 8], [-2, 4, 2], [-2, 2, -2], [-34, 4, 8], [6, 2, -6], [-32, -12, -9], [-24, -8, -8], [-2, -4, -2], [-8, 24, 8], [-36, 0, -2], [2, -17, 11], [22, 0, -2], [-14, -5, 0], [34, 1, -6], [-4, 18, -8], [14, 18, 21], [0, 6, 7], [-18, -12, -8], [-36, -9, 1], [-10, -2, 7], [-36, 4, -1], [4, -1, -9], [-32, -2, -11], [-42, 10, 4], [-26, 5, -1], [-12, 8, 14], [4, 18, 14], [0, -2, -10], [40, -6, 0], [10, 8, -18], [14, -8, -3], [-2, -3, -11], [2, -20, -6], [22, 3, 13], [28, -2, 2], [-22, 7, 14], [0, -2, 6], [-22, -8, 8], [-18, 3, -3], [-4, -8, -20], [-6, 12, 6], [-22, -13, 11], [36, -13, 3], [-42, 5, -3], [-44, 14, 2], [-12, 4, 0], [-38, 13, 0], [-40, -2, 3], [14, -1, 17], [12, -8, -10], [32, 10, 22], [18, 16, 12], [-12, 20, 0], [32, 14, 18], [10, -17, -1], [-48, 10, 8], [-22, -10, -1], [36, -14, -6], [8, -18, -5], [-26, 10, -5], [10, 15, 5], [24, 6, -12], [20, 4, -14], [6, -12, -12], [8, -14, -1], [-12, -1, -19], [-36, -10, -19], [-16, 26, 2], [8, -22, -11], [-20, 5, 15], [28, -8, 0], [-34, 17, -1], [-4, 2, 9], [24, 2, 10], [-42, -5, -9], [20, 8, 0], [-8, 6, 3], [-22, 15, -2], [4, -26, -4], [28, 4, -17], [-8, 26, 14], [14, -29, -5], [50, -17, -2], [14, -16, -10], [28, 6, 5], [22, -6, -18], [-22, 5, -13], [-48, 0, 2], [-26, -10, -2], [-44, 2, -2], [12, 17, 19], [-10, 22, 8], [28, 18, 14], [10, 12, -8], [-26, 32, 4], [48, -16, -2], [24, -4, -1], [-20, 14, -3], [18, -1, -13], [-4, 2, -3], [-40, -8, -15], [-8, -14, 8], [-50, 1, -2], [18, 11, -10], [2, 13, 12], [-10, -25, 1], [6, -18, -24], [-26, 21, 9], [-14, 8, 16], [16, -8, -16], [-6, -6, -9], [-30, -16, -18], [4, 10, -3], [-14, 10, -1], [18, 1, -14], [14, -18, -2], [40, -8, -9], [16, 10, 16], [-18, -12, -10], [-2, 8, -20], [8, 18, 4], [4, 4, 10], [8, 2, -13], [-6, 8, 6], [32, -20, -12], [-20, 4, -9], [-14, -14, 4], [-4, 0, 17], [-54, 22, 7], [-28, -5, -19], [-10, 10, 7], [0, 2, 11], [-10, -17, -1], [8, -14, -10], [-34, 17, -3], [22, 6, -17], [-4, 0, 5], [-28, 18, 2], [28, -2, 5], [-36, -6, -16], [38, -4, 6], [26, 2, 17], [-2, 1, 15], [-6, -12, -16], [-14, 9, -5], [50, 13, 17], [28, 0, -16], [12, -14, 0], [-14, 0, 8], [-12, 6, 12], [-22, 6, 2], [-38, 6, -10], [-6, 2, -13], [56, -6, 6], [30, 12, 14], [-2, 19, 16], [36, 8, 26], [54, -5, 1], [4, 20, -14], [46, -24, -4], [0, 14, 14], [-24, 2, 4], [-66, -1, -5], [14, -17, -6], [10, -21, -21], [6, -16, -14], [-2, 14, 10], [64, 6, 1], [24, -8, -17], [14, -28, 9], [-56, 0, 6], [-4, -18, -15], [-42, 16, -6], [-40, -8, -12], [-48, -8, 8], [-74, -6, -4], [44, 2, 13], [2, -23, -1], [-2, -30, -6], [2, 16, -10], [28, 10, 2], [4, -16, -11], [14, 8, 10], [-18, 2, 15], [-18, -3, 17], [0, -12, -7], [-8, -18, -3], [52, 6, 2], [-8, -6, -7], [-46, 8, -1], [-10, 8, -16], [-50, 3, 3], [8, 10, -14], [24, 20, 36], [-6, -5, 28], [-16, -10, -15], [-24, -11, 1], [18, 20, 18], [-18, -1, 2], [-46, 14, -11], [-20, -18, -5], [6, -24, 7], [-32, -6, -19], [-40, 14, -12], [-58, -5, -13], [-20, 20, 6], [-46, 4, -18], [-4, -15, 11], [-6, 16, 14], [-20, -2, -22], [-36, 18, 1], [-42, 13, 10], [24, 0, 12], [-36, -12, -23], [58, -18, -8], [-12, 6, 21], [22, -19, 15], [-18, 10, 6], [-28, -8, -19], [32, 14, -2], [32, 16, 0], [6, 10, 20], [44, 14, 26], [-6, 18, -1], [-28, -8, -30], [18, 9, -3], [6, 21, -2], [-54, -2, -18], [-20, -10, -18], [14, 16, -31], [-36, 32, 1], [40, 12, -3], [-42, -15, 4], [4, -6, -24], [-10, -2, -2], [-50, 9, 13], [42, 15, 32]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2842_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2842_2_a_n();".
// 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_2842_2_a_n(:prec:=3)
    chi := MakeCharacter_2842_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_2842_2_a_n();".
// 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_2842_2_a_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2842_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-4, -8, 1, 1]>,<5,R![-10, 2, 5, 1]>],Snew);
    return Vf;
end function;