
// Make newform 6048.2.a.i 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_i();".
// 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_i();".
// 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], [2], [0], [-1], [-4], [-4], [8], [4], [-7], [5], [1], [-9], [-2], [3], [-2], [-4], [12], [-16], [-15], [-3], [-6], [-4], [-2], [8], [0], [7], [-10], [7], [4], [-12], [-2], [18], [7], [-16], [11], [3], [6], [10], [-10], [6], [-17], [0], [2], [16], [-4], [-28], [-18], [-4], [-6], [12], [5], [-18], [-24], [-1], [-22], [-15], [0], [-6], [-15], [-28], [-13], [-14], [8], [5], [-17], [8], [-24], [-33], [18], [6], [11], [11], [19], [22], [4], [-22], [-4], [-3], [-10], [24], [-6], [-26], [-32], [-12], [6], [17], [35], [12], [-27], [-16], [0], [-29], [39], [27], [-17], [14], [-11], [41], [24], [28], [0], [-31], [26], [-12], [-9], [6], [4], [-14], [-22], [-24], [20], [27], [-2], [-46], [-16], [10], [14], [6], [26], [-18], [-8], [-18], [18], [-1], [11], [4], [22], [28], [44], [8], [-17], [33], [26], [45], [40], [18], [-10], [-38], [-32], [43], [22], [28], [-49], [54], [33], [-30], [22], [5], [-42], [47], [-25], [51], [-30], [-29], [-55], [-44], [39], [-40], [24], [16], [61], [-50], [3], [1], [-32], [5], [9], [-24], [12], [46], [43], [40], [-25], [44], [-30], [-26], [6], [-59], [-15], [26], [11], [-62], [-51], [38], [16], [30], [13], [56], [-54], [27], [21], [34], [43], [58], [19], [50], [-11], [18], [-54], [-14], [-20], [15], [-51], [14], [24], [12], [-54], [13], [-10], [29], [57], [5], [-4], [13], [-58], [38], [4], [63], [-2], [42], [-23], [-23], [37], [21], [-12], [-34], [-60], [-46], [20], [57], [6], [-34], [-24], [-38], [-34], [-60], [-5], [-34], [-66], [66], [-50], [-54], [-9], [0], [13], [19], [-12], [49], [34], [-2], [64], [-27], [-48], [55], [68], [-42], [10], [-20], [-6], [22], [2], [54], [4], [64], [54], [71], [-2], [28], [-24], [28], [37], [14], [-68], [18], [-41], [75], [53], [-27], [29], [11], [-28], [-44], [52], [25], [-72], [-10], [17], [-6], [69], [74], [-63], [-65], [77], [-72], [-41], [1], [-30], [26], [24], [40], [54], [-25], [-2], [72], [-42], [38], [-62], [-36], [-60], [-54], [7], [58], [-42], [-81], [-4], [-42], [-16], [6], [-7], [17], [-12], [6], [-2], [-43], [34], [54], [-50], [62], [-74], [-88], [69], [55], [-61], [-34], [21], [54], [50], [-33], [66], [-33], [88], [6], [84], [-8], [-35], [65], [30], [60], [-83], [-76], [-66], [7], [95], [0], [-61], [36], [34], [-13], [-55], [-68], [18], [72], [-27], [-37], [65], [23], [12], [-64], [60], [92], [10], [-34], [28], [-66], [-32], [-62], [-48], [-7], [-20], [12], [42], [-98], [24], [-40], [-58], [-73], [-12], [-21], [-86], [-36], [-82], [72], [14], [-12], [51], [-52], [-72], [-40], [-102], [47], [93], [-46], [-90], [-19], [38], [64], [52], [-8], [-92], [-74], [11], [-53], [-54], [78], [4], [-41], [-12], [38], [-84], [18], [63], [-38], [77], [-32], [66], [54], [-88]];
    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_i();".
// 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_i(: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_i();".
// 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_i( : 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![-2, 1]>,<13,R![0, 1]>,<17,R![1, 1]>],Snew);
    return Vf;
end function;