
// Make newform 8030.2.a.v in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8030_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_8030_2_a_v();".
// 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_8030_2_a_v();".
// 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, 1, 7, -4, -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], [-2, -1, 1, 0, 0], [3, 2, -5, -1, 1], [-1, -6, 4, 2, -1]];
    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_8030_a();"
function MakeCharacter_8030_a()
    N := 8030;
    order := 1;
    char_gens := [1607, 2191, 881];
    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_8030_a_Hecke(Kf)
    return MakeCharacter_8030_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], [-1, 0, 0, -1, 0], [1, 0, 0, 0, 0], [-1, -1, 0, 0, -1], [1, 0, 0, 0, 0], [-2, 1, 2, 1, 1], [0, -2, -2, -2, 1], [0, 1, 0, 3, 2], [-1, 2, 0, 0, -2], [-3, 2, 0, -1, -1], [-2, 5, 2, 4, -1], [1, -3, 0, 1, 1], [-1, 2, -2, 2, 2], [1, -2, 1, -3, -1], [-3, -2, -1, -1, 2], [-9, 1, 1, 1, 0], [-2, 0, 3, -1, 1], [-5, 2, 0, 0, -1], [-1, -3, -5, -1, 2], [-6, -3, -2, 2, 2], [1, 0, 0, 0, 0], [-3, -3, 1, -4, -3], [0, -3, -1, -3, 1], [13, -3, -3, -1, -1], [4, -2, -3, -1, -3], [2, 2, 0, 8, 3], [-5, 3, -1, -1, 2], [8, -5, -2, -4, -5], [-3, -4, -6, 0, 3], [3, -1, 2, 3, -4], [-12, 4, -1, 4, -1], [5, 3, 4, -3, -2], [-3, -4, 4, 0, -1], [-9, -3, 0, 3, 2], [-1, 3, 1, -4, -1], [-11, 2, 3, 0, 1], [-14, 2, 1, -3, -1], [-3, 0, -1, -5, -2], [-3, 1, 0, 2, -3], [7, -1, 2, -2, 4], [5, -6, 1, -7, -2], [5, 1, -3, -2, 1], [-13, 5, -1, 8, 1], [-4, 5, 1, -5, -4], [2, -2, 2, -6, -8], [-7, -5, -1, -3, 1], [6, -7, -3, 5, 0], [-4, 6, -2, 1, -4], [-6, 11, 5, 11, -3], [6, -14, -4, -6, 1], [1, -2, -2, -4, -5], [-5, -6, 3, 2, 0], [-6, -8, -3, -2, 4], [-9, -5, 3, 3, -1], [-2, 5, 9, 2, 2], [-17, 8, 5, 3, 0], [5, -5, -1, -3, -2], [-3, 7, 2, -7, 2], [-2, -1, 2, 9, 1], [9, -4, 0, -1, 4], [5, 7, -4, -2, -5], [-6, 10, -1, -4, 3], [4, 10, 7, 2, -3], [-8, 1, 1, -11, -1], [-4, 3, -1, 8, 3], [-9, -9, 2, 1, 3], [4, -6, 2, -13, -5], [7, 8, 3, 3, -3], [-9, -8, -2, 1, 0], [9, 5, 3, -1, -2], [-11, -1, 0, -1, 6], [12, -2, -3, -6, -8], [-19, 9, 4, 4, 3], [6, 5, 1, -1, -9], [-12, 15, 4, 0, 2], [-13, -7, -2, -9, -2], [14, 2, 1, 1, 7], [0, -3, 1, 4, 4], [-3, 8, -4, -3, -7], [-7, -7, 5, 0, -5], [-18, 4, 0, 5, 12], [9, 12, -6, 6, 8], [-1, 3, -10, -3, -1], [-5, 0, -2, 5, 0], [14, -19, -9, -13, 1], [-8, 15, 4, 7, 0], [-1, 2, 7, 9, 2], [-9, 4, 0, -3, 4], [-4, 3, -4, 2, 6], [-16, 3, -3, -6, 0], [2, -11, -10, -8, 7], [5, 6, -2, -6, 7], [-8, 5, -1, 12, 9], [5, -8, -4, 1, -2], [7, -14, 1, 10, 4], [-6, -5, -3, 1, 4], [-6, 0, 10, 1, -3], [-6, 9, 5, -3, -3], [6, -3, 6, 0, 6], [-4, 14, 9, -6, -5], [11, -15, -5, -10, 1], [15, -1, 4, 9, -5], [8, -14, 1, -17, -7], [0, 7, 0, -6, -4], [-9, 2, 1, -13, -6], [15, 4, 2, -3, 1], [-4, 1, 0, 15, -3], [-6, 14, 1, 0, 4], [6, -4, 7, -19, -4], [-18, 11, 8, 3, 1], [-1, 5, -3, -5, -14], [-6, -7, -7, 5, 7], [0, -6, 5, -15, -12], [-4, -9, 10, -1, 2], [7, -3, -9, 7, 5], [9, -1, 2, 0, -6], [-4, -11, -3, 4, 1], [-7, 3, 4, -4, -9], [15, -11, 5, -10, 5], [-3, 8, -9, 9, 5], [1, -5, -9, -4, -3], [13, -11, -14, -2, 1], [2, 1, 0, 13, -5], [7, 5, -2, -5, 11], [0, 0, 0, 12, 2], [13, -9, 5, -2, 0], [-8, -1, -5, 1, -5], [-8, 0, 8, 7, 6], [2, -3, -3, 1, 8], [-4, 5, -9, -6, 5], [12, -6, 6, -3, 3], [-6, 0, -6, -6, -4], [-1, -4, -1, -18, -7], [1, -5, -1, 3, 2], [8, -10, -4, 10, 4], [5, 4, 5, 5, -4], [14, -2, 7, -3, -3], [21, -6, -10, 2, 5], [-26, 20, 10, 9, 6], [13, -5, -1, 11, 7], [9, -4, 9, -2, -9], [-7, 2, 5, 1, -12], [0, -5, 9, 0, -14], [-13, 8, -5, 0, -13], [-2, 10, 4, 8, 4], [9, 1, 2, -7, -4], [-5, 15, -2, 11, -5], [-6, 11, 7, 0, 4], [11, 8, 4, 12, 3], [-18, -13, 5, -7, -9], [22, 3, 2, -6, -8], [-7, -16, 0, -7, -8], [-2, -13, -1, 4, -4], [-15, -13, -6, 3, 16], [-2, 10, 19, 13, 1], [20, -5, 1, -14, -14], [4, -10, -14, 1, 2], [20, -14, -1, -16, 2], [16, -4, 3, 20, 8], [7, 7, -1, -14, 7], [-16, 14, -1, 1, -9], [13, -18, -9, -13, -6], [-15, -3, -7, -1, 7], [-10, -13, -20, -1, 9], [13, -22, -4, 4, 8], [-21, -1, -2, -10, -1], [-34, 11, 0, 13, 3], [-4, 12, -9, 4, 1], [-17, -7, -2, -24, -5], [-31, 6, -4, 3, 8], [4, -2, 4, -4, 8], [0, -6, 11, 5, -1], [0, 10, 1, 9, 1], [15, -21, -4, -19, -13], [-19, 8, 2, 9, 9], [-1, 3, 5, -1, 1], [-18, 9, 10, 5, 1], [29, -15, -9, 4, 2], [4, -27, -3, -2, 3], [-22, 23, 12, 8, 9], [-8, 12, 8, -8, 8], [13, 15, 3, 10, -7], [6, 3, -15, -10, 1], [4, 14, 17, 13, -9], [28, -3, 5, 1, -8], [33, -18, -7, -4, -2], [-4, 9, 15, 13, 7], [2, -19, -12, -18, 5], [10, -25, -5, -22, -2], [-12, 8, 12, 5, -4], [-34, -5, -3, -1, 6], [-31, -7, -4, -4, -6], [-18, 3, 3, -24, -8], [-6, -20, -7, 8, 5], [-12, 3, 5, 4, 16], [-21, 13, 10, 10, -7], [9, 21, -1, 25, 10], [22, -15, -7, -11, 1], [48, 1, -3, -2, 2], [-9, 7, -5, 20, 2], [5, 23, 3, 16, 3], [-26, -1, -7, 6, 15], [-5, 6, 0, 4, 8], [13, -13, -18, 3, -3], [8, -4, -3, -6, -14], [-29, -5, 8, -4, -2], [14, 8, 4, 8, -2], [6, 15, 2, 27, 9], [8, -1, 0, 10, -9], [-19, 13, 20, 4, 2], [30, 7, 5, 17, 1], [12, -18, -1, 15, -6], [-12, 0, 5, 11, -7], [21, -14, 6, 6, 0], [1, -5, -4, -2, -7], [28, -23, -4, -21, -15], [2, 1, 11, -7, -1], [23, 4, 6, -5, 12], [24, -6, -7, 8, 10], [2, 6, -13, -2, -6], [2, -1, 6, 10, 6], [5, 22, 13, 29, 2], [14, -1, -6, -11, 3], [25, -18, 0, -16, 1], [-25, 12, -3, 25, 19], [7, -21, -10, -1, 0], [7, 14, 12, 11, -12], [9, 0, -8, -2, -17], [-7, -7, 3, 9, 18], [14, -35, -5, -21, 4], [13, 4, 6, -10, 15], [23, 13, -3, -3, 4], [22, -9, 3, -10, -11], [5, -7, 13, -7, -16], [-15, 8, 0, -19, -8], [-16, 6, -14, 2, -11], [-4, 25, 0, -13, -5], [-5, -4, 3, 19, 16], [-14, 14, 0, 19, 17], [20, 17, -4, 16, 7], [-32, 25, 5, 21, 10], [-22, 18, -1, 1, -4], [28, -19, -22, -9, -1], [-10, 28, 7, -2, 2], [47, -1, -10, -2, 2], [-9, 14, 17, 5, 10], [-20, -19, -2, -18, -4], [22, -5, -6, -4, 0], [-2, 26, 0, 13, 0], [29, 12, -7, 14, 4], [24, -5, 2, -20, -1], [-7, 10, 11, 8, -3], [27, -4, -7, 4, -2], [18, -34, -6, -4, 1], [-7, 14, 23, -3, -6], [1, 7, 0, 7, 8], [-11, 14, 14, 9, 15], [-27, 33, 7, 29, -3], [10, 18, -4, 24, 12], [14, -13, -4, -16, -10], [10, -6, 9, -21, 0], [28, -22, -5, -8, -4], [6, -9, -6, -7, -20], [18, -21, -3, -15, 3], [37, -20, -4, -19, -12], [-10, -6, 8, 10, -14], [-19, 3, -4, 24, 5], [-6, 32, 9, 20, -14], [-25, -3, -3, 9, -7], [-28, 18, 4, 8, 13], [-8, 14, 20, 23, 6], [11, 3, -4, -9, -13], [-49, 7, 4, 5, 0], [12, -23, 2, -14, 5], [2, -12, 11, -2, -12], [-3, 7, 17, 13, 14], [-15, 24, 19, 14, -1], [35, -22, -11, -22, -7], [7, -21, -11, -20, -2], [-19, -19, -10, -3, 22], [35, -34, -13, 11, 0], [-12, -13, 4, -7, -9], [-15, -15, -10, -13, -4], [-10, 13, 24, 11, -1], [-7, 28, -7, -10, -5], [11, -11, 5, -7, 18], [-21, 36, 9, 6, -7], [23, -18, -2, -20, -5], [34, -19, -3, -10, -16], [8, 14, 21, 28, -5], [47, -17, -4, -18, 5], [-1, 29, 8, 16, -7], [-17, 26, 19, 11, -1], [24, -5, -11, -14, -18], [8, 16, 7, 22, 8], [28, 5, 2, -10, 13], [-16, 16, 5, -4, -8], [3, 12, -3, 1, -11], [-15, 13, 7, 24, -2], [-14, 21, -2, 16, 20], [-28, 30, 6, 5, 0], [-8, 12, -2, -7, -9], [0, -26, 5, -10, -23], [17, 5, -4, 22, 9], [7, 17, 7, 19, -10], [6, -6, -3, -15, -23], [-40, -6, -4, 5, -6], [-21, 10, 4, 9, 0], [13, -28, 4, -15, -11], [7, 1, 1, 5, 3], [27, -24, -19, -19, -7], [-14, 12, 2, 10, -14], [26, -19, -12, 6, 11], [18, 8, 21, 23, 16], [-17, 9, 2, 21, 26], [37, -10, -1, -5, 14], [12, 4, 19, -8, -20], [-14, 13, 12, 6, -6], [37, -8, -17, -12, 11], [-11, 14, 3, -29, -1], [-3, 9, 0, 14, -7], [8, -37, 5, -7, 8], [4, 3, -11, -1, -11], [-12, 12, -10, 24, 12], [-27, -1, 7, -2, 13], [-13, 9, -11, 3, -10], [31, -36, -13, -28, -7], [-16, -7, 16, -5, -10], [20, 5, 18, 19, 3], [-16, -3, -13, -2, -9], [-12, 21, 1, 10, -13], [-6, -15, -4, -32, -24], [-2, 18, -11, 5, -5], [-10, 1, 5, 14, 1], [-21, 1, 20, -4, 1], [-2, 15, -4, -13, 23], [32, -18, -19, 2, -6], [-9, 29, 15, 22, -6], [27, 18, 10, 12, 8], [-22, 26, -8, 19, 7], [-20, -1, -2, 15, -15], [2, 32, -8, 22, 13], [7, 8, 15, -23, -8], [-31, -7, -9, 3, -2], [-9, -6, 17, 6, -14], [4, 16, -5, -11, 6], [12, -9, 8, -3, -5], [-35, 18, 0, 12, 13], [1, 9, 10, 25, 2], [-16, -11, -12, 15, -3], [15, 35, -10, 3, 1], [-31, 10, -7, -14, 15], [29, -6, -10, -8, 3], [-32, -2, -4, -14, -6], [21, -33, -13, -5, 2], [36, -13, -5, -14, -6], [13, -26, -3, -6, 8], [24, -5, 0, -19, -15], [-3, -1, -5, 2, 19], [-46, 28, 24, 15, 1], [12, -13, 15, -25, -13], [19, 6, 19, 34, 6], [-15, 7, -13, 16, 24], [-36, 0, 6, 10, 7], [-5, 4, -7, -26, 6], [-1, 23, 14, 9, -4], [-15, -16, 8, 3, 14], [15, -10, -3, 22, 19], [4, -18, -14, -27, 7], [-32, 14, 0, 18, 9], [15, 14, 12, -8, -8], [-37, -5, -17, -8, 13], [16, 8, 17, 0, -20], [-26, 11, -4, -7, -13], [-35, 8, -11, -17, -11], [-19, 41, -1, 13, -14], [-7, 32, 5, 11, 4], [20, 12, 25, -1, 1], [-18, 0, 6, -32, -11], [-1, 19, -1, -3, -18], [-10, 16, -13, 2, 1], [41, -20, 4, -18, 1], [-7, -26, -12, -27, -5], [57, 15, 2, 26, 10], [14, -41, -3, 9, 9], [-40, 32, 19, 22, 15], [25, 15, -4, 30, 10], [-21, -22, -23, -13, 6], [31, -1, 1, -18, -13], [6, 2, 7, 16, -18], [-20, -21, -30, -25, 10], [-17, -6, -7, -38, -8], [17, 29, 15, -14, -22], [20, -18, -9, -13, -17], [-5, -38, -7, -12, 18], [-6, -12, 5, 23, 1], [-43, -3, -9, 6, 5], [-5, -7, -18, -13, 4], [-3, 18, 10, 17, -2], [13, 21, 3, -2, -9], [-34, 3, -2, -6, -16], [0, -37, -4, -15, 18], [-6, 10, 15, 3, 19], [-27, 11, 4, 14, -13], [2, 1, -2, -12, -2], [0, -2, -15, 2, -6], [-11, -4, -6, -14, -14], [-20, -16, -20, 7, 6], [-17, 21, 11, 20, 6], [5, -26, -10, -20, 19], [-2, 0, 12, -31, -2], [-8, 15, -12, 11, 5], [-57, 14, -2, 22, -11], [-4, 2, 6, 22, 19], [44, -7, 9, -1, 0], [-30, -4, -18, 18, 27], [7, -15, -14, -15, -12], [-30, 32, 4, 4, -2], [-45, 2, -6, -13, 6], [14, 17, -3, 34, 18], [19, -14, -8, 4, 4], [16, -20, -38, -13, 8], [-20, -22, -23, -20, 14], [-35, -7, -22, -5, 4], [-9, -25, -7, 9, 17], [33, 9, 12, 2, 3], [6, 31, -4, 0, 8], [-11, -10, -13, -7, -10], [-13, 1, -20, 4, -19], [-12, 30, 0, 25, -7]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8030_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8030_2_a_v();".
// 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_8030_2_a_v(:prec:=5)
    chi := MakeCharacter_8030_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_8030_2_a_v();".
// 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_8030_2_a_v( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8030_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-4, -17, -13, 3, 5, 1]>,<7,R![86, -41, -46, 8, 8, 1]>],Snew);
    return Vf;
end function;