
// Make newform 6019.2.a.a in Magma, downloaded from the LMFDB on 17 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6019_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_6019_2_a_a();".
// 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_6019_2_a_a();".
// 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_6019_a();"
function MakeCharacter_6019_a()
    N := 6019;
    order := 1;
    char_gens := [2316, 1392];
    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_6019_a_Hecke(Kf)
    return MakeCharacter_6019_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 := [[0], [0], [3], [-3], [-1], [1], [2], [-1], [2], [5], [4], [-9], [2], [-4], [0], [6], [10], [-5], [12], [-7], [-6], [5], [-4], [-8], [-2], [0], [11], [-16], [-16], [-13], [-2], [-5], [-15], [-18], [0], [0], [-22], [-4], [14], [10], [-5], [-14], [18], [-10], [15], [-12], [-1], [24], [24], [-2], [24], [4], [-17], [5], [12], [-26], [-24], [6], [-11], [6], [-5], [-14], [-12], [-5], [-10], [-31], [-25], [-14], [-2], [-14], [25], [0], [-17], [1], [-11], [20], [33], [-14], [15], [14], [15], [-26], [0], [-16], [16], [4], [24], [-36], [21], [1], [-25], [-2], [-23], [6], [-40], [12], [-35], [6], [5], [0], [-8], [-18], [-5], [22], [18], [-10], [-30], [20], [-8], [-2], [-12], [-7], [-12], [40], [-8], [2], [-25], [-30], [-9], [12], [-18], [12], [26], [8], [14], [-6], [-16], [21], [7], [26], [10], [38], [-28], [8], [10], [-44], [26], [-52], [-21], [31], [-29], [18], [30], [-32], [20], [-2], [55], [42], [40], [-32], [50], [29], [18], [38], [35], [12], [56], [51], [-38], [12], [42], [-24], [27], [-12], [27], [-24], [9], [-28], [-7], [-34], [-57], [10], [-36], [-17], [0], [13], [4], [4], [-44], [-5], [-60], [-44], [35], [-43], [12], [-2], [34], [-61], [-5], [30], [-40], [-12], [58], [-8], [60], [4], [17], [-22], [3], [36], [12], [-30], [26], [4], [-51], [-63], [63], [-71], [9], [-10], [-38], [-30], [36], [24], [-51], [-53], [16], [18], [-14], [51], [-50], [-51], [39], [70], [12], [20], [-14], [-1], [0], [22], [14], [68], [47], [0], [-35], [76], [22], [57], [-9], [15], [-24], [26], [19], [65], [2], [-36], [-12], [40], [-20], [3], [-67], [-13], [54], [-75], [24], [-50], [-2], [-67], [79], [-64], [4], [-2], [24], [-2], [18], [-64], [34], [-27], [8], [17], [2], [46], [36], [8], [33], [29], [51], [24], [-22], [-15], [-8], [13], [-9], [2], [62], [-12], [53], [-12], [-35], [-50], [-23], [-57], [-60], [12], [-17], [-73], [-30], [-54], [10], [-68], [-56], [63], [-14], [6], [59], [-47], [12], [-66], [-20], [30], [32], [-51], [-9], [-18], [-24], [40], [14], [-76], [66], [-37], [-35], [-42], [38], [33], [70], [86], [39], [18], [21], [-85], [-18], [84], [8], [69], [-45], [-36], [48], [81], [75], [-71], [46], [56], [-14], [0], [90], [90], [52], [-14], [-28], [13], [28], [-22], [-58], [-39], [-20], [-33], [36], [-21], [6], [-11], [44], [-78], [-49], [36], [70], [-9], [30], [88], [-7], [-62], [38], [24], [-28], [-5], [-7], [-30], [-1], [-11], [-24], [-40], [-68], [46], [-43], [22], [6], [24], [-38], [-59], [3], [-72], [-69], [-16], [71], [28], [-52], [-40], [-52], [34], [-80], [-44], [58], [-4], [-38], [-9], [81], [-80], [18], [25], [10], [-44], [-37], [9], [-65], [60], [81], [-14], [-79], [-1], [-21], [54], [-39], [79], [62], [-52], [-13], [2], [37], [6], [39], [22]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6019_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6019_2_a_a();".
// 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_6019_2_a_a(:prec:=1)
    chi := MakeCharacter_6019_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_6019_2_a_a();".
// 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_6019_2_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6019_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![0, 1]>],Snew);
    return Vf;
end function;