
// Make newform 6422.2.a.m in Magma, downloaded from the LMFDB on 17 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6422_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_6422_2_a_m();".
// 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_6422_2_a_m();".
// 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, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-3, -1, 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_6422_a();"
function MakeCharacter_6422_a()
    N := 6422;
    order := 1;
    char_gens := [4903, 4733];
    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_6422_a_Hecke(Kf)
    return MakeCharacter_6422_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], [-1, 1, 0], [0, -1, 1], [0, 1, 0], [2, 1, -1], [0, 0, 0], [0, -2, 0], [-1, 0, 0], [1, 1, 2], [-6, 1, -3], [4, -4, 3], [-2, 2, -4], [-4, -1, 2], [-1, -2, 0], [3, 3, 1], [4, -4, 3], [0, -1, -5], [1, -2, -1], [0, -2, 4], [3, 0, 0], [-9, 4, -8], [1, -5, 0], [-6, 4, -9], [10, 0, 3], [6, 2, 0], [-3, -2, -4], [-2, 4, 5], [-2, -1, 2], [3, -6, 0], [7, 6, -2], [-4, -4, 5], [-13, 1, 1], [-3, -1, -6], [-6, -2, -3], [15, 1, 2], [11, -3, 0], [-6, 3, -3], [1, -1, 1], [7, -5, 3], [3, 7, 2], [4, 6, -7], [-3, -7, -3], [2, 1, -4], [3, -2, 9], [-10, -3, 6], [17, -3, 11], [-13, 9, -3], [7, 2, 2], [5, 1, -5], [2, -9, 8], [-4, -4, -1], [10, -11, 14], [-5, -1, -1], [-2, 1, 2], [-3, 8, -5], [-15, -6, 1], [10, -3, 10], [2, -3, -7], [-16, 5, -4], [-16, 5, 3], [-3, -11, 6], [4, -9, 15], [-5, -6, 2], [5, 5, -2], [-15, 7, -2], [-9, 3, -16], [4, -7, 5], [-1, 3, -2], [-14, 8, -11], [-8, 17, -11], [-10, -9, 6], [11, 1, -3], [-16, 4, 2], [3, 15, -13], [-1, -5, -13], [-17, 14, -1], [20, 2, 7], [-11, 9, 9], [-9, 2, 2], [-10, 11, -16], [-7, -12, 8], [-16, -1, -4], [3, -2, 9], [-18, 7, 3], [-11, -9, -1], [-24, 10, -1], [-4, 15, -10], [16, -16, 7], [-22, 4, -17], [12, -9, 8], [3, -9, -7], [10, 4, -2], [5, 4, 6], [11, -11, 16], [-1, -2, 0], [-12, 20, -6], [14, -12, -5], [-7, 2, -3], [-14, 17, -6], [-21, 11, 0], [-15, -13, 12], [-13, -3, 6], [-10, 19, -19], [-16, 10, 3], [1, 5, -7], [9, 6, 13], [-17, 17, -2], [-20, 4, 6], [-21, 14, -16], [-8, 20, -19], [-25, 2, -1], [-7, 19, -14], [20, -13, 6], [34, -1, 9], [-23, 2, 2], [-17, -1, -4], [-30, -6, 1], [8, -14, 17], [16, -11, 16], [-2, 14, -7], [-5, -16, 15], [23, -6, 12], [5, -8, 12], [30, -5, 2], [-4, -3, 6], [22, -14, 1], [9, -3, 11], [-14, -1, -24], [-17, -6, -7], [-33, 12, -4], [-1, 4, 13], [-14, 4, 4], [-19, 3, 10], [-26, 0, 1], [14, 15, -8], [10, -25, 25], [-11, 12, -2], [-15, -1, -15], [12, -21, 12], [11, -3, 3], [-18, 4, 1], [3, -1, 15], [-31, 6, -4], [24, -3, 8], [-3, 7, -1], [-14, -3, -14], [-14, 20, -24], [14, -18, -4], [-11, 14, -14], [-16, -11, 5], [-26, 11, 5], [5, -11, -9], [-3, 2, -9], [24, 0, -7], [-19, 10, -10], [18, -25, 10], [-29, -2, -16], [8, -2, -15], [-11, 5, -20], [-25, -4, 9], [5, 20, -2], [-28, 5, 8], [-15, 0, 5], [20, -5, 0], [-8, -3, -22], [-2, 15, -8], [-16, 7, -15], [-23, 6, -4], [19, -10, 12], [4, -31, 13], [6, 15, -19], [5, -8, 13], [15, -22, 6], [-27, 4, 7], [21, 2, 14], [40, 1, 2], [-35, 17, -6], [-11, 14, -1], [-35, 15, -17], [5, -22, 19], [0, -13, 2], [13, -1, 11], [7, 3, 25], [39, -3, 3], [6, -14, 7], [-4, 4, -7], [-24, 11, 8], [5, 6, -3], [-15, -14, -8], [39, -8, 0], [42, 7, -6], [-9, 23, 1], [5, 20, -11], [12, 12, 5], [-1, 3, -23], [19, 9, 7], [4, 13, 18], [-22, -1, 13], [-30, 8, 13], [38, 0, 7], [18, -21, 11], [-16, 31, -3], [8, 3, -14], [-29, 9, -11], [26, -10, 14], [-13, 15, -7], [47, 1, -5], [24, -30, 11], [1, -31, 19], [15, -10, 0], [45, -1, 15], [-15, 12, -2], [14, 20, -7], [31, -6, 23], [24, 4, -6], [13, 9, -6], [25, -22, -4], [46, 3, -5], [32, -27, -9], [-5, 18, 1], [34, 1, 3], [28, 14, 3], [-6, -3, 13], [-8, -12, 10], [29, -9, 9], [-11, 7, -21], [34, 5, -6], [-18, 2, 14], [17, -6, 11], [5, 6, -3], [-19, -17, 17], [-1, -17, -19], [8, -22, -2], [-17, 14, -24], [24, -23, -12], [-34, 4, -11], [-3, 27, 5], [-18, -10, -2], [27, -24, 5], [20, -4, 19], [10, 4, 13], [26, -2, -2], [-6, -12, 6], [27, 24, -18], [-18, 8, 6], [-30, 23, -7], [-2, 14, -31], [-18, 36, -38], [13, 5, 34], [-34, 19, -8], [38, -4, 17], [-19, -8, -4], [11, -23, -7], [6, -8, 0], [-20, -2, -21], [9, 7, 20], [12, -5, 11], [-13, 7, -3], [28, -13, 29], [-3, 13, -26], [-19, 22, -6], [3, 14, 6], [-57, 15, -10], [26, -16, 35], [3, 31, -21], [-33, 19, 14], [18, -27, -18], [-45, 7, -1], [-4, 27, -18], [-32, 24, 12], [-11, -17, -1], [45, -1, -5], [5, 4, 1], [32, -3, 10], [-47, 13, -2], [44, -5, 10], [-43, -3, -6], [-12, -3, -28], [14, -40, 34], [-23, 21, 16], [1, -3, -26], [-23, 36, -14], [3, 5, 9], [48, -7, -9], [38, -3, 1], [-18, 29, 3], [24, -13, 41], [-21, -16, 12], [-9, -15, 19], [16, 5, 11], [2, 21, -7], [-64, 9, -7], [22, -2, -9], [-21, 16, 15], [-23, 4, -33], [-33, 14, -26], [-17, -17, 9], [42, 14, -12], [-15, 40, -35], [14, 3, 22], [9, 32, -25], [-35, -3, -16], [35, -30, 10], [-16, -13, -18], [-65, -7, 1], [12, -6, 22], [-21, 10, -24], [12, -20, 6], [-18, 13, -26], [-53, 16, 5], [26, 4, 20], [-30, -2, -19], [2, 22, 12], [10, 14, 5], [26, 9, 0], [14, 27, -6], [31, -9, 20], [-18, 40, -23], [-12, 4, -12], [-19, -13, 3], [12, -30, 25], [24, 29, -24], [39, 0, -4], [-19, 1, -29], [10, 14, 15], [-13, -41, 21], [-21, 1, -34], [61, 11, -9], [-2, -9, -6], [-26, -8, -18], [-32, 10, 10], [24, -2, 25], [-2, 4, 6], [67, -8, 11], [19, -6, 5], [-23, -31, 21], [-64, 18, 4], [40, -31, 8], [58, -16, 21], [11, -6, -20], [20, -21, 36], [41, -29, 23], [-6, -27, 18], [-25, 16, 3], [-44, 6, -24], [33, -24, -9], [29, 11, 19], [-44, -3, -18], [22, -14, 27], [31, -17, 42], [45, -15, -11], [-41, 22, -24], [-9, -6, 24], [-29, 10, 17], [7, 9, 4], [-21, -30, 10], [-67, 2, 5], [22, 11, 16], [19, -35, 32], [-58, 1, -3], [-19, 27, 6], [7, -25, 12], [32, -37, 51], [10, -25, 20], [9, 13, -30], [-15, -33, 29], [-13, -28, 33], [24, 19, 3], [-37, 7, 6], [14, 12, -27], [-50, -5, -11], [-3, -29, 28], [6, -16, -2], [33, -35, 51], [-2, -6, -26], [13, 20, -17], [34, 14, -12], [68, -10, 4], [22, -17, 0], [7, -29, -1], [-49, -5, 15], [16, 20, -5], [-5, 0, -11], [8, 3, 6], [-36, 21, 17], [54, -31, 14], [18, -34, -20], [0, -42, 6], [-51, 1, -23], [-30, 24, 8], [-10, 28, -18], [-6, 13, -3], [4, -17, 16], [-23, -17, -6], [-8, 1, -10], [-28, 14, -11], [14, 20, -20], [20, 21, -3], [-24, 3, -28], [35, 4, -12], [66, -15, 11], [28, -33, 47], [37, -17, 26], [-12, -3, 0], [-29, -4, -23], [14, -12, -5], [-47, -3, -3], [49, -36, 15], [-19, 8, -32], [32, -7, 44], [-31, -14, -15], [-22, 37, -41], [-12, -12, -6], [-22, 7, -8], [32, -8, 22], [-6, -35, 34], [-26, -5, 20], [15, -17, 21], [-66, 7, -23], [61, -11, 8], [-36, 40, -49], [-35, -6, -5], [-5, -5, 31], [30, -29, 37], [-28, 18, -33], [34, 0, 27], [43, -20, 41], [13, 4, 21], [-61, -17, 13], [-15, -46, 27]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6422_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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