
// Make newform 6042.2.a.q in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6042_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_6042_2_a_q();".
// 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_6042_2_a_q();".
// 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 := [3, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-3, 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_6042_a();"
function MakeCharacter_6042_a()
    N := 6042;
    order := 1;
    char_gens := [2015, 4771, 2281];
    v := [1, 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_6042_a_Hecke(Kf)
    return MakeCharacter_6042_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, 0, 0], [-1, 0, -1], [0, -1, -1], [2, -1, 1], [1, 0, 1], [2, 1, 1], [1, 0, 0], [4, -1, 2], [2, -4, -1], [2, -2, 2], [4, -1, 1], [5, -1, -2], [-4, 1, -2], [-3, -2, 0], [-1, 0, 0], [0, 6, -1], [-2, -4, -1], [7, -2, -1], [6, -2, 0], [4, -3, 1], [-8, 3, -6], [6, -3, -4], [-1, -1, -3], [-4, 1, -4], [-2, -2, 3], [3, 1, -1], [9, 0, -1], [-2, 5, 1], [3, 0, -4], [-5, 3, -1], [2, 9, -4], [11, 5, -3], [0, 5, 3], [-9, 2, 0], [-8, -2, 2], [-4, 0, -1], [2, 0, -4], [7, 0, 2], [8, -4, 7], [0, 6, 2], [-11, 5, -3], [7, 4, 4], [6, 0, 6], [1, 1, -3], [3, 7, -7], [-5, 3, -1], [7, -7, -6], [4, -3, 7], [-3, -12, 0], [2, 3, -8], [3, -2, 1], [12, -10, -5], [5, -5, 9], [18, -4, -1], [-8, 0, 5], [2, -9, 1], [0, -1, 0], [5, -1, 10], [2, 11, -6], [7, 8, -3], [7, -1, -4], [-7, 2, 1], [-21, 8, 5], [-11, 9, 5], [1, 8, -1], [12, -9, -6], [-4, -5, -1], [-15, 9, 0], [14, -3, -1], [1, -8, -1], [-5, -17, 5], [-6, -1, 4], [-7, -6, 3], [-19, 2, -5], [16, -15, -10], [5, -1, -14], [-3, -6, 3], [3, 7, -2], [-3, 4, -11], [12, 8, -7], [9, 10, -6], [24, 1, 4], [17, -2, -1], [11, 5, -5], [-4, 17, -4], [-3, -3, -11], [-11, 12, 0], [9, 6, 3], [-3, 3, -6], [26, 2, 5], [24, -3, -1], [15, 2, 7], [12, -14, -5], [11, -13, -2], [9, 9, -3], [-15, -3, 4], [-21, 0, 5], [13, -9, 3], [-12, -5, 8], [7, -2, 8], [8, 10, -12], [15, 14, -1], [6, 11, 2], [9, -13, -11], [-8, -1, -5], [9, -12, -11], [-21, 3, 9], [8, -19, -1], [2, -12, 3], [8, 6, 12], [14, 3, 3], [-9, 13, 0], [11, 2, 4], [-1, 6, -10], [-4, -3, 1], [19, -14, 5], [-3, -7, -6], [9, -9, -12], [27, -6, 9], [-9, -7, 13], [-2, 9, 13], [14, -3, 23], [1, 1, -10], [13, 3, -4], [-24, 6, -13], [1, -1, 7], [-7, 3, -8], [-9, 12, 3], [-4, 16, 7], [-15, 7, 9], [6, -10, 9], [10, 3, 12], [15, -2, 5], [-2, -2, -3], [3, 7, -6], [24, 0, 4], [0, 7, 3], [4, -3, 5], [-9, 19, 6], [10, 12, -14], [9, 3, -7], [-6, -4, 4], [15, 3, -10], [37, -4, -3], [-17, 4, 8], [14, 2, 10], [-11, -2, 9], [-3, 23, 1], [6, 9, 0], [-15, -14, 12], [-10, 17, 9], [2, 6, -17], [15, -7, -1], [2, 20, -5], [-27, 9, 0], [-24, 2, 2], [7, -4, 12], [3, 24, -9], [0, 15, -14], [20, 14, -7], [4, 9, 7], [-7, 10, 14], [18, -13, 17], [13, 10, 0], [18, 14, -3], [6, 3, -9], [-1, 9, 8], [4, 7, -16], [-19, -1, -17], [-8, 10, 19], [-7, 12, 12], [10, -3, 14], [19, -14, -4], [16, -14, 5], [-34, 1, 0], [4, 1, -1], [-43, 2, 1], [6, 7, 0], [-26, -7, 4], [25, -8, -7], [-25, -16, 6], [16, -10, -3], [-22, -1, -11], [-39, -1, -6], [-30, 11, -6], [-11, 24, -1], [-21, 6, -18], [-25, -8, -9], [-19, -4, 1], [-7, -18, 10], [6, 9, 4], [32, -1, 19], [-3, 12, 0], [21, -21, -16], [8, 2, 2], [-7, -22, 13], [14, -2, 7], [3, -9, 17], [28, 16, -6], [8, -3, -16], [-32, -9, 7], [18, 24, -12], [-17, -16, -8], [4, -23, 18], [25, 10, 8], [-23, -14, 8], [2, -9, -2], [-7, 0, 14], [5, 11, -11], [-23, 8, 13], [39, -3, 6], [-8, 17, -15], [0, 9, 15], [-18, 18, -10], [-23, 21, 22], [-25, 0, 9], [21, -18, 0], [-14, -5, 8], [24, -24, -17], [-26, -1, -2], [-7, 21, -16], [-10, -22, 9], [12, 1, -10], [42, 11, 2], [-40, 4, 12], [-28, -13, 12], [-21, 30, 11], [11, -16, -2], [15, 9, -6], [24, 15, -3], [48, -11, 7], [-8, 12, -16], [-39, 0, 1], [0, 3, -3], [-16, 5, -14], [22, 11, 11], [-42, 12, -9], [-33, -2, -9], [-7, 16, -23], [-3, -21, 18], [-9, -2, -7], [5, -6, 1], [10, -6, 30], [4, 4, 9], [36, -5, 15], [20, 9, 2], [-18, 6, 16], [18, 4, 3], [0, -2, -8], [-11, 20, -19], [51, 5, -1], [13, -20, 13], [-15, -23, 8], [12, 1, -2], [21, -11, 16], [-37, -2, -6], [20, -20, 13], [-33, 1, -5], [25, -12, 2], [26, 7, -10], [3, 0, 7], [7, -17, 2], [43, -3, 17], [-11, 31, -17], [-32, 23, 4], [-20, -3, 16], [-6, 9, 19], [27, -13, -16], [-36, 6, -9], [14, -19, 16], [-39, 17, 10], [-2, -14, -22], [-38, 4, -16], [-10, 31, -1], [22, -5, 11], [30, -20, 18], [-23, 0, -21], [19, 19, 11], [9, -9, 0], [-24, 15, -2], [33, -16, 0], [-15, -18, 19], [-39, 1, -12], [7, -6, 6], [63, 0, 3], [20, -3, 10], [21, -11, -23], [0, 8, 13], [-37, 21, -4], [-41, -4, 12], [6, 3, 18], [39, -8, -5], [6, 20, 5], [17, -5, 14], [0, -15, -23], [-11, -15, -1], [-21, 0, -31], [35, 11, 2], [46, -10, -2], [-7, 7, 15], [49, 1, 14], [-16, 1, 2], [49, -12, 11], [55, 6, -10], [-44, -9, -13], [30, 4, -8], [13, -5, -4], [-36, -3, -9], [-32, 19, -25], [-24, 1, 19], [-36, 9, -27], [8, 5, 33], [-18, 1, 2], [-5, -36, 16], [-21, 5, -7], [1, 21, -5], [23, -1, 11], [-4, -11, -21], [27, -6, 25], [-46, 4, -3], [41, -3, -21], [33, 6, 12], [14, -22, 1], [-21, -6, 14], [19, 29, -13], [42, 6, 0], [-14, 32, 6], [6, 1, 28], [-30, 17, 15], [-19, 31, -17], [11, -27, 22], [4, 25, 17], [-26, -5, 7], [-22, 6, 10], [-24, -12, 4], [17, -18, 0], [13, -11, -9], [-24, 8, 16], [22, -14, -19], [37, -8, 17], [-36, 6, 7], [32, 1, -18], [8, -2, 34], [0, -15, 11], [-45, 6, -20], [-40, 20, 1], [33, -14, -10], [-25, 0, -10], [-40, -28, 6], [38, -12, -15], [-34, 6, -18], [-8, -19, -9], [34, 32, -6], [54, -8, 4], [-68, 4, -6], [24, 5, 6], [10, -17, 13], [-4, 17, -21], [9, 29, 2], [-25, 17, -35], [40, 21, -7], [-12, 21, 25], [39, -6, -5], [31, -12, -12], [23, 24, -1], [24, 15, 2], [-76, -9, 0], [48, 12, -9], [16, -11, 2], [-2, -30, 30], [23, -19, -21], [-59, -1, 0], [-35, -17, -13], [58, -16, -11], [26, -4, 2], [-3, 0, -18], [-19, -33, 0], [-39, -30, 15], [-17, 19, -22], [33, 22, 9], [-2, -18, 10], [31, -6, 18], [-29, -5, -10], [-2, -31, 16], [21, 7, 19], [-8, -20, -7], [8, -23, 15], [11, -16, 19], [15, -28, 15], [-12, -11, 24], [-23, -20, -11], [-59, 16, -7], [14, 9, 9], [-21, 13, 6], [35, -26, -22], [-20, 13, -10], [-24, 12, -12], [25, -5, -31], [8, -21, 10], [70, 8, 3], [-21, 0, -2], [19, 36, -16], [-58, 11, -17], [59, 12, -8], [29, -1, 4], [-47, -4, -8], [1, 18, 34], [-3, 3, 39], [-7, -21, -2], [38, -13, -5], [-29, 17, -24], [23, 2, 1], [38, 4, 11], [67, -12, -9], [33, -3, -9], [-42, 37, 28], [20, -29, 14], [28, -20, 31], [-2, 31, 5], [-10, 13, 1], [-3, 2, -6], [-46, 6, -25], [30, 3, 2], [-1, -15, 29], [-2, 6, -2], [-38, 16, -10], [-12, 37, -17], [6, 1, 0], [4, 41, -12]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6042_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6042_2_a_q();".
// 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_6042_2_a_q(:prec:=3)
    chi := MakeCharacter_6042_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_6042_2_a_q();".
// 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_6042_2_a_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6042_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-7, -2, 3, 1]>,<7,R![9, -10, 1, 1]>,<11,R![9, 0, -5, 1]>],Snew);
    return Vf;
end function;