
// Make newform 6048.2.a.y in Magma, downloaded from the LMFDB on 25 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_y();".
// 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_y();".
// 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
        poly := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 2]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
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, 0], [-1, 1], [-1, 0], [-2, -1], [0, 1], [3, -1], [-4, -1], [4, 0], [0, 1], [4, 1], [-3, 2], [1, 1], [-5, -1], [-3, -2], [-2, 0], [5, -2], [6, -1], [-4, 0], [4, -2], [0, -2], [-1, 1], [11, -2], [-6, 0], [-4, -5], [-2, -6], [-8, 2], [0, 2], [-5, -2], [-10, 1], [-15, 1], [-4, 0], [12, 1], [-14, 1], [-6, -5], [-15, -1], [0, 1], [-7, 3], [1, 6], [-2, 0], [-10, 5], [14, 2], [2, 8], [-1, 4], [-8, 7], [-2, -6], [0, -6], [-4, -5], [-12, -2], [-10, 4], [4, -5], [-2, 5], [-4, -5], [-13, 6], [14, 0], [8, 1], [-1, -5], [6, 0], [-19, -2], [16, 6], [-26, 1], [-15, 1], [-4, 10], [-7, 6], [2, 8], [24, 2], [-9, -7], [-9, -4], [8, -5], [8, -10], [19, -5], [22, -2], [-22, 0], [15, -4], [9, 3], [1, 0], [-18, 7], [20, -2], [-14, -4], [-20, 6], [-13, -2], [-2, 6], [8, 6], [26, 3], [-22, 0], [-32, -1], [-4, 1], [30, 4], [9, -3], [21, -1], [12, 10], [-1, 0], [16, 0], [-16, -5], [-7, -13], [13, -8], [3, -3], [-13, -9], [2, -15], [1, -10], [3, -3], [-24, -4], [28, 4], [32, -2], [-5, 13], [-6, 6], [-12, 6], [3, 3], [-30, 1], [-12, 11], [-10, 5], [-14, 0], [24, 4], [4, -1], [-3, 11], [14, -9], [-26, 0], [-16, -2], [2, -3], [18, -2], [14, -11], [-30, -2], [14, 4], [24, -1], [18, 1], [-38, -3], [3, 10], [-7, 2], [4, -5], [14, -4], [-4, -12], [4, -1], [24, 0], [-13, -8], [5, -1], [10, -2], [-35, -1], [-8, 12], [2, 4], [-2, 12], [6, 13], [-16, -2], [29, -1], [-6, 1], [12, -1], [13, 4], [-2, 6], [29, 5], [6, 2], [-30, 4], [-15, -6], [-10, -6], [-11, -7], [13, 14], [-7, 13], [22, 3], [-3, 17], [13, 1], [36, -1], [23, 7], [-24, -12], [8, -4], [0, 2], [-5, -2], [-26, -6], [-31, 10], [15, -15], [-32, 5], [-35, -2], [-55, 1], [8, 10], [28, -5], [10, -3], [-29, -4], [0, 21], [19, 3], [36, 2], [2, -16], [-6, 2], [14, 12], [-45, 3], [-9, 4], [-30, 2], [-33, 11], [-10, -7], [-11, -1], [14, 14], [40, 3], [38, 2], [7, 4], [-8, -7], [22, 4], [9, 15], [-3, 11], [-2, -8], [-17, -5], [-30, -6], [-1, -8], [-54, 0], [-33, 12], [18, -12], [22, -8], [26, 2], [28, 4], [1, 0], [-3, 15], [26, -3], [-8, 18], [12, 4], [6, -5], [13, -12], [-2, -4], [-13, 3], [39, 2], [-1, -2], [12, -11], [-13, -5], [-10, 18], [34, 5], [20, 4], [3, 16], [26, -11], [26, 7], [7, 17], [-33, -2], [-23, -16], [49, 7], [-4, -16], [-30, 10], [-36, 5], [2, 12], [4, -3], [47, 3], [14, -14], [-6, 2], [-64, 0], [-6, 24], [6, 11], [12, -4], [9, 12], [2, 8], [58, 0], [22, -1], [54, 8], [-6, -6], [-11, -18], [16, 0], [51, -2], [-47, -1], [12, 18], [-27, 8], [-30, 8], [-22, -4], [48, 0], [37, 3], [-16, -1], [-13, -22], [12, -12], [-26, 10], [-6, 2], [36, 10], [-26, -6], [-34, 14], [-38, -15], [-10, 20], [-20, 10], [64, 2], [62, 4], [-51, 5], [-18, -8], [44, 9], [16, 2], [-20, -9], [27, 5], [-34, 6], [-20, -9], [-2, 7], [-5, -12], [19, 10], [3, -12], [15, -10], [27, 17], [65, 6], [36, -2], [-20, -8], [60, -4], [-23, 2], [16, -17], [-22, -16], [-27, -9], [-38, -2], [-37, -12], [-6, 3], [-25, -12], [-77, -2], [-35, 1], [8, 0], [-17, -21], [-49, -2], [46, -3], [-38, -3], [40, -12], [-40, 8], [-70, 3], [21, -15], [-42, -2], [24, -8], [30, 14], [66, 3], [26, -6], [-12, -8], [-20, -23], [-62, 2], [21, -1], [-2, -10], [-26, 4], [57, 4], [-28, -6], [22, 15], [-48, -10], [-14, 8], [1, 10], [41, -9], [-52, -6], [-10, -21], [62, 2], [-25, 1], [-58, 8], [2, 15], [22, -7], [-10, 2], [30, -11], [-16, -5], [19, 2], [61, -5], [5, 24], [38, -6], [-31, 5], [-10, 12], [-50, -4], [59, 0], [-30, -15], [-25, -1], [-16, -10], [-10, 14], [44, 15], [24, -14], [-49, -3], [11, -16], [14, -18], [12, 23], [-3, -8], [-12, 16], [-6, 19], [11, 2], [51, -1], [-72, 0], [13, 16], [-12, -22], [-10, 9], [-33, -2], [-43, -11], [-44, 13], [-34, 0], [-56, 10], [-3, 16], [19, 7], [-65, 3], [-25, 2], [20, 0], [-24, 3], [36, 3], [-44, -3], [30, -5], [14, -4], [44, 18], [42, -11], [16, -21], [-62, -8], [-32, 22], [17, -7], [4, -11], [-44, -2], [-46, -18], [-38, -2], [16, 16], [-8, -4], [-2, -25], [-3, -9], [28, 0], [-53, -4], [10, 10], [4, 2], [50, -13], [-24, 17], [-42, -12], [-36, 22], [-65, 1], [28, 8], [72, -4], [-8, -30], [-14, 18], [25, -9], [41, -1], [2, 2], [50, -11], [-7, 0], [-18, 18], [0, 14], [4, -8], [-8, -14], [28, 3], [-6, 19], [-15, -1], [-69, 2], [42, 22], [10, -21], [-60, -11], [-5, 15], [28, -20], [-2, 7], [60, -5], [38, -13], [-55, -6], [58, 7], [37, -19], [-80, -10], [50, 15], [50, -16], [-96, 0]];
    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_y();".
// 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_y(:prec:=2)
    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_y();".
// 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_y( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6048_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-7, 2, 1]>,<11,R![-4, 4, 1]>,<13,R![-8, 0, 1]>,<17,R![1, -6, 1]>],Snew);
    return Vf;
end function;