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