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


// To make the newform (type ModFrm), type "MakeNewformModFrm_6048_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_6048_2_a_e(:prec:=1)
    chi := MakeCharacter_6048_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_6048_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_6048_2_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6048_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![1, 1]>,<11,R![3, 1]>,<13,R![-2, 1]>,<17,R![-2, 1]>],Snew);
    return Vf;
end function;