
// Make newform 6048.2.a.bg in Magma, downloaded from the LMFDB on 19 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_bg();".
// 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_bg();".
// 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;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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], [-1, -1], [0, 2], [0, 2], [-1, -2], [-1, -3], [0, -2], [1, -4], [3, -2], [5, -5], [-2, -2], [-6, 4], [-4, 0], [-2, 4], [0, -8], [-4, 6], [-7, 1], [-6, 2], [2, 2], [-8, -2], [-3, 3], [-4, -4], [-4, -6], [1, 4], [-6, 8], [7, 8], [-2, 10], [0, 2], [-2, 0], [0, -2], [4, -4], [6, -2], [6, -8], [0, -10], [8, 6], [-10, 6], [5, 3], [-14, -4], [14, 4], [-11, -1], [2, -4], [-22, -2], [-5, 6], [6, 0], [5, 14], [-18, -2], [8, 8], [-10, -2], [-10, -4], [-10, -10], [-8, -12], [19, -9], [-5, 13], [-17, 1], [0, 0], [11, 2], [-10, 0], [4, 8], [12, -2], [11, 2], [-8, 6], [-16, -2], [6, 20], [12, 16], [3, 16], [-11, -5], [14, 4], [-1, 1], [-10, -8], [11, -6], [15, -8], [6, 6], [-10, -18], [0, -8], [2, -4], [20, 2], [-26, -6], [-14, 10], [19, -6], [1, 15], [-4, 18], [8, 0], [-7, 5], [-26, -2], [-3, -4], [21, 3], [-18, 4], [-6, 16], [-20, -12], [-14, -6], [1, 19], [2, -26], [-4, 10], [24, 6], [-23, -3], [5, -12], [-5, -14], [0, -12], [-6, 26], [-4, -14], [10, -14], [10, -16], [-6, -24], [-6, -18], [-15, -3], [-3, -17], [-24, 10], [20, 4], [25, -12], [-18, -20], [-29, -8], [-18, 10], [-14, 6], [-5, 6], [22, -8], [22, -12], [27, 7], [8, 2], [6, 20], [19, -17], [-3, -7], [-36, 8], [-40, 6], [15, 8], [-2, -4], [16, -16], [2, -2], [14, 12], [-7, -7], [-42, -6], [2, 20], [28, 14], [16, -10], [-37, -1], [-8, 24], [31, 7], [-40, -6], [15, -4], [22, -20], [26, 16], [-9, 1], [-6, 10], [20, 10], [28, -12], [-23, 11], [15, 22], [30, 4], [6, 24], [19, 9], [28, -8], [-4, 26], [-22, 8], [26, -12], [-36, 4], [32, 10], [0, -8], [-11, 13], [-9, 9], [-56, 2], [18, -20], [44, -2], [32, -12], [-14, 28], [12, 18], [34, -8], [7, -22], [25, -5], [10, 16], [-14, -10], [26, -12], [-11, -26], [15, 30], [17, -15], [-24, 28], [-14, -10], [-33, 4], [-16, 12], [6, 24], [42, -2], [21, -26], [24, -10], [31, 23], [-7, 35], [-34, 4], [-20, 0], [-19, 22], [44, 4], [4, 10], [26, -20], [66, 0], [12, 2], [-13, -5], [11, -23], [27, 6], [-10, -4], [15, -9], [6, -18], [-12, -30], [13, 26], [26, -2], [-8, 20], [-16, 18], [-24, -30], [20, -12], [-1, 21], [-42, 16], [12, -16], [49, 0], [53, 5], [14, 30], [-6, -28], [40, 4], [12, 8], [-16, 14], [-11, -15], [11, 17], [-44, 16], [18, 8], [-16, -4], [28, 22], [-26, 10], [6, -26], [-5, -2], [35, 7], [-5, 11], [21, -16], [21, 11], [-25, 12], [13, 6], [-40, -6], [-2, 46], [15, -2], [-56, -6], [18, -24], [-12, 38], [6, -28], [0, -6], [37, -1], [-17, 36], [37, -14], [-3, -14], [3, 3], [-10, 0], [-11, 36], [24, -14], [-20, 22], [3, -21], [-18, -8], [12, -22], [-14, 8], [-30, -12], [-13, -33], [7, -31], [5, 10], [-51, -6], [20, -26], [-6, 22], [30, -34], [17, 45], [8, 34], [-26, 6], [-59, -7], [-41, -16], [-40, 2], [-8, -26], [30, -20], [-24, -2], [-10, 6], [16, -32], [-20, 6], [-36, -26], [62, 6], [-17, -36], [11, -11], [-2, -48], [22, 8], [-12, 42], [-18, -28], [6, -20], [22, -18], [18, 14], [-11, -4], [21, -31], [1, -20], [-34, 28], [35, 28], [21, -21], [-22, -14], [10, -36], [-12, -42], [10, 18], [-53, -4], [5, 31], [29, -18], [44, 6], [-8, 22], [-11, 36], [-2, 36], [20, 6], [2, -20], [-17, 21], [42, 12], [15, 32], [21, -35], [-30, -14], [-3, 21], [-7, 30], [-18, -26], [38, 28], [8, -4], [-12, 10], [-73, -1], [4, -16], [12, 34], [-5, 33], [4, -48], [-66, -4], [-44, 4], [-17, -46], [13, 15], [-34, 6], [-20, -24], [44, 4], [38, -4], [-43, -14], [-50, -24], [-46, -22], [-43, -8], [-18, -14], [5, -16], [-64, 2], [-8, 26], [-32, -12], [-31, 0], [31, -25], [62, -6], [43, 16], [-1, 0], [-36, 6], [28, 14], [44, -2], [58, -4], [-62, -12], [-6, 14], [56, 6], [28, 38], [52, 18], [-27, -26], [42, -16], [-12, 16], [9, -46], [35, -20], [51, 29], [-30, -12], [68, 4], [18, -4], [34, -12], [-54, -16], [19, -17], [-46, -32], [-41, 3], [28, -28], [51, -10], [-19, 37], [-2, 12], [-19, 22], [49, -15], [-21, 6], [-6, -12], [2, 0], [39, 8], [-37, 34], [-26, 24], [6, 64], [22, 0], [41, -11], [-44, 14], [-35, 11], [-46, 34], [-20, 2], [22, 36], [-35, -28], [50, 4], [10, 40], [-32, -20], [48, 24], [-40, -24], [34, 4], [29, -11], [-85, -7], [-16, 28], [-30, 44], [3, 12], [51, 2], [23, 37], [10, 22], [-36, -10], [10, 54], [-4, -42], [-14, -36], [1, 35], [1, 17], [-31, 14], [-1, -18], [-60, -18], [-15, -8], [-28, -44], [64, -4], [14, -48], [-66, 16], [-12, -8], [18, -32], [45, -35], [-1, 39], [72, -16], [20, 18], [-10, -2], [-52, 4], [-12, -16], [13, 35], [-26, 12], [-2, 8], [-4, 14], [-58, -28], [16, -36], [-49, 40], [-84, 18]];
    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_bg();".
// 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_bg(: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_bg();".
// 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_bg( : 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, -2, 1]>,<11,R![-1, 2, 1]>,<13,R![-8, 0, 1]>,<17,R![-8, 0, 1]>],Snew);
    return Vf;
end function;