
// Make newform 6003.2.a.e in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6003_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_6003_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_6003_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
        poly := [-6, 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_6003_a();"
function MakeCharacter_6003_a()
    N := 6003;
    order := 1;
    char_gens := [668, 3133, 4555];
    v := [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_6003_a_Hecke(Kf)
    return MakeCharacter_6003_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], [0, 1], [-2, 1], [0, 0], [1, 0], [-1, -1], [-1, 0], [1, 0], [-1, 0], [-8, 1], [5, -2], [2, -3], [-5, -2], [10, -1], [2, 0], [3, 1], [-8, -2], [-4, 2], [5, -3], [-2, 5], [1, -2], [10, 1], [-3, 1], [12, -2], [-8, 1], [-8, -4], [2, -5], [-4, 1], [12, -2], [-2, -5], [-4, 6], [-3, 7], [6, 0], [-4, -2], [-1, -8], [-1, 8], [8, -2], [1, 3], [-11, 5], [-9, -3], [-6, 4], [5, -7], [-6, 4], [-7, 7], [-8, 5], [4, 9], [-17, 2], [-14, 0], [-17, -4], [-5, -7], [-11, -1], [6, -6], [11, 1], [-13, 1], [12, -2], [4, -8], [12, 2], [-7, 0], [0, 10], [0, -9], [15, 5], [20, -3], [0, 4], [8, -3], [-6, -5], [14, -8], [-3, -4], [-5, -7], [3, -6], [-4, 2], [7, 9], [-14, 0], [-12, -3], [-5, 0], [-6, 4], [-23, 3], [-8, -6], [-2, -6], [6, -7], [-12, -8], [5, 6], [10, -10], [-6, 0], [23, 6], [6, 7], [-24, -4], [14, -1], [-4, 0], [9, 2], [13, -7], [-12, 2], [10, -6], [18, 1], [-33, -2], [13, 5], [-19, -7], [4, -9], [6, 3], [-12, 2], [1, 6], [18, -7], [-3, -5], [26, 4], [12, -9], [16, -5], [-1, -9], [-27, 5], [-6, 3], [16, 6], [-2, -3], [10, 0], [-18, -4], [1, -4], [-18, 6], [11, -9], [-8, -2], [-11, -5], [-6, 15], [7, -1], [0, 3], [-3, -2], [-14, 4], [-12, 6], [34, 2], [30, 5], [8, -3], [15, 15], [-16, 8], [-36, 2], [26, -4], [-29, -5], [13, 10], [17, 2], [-9, -5], [-47, -2], [22, -6], [-6, 14], [-18, 6], [-26, -2], [34, 6], [17, -3], [-34, -7], [15, -3], [-16, 14], [-22, 12], [6, 12], [-6, 14], [-20, -3], [4, 14], [-27, 8], [7, 3], [9, 18], [4, 19], [-7, 8], [45, -1], [-14, 6], [-27, -13], [-10, -16], [8, -10], [-8, -6], [34, 3], [-24, -1], [12, 14], [-24, 1], [25, 15], [-32, 8], [-12, 20], [26, 2], [28, 7], [30, -5], [3, 18], [34, -5], [-5, 16], [6, 18], [-12, -6], [19, -6], [8, 1], [-10, -8], [-4, 10], [0, 0], [19, 9], [-28, 4], [3, 1], [-36, -3], [36, -4], [-6, 11], [14, 0], [-8, 12], [-12, -10], [7, -14], [12, 19], [-14, -14], [-12, -12], [5, 3], [8, -7], [24, 4], [-40, 6], [-8, 8], [29, -11], [-47, -3], [-53, 0], [28, 1], [-5, -2], [19, -11], [-35, 7], [-5, 4], [3, 3], [-23, 3], [16, 1], [8, 25], [13, -1], [25, 8], [-35, 3], [18, 15], [-12, -13], [29, -12], [-28, -3], [8, -21], [26, -7], [28, -8], [0, -14], [12, 8], [-31, 4], [21, 13], [-18, -3], [-21, -3], [-18, 7], [31, -18], [50, -8], [-4, 3], [16, 0], [-7, 26], [6, -19], [-2, 19], [12, 10], [3, -18], [-27, 11], [-15, -7], [4, -12], [19, 23], [7, 20], [25, -8], [-14, -5], [0, 6], [27, 9], [-22, 4], [-14, -7], [-34, 1], [-5, 11], [-4, -18], [48, 11], [-29, 5], [-16, 4], [-36, -5], [12, 18], [32, -6], [-14, 6], [-27, 9], [57, 8], [32, 12], [-31, -1], [-47, 0], [-50, 4], [-38, -9], [-17, 4], [3, 17], [-77, 1], [-42, -4], [-54, -10], [-3, 2], [-2, 12], [72, -2], [-35, -4], [-6, 4], [28, 8], [0, -22], [28, 6], [-22, -12], [-40, 13], [-32, -8], [-28, -19], [-24, -2], [-40, -3], [6, 0], [-18, 21], [1, 20], [17, -23], [-18, 12], [25, 15], [64, 1], [22, -11], [-7, -11], [-15, -7], [44, -12], [66, -8], [31, 2], [-3, 7], [-8, 12], [26, 8], [-17, 12], [-32, 23], [-8, -12], [58, -8], [-46, -6], [-23, -14], [-52, -11], [44, -3], [12, 20], [17, 6], [36, -8], [-60, -10], [-12, 12], [21, -2], [-36, 13], [28, 8], [-4, -5], [50, -4], [34, -8], [-34, 5], [-42, 8], [8, 14], [-11, -9], [-8, 3], [48, -1], [36, -8], [-20, -24], [41, 20], [8, -22], [0, 6], [22, 4], [-27, 7], [-23, 16], [-12, 9], [55, -2], [10, 0], [2, 15], [-2, 0], [-16, 19], [-50, -17], [-4, 15], [54, -4], [8, -22], [-24, -16], [6, -35], [-8, 14], [2, 2], [60, 3], [-8, 2], [-65, 5], [11, 24], [49, -8], [-14, 8], [24, 15], [-52, 6], [-24, -21], [-33, -3], [-42, -18], [58, -15], [53, 3], [52, -11], [68, -10], [-62, 1], [16, -25], [32, 10], [56, -2], [-12, -2], [10, -11], [65, 6], [-12, -1], [25, -26], [-39, 5], [-29, 15], [-6, -8], [-65, -10], [24, 11], [68, 4], [-21, -30], [60, 0], [37, -18], [-3, 19], [28, -13], [40, -11], [-14, 3], [-28, 23], [13, -1], [-44, -9], [-8, 14], [27, -10], [55, 13], [29, 4], [-12, 22], [-42, 8], [-56, 7], [23, -25], [0, 10], [-10, -12], [-83, -3], [-78, 7], [32, 13], [50, 4], [-32, -5], [-39, -6], [-60, -7], [48, -2], [-71, -12], [-40, -9], [44, 10], [17, 16], [31, 11], [-55, -4], [-52, 6], [-36, 22], [-72, 6], [-41, -8], [50, -20], [-6, -2], [-13, 24], [-33, 25], [-52, -14], [-44, 0], [9, -2], [6, -4], [-66, 12], [-15, -16], [-22, -26], [-14, -2], [38, -16], [-6, 2], [-8, 30]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6003_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6003_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_6003_2_a_e(:prec:=2)
    chi := MakeCharacter_6003_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_6003_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_6003_2_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6003_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![0, 1]>,<5,R![-6, 0, 1]>],Snew);
    return Vf;
end function;