
// Make newform 8619.2.a.u in Magma, downloaded from the LMFDB on 02 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8619_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_8619_2_a_u();".
// 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_8619_2_a_u();".
// 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_8619_a();"
function MakeCharacter_8619_a()
    N := 8619;
    order := 1;
    char_gens := [5747, 5917, 2536];
    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_8619_a_Hecke(Kf)
    return MakeCharacter_8619_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, 1], [1, 0, 0], [2, 0, 0], [1, -1, -1], [2, 2, 0], [0, 0, 0], [-1, 0, 0], [2, -2, 0], [-2, 2, 0], [-2, 0, 2], [-1, 5, 1], [3, -1, 1], [4, 2, 2], [2, 2, 0], [-1, 1, 1], [2, -4, -4], [3, 1, -3], [-2, 0, 0], [0, 0, 6], [6, 2, 4], [7, -9, -3], [2, -6, -6], [11, -3, 1], [-1, 3, -7], [5, 5, -1], [0, 6, -2], [4, 4, -4], [0, 4, 8], [3, 3, -3], [-6, 0, -2], [-6, 6, 0], [-10, 6, 0], [1, -3, -9], [0, -4, -4], [-5, -5, -3], [-4, 8, -2], [6, -4, -2], [-1, 1, -11], [10, -10, -4], [6, -4, 4], [2, -2, 2], [-2, 4, -4], [8, 4, 12], [5, 1, 11], [2, -8, -4], [14, -6, 2], [6, 10, -6], [-8, 12, 2], [-4, 0, -6], [-8, 10, 6], [-6, -4, -4], [1, -1, -9], [1, -7, 3], [8, -4, -8], [4, -10, 2], [0, -4, -4], [-6, 8, 8], [-4, -8, -2], [8, -2, 10], [1, 13, 7], [-4, -12, 0], [3, -13, 5], [-10, 2, -4], [-4, -4, -12], [-16, 6, -2], [14, -4, -4], [-2, 10, 0], [-18, -8, 4], [18, 2, -4], [-4, 6, -10], [7, -1, 5], [-7, 3, -13], [2, 2, 10], [-6, 0, 6], [-11, -9, -1], [-9, -3, 5], [-2, -4, 0], [15, 7, 1], [0, -2, -6], [0, 6, 14], [0, 4, 0], [6, 4, 8], [-16, -8, 6], [2, -4, 6], [-14, 14, 6], [6, 6, -2], [12, 10, 6], [16, -2, 6], [-17, -1, -15], [-6, 2, 8], [-6, 6, -10], [16, 8, -2], [9, -5, -13], [-6, -10, -10], [9, -13, 3], [10, -10, 0], [13, 5, 19], [-18, -8, -8], [10, -6, -8], [15, -5, -11], [-10, 10, 2], [1, -7, 15], [-2, -14, 6], [-4, 22, 6], [2, 2, 10], [-8, 6, -2], [-27, 7, 3], [15, -25, -3], [12, 0, -12], [-8, -10, -6], [36, 4, 0], [6, -4, 0], [24, -26, -10], [-37, 1, 1], [-10, -18, 4], [-10, 8, -8], [-17, 13, 9], [-2, -10, -10], [22, -4, -12], [4, -12, -8], [-8, -6, -2], [2, -12, -12], [-10, -8, -2], [6, 14, 16], [3, -11, 5], [-14, 8, -4], [-23, 1, -1], [-14, 6, -4], [16, 8, 12], [-14, 24, 0], [18, -10, -8], [16, -24, -2], [0, -20, -4], [2, 8, -6], [-19, -3, 7], [4, -6, 22], [-25, -5, -11], [5, 11, 3], [14, 4, 24], [-34, -8, 8], [-17, 5, -7], [34, 0, 8], [12, 8, 24], [-18, 6, 4], [-10, 0, 16], [-8, -16, 2], [-33, -9, 1], [6, -4, 2], [4, -16, 16], [7, -3, -3], [31, -9, -7], [18, 8, -6], [-4, 8, 24], [4, 4, 12], [-36, 4, 4], [-8, -8, 0], [32, -24, -16], [14, 8, -12], [-6, -4, 14], [12, 6, 18], [10, 2, -8], [-24, -6, 2], [26, -14, 0], [-6, 10, 18], [11, 15, -19], [6, 2, 8], [16, -8, -16], [-18, 8, 4], [1, 17, 27], [-6, -12, -18], [11, 1, 1], [-8, 10, 2], [-16, -16, 12], [6, -8, -24], [-6, 14, 12], [26, -28, -4], [-21, 21, 17], [4, -18, -10], [-32, 16, 4], [22, -4, -2], [-28, -8, -26], [-30, 10, 0], [-10, 8, -24], [43, -25, -11], [13, 11, -17], [18, -8, -20], [2, -24, -8], [-2, -22, -12], [55, 3, 1], [20, -4, 14], [-32, 6, 6], [-24, -4, -18], [-10, -2, -20], [-1, 15, 17], [14, -26, -20], [18, 4, 4], [-37, 7, 5], [-50, 4, 8], [-4, 26, 6], [-22, -18, 18], [-8, -6, -6], [14, -10, 2], [24, -6, -6], [42, -12, -6], [-5, 21, 13], [6, -8, -12], [-24, -12, 10], [-26, 22, 18], [40, -26, -10], [-8, 12, -12], [-28, -10, -10], [6, 0, 12], [-28, 20, -4], [-5, 13, -3], [26, 6, 8], [-11, -15, 11], [-12, -4, -16], [-2, 12, 0], [-48, 16, 10], [-15, 9, -1], [26, -16, 10], [11, -31, 1], [-17, 19, -7], [35, -15, -11], [4, 0, -28], [30, 4, 26], [-2, 4, 14], [12, 28, -16], [-56, -8, 4], [20, 16, 26], [-2, 16, -8], [58, -2, 2], [-10, -2, -16], [18, -20, -16], [4, 8, 12], [-15, 11, -9], [-5, -29, -7], [-32, 42, 22], [2, 2, 28], [0, 4, -16], [-10, -10, -4], [-38, 10, 12], [-42, 18, 16], [58, 0, 4], [10, 4, 8], [-32, 16, 12], [7, -15, -3], [-26, -18, 4], [-2, -6, -24], [16, 8, -4], [-20, -2, -10], [44, 2, -2], [-39, 3, 3], [14, 0, -12], [-12, 6, -26], [23, -27, -23], [-16, 2, -14], [1, 15, -21], [-6, -12, -18], [-6, -4, 4], [6, -6, -2], [14, 6, 14], [19, -17, 1], [-42, 0, 8], [-4, -22, -6], [-22, -22, 4], [19, -1, 25], [-17, -1, 5], [9, -13, 31], [0, 6, 26], [4, -14, 10], [-34, 26, 24], [-2, -24, -28], [-52, 4, -12], [2, 16, 16], [-16, 36, 22], [1, 3, -9], [-16, 18, 30], [48, -2, -2], [16, -20, 16], [52, -16, 4], [-7, 23, 7], [54, -14, 4], [0, 2, 6], [-29, -19, 17], [-58, 14, 6], [10, -16, -12], [-24, -22, 2], [36, -16, -22], [-8, -14, 10], [-34, 8, 18], [26, -22, 8], [41, 9, -13], [14, 14, 24], [12, 6, 14], [-18, 28, 28], [-22, -2, 12], [30, -12, 12], [0, -20, -8], [-16, 0, -18], [-2, 16, 22], [9, 9, -33], [22, 10, 6], [14, -26, -8], [-68, 16, 8], [25, 1, -5], [-36, -8, -12], [2, 28, -20], [37, 3, -9], [-18, -12, -22], [-20, -12, 16], [-16, 34, 18], [2, -8, -10], [22, -18, 4], [11, 9, 21], [-34, 24, 10], [1, 15, 31], [-2, 2, 32], [41, 13, -17], [-18, 24, -12], [4, -20, -20], [17, -11, 7], [10, -12, -12], [52, 0, 14], [-38, 4, -12], [62, -4, -4], [-5, -3, 33], [-35, -1, 7], [20, -4, 24], [-2, -28, 4], [11, 27, 29], [-10, 20, 4], [-26, 46, 10], [11, -43, 5], [-47, -9, -5], [-14, 2, -28], [0, -38, -14], [2, 12, -8], [-7, -23, 27], [26, -26, 4], [40, 18, -10], [56, 14, -10], [10, 0, 16], [-18, -6, -12], [-37, -17, 1], [-2, 38, 28], [36, -2, 18], [-28, -4, -38], [6, -22, -8], [10, 20, 22], [44, -20, -6], [43, -1, 21], [-33, 11, -11], [-6, 6, -18], [58, -12, -4], [16, -2, 10], [23, -3, -7], [-4, -24, -10], [30, -20, 2], [37, -17, 11], [35, -5, -11], [2, -40, 6], [-18, 10, 6], [-2, -10, 4], [14, 6, -20], [-66, 20, 12], [-32, 10, 18], [-24, 12, 10], [10, 28, 16], [2, 2, -14], [26, -46, -26], [28, -20, -14], [30, -24, 8], [4, -4, 32], [10, 4, -16], [46, 14, 8], [14, -30, 8], [-50, 48, 20], [82, 8, -4], [30, 0, -22], [38, 4, 0], [21, -3, 23], [-41, -15, 13], [22, -8, 8], [-47, -1, -25], [20, 20, 18], [0, 36, -10], [10, 12, 28], [-33, 29, -15], [2, 38, 30], [-7, 37, 7], [0, -14, 6], [5, 19, -25], [32, 20, 8], [-11, -1, 15], [-30, 0, 24], [2, 10, -24], [18, 4, -16], [0, 12, -24], [-1, -13, -3], [-33, 35, 13], [14, 8, 36], [-12, 24, 34], [-2, -32, 12], [-7, -7, -9], [-8, 40, 0], [-8, 2, -38], [-13, 3, 1], [14, 10, -4], [38, -2, 32], [28, -10, -26], [2, -28, -44], [-46, 18, 18], [0, 8, -8], [-42, -8, 14], [22, -48, -22], [28, 28, 2], [-54, 58, 26], [62, -16, -8], [-50, 22, -14], [48, -10, 2], [43, -45, -19], [-24, 48, 38], [4, -4, -20], [27, 7, -11], [-57, 15, 17], [-2, -26, -8], [-4, 18, -2], [0, -24, -2], [60, -20, -16]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8619_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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