
// Make newform 6042.2.a.s in Magma, downloaded from the LMFDB on 17 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_s();".
// 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_s();".
// 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_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], [-2, -1, 0], [-2, 0, 1], [2, 0, 1], [0, -1, -2], [-2, 2, 1], [1, 0, 0], [-3, 5, -5], [-1, -3, 2], [-6, 4, -6], [-2, -2, 5], [-4, 5, -7], [3, 1, 1], [-1, -6, 4], [1, 0, 0], [-3, -3, 0], [-5, -1, 2], [-6, 7, 0], [-4, -2, 6], [6, -8, 3], [9, -9, 9], [3, -3, 7], [1, 4, 3], [-11, 3, -1], [5, -9, -4], [-7, -2, 3], [-8, -3, 4], [-10, 4, -3], [-1, -4, -6], [-5, 4, -3], [-3, -1, 1], [3, -6, -3], [-2, -2, -3], [1, 12, -8], [8, -12, 10], [-11, 7, -10], [10, -8, -4], [-11, 6, -2], [-5, -5, 10], [-12, 12, -18], [11, -2, 9], [-11, 8, 2], [-4, 6, -4], [-1, 8, -1], [-7, -2, -3], [-7, -6, -5], [0, -1, -7], [-8, 4, -7], [-5, -2, -8], [7, 1, 17], [-6, 3, -12], [-3, 1, -2], [-3, 10, 1], [7, 3, 8], [11, -15, 12], [-10, 0, -11], [-13, 9, -15], [-14, 17, -17], [13, -5, -7], [-6, -11, 2], [-6, 19, 1], [14, -9, 4], [4, -5, 6], [-3, 8, 3], [20, -9, 20], [-9, -7, 9], [-6, 0, 11], [22, -11, 3], [-4, -6, 15], [24, -3, 2], [-1, 24, -11], [-15, 9, 13], [0, -19, 4], [-4, 7, -8], [1, -15, -1], [2, 13, 5], [-28, 11, -24], [14, -15, -7], [20, -11, 12], [29, -15, 18], [-1, -6, 18], [13, 1, 5], [-16, 1, -14], [-1, -26, 9], [-7, -15, 11], [13, -6, 9], [11, -20, 4], [18, 15, -6], [8, 13, -9], [15, 13, -8], [10, -8, 25], [18, -1, 2], [9, 9, -16], [16, 7, -11], [-9, -2, -1], [2, -5, 13], [16, 3, 14], [19, -6, -5], [-7, 11, 13], [-25, -4, 6], [-2, -2, 18], [4, -15, 18], [23, -19, 7], [5, 12, -13], [18, -20, 27], [-14, 25, -16], [-9, 8, -23], [26, -20, 5], [-1, 1, 0], [2, 18, 10], [18, -16, 13], [10, 3, -7], [9, 4, -2], [-1, 8, 6], [20, -10, -3], [-8, 9, -16], [2, -7, -19], [-36, 13, -9], [22, -9, 2], [-21, 22, -9], [-16, 16, -17], [34, -12, 21], [8, -15, 1], [8, -11, 5], [27, -9, 20], [-15, 2, 13], [-6, -9, -23], [-12, 15, 8], [7, 9, -2], [13, -4, 11], [-25, 11, -30], [-9, -17, -9], [-16, 11, 16], [5, -15, 26], [-6, -1, 17], [-32, 16, -8], [-4, 8, 5], [-30, 10, 5], [38, -25, 39], [0, 6, 8], [7, 2, -17], [-10, -8, 12], [4, -3, -11], [8, 9, 14], [-11, 16, -10], [6, -20, 22], [-24, 13, -8], [3, 0, 9], [-37, 13, -23], [-1, 12, -26], [-26, 2, -9], [7, -9, -4], [1, -12, 5], [-19, 5, -6], [-4, 25, -21], [8, -20, 18], [-39, 20, -34], [-28, 25, -16], [19, -1, 7], [-7, 17, -4], [-14, 12, -21], [15, -8, -6], [-10, -20, -1], [-7, 2, 0], [15, -25, 34], [8, -12, 3], [-44, 19, -21], [-43, 11, -25], [-17, 24, -35], [11, 31, -16], [35, -22, 20], [7, -11, -9], [-29, 30, -14], [31, -1, 26], [31, -31, 29], [-2, -22, 15], [-24, -3, 10], [-23, 37, -19], [9, -15, 7], [-24, 19, -40], [3, 32, -2], [-13, 21, 4], [0, -24, -3], [12, -21, -9], [43, -7, 1], [6, -15, -10], [-19, -10, 14], [-8, 15, -12], [10, 11, 6], [7, -4, 14], [-5, 21, -21], [12, 20, -11], [-9, -2, -6], [-4, -31, 19], [-32, -8, -6], [14, -37, 6], [-25, -13, 16], [13, -28, 11], [-30, 10, -20], [3, -13, -19], [14, -20, -19], [-42, -4, 0], [-25, -4, -20], [45, -31, 33], [33, -36, 32], [-15, 42, -2], [27, -27, 17], [-23, 18, 30], [-21, 28, -27], [12, -17, 24], [-6, -3, 1], [6, -8, 9], [-16, 4, 3], [6, 12, -2], [-14, 41, -13], [-26, 7, -28], [-13, -14, 8], [13, 11, -13], [13, 5, 14], [-23, 17, -11], [-12, 19, 3], [35, 3, 6], [-19, 39, -39], [-1, -3, -35], [32, -36, 20], [-37, 27, -25], [0, 55, -20], [5, 34, -4], [10, 17, -19], [-2, 18, -35], [-10, -2, 5], [0, -32, 28], [-10, -11, -26], [22, 6, 21], [23, -13, -3], [32, 12, -11], [-3, 23, -10], [-12, -19, 6], [-2, 11, -14], [6, 17, -27], [-16, 41, -36], [14, -17, 38], [58, -4, -10], [9, -21, -4], [-24, -22, 3], [-39, 7, 9], [-20, -6, -38], [-19, 29, 18], [26, -2, 6], [56, -11, 18], [-29, 44, -37], [-42, -5, 18], [-32, -3, -15], [13, -39, 21], [6, 17, -33], [-9, 26, -2], [13, -17, 14], [-43, 2, -11], [17, 6, -4], [-25, -1, -23], [-6, 45, -28], [-12, -3, 15], [-39, -2, 17], [43, -6, -7], [-1, 13, -21], [-17, 7, 21], [8, 16, -3], [18, -5, -5], [-11, 41, -28], [17, 21, 19], [8, -13, 5], [-2, -20, 14], [14, -16, -28], [12, -24, 17], [4, -44, 31], [20, 6, -16], [-2, 41, -22], [31, -28, 13], [20, -29, 13], [-13, 39, -23], [-1, 40, -20], [18, -11, 0], [-14, -11, -11], [5, 6, 26], [14, -27, 42], [27, -31, -13], [-17, 24, 15], [49, -35, 16], [2, -15, 39], [-1, -6, 10], [1, 7, -13], [-14, 15, 2], [25, -33, -6], [38, -19, 47], [18, 30, -9], [-23, -34, 13], [-8, 33, -12], [8, 25, 17], [18, -12, 34], [-27, 32, -31], [-24, -9, -13], [-13, 25, -1], [24, 25, -16], [-15, -10, 14], [-6, 12, -9], [18, 8, 28], [-8, -1, -5], [38, -40, 7], [40, 0, 9], [34, 20, 11], [6, -22, -1], [8, 30, 13], [27, -37, 11], [-31, 16, 18], [21, -24, -19], [17, -14, -33], [21, -46, 41], [-48, 22, 5], [22, 11, -4], [-29, 7, 2], [37, -34, 49], [-13, 12, -44], [37, 31, -18], [-49, 48, -52], [-13, 38, -3], [20, -18, -22], [0, 10, 36], [45, -41, 47], [-42, 48, -35], [-67, 18, -31], [2, -33, 23], [-18, 32, 7], [-36, 18, -15], [-2, -12, 26], [52, -24, -16], [-45, 28, -62], [-61, 24, -19], [-68, 32, -28], [-5, -15, 34], [16, -7, -30], [5, -1, 14], [-17, 31, 43], [44, 24, -14], [16, -16, 11], [21, -16, 28], [-35, 7, -18], [23, 22, -6], [9, -6, 2], [-50, 22, -12], [17, 21, -22], [-26, -8, -26], [56, -8, 13], [-20, 34, -8], [-2, 0, 0], [-54, 10, -28], [11, 35, -23], [18, -24, 7], [14, -36, -25], [2, -77, 35], [-23, -14, -3], [-48, 22, -9], [-32, -18, -3], [-20, 61, -10], [31, -14, 44], [-28, -7, 8], [11, -9, -1], [-25, -19, 5], [37, -15, 48], [21, -15, -43], [18, -28, 14], [29, -24, 49], [-28, -3, -41], [-7, -48, 29], [-21, 43, 18], [44, -18, 0], [-9, -38, 10], [-62, 27, -17], [46, -21, 16], [30, -43, 19], [-12, 7, -30], [-14, 24, -2], [55, -32, 14], [-22, 33, -15], [37, -27, 47], [-33, 22, 13], [27, -65, 24], [-46, 14, -5], [-60, 7, -6], [30, -13, 50], [67, -3, 9], [-22, 5, -52], [-22, -15, 8], [-26, 0, -49], [4, -27, 49], [33, -20, -30], [53, -25, 1], [-80, 12, -24], [-11, 64, -45], [-11, 41, -39], [-33, -5, 26], [-55, -2, 18], [7, -44, 16], [-42, -2, 23], [27, 34, -2], [-58, 3, -9], [-43, 38, -4], [31, -8, 12], [-13, 14, 3], [42, 1, -23], [-4, -4, 5], [-36, -17, -7], [-38, 31, -38], [3, 19, -34], [8, -61, 36], [21, 10, 23], [19, -51, 49], [51, -7, -17], [3, -31, -20], [-4, -32, 13], [-8, 54, -29], [-37, 54, -50], [1, 49, -10], [7, -19, -43], [3, 16, -21], [-22, 68, -22], [12, -42, 12], [34, -8, 9], [33, -23, 35], [1, -7, 33]];
    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_s();".
// 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_s(: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_s();".
// 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_s( : 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, 14, 7, 1]>,<7,R![7, 14, 7, 1]>,<11,R![-1, 6, -5, 1]>],Snew);
    return Vf;
end function;