
// Make newform 4014.2.a.r in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4014_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_4014_2_a_r();".
// 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_4014_2_a_r();".
// 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 := [-4, 14, 9, -7, -2, 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], [1, -4, -1, 1, 0], [-2, 5, -3, -2, 1], [4, 7, -5, -2, 1]];
    Rf_basisdens := [1, 1, 1, 2, 2];
    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_4014_a();"
function MakeCharacter_4014_a()
    N := 4014;
    order := 1;
    char_gens := [893, 2233];
    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_4014_a_Hecke(Kf)
    return MakeCharacter_4014_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, 0, 0, 0, 0], [-1, 1, -1, 0, 0], [0, -1, 1, -1, 1], [-3, 1, 1, 0, -1], [1, -1, -1, 1, 0], [-1, -1, 0, 1, -1], [-1, 0, 1, 1, 0], [-2, -1, 0, 0, 2], [-1, -1, -2, 1, -2], [-1, 0, 1, 2, -2], [0, -1, 0, 4, -2], [-1, -2, 2, -3, 1], [0, 4, -1, -1, 2], [-4, -1, 0, -2, -1], [-5, 0, 1, -1, 2], [-5, 1, 4, 0, 3], [-5, 3, -2, -3, 0], [-3, 3, -1, 2, -4], [-2, 0, -1, -1, 3], [3, -1, -2, -2, 3], [-3, -1, 1, -4, 5], [-3, 0, 1, -6, 2], [0, 1, -1, 1, -3], [-3, 4, -1, -2, 2], [2, 1, -3, 4, 1], [0, 2, 0, 5, -4], [-5, 4, 1, 1, 0], [-3, -2, -5, 4, -2], [-2, 3, -1, -2, -1], [3, -8, 2, -1, 1], [-2, -6, -1, 1, -1], [-4, -4, 1, 1, -2], [0, 3, 3, -1, -6], [1, 2, -1, -2, -2], [-5, 2, -5, -3, 2], [3, 5, 1, -6, 3], [6, 0, -2, -2, 2], [-7, 6, 2, -3, -1], [-3, -3, 4, 1, 3], [-6, 3, -5, -3, -3], [-5, 3, -5, -2, -4], [7, -6, -1, 2, 4], [0, 5, -1, 1, -1], [8, -3, -7, 1, 4], [6, -5, 3, -1, 7], [-3, 0, 6, 3, 4], [-1, 0, 0, 0, 0], [-2, -1, 2, 12, -6], [-5, 0, 3, -4, 4], [4, 5, 0, -2, -3], [9, -4, -2, 6, 5], [-3, 0, 0, 9, -2], [1, 3, -6, 5, -3], [3, 1, 3, -8, 6], [-6, -3, 3, 5, 1], [11, -2, 0, 7, -1], [1, -4, -3, -4, -3], [-12, 0, 11, -1, -5], [0, 1, 2, -8, 4], [12, -2, -2, -1, -6], [9, 3, -5, 6, 2], [-18, 4, -3, 5, -5], [1, -5, 1, 0, 2], [11, 0, -6, -1, -3], [12, -5, -4, 1, -8], [-8, -3, -5, 7, -7], [-3, 1, -3, 8, -8], [2, 5, 7, -1, -3], [-2, 1, -3, -7, 7], [-6, -3, 9, -5, 3], [-2, -2, -2, 3, -8], [-2, 5, 2, 4, -8], [-5, 8, 2, -3, -3], [1, 1, 1, -1, 8], [-9, -2, 1, 12, -4], [-3, 9, 5, 0, -1], [0, 2, -1, -13, 4], [1, 1, 7, 0, 8], [-9, -1, 16, -1, -1], [1, -11, 9, -12, 10], [-6, -10, 8, -7, 4], [7, 1, 8, -5, 1], [-6, 7, 3, 2, 3], [4, 5, 5, -1, -7], [-11, -7, 2, 3, -9], [10, -14, -7, 3, 11], [-8, 0, 1, -1, -3], [17, 1, 0, -2, -1], [5, 1, 3, -4, 10], [-5, -7, 7, -3, 0], [2, 0, 0, 8, 1], [-11, 1, 6, -5, 5], [15, -8, -2, -3, 0], [34, -2, -2, -2, 3], [1, 7, -2, -3, 9], [3, -4, 3, -12, 9], [1, 4, -2, 3, -13], [5, 5, 9, -8, 4], [-6, -4, -2, 7, -6], [-3, 5, 1, -3, 0], [3, 1, 11, -8, 4], [-13, 4, -8, -1, -10], [-5, 2, 9, 3, 6], [4, 5, 0, -14, 6], [8, -4, 5, -11, 6], [10, -7, 5, 8, 3], [9, 9, 1, 4, -14], [-4, 0, -5, -9, 2], [-8, -7, 3, -5, 15], [16, -13, 4, 8, 10], [-7, 10, 5, 0, -7], [16, -3, -10, 0, 8], [15, -8, -8, -7, 11], [9, -2, -15, 0, 7], [-5, -11, 7, -5, -2], [22, -2, 2, 6, -7], [17, -10, -3, -5, 10], [-9, -2, -6, 1, -3], [-25, 4, 0, 3, -1], [-6, 1, -8, 0, 7], [15, -2, -1, 5, 0], [-7, 1, 3, 6, -12], [-21, 9, 3, 6, -4], [5, 3, -8, -7, -1], [8, -7, 8, -6, 8], [-1, 5, 0, 11, -15], [-6, -1, 13, -7, 3], [12, 3, -5, 15, -1], [12, -5, -7, 3, -1], [-2, -5, 0, 0, -8], [-11, -5, 2, 6, -5], [-16, 8, 7, 3, -13], [-2, 4, -9, -4, 5], [9, 2, -10, 6, -5], [5, 9, -9, -6, 5], [-18, 17, -13, -3, -1], [4, 7, 1, -3, -9], [-1, 1, 0, -1, 5], [-1, 12, -11, -2, 2], [-1, 1, -15, 14, -16], [4, 8, -6, 4, -5], [23, -3, -12, 1, -1], [-5, 7, -4, 22, -9], [-7, -2, -4, 9, 2], [-1, -1, 0, 13, -11], [-15, 0, 9, -16, 1], [-14, 5, 2, -2, -8], [28, -3, -1, 7, -5], [7, 4, -12, -9, 9], [7, 5, -15, -10, 13], [14, -10, -1, -3, 11], [5, 11, -4, 3, -7], [16, -6, 3, 10, -3], [-10, 2, 8, 3, -2], [1, 3, 0, -5, -11], [-18, -11, 0, 5, -4], [21, -5, -3, 8, 0], [-1, -11, 1, 4, -2], [24, -3, 17, -8, 11], [-10, 15, -2, 0, -10], [25, -3, -8, 5, 11], [13, -1, -9, 7, -6], [-25, 6, 3, -4, -1], [-2, 6, 12, 0, 9], [20, -16, 0, -4, 10], [-14, 11, -5, 6, -15], [-3, 1, 6, -21, 5], [-9, 6, -11, 0, -4], [-20, 14, -5, -1, -4], [-11, 16, -9, -8, -4], [-27, 12, -2, 8, -9], [8, -6, -5, 7, 6], [5, -11, 11, 6, 0], [-6, -9, 7, -19, 12], [31, -18, 5, 2, 11], [21, 14, -3, -4, 6], [24, -9, 5, 9, -1], [-18, 3, -6, -10, 4], [5, 1, 3, 18, -2], [-9, -6, -8, 5, -7], [-16, 13, 2, 0, 4], [5, -9, -4, -3, 13], [-11, -8, 7, 6, -11], [-2, 1, 1, 14, 3], [-4, -9, -2, 3, 6], [-8, 4, -9, 7, -7], [16, -9, -3, -3, -2], [19, -11, -1, 15, 6], [1, 10, -2, 3, 10], [32, -15, 4, 6, 15], [-16, 12, -16, -5, -12], [-18, 10, 11, 2, -5], [-6, -20, 6, -10, 14], [-14, 15, -19, 1, -9], [-12, 20, -3, 13, -5], [-42, -5, 8, -12, 1], [27, -9, 10, -7, 7], [14, -11, 0, -15, 14], [-9, 0, 15, 4, -10], [-19, -3, 11, 8, -14], [-29, -6, 5, -2, 8], [27, -3, 2, 9, -13], [5, -19, 8, -9, 5], [10, 6, -2, -14, -8], [-30, -4, 4, 0, 1], [2, 6, -14, 18, -24], [-16, -18, 7, 6, -11], [-9, -7, 4, 14, -11], [-36, 21, -10, 6, -14], [35, -10, -4, -9, 1], [-12, 11, -7, 13, -5], [-12, 0, 1, 11, -15], [-33, 8, -7, 6, -3], [6, -11, 12, 10, 2], [2, -14, 9, -7, 11], [-10, -5, -1, -3, 19], [24, -8, 6, -3, 0], [10, -7, 21, -2, 11], [-13, -4, 1, 6, 0], [-2, -16, 6, 4, 6], [-18, 10, 5, -7, 13], [-33, 9, -8, -5, -12], [5, -21, 11, 3, 2], [0, -9, 5, 5, -19], [-2, -1, 1, 0, -19], [-14, -3, -8, 16, -7], [11, 5, -11, 2, -15], [-1, 16, 2, 3, -23], [15, -23, -4, -5, 10], [-2, -15, 17, -9, 7], [-11, -1, 20, -9, 17], [-9, 0, 3, 2, -24], [-13, -5, 12, -7, 23], [-4, -13, 7, 9, -13], [-25, 8, -11, 8, -6], [25, -1, 3, 10, -10], [-11, -1, -3, -20, 14], [-9, 16, -11, 1, -4], [-2, 20, -2, -6, -12], [-17, -15, 13, -17, 14], [18, -19, 11, -1, 13], [-18, -9, 14, 6, -3], [3, 14, 2, -19, -3], [11, 8, 8, -5, 18], [-13, 15, -14, 19, -15], [-10, -10, -7, 11, -10], [-12, 10, 5, 6, -9], [-14, 25, -5, -6, -7], [-27, 19, -7, -6, -20], [-29, -5, 6, 11, 1], [-17, 19, -16, -8, 1], [17, -24, -7, -4, 22], [12, -5, -4, 16, 4], [16, -15, -6, -6, 6], [-29, 2, 4, 9, -9], [-12, 2, 2, 4, 4], [2, -9, -14, 16, -6], [17, 4, -17, 14, -2], [5, 6, -4, -9, -5], [-38, 19, -14, -18, -9], [-3, -5, -4, 5, -3], [-24, 14, -6, 5, -4], [1, 14, 8, -3, -11], [-28, -11, 5, -13, 7], [18, -11, 0, 6, 20], [20, -2, 7, -12, 19], [-12, 6, 4, -10, -5], [-2, 9, -6, -10, 9], [-35, -8, 0, 22, -7], [18, -29, -5, 2, 3], [-10, -5, 7, -5, 15], [32, 0, -1, -13, 9], [-7, -18, 11, -4, 0], [19, -10, 0, -13, 7], [-4, -5, 2, 0, 15], [-17, 11, -9, 2, -8], [-5, 14, 1, -9, 10], [31, -9, -2, 21, 12], [-6, -11, 14, 0, 14], [41, 3, -14, 7, 6], [-28, -14, 2, -16, 26], [-10, -3, -1, 16, -23], [-1, -12, 7, 20, -7], [-2, -3, -7, 1, -1], [-30, -5, 19, 7, -13], [-17, 24, -10, 13, -12], [-8, 6, -6, -10, -6], [6, 5, -4, 32, -17], [17, 12, -9, 26, -24], [-11, -3, 3, 4, 14], [-16, -14, 18, 0, -7], [-18, 16, -4, -21, -4], [37, 8, -15, 2, 6], [-19, 2, 1, 7, -8], [13, 5, -23, 6, 6], [-32, 18, 11, -8, -11], [-3, 11, -18, -7, 5], [-9, -9, -14, -3, 16], [2, 2, 5, -25, 10], [34, -8, 1, -23, 13], [-25, 4, 12, 0, -5], [-17, 18, -6, -28, -1], [6, -12, -15, 19, 2], [-19, -7, 0, -7, 12], [-22, -12, -7, 17, -9], [-11, 17, -10, 5, -25], [-5, -2, 15, -7, -8], [27, -17, 9, 18, -15], [-3, 19, 6, -1, 10], [-15, -1, 12, 2, -15], [-26, -10, 12, -5, 8], [3, -7, 25, -6, 4], [-20, 1, -7, -6, 17], [-15, 10, 0, -25, -1], [5, -18, 17, -19, 20], [-18, -6, -18, 14, -5], [-49, 5, 22, 7, -1], [9, 0, -4, 16, -19], [-25, -4, 7, 13, -4], [-13, -14, 5, 6, -7], [37, -21, 13, -1, 6], [-12, 13, 8, -6, -20], [49, -6, -1, 6, 14], [7, -7, -10, 3, -19], [7, -20, 18, -11, 7], [8, -4, -5, 1, -27], [-3, 4, -11, -1, -2], [3, -4, 21, -1, 28], [11, -12, -7, 6, -24], [39, 10, -10, 17, -28], [38, -5, -1, -3, -9], [-16, 20, -29, 7, -13], [10, -2, -4, -4, 5], [-33, 6, 1, -6, 18], [10, 14, -8, -16, 26], [-11, 0, 21, -14, 4], [24, -15, -2, 2, 18], [-6, 5, -11, -9, -9], [1, 9, -9, -3, 10], [12, -19, 1, -15, -3], [-13, -2, 28, -9, 28], [-1, 1, -10, -13, 3], [-59, 13, -12, -3, -1], [-39, 14, 1, -6, 6], [10, -5, 3, 1, 11], [-35, 31, -17, -7, 0], [-26, -16, 6, -6, 0], [-23, 23, -25, 0, -6], [-48, 0, 4, -14, -3], [13, -14, -16, 1, 9], [-9, -11, 16, 7, 3], [-23, -12, -7, 12, -8], [5, -11, -11, 4, 6], [33, 17, 5, -16, 2], [9, 13, 2, -26, 9], [15, -19, -9, -1, 16], [12, 5, -15, -21, 3], [18, -6, -22, -13, 10], [-11, -19, 26, -3, -3], [-29, -13, 7, -8, -17], [-29, 24, -13, -20, 6], [30, 7, -17, 22, -19], [41, 14, -6, 9, -19], [24, -20, 15, 15, -6], [-1, 19, 10, -3, -7], [10, 24, 12, -18, 14], [-33, 7, 8, 1, -17], [13, -9, -16, 17, -6], [-45, -14, 2, 1, -5], [15, 19, -8, -5, 4], [1, 1, 11, -12, 14], [10, 11, 2, -4, 22], [13, -19, 18, -5, 7], [14, -11, 28, -9, 26], [31, -2, 19, -12, 10], [-40, 5, 8, -12, 6], [37, -11, -16, 7, 3], [-11, 4, -9, 26, -16], [5, 5, 5, 12, 13], [-30, 2, 11, -9, 3], [22, 1, -6, -10, 24], [28, -15, -5, -28, 19], [8, -5, -3, -11, 6], [26, 9, 6, -6, -10], [22, -13, 5, 10, -17], [-15, -17, -2, -13, 25], [15, -1, -25, 18, -12], [-10, -31, 10, 7, -6], [-13, 4, -17, -10, 18], [11, 2, -13, 0, -32], [13, 11, -10, -5, -10], [57, 3, -4, 13, -14], [1, -30, -7, 2, 18], [-20, -17, -2, -14, 10], [-20, -7, 12, -6, -5], [16, 18, 2, 8, 18], [-18, 4, -6, 10, -2], [-46, 5, 16, -11, -8], [1, 2, -1, -10, 17], [51, -6, 15, -8, 8], [31, -1, 5, 25, -20], [-31, -7, 4, 21, -4], [47, -1, -19, 14, -8], [-26, 34, 9, -1, -9], [-11, -2, 16, -13, 19], [-7, -11, -8, 5, 15], [-4, -5, 19, 7, -26], [-40, -3, 10, 4, 1], [-34, 1, 13, -31, -3], [-19, -4, 2, 37, -5], [-8, 11, -25, -5, 13], [-19, -1, 24, 5, -2], [-18, -4, 11, 4, 11], [0, 1, -15, -15, 18], [8, -13, 6, 18, -10], [10, 0, 0, -9, 26], [-15, -27, 9, -4, -6], [39, -19, -1, 1, -10], [6, 3, -41, 18, -19], [2, 4, -6, 50, -22], [-27, 20, -21, -18, 4], [-2, 8, 8, -8, -15], [-11, 27, -9, 25, -22], [46, 0, -12, -2, -4], [-56, -2, 13, -3, -14], [55, 3, 9, -8, 2], [3, 22, 5, -10, -14], [13, 10, 3, 19, -12], [50, 4, 2, 3, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4014_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4014_2_a_r();".
// 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_4014_2_a_r(:prec:=5)
    chi := MakeCharacter_4014_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_4014_2_a_r();".
// 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_4014_2_a_r( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4014_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-20, -54, -41, -4, 5, 1]>,<7,R![80, 72, -15, -18, 1, 1]>,<11,R![67, -38, -82, 6, 9, 1]>],Snew);
    return Vf;
end function;