
// Make newform 6018.2.a.o in Magma, downloaded from the LMFDB on 18 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_o();".
// 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_o();".
// 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 := [1, 1, -3, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-1, -1, 1, 0], [1, -2, -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], [-1, 1, 0, 1], [0, -1, 1, -1], [-2, 0, -1, 0], [-1, 0, 0, -3], [1, 0, 0, 0], [-3, -2, -2, 2], [-5, 0, 1, 3], [1, -3, -5, 1], [-5, 5, 2, -1], [-3, -7, 0, 4], [-1, 2, -1, -1], [-3, 0, -3, -1], [0, 0, -1, -1], [-1, 5, -1, -2], [1, 0, 0, 0], [-2, 2, 3, 1], [-4, 3, 4, -1], [2, 2, 5, 0], [-3, -2, -1, 0], [7, 2, 0, -4], [-3, -5, 6, 6], [-5, 1, 4, 7], [1, 6, -2, -11], [-12, 3, 3, 5], [7, -3, -5, -1], [7, -1, 1, -8], [2, -2, 0, -9], [-3, 7, 6, -6], [1, -3, -11, 4], [-4, 8, 2, -2], [-8, -2, -5, 9], [6, -10, -3, 4], [-6, 3, 1, 8], [3, 2, 6, -7], [-7, -8, 2, 6], [-5, 8, -2, -9], [-4, 2, -6, -7], [-1, 1, -1, 5], [-8, -3, -3, 10], [-3, -1, -2, 1], [-10, 15, 5, -1], [10, 1, 5, -2], [-3, -8, -3, 7], [7, 4, 0, 0], [2, 2, -3, 6], [-8, -1, 13, -4], [4, 2, -5, 3], [9, -4, -12, 3], [3, -2, 8, 2], [-1, 5, 12, -6], [9, 1, 7, 0], [-5, -4, -7, 5], [-3, -1, 12, -7], [-4, -4, 0, 18], [-3, -16, 4, 6], [-7, -1, -5, 8], [-4, -11, 2, 16], [-1, 14, -2, 0], [2, 9, -2, -6], [1, 0, -6, -7], [23, -8, -2, -1], [13, 2, -13, -7], [-9, -16, 6, 2], [-11, 3, -1, 8], [0, -3, -1, -7], [-6, -4, -2, -9], [-3, -4, -4, 1], [1, 11, -3, -6], [-11, -23, -7, 19], [19, 1, -1, -5], [-7, -8, 4, -1], [5, 3, 3, -17], [8, -9, -13, 10], [16, 9, -1, 3], [16, 1, -6, -15], [24, 6, -4, 3], [-3, 3, 8, -15], [-9, -18, -11, 14], [-8, -20, -3, 14], [-5, 10, -11, -19], [7, -5, -4, 7], [12, 1, -6, -13], [5, 1, 0, 14], [-5, 20, 8, -12], [0, 18, -1, -15], [-18, 5, 1, 1], [8, 2, -5, -14], [9, -19, -3, 11], [-7, 12, 21, -9], [5, 0, -18, -4], [18, -16, -8, 6], [0, -6, 9, -22], [5, 4, 2, -8], [-11, 1, 14, -18], [-19, -19, -13, 30], [-4, -10, -2, 4], [-15, 4, 15, -1], [4, 0, -21, -14], [18, 13, -9, -9], [-1, -8, 3, -6], [2, 11, -4, -11], [-16, 10, 11, -8], [-18, -11, 4, 1], [-4, -3, 2, 10], [-7, 2, 11, 0], [0, 2, -6, 13], [-26, -5, 9, 0], [16, -9, -9, 14], [0, 23, 12, -13], [5, -11, -16, 1], [6, -6, 12, 21], [-1, 1, -5, 14], [19, -1, -12, 13], [-12, 4, -4, 6], [13, -11, -1, 1], [6, -9, 10, -4], [7, 10, 15, -14], [26, -16, -12, -4], [3, -7, -9, 10], [10, 2, -12, -19], [-10, -7, -11, 33], [4, -4, -10, 10], [2, 9, 2, -6], [7, -9, -23, 14], [17, 19, 0, -6], [7, -8, 3, -2], [-3, 2, 7, -16], [-7, 9, -7, -20], [-27, 21, 3, -7], [15, -1, 12, -2], [13, -3, 1, 22], [14, 11, 17, -25], [16, 11, -1, -33], [13, 0, -16, -8], [5, 6, 17, -13], [-25, 24, 8, 6], [0, -11, 9, -14], [-5, -17, 14, -11], [-1, -24, -6, 17], [-12, 11, 11, -3], [-24, 16, 19, 7], [8, -4, -8, -12], [-4, -16, 2, 27], [15, 19, 16, -25], [34, 2, -8, -15], [-20, -24, -1, 19], [13, -6, -3, -13], [17, -12, -9, 1], [-15, -5, 22, 3], [4, 17, -8, -8], [-38, 24, 15, 11], [7, -2, -26, 2], [19, -19, -12, -10], [-13, -16, 10, 27], [16, 9, -8, -15], [2, -16, 6, -3], [9, -9, 0, -16], [-10, -2, 6, -9], [0, -2, -12, 19], [-46, 9, 15, 0], [17, -13, -11, -5], [-3, -27, -9, 9], [-24, 10, 11, 19], [-6, 4, -7, -18], [-16, -19, 1, 11], [4, 14, 16, -7], [8, -13, -13, 2], [20, -9, 1, -26], [-19, -3, -7, 25], [2, 8, -11, 20], [-14, 19, 13, 3], [-8, 6, 20, -18], [4, 9, 5, 15], [-25, -11, -1, 34], [-12, -3, -14, 28], [-21, 10, 22, 1], [-22, 12, 3, 12], [-5, -22, 9, 26], [-10, 19, -10, -1], [20, 35, -7, -18], [-17, 4, 8, -3], [28, 19, 8, -40], [35, -27, -26, 3], [-17, 31, 8, -11], [2, 16, -20, -7], [-35, 20, 14, 9], [-6, -8, -21, -2], [18, -15, -8, 9], [-6, 6, 0, 26], [4, 4, 9, -4], [-6, 9, -12, -18], [-5, -3, -11, 24], [-19, 1, 17, 15], [11, -1, -1, 19], [28, -9, 2, -1], [-12, 14, 0, 3], [21, 9, -22, -17], [23, 15, 21, -31], [-20, 15, 6, 7], [30, -25, -9, 9], [-14, -5, 8, 11], [14, -26, -4, 9], [13, 6, 13, -22], [15, -13, -10, -18], [-10, 24, 28, -12], [-47, -11, 1, 12], [5, 22, 19, -37], [19, 8, -32, 5], [-16, 8, 0, 0], [-44, 12, 19, 8], [45, -23, -23, 1], [-23, 21, -9, -5], [-21, 18, -4, -5], [13, 14, -6, -20], [-25, -6, 3, 14], [23, 22, 5, -26], [-6, -16, 2, 35], [10, -22, -4, -7], [-15, -23, -2, 19], [3, -14, -3, -3], [-20, 15, 35, 0], [-39, -22, 4, 3], [-24, 11, 5, 12], [9, 6, -14, 13], [-1, -6, 3, -14], [8, -31, 5, 8], [1, 14, -15, 24], [-22, -24, 1, 16], [-7, -8, -4, 42], [1, 8, 17, 22], [14, 26, -6, -21], [-10, 3, 1, -4], [-6, 4, -20, 17], [33, -4, -3, -37], [-7, 1, 17, -14], [17, 16, 10, -24], [-16, 14, 5, 18], [-35, 17, 12, 11], [-1, 3, 31, 4], [27, 25, 12, -31], [-5, -28, 6, 18], [-26, -14, 0, 34], [3, -32, 5, 5], [25, -12, -15, 2], [19, -3, 16, -8], [-1, 7, -18, 2], [13, -1, 18, 5], [26, 14, -7, -9], [7, 15, 2, -21], [-17, 16, -15, 6], [-7, -5, 2, 19], [-4, 4, 36, -8], [-29, 3, 27, 9], [-37, 5, 20, -10], [-9, 2, -13, 5], [5, 3, -11, -14], [-27, 21, 15, -23], [17, 9, -16, 5], [5, 13, -14, 17], [15, 12, -21, -11], [30, -3, 9, 5], [-9, -38, 11, 13], [3, 14, -17, 9], [-31, -4, 0, -2], [-35, 1, 18, 9], [-20, -10, -6, 4], [-8, -34, 20, 9], [-34, 9, -10, -14], [14, 21, -7, -3], [8, 25, 16, -37], [-12, 8, 22, -7], [35, -4, -8, -19], [8, -10, -24, -15], [11, -7, -25, -23], [18, -31, -3, -14], [-31, 16, -6, 10], [29, -37, -2, 3], [14, -9, -6, 30], [-12, 4, 17, -5], [-17, -10, 20, 20], [-20, -23, -3, 3], [15, -14, 7, -5], [-9, -4, 0, -37], [48, -22, -28, 3], [11, 33, -25, -32], [8, -20, 5, -30], [3, 0, -26, -30], [-26, -9, -14, 23], [-20, -15, -10, 2], [17, -46, -18, 20], [0, -23, 17, 48], [-45, -6, -1, -1], [-4, 45, 6, -18], [-25, 29, 19, 10], [19, -24, -11, 10], [2, -25, -8, 3], [-10, -39, 2, 19], [14, -57, -3, 22], [9, 31, 5, -6], [28, -16, -18, -5], [16, -13, -34, 21], [16, -32, -36, 15], [10, -24, -11, 31], [35, -5, -7, 17], [-9, -1, 0, 2], [-16, 18, 32, -9], [10, 6, -22, -40], [-7, 15, 30, -31], [11, 15, -6, -4], [-4, 47, 4, -29], [-44, 20, 6, 41], [-36, -12, -15, 1], [23, 24, 29, -48], [-13, 19, -19, -26], [-20, -2, -13, 60], [15, -23, 5, 16], [10, -23, 11, -8], [-20, 38, 6, -25], [48, 27, -3, -13], [-55, 32, 21, 26], [8, 0, 7, -52], [-26, -43, -15, 50], [20, -16, -32, 13], [30, -8, -14, -41], [-18, 8, 28, 29], [-3, -20, -25, 4], [-56, 14, 3, -10], [-12, -13, 14, -11], [30, 14, -20, 5], [-45, 36, 9, -1], [16, -4, 7, 19], [-28, 4, 30, 28], [14, 21, -5, -41], [17, 8, 30, -22], [29, 14, 1, -23], [8, 3, 25, 6], [-27, 30, 13, 3], [11, 12, 32, 0], [-1, 4, 0, -26], [19, -28, 11, 32], [-20, 26, -3, 5], [-39, 20, 11, 40], [11, 7, -11, 18], [-7, -3, -18, 3], [59, -17, -27, -10], [-58, -22, -7, 25], [-11, -1, 17, 40], [-27, 20, -20, -25], [16, 27, 5, -26], [-14, 0, -7, 40], [-4, 3, 29, -6], [27, -7, -20, -32], [9, -5, -34, 13], [-45, 2, 14, -6], [-8, 26, -3, 1], [-40, 37, 25, 4], [-57, 49, 24, 2], [17, -9, 6, -21], [-15, -32, 4, 42], [-19, 47, 15, -27], [-40, 4, -2, 28], [-1, -11, 7, 7], [-8, -38, -6, 51], [3, 21, 10, -2], [-13, 20, 25, -4], [7, 22, 20, -27], [-35, 0, 41, -23], [17, 15, -18, 1], [-14, 2, -5, 1], [-31, 13, 22, -6], [-26, -16, 6, 56], [6, -13, -34, -16], [-55, 13, 31, 25], [-21, -21, 28, 47], [23, -36, -4, 20], [35, -23, 6, 2], [-39, -19, -2, 16], [-48, -1, 23, 9], [50, 28, -9, -16], [-34, -7, -4, 6], [13, 15, 6, -9], [-10, 11, -24, -5], [37, -29, -13, -30], [80, 3, 7, -13], [-23, 14, -7, 13], [20, -9, 12, -1], [-51, 32, 24, 2], [5, -10, 25, 19], [-47, -25, -11, 44], [11, 37, -8, -60], [43, 37, 18, -29], [-26, 18, -25, -16], [1, 22, -17, -30], [-50, 35, 28, -2], [-7, 38, 9, 2], [36, -10, -18, -2], [44, -8, -18, 4], [-17, -13, 5, -17], [25, -18, 1, 18], [-34, -9, 7, -13], [-52, -12, 5, 8], [-3, -12, 5, -19], [-61, -3, 1, 52], [33, 29, 5, -67], [-31, -14, 15, -15], [8, 14, -9, -65], [-25, 26, 1, -19], [16, 5, -26, 17], [19, 3, -14, 17], [-26, -50, -1, 35], [3, 33, -14, -38], [-5, 61, 5, -33], [-9, 17, -24, 16], [-8, 3, 29, 19], [-17, 53, 8, -28], [-13, 8, 30, -36], [21, 22, -10, -48], [30, 26, -17, 5], [-65, 6, 2, -12], [-24, 7, 40, -5], [-9, 46, 52, -31], [21, 17, 19, -22], [-49, 16, 19, -18], [-26, -24, 37, -4], [36, 6, 18, -59], [26, -9, -17, -35], [-3, -42, 2, 41], [-9, 30, 4, -19]];
    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_o();".
// 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_o(: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_o();".
// 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_o( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6018_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![1, -6, -8, 1, 1]>,<7,R![-19, -31, -13, 1, 1]>],Snew);
    return Vf;
end function;