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