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