
// Make newform 6422.2.a.r in Magma, downloaded from the LMFDB on 24 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_r();".
// 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_r();".
// 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, -2, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, 0, 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, 1], [0, -2, 1], [-2, 2, -2], [0, 0, -2], [0, 0, 0], [4, -3, 4], [-1, 0, 0], [-4, 4, 0], [2, -4, 4], [-3, 1, -5], [-6, 2, 2], [-2, 2, -6], [4, -2, 4], [0, 0, 0], [-2, -4, -2], [-8, 6, -7], [4, -2, -3], [-5, 1, -7], [8, -7, 2], [0, 1, 8], [8, -5, 2], [4, 2, -6], [4, -4, 8], [-6, -2, 0], [-8, 10, -5], [-8, 8, -7], [-6, 1, -6], [4, -2, 6], [2, -2, 4], [-5, -1, 9], [10, -6, 2], [0, -12, 3], [-12, 6, -10], [-10, 5, -8], [0, -5, 10], [-2, -7, 8], [-8, 12, -2], [-19, 1, -5], [6, 8, -4], [-6, 5, 2], [6, -8, 14], [-8, 10, 0], [-6, -6, 10], [-2, 11, -4], [-8, 0, -2], [3, -7, 5], [8, -11, 6], [7, -3, 1], [4, -2, -5], [-16, 0, 1], [-22, 8, -14], [0, 0, -6], [-10, 2, -2], [6, 4, -4], [6, -4, -4], [-8, 0, 8], [8, 0, 2], [12, -2, 11], [10, -8, 16], [4, 2, 12], [-18, 12, -6], [-13, 9, 13], [4, -14, -2], [-24, 4, 5], [0, 4, 8], [-9, 1, -19], [18, 6, 0], [-14, 12, -8], [15, -13, 19], [-7, 7, 13], [30, 0, 4], [-22, 8, -2], [14, 2, -4], [-20, 0, 4], [8, 4, 11], [-30, 16, -24], [-20, -14, 7], [-16, 8, 8], [-14, 12, -26], [-10, -4, -6], [-10, 18, 2], [3, 7, -7], [2, -22, -2], [27, 3, -7], [-10, 8, 16], [-18, 2, 0], [-8, -4, 5], [2, 21, -16], [8, 12, 4], [-24, 14, -8], [-18, 10, 14], [-9, 15, 1], [24, -6, 10], [-6, -8, -8], [24, -4, 4], [10, -10, 14], [4, 10, 4], [24, 0, 0], [-7, 5, -15], [-6, 7, -18], [4, -10, 23], [21, 11, -1], [-14, 2, -2], [-6, -22, 6], [-13, 21, -9], [12, -26, 26], [6, 8, -12], [7, -1, 13], [0, 18, -4], [20, -16, -17], [-13, -9, 3], [4, 21, 4], [8, -14, 28], [-12, -8, -14], [-20, -2, -12], [14, -32, 22], [24, -24, 24], [18, -7, 8], [16, -10, 21], [-8, -8, -16], [10, -24, -8], [12, 16, -6], [-4, 38, -17], [30, -2, 12], [31, -9, -13], [-18, -7, -8], [-8, -14, 0], [-14, 8, 8], [-2, 15, -4], [10, -6, 14], [43, -1, 5], [-16, 24, -4], [32, -14, 17], [8, -3, 8], [-32, 12, -15], [-2, 6, 22], [20, 2, -9], [4, 4, -18], [11, -19, -5], [28, -22, 11], [12, -22, 15], [-8, -12, -6], [-10, 13, -14], [32, -28, 34], [8, -32, 7], [8, 6, -7], [16, 22, -6], [-14, 34, -22], [-16, -20, 16], [-10, 18, 4], [-11, -25, 17], [0, 14, -26], [1, 17, -5], [-20, 16, -24], [-12, -20, 3], [-4, -6, 4], [-13, 1, -9], [33, 3, 1], [24, -18, -2], [-6, 4, -20], [-2, 32, -18], [-52, 6, -14], [-31, -5, -1], [-46, 10, -20], [16, 7, -6], [20, -32, 29], [35, -9, 7], [4, -2, -4], [8, 2, 27], [22, -23, 34], [2, 0, -2], [-46, 6, -14], [-21, 1, 3], [48, -13, 14], [-33, 9, 7], [-2, -26, 28], [-14, 40, -32], [-31, -7, 7], [-35, 9, 5], [-22, -10, -2], [-14, -9, -26], [-4, -14, 0], [14, -18, 8], [-18, 24, -14], [-16, 22, 3], [32, -22, 16], [-30, -13, 10], [-22, -22, 6], [32, -18, 20], [-28, -10, -6], [-20, 12, -16], [19, 13, 5], [22, -10, -14], [4, -26, 14], [-16, -34, 12], [8, -12, -21], [-28, -2, -23], [2, 16, -28], [8, -4, 18], [-6, 48, -16], [0, 0, -33], [8, -2, -12], [20, -18, 38], [-46, 18, -22], [0, -42, 11], [-42, 24, -32], [17, -25, -5], [44, -4, 7], [-10, -31, 2], [20, -29, -8], [17, -19, -31], [4, 16, -6], [11, 25, -15], [25, -31, 7], [26, -12, 34], [-4, 2, 16], [-8, 12, -36], [-8, 8, -5], [5, -3, 33], [-18, -6, -14], [44, -8, -7], [-12, 26, -24], [-16, 16, -38], [6, 3, -2], [29, -15, 29], [32, 8, 2], [-1, 3, -3], [56, -8, 0], [-8, 10, 10], [18, 15, -4], [-38, 21, -22], [-24, -8, -13], [0, 2, -4], [-34, 6, -36], [24, -6, 50], [22, -32, 4], [18, -28, 44], [8, -6, 30], [-9, -1, -31], [-6, 31, -2], [-44, 20, -32], [-34, -8, -10], [10, 0, -24], [-10, 14, 6], [-12, 8, -40], [24, -28, 34], [-16, 12, -40], [-10, 49, -14], [12, -2, -2], [-22, 31, -40], [38, 4, -8], [-4, 36, -34], [14, -14, -22], [12, -42, 29], [-10, -12, 10], [-30, -15, 12], [50, -5, -14], [14, -54, 24], [-43, 7, -3], [-19, 53, -17], [-20, -6, 11], [-11, 17, 5], [-20, 32, 10], [-40, -5, -4], [18, -17, -2], [44, -6, 20], [19, -15, 43], [22, 9, 18], [17, 29, -7], [26, -2, -18], [28, -22, 49], [-16, 0, 11], [28, 14, 18], [-2, -16, 20], [28, 2, -8], [22, -8, -4], [8, 10, -2], [0, 2, 36], [8, 12, -12], [48, -19, 2], [22, -16, 10], [2, -8, 0], [20, -26, 8], [-16, -20, 12], [2, 2, 22], [-29, -7, -21], [60, -10, -16], [-12, 10, 2], [-14, -6, 26], [-28, 6, -17], [2, 26, -20], [-48, 18, -16], [8, -4, 16], [2, 14, -4], [48, -10, 25], [-19, 41, -29], [-2, -24, -8], [-48, -2, -3], [-4, -22, 16], [36, -28, 43], [-28, 12, -24], [-36, 20, -44], [20, -48, 12], [54, -14, -4], [-12, 2, -38], [24, -44, 16], [-4, 24, 18], [-16, 46, -6], [-2, 8, -20], [-16, -22, 20], [1, 13, -7], [60, -38, 48], [-44, 34, -13], [-12, 8, -16], [10, 34, -4], [-38, 36, -14], [12, -37, 10], [-20, 20, -3], [4, -12, 3], [65, -13, -5], [4, -7, 32], [22, 4, -12], [20, -31, -38], [25, 35, -23], [18, 38, -18], [-8, 16, 0], [12, -16, -8], [-4, 24, 9], [18, -7, 20], [30, -5, 24], [24, -12, 30], [-60, 22, -22], [-38, 2, -8], [-18, -32, 26], [20, 40, -12], [-10, 10, 42], [20, 12, 0], [-44, 39, -44], [-52, -4, 12], [-52, 0, 2], [-12, 32, -1], [36, -10, 12], [68, -8, 4], [-16, -32, 6], [-39, 19, -57], [6, 35, 12], [10, 31, -18], [0, -16, 25], [-12, 2, 19], [47, -11, -3], [-24, 26, 36], [48, -10, -15], [-32, 29, -30], [-6, 20, 4], [-30, -4, -6], [-50, 36, -16], [-34, -28, 10], [28, 5, 20], [28, -12, 19], [26, 8, -36], [72, -4, -9], [-67, -3, 15], [22, -21, 2], [6, 6, -30], [-56, 30, -18], [-73, 11, -33], [-8, 12, -23], [-8, 10, 10], [-50, -4, -10], [8, -22, -5], [18, 4, 14], [20, -10, -10], [28, -46, 12], [-20, 26, 3], [2, -13, -10], [-12, 36, -46], [31, -55, 31], [-28, -20, -7], [-68, 0, -20], [-42, 0, -40], [-24, 15, 20], [10, -26, -40], [24, 0, -27], [-21, 53, -47], [12, 20, -20], [-72, 36, -58], [20, -26, 47], [-24, -6, -38], [4, 11, -10], [10, 6, -14], [48, -34, 36], [-24, -12, 32], [-12, 42, 0], [-37, 19, -51], [38, -42, 42], [-20, 32, -24], [-34, -16, 24], [-66, 33, -46], [-59, 21, -39], [42, -24, 48], [-44, 40, -35], [4, -20, 45], [18, 14, 14], [32, -16, -14], [-36, 18, -42], [-50, 9, -16], [-10, 2, -24], [4, 26, 35], [44, -16, -20], [-30, 26, 20], [28, -46, 49], [-55, 11, -17], [-36, 8, -54], [-36, -20, 7], [28, -30, -5], [45, -23, 35], [0, -72, 28], [-4, -24, -33], [28, 9, 30], [44, -16, 26], [-16, 50, -46], [-52, 2, -32], [18, -11, -50], [10, 14, -42], [-76, 26, -44], [21, 3, 31], [-37, 45, -49], [58, -56, 70], [-42, -18, 28]];
    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_r();".
// 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_r(: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_r();".
// 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_r( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6422_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-13, -4, 3, 1]>,<5,R![-13, -4, 3, 1]>,<7,R![-8, -8, 2, 1]>],Snew);
    return Vf;
end function;