
// Make newform 8019.2.a.b in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8019_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_8019_2_a_b();".
// 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_8019_2_a_b();".
// 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, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, 0, 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_8019_a();"
function MakeCharacter_8019_a()
    N := 8019;
    order := 1;
    char_gens := [5105, 2917];
    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_8019_a_Hecke(Kf)
    return MakeCharacter_8019_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 := [[0, 1, 0], [0, 0, 0], [1, -1, 2], [-1, 0, 1], [1, 0, 0], [-3, -3, 2], [-4, -1, 0], [4, -2, -1], [0, 0, -2], [-2, 4, 2], [1, 2, 2], [0, 2, -4], [-1, -1, -3], [-1, 6, -4], [-5, 2, 1], [7, 0, -2], [-3, -2, 2], [-2, -2, 2], [-1, 1, -8], [-7, 1, -6], [1, 7, -2], [-7, 1, -5], [-1, 4, -9], [-6, 6, -9], [9, -2, -4], [-2, -2, -6], [-8, -1, 4], [6, -3, 3], [-4, 6, -2], [5, -8, 3], [-2, -6, 5], [5, 3, -4], [-2, 11, -2], [-13, 1, -4], [15, 5, 0], [5, 5, 2], [-7, 9, 6], [-12, 2, -5], [13, -1, 0], [-5, -2, 5], [-5, -10, 9], [-8, 7, 1], [3, -13, 9], [-2, 4, -2], [-11, -5, 4], [-11, -4, 0], [17, -3, 5], [-1, -3, 13], [-6, 9, -6], [-14, 4, 2], [6, 6, 0], [9, -9, -6], [7, 3, 6], [2, 0, 1], [8, -8, 8], [0, -11, 8], [1, -13, 11], [-3, -3, 1], [1, -11, 10], [1, 0, -14], [2, 6, -2], [1, 5, -15], [11, -14, 4], [-1, 9, 8], [3, 2, -9], [22, -2, 1], [-6, -8, 6], [11, -4, 5], [6, -9, 17], [9, 2, -7], [-7, -1, -17], [-10, 10, 8], [-13, -18, 7], [13, -12, 0], [-6, 1, 0], [-20, 6, -1], [-7, -4, 7], [14, 15, -5], [9, 2, 15], [-22, 0, 8], [1, -16, 4], [-5, 1, -5], [22, 7, -10], [-13, -16, 12], [-23, 2, 5], [12, 7, -6], [-15, -2, -7], [-11, -9, 4], [26, -7, -2], [24, 15, -7], [-9, 11, -1], [-2, 8, 7], [-11, 3, -7], [1, -13, 14], [11, -9, 15], [-3, -6, 2], [13, 19, -10], [-12, -14, 7], [23, -5, 19], [4, -20, 4], [18, 15, -11], [5, 15, 7], [10, 16, -8], [8, -19, 1], [-6, -18, 7], [-12, 9, -6], [-9, -19, 7], [9, 1, -1], [13, 17, -7], [-25, -11, 4], [13, -5, 12], [-25, 5, -7], [-7, 5, -2], [-4, 8, -7], [-24, 1, -6], [-22, -2, -6], [2, 5, -16], [22, -4, 4], [1, 15, -15], [5, 11, -6], [-9, -16, -5], [-13, 8, -4], [13, 13, -1], [-5, -13, 25], [-31, 5, -7], [5, 14, -10], [22, 22, -9], [31, -6, 7], [-9, -14, 13], [5, 13, 3], [18, 5, 9], [4, 6, 15], [-24, 8, -5], [34, -4, -5], [19, 0, -5], [-19, -14, 19], [22, -8, -4], [22, 14, -10], [-3, 16, -19], [-8, 12, -32], [-19, 1, -16], [21, 1, 15], [9, 38, -19], [19, 11, 10], [-26, -3, 0], [9, 26, -17], [-39, -1, -3], [25, 22, -18], [-13, 19, -9], [33, 15, -12], [2, -6, 2], [-1, -24, 21], [-11, 6, -33], [4, 1, 6], [10, 6, 16], [-8, 3, -11], [-4, -22, 27], [22, 6, -11], [-6, -21, 28], [-19, -5, 9], [-23, -9, 7], [-21, 15, -1], [4, -6, -6], [-10, -34, 20], [6, -11, 1], [-42, -8, 7], [1, 0, -21], [7, 17, -5], [12, -21, -2], [-6, -7, 5], [-5, 1, 9], [-11, -14, -8], [20, 7, -2], [-40, -7, 8], [4, 7, -12], [-39, -23, 14], [-20, -19, 7], [13, 23, -5], [25, -1, -17], [12, -26, 18], [-22, 4, -11], [20, -3, 3], [-10, 25, -33], [17, -9, 14], [7, 0, 4], [-8, -7, 12], [-22, -10, 13], [18, -10, 14], [-16, 1, -2], [12, -14, -4], [14, -19, -4], [-32, -21, 12], [2, -11, -3], [5, -23, 15], [17, -6, 5], [-24, -13, -10], [-33, 4, -10], [-24, 16, -3], [-20, 34, 11], [17, -21, -6], [6, 27, -18], [-26, -15, -2], [-5, 0, 13], [18, -1, -23], [-32, -2, 12], [-25, 1, 8], [-9, 24, -9], [26, 8, -17], [-31, 24, 11], [-11, 9, 18], [-11, 0, -8], [-12, 12, -3], [27, -4, 26], [-29, 18, 0], [14, 12, -13], [30, -3, 19], [-7, -14, 1], [-15, -9, 6], [-5, 0, 19], [10, -10, -9], [12, -28, -11], [-19, 13, -27], [-35, -27, 16], [40, -9, -13], [16, 0, 4], [-13, 32, -31], [1, 13, -22], [-28, 16, -18], [-43, -5, 2], [-6, 21, -37], [15, -24, 5], [-31, -30, 19], [25, 10, -17], [9, 10, -16], [-26, 10, -23], [16, -30, 24], [1, 11, 9], [-3, -26, 25], [9, -14, 18], [-11, 10, 13], [1, -42, 33], [11, -33, 39], [-13, 5, 22], [-14, -22, 6], [-29, -20, 28], [45, 11, -13], [32, 11, -25], [7, -12, 32], [-3, 4, 1], [-10, -20, 2], [-10, 27, -23], [1, -2, -6], [-10, -5, -9], [31, 24, -13], [-9, -37, 11], [5, -24, 22], [-14, 19, 19], [60, -2, 1], [-15, -36, 24], [0, -8, 21], [19, 18, 3], [7, -25, 42], [-6, 24, -32], [-13, 6, 8], [-16, 14, -32], [33, -33, -13], [-1, 12, -40], [-19, -8, -15], [7, 1, -30], [-10, 2, 1], [25, 40, -12], [-3, -14, 31], [0, -30, 20], [-6, 10, -7], [35, 31, -29], [19, -15, -7], [-15, -6, -15], [-20, 14, -13], [-36, 21, -1], [-16, 5, 7], [-22, 21, -17], [-13, 23, -22], [50, 11, -19], [-36, 7, 5], [1, -17, 1], [13, -20, -10], [12, -20, 4], [26, 18, -22], [-19, -9, 13], [21, 12, -22], [14, -33, 30], [14, -8, -20], [2, -2, -9], [-35, -3, 1], [10, -21, 46], [21, -36, 31], [20, 31, -31], [-13, 38, -33], [0, 25, -38], [-20, -6, 8], [27, -3, -6], [-17, -13, -24], [20, -22, 39], [-12, -18, 5], [47, -11, 28], [-23, 0, -27], [-2, -12, 13], [-15, -8, 37], [17, -8, 3], [15, -19, -4], [19, -5, -4], [-26, 8, -1], [27, 1, 7], [0, 36, -2], [-25, -25, 22], [-10, -23, -5], [-29, 4, -3], [-5, 4, 1], [5, 11, 39], [-35, 32, 7], [20, 9, 34], [35, 10, -7], [-18, -8, 26], [-22, -23, 13], [9, -44, 33], [-29, 21, 23], [-26, -43, 18], [-7, 16, -8], [11, 32, -23], [73, -5, 4], [-23, -3, 9], [14, -2, -9], [1, -10, 46], [18, 33, -22], [56, 1, -6], [10, 7, 23], [3, 40, -21], [23, -22, -21], [-32, -3, 21], [21, -21, 1], [7, -11, -21], [17, 6, -25], [15, 6, 12], [-27, 0, -20], [6, -3, -29], [-8, 2, 35], [-25, 18, 1], [13, 1, 39], [-24, 4, 10], [-7, -34, 34], [-24, 2, -36], [8, -48, 17], [-12, -16, 20], [46, -19, 18], [-8, -33, 24], [20, 36, -25], [-4, 11, 25], [-7, 29, -22], [-38, -12, 2], [19, 10, 6], [-73, -9, 9], [-21, -1, -10], [-41, 29, 15], [23, 13, 11], [47, -14, 27], [-26, 9, -21], [-14, 4, 14], [57, -17, -10], [-70, -22, 10], [-37, 15, -34], [33, -28, 20], [-45, 5, -23], [-10, 6, -2], [-27, -4, -38], [21, -17, 33], [15, 18, 25], [46, 25, 0], [-10, 27, -42], [-10, 35, -47], [-51, 20, -1], [-21, -17, 27], [65, -5, 27], [12, 25, 2], [-38, 20, 16], [19, -18, 33], [-12, 25, 13], [15, 4, -8], [5, -4, -37], [26, 20, 23], [-25, -46, 23], [32, -16, 44], [-15, -12, -25], [-58, 3, 12], [37, -11, -17], [-33, -41, 40], [17, 10, 2], [-28, 21, -39], [-42, -4, -13], [48, -19, -2], [-8, -2, -6], [-34, -19, -7], [-35, 26, -10], [-13, -39, 38], [-27, 3, 0], [-11, -13, 32], [0, 30, -18], [-34, 27, -4], [-6, 47, -44], [-3, 5, 18], [-9, -19, -3], [27, -4, -22], [-9, -16, -8], [-7, 22, -46], [-36, 27, -29], [48, -17, 17], [-40, 18, 26], [-12, 20, -21], [-27, -7, -1], [19, 25, -18], [-15, 47, -49], [35, -18, 15], [-30, 27, -7], [47, -22, 16], [-16, -36, 40], [-20, 28, -11], [19, 18, 28], [9, -17, -26], [23, 56, -42], [-59, 20, -16], [-19, -32, 11]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8019_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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