
// Make newform 6042.2.a.e 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_e();".
// 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_e();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [1], [-3], [-3], [-4], [-6], [0], [-1], [-5], [-5], [-1], [0], [-10], [-1], [0], [-1], [-13], [2], [-3], [-6], [-4], [-8], [12], [-7], [2], [-3], [-13], [-11], [9], [11], [17], [14], [-15], [18], [-4], [-7], [-14], [-7], [-22], [-4], [12], [-7], [-4], [10], [-18], [23], [0], [14], [-7], [1], [22], [-20], [12], [-12], [6], [7], [-15], [-7], [22], [-17], [20], [6], [26], [-6], [-6], [30], [2], [-35], [-2], [-14], [-18], [-3], [0], [-29], [-20], [-30], [-25], [12], [-6], [28], [4], [23], [-17], [-38], [-32], [-15], [-10], [22], [-16], [-2], [32], [-27], [-16], [-37], [-24], [-21], [-20], [-6], [28], [-29], [8], [-23], [18], [6], [20], [-18], [-12], [44], [-12], [-13], [-22], [16], [6], [13], [-46], [30], [-19], [48], [-6], [16], [-20], [34], [18], [-12], [-8], [-25], [10], [27], [-32], [33], [44], [-24], [-2], [-33], [42], [-8], [4], [-33], [12], [-21], [-20], [-3], [-24], [22], [-17], [-17], [20], [-3], [-4], [-45], [-14], [-35], [6], [32], [28], [39], [-26], [36], [-37], [7], [-28], [-15], [16], [47], [20], [-31], [38], [21], [6], [48], [36], [14], [-6], [-8], [-9], [-42], [8], [30], [-19], [-35], [26], [60], [29], [-30], [26], [-18], [-12], [-10], [16], [-30], [-24], [-1], [-7], [-3], [57], [-60], [-4], [-18], [-3], [22], [-69], [-55], [-35], [11], [-34], [-31], [-43], [-63], [-36], [-53], [-9], [6], [8], [6], [-23], [-50], [-12], [21], [-57], [6], [-59], [49], [-30], [8], [9], [-62], [-56], [-46], [22], [-61], [-42], [50], [-6], [64], [-17], [57], [-70], [-60], [-46], [-26], [-58], [-7], [-19], [30], [45], [-69], [50], [0], [50], [-34], [-6], [62], [46], [-11], [10], [60], [-38], [-6], [19], [2], [16], [37], [-40], [46], [-2], [-28], [-25], [20], [39], [30], [46], [37], [3], [-28], [-64], [16], [24], [-28], [-18], [18], [-24], [47], [68], [8], [36], [66], [-12], [-18], [-60], [44], [-52], [48], [-4], [-40], [-64], [59], [62], [51], [-54], [-78], [-64], [34], [8], [-49], [32], [-78], [-19], [20], [48], [66], [4], [42], [-12], [20], [-79], [-5], [61], [-40], [-57], [-16], [22], [11], [-72], [73], [-54], [-65], [26], [-71], [-68], [36], [-50], [82], [69], [68], [-69], [15], [16], [9], [24], [72], [10], [-22], [-36], [55], [1], [-81], [-19], [-70], [-18], [46], [-65], [5], [18], [83], [10], [32], [39], [-73], [66], [-65], [38], [10], [29], [26], [31], [-62], [67], [85], [-7], [66], [20], [72], [90], [20], [2], [60], [-72], [-67], [47], [-78], [38], [-76], [72], [-36], [56], [-81], [18], [-50], [-74], [-55], [-9], [-41], [14], [-23], [-10], [-14], [-24], [-42], [18], [-36], [-72], [41], [86], [-24], [-48], [68], [-84], [-72], [76], [52], [4], [-6], [66], [95], [30], [-14], [48], [56], [87], [16], [-95], [6], [84], [-61], [16], [-38], [6], [-4], [-44], [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_e();".
// 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_e(:prec:=1)
    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_e();".
// 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_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6042_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![3, 1]>,<7,R![3, 1]>,<11,R![4, 1]>],Snew);
    return Vf;
end function;