
// Make newform 6018.2.a.n in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6018_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_6018_2_a_n();".
// 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_6018_2_a_n();".
// 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 := [5, 5, -4, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-3, -1, 1, 0], [0, -3, -1, 1]];
    Rf_basisdens := [1, 1, 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_6018_a();"
function MakeCharacter_6018_a()
    N := 6018;
    order := 1;
    char_gens := [4013, 1771, 1123];
    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_6018_a_Hecke(Kf)
    return MakeCharacter_6018_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 := [[1, 0, 0, 0], [-1, 0, 0, 0], [0, -1, 1, -1], [1, 0, 1, 1], [0, 1, 0, 0], [-4, 0, -3, 0], [1, 0, 0, 0], [-3, 2, 0, 0], [-4, -1, -5, 2], [0, 0, 3, -1], [4, 1, 1, -1], [-5, 1, -4, -1], [-2, 1, -3, 0], [-2, -3, 1, -2], [1, 3, 3, 2], [-5, 2, -4, 3], [-1, 0, 0, 0], [-7, -1, -3, 4], [1, -5, -3, 1], [0, 5, 0, -2], [3, -1, -2, 4], [-1, 2, 0, -4], [7, -3, 4, -3], [-4, 3, -1, 5], [4, 0, 5, 0], [3, -2, 5, 1], [0, -2, -3, 1], [-3, 0, 8, 1], [1, -2, 5, -6], [-3, -1, -8, 1], [-3, -2, 8, -3], [-6, 2, 2, -4], [-9, -3, 1, -2], [0, -3, -4, -4], [-2, -2, 12, -1], [2, -6, 9, -6], [-9, 2, 2, -8], [-2, -4, -5, 0], [3, -8, -3, 0], [4, 4, 3, 3], [2, 0, 4, -5], [12, -1, 9, 5], [-3, -4, -5, 7], [-14, 4, 2, 1], [-10, -1, -5, 4], [-1, 0, 4, -2], [-4, 3, 0, -4], [14, -8, 6, 1], [-1, -9, 7, -4], [-8, 0, -1, 0], [11, -10, 2, -2], [5, 1, 8, 3], [-7, -2, 2, -3], [0, -3, -3, -4], [-8, -5, -5, 3], [-10, 8, 2, 0], [1, 10, 2, 0], [-11, 2, -8, -1], [-16, 5, 0, -3], [-1, 6, -6, 2], [-10, 5, -6, 9], [-12, -2, -5, -4], [-12, 4, -5, 4], [10, -11, -5, -2], [11, 4, 4, -4], [13, -2, 8, 9], [-15, 4, 5, -1], [-3, 4, 5, -10], [-12, 2, -21, 4], [1, 0, 10, -9], [8, -12, -3, 3], [-2, 4, -1, 3], [-16, 10, -1, 4], [4, -6, -1, -1], [6, 0, 12, 3], [-3, -2, -9, -3], [11, -3, -5, 1], [3, 6, -7, 6], [-14, 5, -7, 5], [5, -9, -2, 6], [8, -1, 2, 8], [-2, 3, 7, -6], [18, -3, 1, -7], [11, -1, 9, 5], [-3, -5, -6, 3], [-11, 14, 0, 2], [-21, 3, -17, -4], [-17, -4, 5, 1], [-12, 13, 0, 0], [10, 4, 5, -7], [-22, 3, -19, -10], [29, 0, 18, -2], [-28, 0, -18, 4], [-6, -7, 8, -8], [9, 4, -4, 6], [-11, 3, 0, -9], [11, 0, -4, -7], [20, 4, -4, 6], [-12, 1, -13, 0], [-4, 5, 20, 6], [9, -6, -11, 7], [-5, -1, -14, -2], [-13, 17, 1, -11], [18, -3, 2, -12], [-3, -7, -7, 1], [2, -9, 16, -3], [-11, 7, -16, 6], [-21, -2, -15, 0], [2, -14, 14, -3], [10, 0, 14, 1], [9, -5, -1, 11], [-18, 1, 3, 9], [25, 0, 3, 0], [13, -4, -4, -1], [0, -13, -7, -5], [-30, 4, -18, -4], [26, 0, 11, 5], [16, 3, 6, -1], [9, 11, 24, -2], [6, 0, 0, 12], [-15, 10, -2, -5], [15, -16, -1, 0], [27, -6, 3, -5], [22, 2, -6, 8], [18, -3, 10, -11], [17, 4, 8, -1], [13, 3, 4, 11], [9, -5, -2, 14], [3, 3, -8, 12], [-11, 12, 4, 7], [-10, 18, 7, -11], [11, -21, -10, 3], [-5, 18, 12, -9], [1, -2, -9, 11], [-15, -2, -13, -11], [-3, 6, 12, 12], [-18, 9, 1, 10], [-23, 22, -2, -6], [30, 0, 26, -7], [4, -21, -15, 5], [-28, -8, 9, -2], [-17, 8, -9, 17], [13, 13, -5, 0], [-4, 12, 8, 12], [-9, 0, -29, 2], [14, 5, 1, 1], [3, -8, -25, -8], [23, -15, 3, -8], [10, -1, -7, 12], [6, 3, 9, 16], [-2, -9, 3, -11], [-4, -1, 10, 7], [3, 7, 13, 6], [-3, -4, -4, 8], [15, -9, -4, 17], [8, 16, 5, -8], [15, 9, 5, 7], [17, -2, -1, 8], [-23, -9, -12, 1], [7, 14, 9, -4], [-23, 0, -21, -6], [-14, 18, -20, 1], [2, 14, 5, 11], [16, -4, -3, 3], [-9, 13, -7, 4], [8, -15, 28, -8], [-25, -4, -39, 11], [-11, 8, -1, 12], [-22, 0, -10, 5], [10, 8, 10, 3], [8, -14, 9, -1], [-12, -3, -30, 4], [35, 12, 1, -1], [-22, 6, -22, -2], [1, 4, -21, -1], [-5, 6, -18, -3], [-34, -9, -14, 3], [8, -8, 27, -24], [18, -7, -18, -8], [-23, 7, 2, -10], [7, 1, -15, -7], [-16, -8, 4, -9], [10, -16, -3, 12], [12, -5, 20, -23], [12, -13, 15, -3], [18, -5, 23, -13], [3, 4, 23, -4], [8, 8, -23, 6], [12, 7, 6, -2], [3, -5, 1, -3], [20, 10, 22, 2], [-14, 7, -24, 4], [-2, 3, 22, -1], [-23, 24, -10, -5], [16, 4, 19, -9], [24, -2, 1, 9], [-5, 9, -17, 25], [3, -6, -15, -14], [-8, 17, 19, -5], [2, -16, 5, -11], [-23, 3, -13, -19], [-19, 10, 7, 13], [-7, 7, -5, -9], [31, -12, 21, 4], [21, -15, -12, -18], [-19, -1, 8, -11], [10, 4, 20, -28], [-9, -2, -10, 13], [18, -9, 11, -14], [-14, 6, 21, -10], [12, -4, 32, -20], [30, -13, 18, 2], [8, -2, -9, -15], [-2, -24, 3, 7], [20, -12, -15, 6], [-25, -6, -30, 10], [-9, -17, -10, 0], [25, -9, 20, -16], [-1, 8, 3, 4], [9, 6, 1, 14], [-36, -5, 1, -7], [10, 15, -15, 8], [-2, 12, 16, 13], [4, 4, 19, -20], [-8, 10, 14, 9], [2, 8, -3, -2], [-13, -5, 22, -14], [30, -10, 18, -11], [29, 5, 18, 4], [2, -3, 22, -4], [15, -12, -18, 8], [23, -11, 12, 4], [1, -12, -31, -12], [8, -18, 0, 1], [19, 6, -1, 28], [-26, 3, -19, 18], [9, -10, 32, -5], [-1, -20, -24, 0], [20, -3, 2, 14], [-6, -7, -17, -3], [-7, -6, 0, 9], [0, -7, -23, 5], [23, 6, -16, 10], [4, -22, -22, 10], [-40, 1, -25, -2], [57, 1, 0, -2], [-11, 11, 2, 9], [3, 5, -10, 15], [-38, -9, -41, 27], [-7, 11, 5, -14], [-6, -9, -1, 7], [-15, 35, -4, -8], [50, 3, -11, 3], [-8, 8, 8, 4], [-36, 20, -17, 1], [1, 5, -22, 13], [2, 1, -31, 14], [25, -22, 12, 3], [-18, 24, 7, -1], [2, -7, 47, -3], [-8, 9, 23, 7], [-24, 11, -3, 16], [27, -18, 3, 17], [-2, -15, 29, -30], [-4, 5, -37, 4], [9, 16, -8, 22], [8, -11, 1, -7], [-16, 12, -44, 2], [-15, -2, 25, -8], [-24, 13, -16, 5], [5, -4, 3, 1], [21, -3, 3, -1], [1, -8, 5, -6], [-42, 10, -7, -2], [21, 2, -15, -6], [-18, 22, 11, 13], [-14, -16, -8, -15], [-41, 16, -2, 12], [-16, 11, 15, -5], [-14, -7, -42, 5], [7, 9, -23, 0], [-37, 24, -12, 0], [15, -24, -31, -7], [-4, 9, 17, -22], [-30, -6, 19, -14], [-15, 0, -35, 22], [5, -16, 42, -13], [8, 15, 12, 16], [23, 20, 20, -18], [3, 27, -1, -1], [-26, 7, -6, 1], [37, -4, 26, -24], [12, -8, 36, -15], [10, -7, 29, 2], [-2, 21, 14, 1], [47, -6, 26, 13], [-41, 11, -30, 2], [-1, 21, 21, -13], [13, -3, 49, -7], [-42, 12, -24, 5], [-43, -8, -18, 15], [25, -40, 3, -2], [-5, -11, -13, 27], [-3, -12, 11, 6], [3, -5, 3, -8], [22, 10, 25, -13], [-51, -13, -10, 3], [-5, -2, -19, 10], [10, 4, -8, -10], [-54, 9, -17, 3], [-23, -3, -48, -1], [21, -19, 19, 5], [23, -24, 43, -6], [33, -7, -11, 24], [3, 15, 32, -16], [-23, 2, 14, -19], [-14, -11, -36, 4], [7, -8, 12, -19], [32, -22, -4, 1], [25, -14, 11, -24], [15, 2, -7, -19], [5, -9, 48, -10], [34, -25, 2, 2], [14, 10, 0, -9], [7, 14, 43, 2], [-11, 36, -1, -6], [19, 6, 41, -28], [-29, 15, -24, -12], [-6, 9, -28, 26], [-9, 3, 15, 5], [3, -26, 19, -10], [18, -19, -3, 26], [29, -23, 27, -8], [4, -30, -32, 8], [9, 6, -27, 27], [-1, 18, 44, 14], [-18, -19, -43, 12], [-36, 0, -14, 9], [46, -17, 23, -6], [-43, 8, -38, -10], [-35, -14, -50, 16], [37, 11, 44, -2], [-37, -3, -49, 12], [57, -11, 26, 14], [5, -4, 20, -21], [44, 15, 31, -17], [-43, 30, -4, -17], [-19, 3, -13, 24], [15, 8, 16, -23], [8, 20, -47, 14], [4, -36, 0, -7], [20, 23, 14, 6], [-12, -6, 14, -19], [-23, 19, -18, -15], [6, -5, 1, 11], [33, 16, 52, -6], [-33, -13, 5, 4], [-46, 6, -6, -11], [-29, -5, -42, 9], [18, -7, -25, 3], [-23, 8, -12, 8], [-18, 10, 15, 5], [-8, 14, 28, 8], [-16, 30, 23, 3], [27, -16, 25, -12], [-3, 19, -10, 27], [-27, 31, -8, 8], [-14, 4, 33, 4], [-36, 9, 21, 4], [28, -9, 27, 7], [-25, -21, -37, 16], [-51, 7, -24, -29], [-34, 10, -36, 8], [32, 1, 2, 19], [-8, 18, 13, 9], [46, -1, 59, 9], [55, -16, 10, -10], [29, 3, -2, 7], [29, -7, 0, -11], [-1, -18, 25, 3], [-12, -11, -38, 24], [8, -17, 16, -11], [6, -3, -33, 17], [7, -23, 7, 5], [-25, -6, -44, -7], [39, -12, 13, 3], [16, -25, -13, -4], [-21, 23, 7, -17], [-57, 10, -10, -18], [24, -17, -1, 2], [7, 8, -30, 9], [-35, -1, -28, -3], [-24, -21, -21, 9], [-2, 23, 30, 18], [-3, -17, 16, -10], [-12, -11, -10, -29], [25, -27, 38, 0], [-30, 8, 18, -2], [32, 6, 8, -8], [-54, 18, -7, -23], [-79, 9, 4, 8], [-7, 32, -29, 29], [-52, 3, 6, 0], [18, -27, -9, 26], [-7, 0, 22, -5], [-6, -6, -37, 5], [4, 5, 11, 18], [-35, -3, -37, 34], [-10, -17, -5, 4], [-31, -11, 13, -7], [-14, 5, -41, 1], [-31, 5, 1, 16], [-11, 7, -48, 27], [26, -18, 1, -35], [-61, -7, -62, 17], [15, 4, 41, -15], [-31, -11, -14, -1], [19, -20, 24, -10], [15, 12, -20, 30], [-57, 5, -33, -2], [15, -10, -42, -6], [-33, 7, -11, -15], [-18, 8, -17, 2], [-1, -10, 8, -9], [57, 1, 10, -2], [24, 5, 26, 22], [-41, -8, -11, 4], [-3, 12, -5, -3], [-12, 18, -11, -10], [30, 12, 23, -26]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6018_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6018_2_a_n();".
// 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_6018_2_a_n(:prec:=4)
    chi := MakeCharacter_6018_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_6018_2_a_n();".
// 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_6018_2_a_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6018_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-11, -26, -8, 3, 1]>,<7,R![-5, 15, -11, -1, 1]>],Snew);
    return Vf;
end function;