
// Make newform 6014.2.a.d in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6014_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_6014_2_a_d();".
// 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_6014_2_a_d();".
// 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, 5, -2, -8, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [-4, 1, 8, 0, -1], [6, 4, -15, -1, 2], [11, 9, -23, -2, 3]];
    Rf_basisdens := [1, 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_6014_a();"
function MakeCharacter_6014_a()
    N := 6014;
    order := 1;
    char_gens := [1553, 2915];
    v := [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_6014_a_Hecke(Kf)
    return MakeCharacter_6014_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, 0], [0, 1, 0, 0, 0], [-1, 0, 0, 0, -1], [0, 0, 0, 0, 0], [1, 0, -1, -1, 1], [0, 2, 0, -2, 0], [3, 0, 0, 1, 1], [-2, 1, 1, -1, 0], [0, 1, -2, 1, 0], [2, 2, 2, 0, -2], [-1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 2, -2, 0, -2], [-1, 0, 1, 1, -1], [8, -1, 1, -2, 0], [6, -3, 0, 0, 0], [4, -3, -1, 1, -2], [-3, -1, 1, 1, 1], [1, 5, 1, -1, 1], [-8, 2, 0, -2, 0], [4, 4, -2, -4, 2], [4, 0, 0, -4, 0], [8, -2, -2, -2, 2], [4, 2, 2, 2, 2], [-1, 0, 0, 0, 0], [4, 0, -4, 0, -2], [2, -1, 1, 0, 2], [3, 3, -1, -3, -1], [2, 0, -4, -4, 4], [6, 1, -1, 0, 4], [6, 2, 2, -2, -2], [3, -2, 2, -2, 1], [-5, 2, 6, -3, 1], [-2, -4, 0, 4, 0], [7, -3, -5, 3, -3], [2, 2, 0, 0, -2], [4, -7, -1, 1, 4], [12, 4, -2, -2, 4], [0, 2, -6, 0, 0], [2, 1, -3, -1, 6], [0, -4, 2, 0, -2], [2, 0, -2, -4, 6], [8, 2, 0, 2, 0], [0, 0, 4, -2, -2], [1, -9, -3, 1, 1], [-1, -4, 6, 3, -1], [5, 0, 6, 2, -1], [4, -5, -2, 3, 0], [2, -4, -2, 8, 2], [1, -1, 1, -3, 9], [6, 6, 4, 0, 4], [-8, 3, 2, 7, -4], [8, -6, -2, 0, -2], [-6, -10, 0, 4, -4], [4, 2, 6, -2, -6], [-6, 5, 0, -11, 6], [-8, -5, 0, 8, -2], [6, -8, 0, 2, -2], [4, 2, -4, -10, 4], [-4, -4, 4, 0, -2], [4, 0, -4, 0, 4], [-6, -2, -10, 0, 4], [-4, -2, 0, 0, -8], [8, 2, -4, -6, 8], [2, 2, 4, -6, -4], [-2, 3, -1, 5, -6], [4, -2, 6, 2, -2], [-8, 3, -2, -9, 2], [-2, -6, -8, 6, 4], [-1, 9, -1, -1, -3], [-2, -8, -6, -2, 4], [-10, 2, 0, -8, -2], [5, 4, 2, 1, -3], [1, -2, -4, 0, 5], [-2, 2, 10, 6, -2], [-2, 0, -4, -2, -2], [3, -7, 3, -5, -5], [-2, 6, 8, 6, -4], [-6, -6, -6, 0, 0], [-2, 3, 4, -1, -4], [-2, 4, 6, 0, -2], [2, 8, 0, -4, 8], [3, -12, -7, 8, -1], [5, -4, 0, 15, -5], [2, -10, 0, 10, -2], [-7, -11, -7, 3, 1], [0, -2, 4, 8, -6], [-2, -2, -6, -8, 12], [-7, -5, 1, -3, 5], [-6, 4, 8, 12, -10], [-2, -8, -8, 2, 6], [-2, 3, 5, -4, 6], [-18, -8, 0, 2, -6], [13, -3, 3, 1, -5], [0, -4, -2, 6, -2], [1, 4, 3, 4, -3], [3, 2, 9, 5, -7], [-1, -10, -5, 4, 5], [-8, -10, -8, 2, 6], [1, 0, -4, -4, 1], [10, 2, 0, 0, -6], [13, 3, 1, 1, 5], [-21, 3, -5, -3, 3], [-12, 2, 0, -4, -6], [-8, 3, 4, 0, -4], [-2, 4, -4, -10, 4], [0, 2, 12, -2, -2], [8, 4, 0, -10, 2], [-20, 12, 4, -10, 8], [4, -2, -4, -12, 6], [9, 14, 3, -6, 5], [11, 4, 7, 7, -3], [-6, -5, 1, 0, -4], [2, -12, 2, 6, 0], [-2, -14, 4, 0, 2], [8, 10, 4, 0, -2], [-5, 6, -9, 7, 3], [10, 8, -2, -10, 2], [-21, 0, 0, 4, 3], [-3, -2, -6, -6, -1], [14, -2, 8, 12, 4], [4, -4, -12, -18, 6], [5, -10, -1, 19, 3], [-10, -12, 2, 4, -10], [2, 0, 0, -16, 2], [-8, 6, -4, -6, 6], [-4, -18, -8, 6, 0], [9, 4, -2, 1, -7], [27, 4, 5, -4, -1], [4, 6, 12, 2, -2], [-16, -8, 0, 16, -2], [20, 2, 2, 10, -4], [0, -7, 3, -6, 0], [10, 8, -2, -6, 2], [-15, -4, 0, -1, -9], [0, -10, -10, -4, -2], [-11, 12, 5, -3, 3], [-5, 3, -7, -13, 1], [0, -2, -10, 4, 0], [-18, -2, -12, -6, 8], [6, 6, 10, 0, -14], [4, 0, -2, 4, 8], [-4, -8, -8, 2, 12], [14, 12, -6, -16, 8], [14, 5, 12, 4, 4], [-2, -4, 8, 10, -2], [-5, 5, -9, -13, 25], [-12, 0, 4, 10, -6], [-18, 2, 6, 6, -4], [2, 18, -2, -10, -6], [-6, -8, -10, 2, 8], [-12, -2, -2, 2, -6], [-14, 6, 0, 2, -12], [-8, 4, 4, -6, 4], [6, 11, 3, 9, 8], [-4, -3, -14, -7, -4], [14, 4, 8, 6, 6], [-2, -2, -6, 8, -4], [0, 13, 3, -2, 2], [-20, 6, 4, 10, -12], [12, 10, 12, 2, -2], [-2, 2, 2, 4, -4], [-16, 6, -2, -6, 8], [14, 4, -10, -26, 14], [-26, 10, 4, 2, 4], [6, 1, -4, 9, -14], [12, 11, -10, -21, 12], [-10, 4, -4, 10, 4], [-8, -2, -8, -8, -2], [-14, 1, 4, 16, -8], [18, -5, 4, 0, -2], [22, 0, 8, 8, -10], [-7, 2, 11, 14, -3], [-12, -4, 8, 6, -10], [14, -12, -4, 2, -2], [-10, -2, -4, 8, 8], [16, -4, 0, 6, 8], [0, 0, 8, 16, -10], [10, 5, -13, -20, 10], [6, 11, -8, 0, 16], [18, -2, -8, -6, 14], [-25, -9, 1, -1, -3], [1, 15, 5, 1, 3], [-2, 14, 14, 4, -8], [25, -6, 7, 6, 5], [-12, 0, 4, 18, -4], [-10, 12, 6, -6, 4], [-13, -16, 6, 18, -11], [16, -6, 0, 16, -14], [12, 8, -2, -8, 8], [12, 6, 8, 4, -14], [-2, 0, -12, 6, 10], [6, -2, -10, 12, 8], [-12, 16, 8, -8, 12], [27, -13, -5, 13, -1], [-14, -5, 4, 7, -12], [-16, 13, 6, 9, 2], [8, 10, 20, 0, -2], [9, 6, 5, 0, 15], [4, -10, -8, 0, 16], [4, 6, 2, 2, -14], [18, -1, 0, -5, 10], [10, 14, -8, -14, 8], [-8, 12, 12, -10, 2], [0, -14, 4, 10, 8], [-5, 2, 1, -7, 1], [0, -2, 4, 18, -8], [1, 9, -5, -19, 7], [-16, -4, 6, -2, -2], [9, -4, 2, 26, -5], [-6, 10, -2, -14, 16], [-6, 4, -8, -20, 26], [-2, -16, -4, 6, -18], [15, 14, -2, -6, 9], [18, -2, -2, -18, 14], [2, -32, -8, 10, 8], [-27, -8, 7, 0, -7], [-1, -6, 3, 8, -7], [-10, -6, -10, 14, 2], [-14, -5, 3, -7, -10], [-26, 4, -6, -14, -10], [18, 6, 2, 4, 14], [0, -16, 0, 16, 6], [-15, -10, 7, 6, 5], [0, 1, 15, -11, 2], [-32, 14, 6, -10, -4], [-24, -7, -1, 6, -6], [8, 4, -8, -4, 12], [18, -2, 2, -10, 2], [-6, 4, -16, -20, 18], [26, -1, 0, 0, 0], [-18, 0, 2, 0, -6], [17, -8, -9, -16, 13], [-2, -10, 6, 16, -24], [-14, -16, 12, 12, 0], [8, 12, 2, -4, 12], [-6, -34, -4, 10, -8], [21, -1, 13, 21, -1], [9, -8, -5, 15, -15], [3, 2, 8, -13, -13], [23, -14, -2, 22, -19], [-2, 2, 8, -10, 8], [12, -4, 10, 14, 4], [3, 4, 3, 19, 5], [-18, -2, -8, 2, -4], [-26, 28, 8, 4, -6], [-2, -1, 8, 15, -26], [-16, 4, -14, -8, 2], [9, -19, 3, 21, -17], [-12, -6, 8, 2, -12], [12, -1, 13, 3, -16], [-2, -17, -3, 12, -4], [2, -3, 0, 17, 10], [-14, 2, -16, -4, 16], [-10, 6, -4, -14, 16], [-4, 7, -3, -1, -2], [-9, -14, -8, 0, -1], [-4, 17, 12, -24, 0], [36, 10, 20, 6, -6], [-20, 3, 9, -2, -2], [-28, 12, -2, 6, -4], [-6, -7, 20, 20, -10], [14, -14, -12, 22, -6], [0, -18, -14, -12, 10], [22, 14, -2, 2, -4], [24, 0, -12, 2, -4], [20, -15, 3, 13, 16], [-1, 6, -9, -12, 13], [-9, 16, 10, -14, -7], [-33, 1, -5, -17, -11], [-19, 7, -7, -3, -21], [7, -21, -3, -9, 1], [-1, 2, -14, -11, 17], [-26, -10, -6, 10, 2], [26, -4, -4, -12, 12], [0, 6, 6, -4, -16], [10, 17, -11, -1, -8], [29, -4, 5, 9, -13], [-5, -4, -8, -7, -11], [0, -11, 0, 8, -12], [-2, -22, -8, 16, -2], [16, -5, 13, 26, -16], [25, 0, 3, 8, 13], [6, 10, 10, 12, -32], [4, 10, -4, -2, -12], [-3, 2, -4, 1, -7], [2, -18, 2, -4, 0], [-14, -16, 6, 18, -14], [14, -15, -13, 8, 6], [-1, 12, -8, -31, 9], [-7, -18, 0, -8, 5], [6, -20, -18, 4, -6], [-12, 16, 10, -2, 6], [4, -20, -14, 14, 0], [20, -6, -2, 12, -16], [-17, -30, 9, 5, -23], [16, 6, -8, -6, 12], [8, -6, 10, 2, 6], [-22, 14, -2, -18, 12], [-15, -3, 23, 17, -1], [-47, -2, 1, 4, -5], [-4, -12, 18, 26, -24], [18, -4, -4, 26, 6], [-13, 23, -1, -11, 3], [26, 16, 8, -10, -4], [-20, -30, 6, 6, -10], [-18, 6, -10, -28, 8], [-2, 18, 6, -8, 8], [30, -10, -4, -32, 10], [-22, -18, -12, -10, 0], [-18, -27, 8, 5, -6], [-30, -9, 8, -4, -12], [-4, -7, -21, -14, 6], [42, -6, 4, 6, -8], [-1, -4, -3, 8, 19], [-23, 2, -6, 7, -13], [-14, -7, 8, -16, -10], [18, -2, 10, 6, -6], [0, -10, 16, 20, -22], [14, 9, -8, -3, 24], [38, -11, -4, 4, -10], [2, 18, -4, -6, 20], [-21, 0, 12, -16, -5], [34, -9, -15, 16, -14], [-6, 8, 2, -12, -16], [-14, -2, -16, -20, 8], [9, -6, -18, -22, 15], [3, -13, -13, 13, -1], [-8, -12, 2, 30, -12], [-16, -3, -16, -16, 26], [-9, 21, -1, 3, 1], [-10, 0, -12, 6, -12], [27, -4, 9, 24, -17], [-29, 16, 5, 1, -1], [12, -13, -3, -9, 26], [28, 20, 14, -6, 0], [26, -6, 12, 6, -2], [-14, 12, 2, 8, 12], [-16, 36, 16, -10, -2], [18, -1, 12, 19, -22], [10, -19, -24, -12, 4], [10, -4, 2, 0, 24], [12, 4, 8, 8, -16], [34, 8, -20, -6, 6], [8, -5, -11, 7, 12], [24, 14, 26, 10, -8], [28, 1, -17, -31, 12], [-36, 8, 0, -14, -2], [14, -12, 4, 10, -18], [-11, -13, 13, 13, -29], [43, 4, 5, -7, 3], [14, 12, -14, 10, -8], [0, -2, -14, 4, -18], [5, -14, 12, -3, -19], [16, 0, 10, 16, 10], [36, -2, 8, 6, -10], [22, 6, -2, -14, 6], [34, 2, -8, -16, 0], [32, 28, -2, -12, -6], [8, 0, -24, -28, 8], [26, -20, -12, 2, -4], [8, -16, -28, 0, 2], [16, 20, -2, -6, 8], [-25, 2, -14, 18, 9], [21, -19, -19, 11, -7], [0, 16, 12, -20, 2], [20, -9, 1, 19, -8], [11, -6, 0, 3, 19], [6, -16, 0, -12, -4], [-28, 24, 8, 0, 8], [23, 12, 18, -14, -15], [-4, 18, 14, 4, -4], [8, -12, -10, 10, 18], [18, 28, 18, -2, -2], [23, 25, 7, 3, 23], [-52, -6, -14, 10, 6], [-6, 18, 8, 0, 10], [20, 2, 8, 2, -10], [-28, 0, -14, -20, 26], [40, -12, -12, 16, -2], [24, -15, -8, 4, 10], [8, -2, -8, 0, -2], [1, -4, 26, 13, -19], [-9, -20, -12, 9, 1], [-4, 10, 12, 2, 2], [-24, 10, 8, 30, -16], [-66, 8, 8, 6, -2], [-8, -12, -16, 4, 24], [9, 14, -11, -7, 9], [18, -6, 18, 26, -18], [8, -22, -20, 18, 2], [14, 10, 12, -22, 2], [-2, -5, -9, -27, 20], [-6, 24, 10, 0, 18], [20, -4, 8, 28, -12], [-29, -16, 7, 18, -19], [-12, 8, 20, 20, 0], [-12, -14, 8, 18, -34], [-12, 32, 4, -26, -14], [0, 23, -4, -24, -2], [21, 10, 7, -21, -1], [52, 6, -2, 0, -10], [-30, -12, -4, 4, 14], [29, -12, -7, 18, 15], [31, -31, -5, 15, 7], [-8, 2, -8, -6, 32], [28, -16, -18, 26, -2], [24, -26, -8, -10, -2], [24, -18, 10, 0, 10], [15, 3, -15, -9, 13], [38, -5, -8, 15, -8], [18, 26, 6, -6, 0], [18, 4, 0, -8, 16], [28, -12, 8, -16, -2], [-8, -12, 20, 30, -34], [-26, -4, 6, 16, -28], [-26, 20, -6, -2, 2], [-48, 6, -10, -4, -8], [48, 2, 16, 14, -10], [-20, 12, 22, -4, -8], [41, -5, -15, 1, -7], [8, 34, 20, 0, 8], [-6, -20, -12, -6, -14], [55, 7, -1, -7, -1], [-48, 8, 0, -6, -18], [-11, -33, 1, 25, -11], [24, 8, 0, 10, 20], [32, -15, -2, -3, 18], [-27, 26, 5, -19, 5], [62, -6, 0, 16, -6]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6014_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6014_2_a_d();".
// 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_6014_2_a_d(:prec:=5)
    chi := MakeCharacter_6014_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_6014_2_a_d();".
// 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_6014_2_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6014_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![2, 5, -2, -8, 0, 1]>],Snew);
    return Vf;
end function;