
// Make newform 9680.2.a.cn in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9680_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_9680_2_a_cn();".
// 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_9680_2_a_cn();".
// 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, 1, -3, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-1, -1, 1, 0], [1, -2, -1, 1]];
    Rf_basisdens := [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_9680_a();"
function MakeCharacter_9680_a()
    N := 9680;
    order := 1;
    char_gens := [3631, 2421, 1937, 4721];
    v := [1, 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_9680_a_Hecke(Kf)
    return MakeCharacter_9680_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, 0, 0, 0], [0, 0, 1, -1], [-1, 0, 0, 0], [2, -1, -2, 0], [0, 0, 0, 0], [0, -3, 0, 1], [2, -1, -1, -2], [4, -2, 1, 2], [-1, -1, -1, 1], [-4, -2, -1, 4], [0, -5, 0, 5], [6, -3, -3, -4], [-4, -1, 3, 0], [4, 1, 2, -1], [0, -1, -3, 1], [-1, -1, -5, 2], [2, -1, -4, -4], [-4, -2, 2, 1], [9, -3, -4, -3], [-3, -3, 0, 5], [-3, 3, 2, -3], [12, -4, -3, -2], [2, 1, -3, -7], [-5, 0, 6, 0], [3, 0, 2, 8], [5, -3, -7, 2], [-3, 0, 4, -6], [1, -8, -3, 1], [-1, -1, -4, -5], [2, 1, -1, -3], [2, -2, 3, -1], [0, 1, 6, 1], [-4, -9, -4, 6], [3, 5, 5, 2], [-6, 6, 5, 1], [3, 2, 9, -7], [12, -3, -6, -7], [5, 2, -9, 2], [-13, 5, 6, 2], [13, -1, -2, -2], [3, 12, 2, -12], [-8, -3, 8, 7], [-5, 5, 6, -5], [2, 5, -9, -3], [-1, 5, -1, 2], [1, -2, 3, 4], [19, -1, -2, -11], [4, -2, 2, -8], [3, -2, 7, -5], [14, -1, -13, 3], [6, 13, 6, -16], [3, 7, -7, 9], [-2, -10, 0, 1], [-8, 2, -1, 7], [4, 1, 3, -15], [-1, 7, 0, -11], [2, -5, -6, 9], [7, 7, 0, -2], [-6, 2, 0, -1], [3, -8, 3, -8], [7, 9, 10, -6], [12, 1, -2, 6], [7, -5, -7, 12], [16, -13, -7, -3], [-11, -8, 5, 6], [-1, 13, 7, -9], [-2, 20, 4, -8], [-5, 6, -6, -11], [5, 3, 0, -2], [-10, 7, 0, 9], [-2, 17, -2, -10], [3, -6, -8, 6], [14, -2, -11, -6], [4, -6, -5, 17], [-6, -2, 4, -7], [21, -5, -5, -2], [17, -22, -6, 4], [-11, 2, 0, -5], [-18, 11, 3, 2], [11, -8, -2, 5], [2, -9, 9, 4], [5, -15, 0, -2], [15, -11, -13, -4], [1, -18, 7, 1], [5, 0, -5, -8], [1, -17, 2, 20], [3, 0, 13, -7], [-3, 8, -6, -3], [5, 5, 3, -3], [-10, -2, -9, 19], [-12, 4, -6, -13], [-7, -13, -1, 11], [15, 12, -3, -11], [19, -5, -4, 5], [1, -12, -11, 17], [-33, -11, -5, 11], [9, -1, -6, -8], [-5, 13, 0, -16], [-7, -2, -5, 14], [8, -2, -4, 1], [3, 2, -1, 12], [0, -20, 5, -2], [0, 2, -9, -4], [10, 5, -13, 15], [6, -1, 0, 17], [21, 13, 5, -21], [-4, -10, 15, -6], [35, 2, 1, -8], [2, 3, 3, 9], [24, 9, 0, -25], [11, 11, -13, -17], [0, 15, 11, -11], [7, -5, -7, -10], [-4, -10, -17, 15], [27, -16, -12, -4], [-15, 12, -6, 0], [8, -8, -17, 12], [-3, 4, 2, 25], [12, 25, -3, -19], [8, 7, 2, 2], [-9, 14, -9, -6], [9, 20, -13, -13], [3, -4, -22, -2], [16, 11, -1, -3], [-5, -2, -5, -13], [-12, -23, -9, 22], [-8, -10, -7, 12], [4, 9, 15, -3], [-1, 0, -18, 6], [4, 4, 14, 7], [21, 0, -17, 8], [-4, -4, 6, -26], [-7, -4, 12, -9], [-18, 0, -6, 6], [2, -7, -9, -9], [15, 18, -10, 2], [-3, -19, 12, 12], [16, 6, 8, -17], [-12, 6, -5, 1], [7, -2, -10, -6], [7, 17, -3, -22], [-30, 7, 0, 24], [8, 24, -4, -25], [23, -1, 3, -34], [-2, 5, -5, 0], [-9, -20, -3, 12], [28, -10, -17, -2], [-22, -20, -7, 27], [4, -3, -11, 5], [-13, 2, 8, 11], [-17, 14, 4, 0], [31, -10, -17, -5], [8, 13, -8, -32], [4, 16, 7, -33], [0, 23, -2, -15], [-6, 8, -2, 12], [-18, -8, -6, 30], [-19, -14, 11, 27], [1, -7, -13, -5], [-33, 8, -5, -4], [-3, -11, -6, -8], [8, -10, 9, -3], [8, -11, 4, 4], [15, -7, 2, 4], [11, -15, -17, 16], [-9, 8, -14, -25], [-16, 7, 1, -7], [10, -19, -2, 2], [27, -16, -25, -8], [-35, 2, 3, 40], [15, 20, -14, 5], [-30, 8, -3, 16], [11, -10, 1, 6], [-7, -24, -1, 25], [-14, 1, -4, 35], [47, 3, 2, -20], [25, 0, -17, -6], [-1, 6, -1, 23], [1, -20, 8, 4], [-2, 23, 17, -12], [31, -5, -9, -1], [8, 2, 1, 19], [-23, 34, 5, -9], [-35, 30, 12, 2], [-41, 16, 8, 25], [-16, 6, 2, -28], [-25, 9, 20, 2], [-20, 14, 16, -6], [7, 17, 7, -18], [6, 5, 3, -18], [3, 1, -14, -6], [0, -6, -5, 8], [2, 16, -5, -2], [-20, -16, 22, -3], [-32, -25, -18, 45], [31, -20, 1, -7], [-8, 11, 27, -9], [-11, 7, 18, -11], [8, 28, -10, -19], [-29, -15, 21, -5], [-11, 10, 5, -20], [-6, 20, -20, -34], [3, 7, 8, -24], [-26, 14, 9, 28], [-14, -15, 22, 12], [6, 3, 20, -31], [-36, 1, 7, -8], [-25, 25, 4, 5], [-25, -28, -6, 39], [-20, 9, -8, -11], [-9, 1, -5, 18], [3, -5, 13, 8], [-35, -16, -3, 34], [-26, -22, -10, 22], [19, -12, -8, -1], [-23, -22, 3, 27], [-3, -9, -33, -3], [-19, -1, 30, -26], [4, 15, 12, -21], [-27, -13, 17, -4], [21, 37, -5, -20], [3, 9, 4, 23], [-13, -3, -12, 48], [16, 6, 13, -8], [-10, 15, -8, -33], [24, -12, 7, -15], [-12, -21, -2, -1], [10, -8, -9, 7], [-55, 6, 11, 8], [-13, 5, 28, 1], [-10, -8, 14, -12], [27, -9, -11, 21], [-5, -14, 0, 37], [-29, 6, 0, 19], [-14, 30, 2, -20], [-33, -24, -4, 34], [-1, 5, 7, 12], [-4, 4, 29, -14], [-33, 21, 26, 2], [28, 5, 16, 0], [15, 16, -24, -17], [-3, -24, 14, 7], [-14, -24, 13, -11], [9, -11, -16, -4], [3, 3, 12, -1], [3, -3, 28, 10], [41, -4, 3, 21], [12, 22, 11, -20], [-13, -16, -2, 34], [-32, 14, -2, 8], [-27, -26, 4, 6], [39, -28, -24, -7], [-10, -18, -10, -9], [-10, -4, -3, 11], [-16, -10, -5, -4], [25, 16, -10, -21], [14, 15, 18, 2], [-28, -2, 21, 8], [12, -33, 13, 34], [24, 12, -6, -42], [36, -4, -18, 9], [-12, -33, -11, 42], [20, -1, 14, -32], [-8, 13, 24, -12], [3, -18, -18, 32], [34, 5, 7, -11], [-5, -5, 4, 27], [17, -21, -15, -9], [34, 36, 26, -54], [-29, -4, 5, 6], [29, -2, 10, -24], [-34, -10, 14, 17], [-32, 13, 23, -4], [32, 6, -13, -44], [19, -28, -40, 19], [4, -24, -6, 14], [25, 21, -5, -43], [-31, 3, 22, -18], [13, -24, -10, 13], [-28, 17, 32, -3], [-15, 2, 4, -20], [22, -15, 3, -8], [-18, 7, -29, -16], [1, -28, 7, 35], [43, -33, -21, -4], [-37, -27, 15, 3], [-17, 2, 2, -4], [-33, 11, 21, -7], [-8, 14, -10, -9], [25, 5, -5, -30], [37, -3, -35, -4], [39, 24, -3, -14], [-1, -12, -29, 1], [-33, 10, 20, -2], [11, 14, -35, -9], [-2, -14, 9, -42], [7, 2, -3, 18], [10, -4, -1, 4], [-9, -52, -21, 35], [5, 1, -26, -21], [2, 12, -9, 28], [53, -39, -13, -9], [20, 20, -29, -15], [11, -16, -6, -9], [-13, -37, -29, 31], [-21, 19, 1, 19], [-1, -3, 16, 3], [38, 25, -19, -5], [-28, -18, -17, 20], [-13, 9, 23, -10], [-6, -31, -16, 3], [15, 1, 19, -20], [17, 18, -24, 22], [6, -5, 15, 27], [-47, 19, 0, 14], [29, 20, -9, -35], [38, -7, -13, -38], [24, -17, -22, -4], [-22, 3, 32, 7], [23, 0, -4, 2], [-13, -23, -6, 0], [-2, -20, 5, -8], [-8, 33, 12, -32], [-13, -43, -20, 40], [-34, -12, 15, 16], [19, 19, 27, -16], [1, 29, -1, 15], [28, 23, 15, -16], [-13, -8, -24, 16], [1, -3, 3, 39], [-9, -4, -11, -9], [-26, -30, -20, 50], [-29, -9, 4, 47], [16, 43, -3, -30], [-39, -15, 31, 11], [-9, 24, 0, 9], [25, -29, -18, 5], [-6, 31, -9, 16], [-31, -15, -18, 49], [-28, 34, 26, -18], [-6, 0, -15, 40], [-33, -15, 13, 3], [18, -41, -10, 12], [-38, 11, 42, 17], [-3, -25, -42, 16], [-12, -16, -11, 39], [-37, 3, 6, -13], [-57, -1, 6, 10], [-9, -36, -16, 43], [-8, -1, 21, 25], [47, -7, -11, -17], [-44, 27, -6, -22], [16, 16, 7, -30], [-41, 26, 17, 24], [49, -5, -4, 13], [23, -10, -30, 17], [44, -2, -7, -62], [-13, 3, -14, -42], [32, -22, -47, 15], [-7, 7, 5, 28], [-11, -2, 37, 17], [-55, 27, 16, 10], [-25, -9, -14, -5], [8, 25, 20, -44], [37, 8, -3, 2], [28, 30, -4, -12], [-65, 19, 38, -7], [18, 31, -1, -7], [-26, 9, -28, -11], [-4, 7, 5, 22], [-21, -17, -37, 13], [-13, 1, -16, 40], [1, 16, -8, -29], [-35, -19, 18, -12], [-3, 23, 28, -33], [-14, 16, 15, -14], [-28, -31, 17, 35], [-4, 33, 4, 1], [8, 11, -4, -13], [-17, -13, -18, 44], [3, -53, -18, 39], [57, -28, -46, 6], [41, -3, 12, -37], [-23, 26, 15, -22], [51, -17, -16, 5], [25, 39, -11, -27], [-17, 19, 27, 16], [38, 18, 1, 3], [64, -8, -30, -2], [44, -22, -46, -8], [-40, 5, 36, 15], [16, 16, -13, -49], [-28, 1, 11, 36], [15, -9, -19, 8], [-31, 26, 11, 9], [29, -1, -36, -19], [-20, 6, 22, -12], [26, 38, 2, -14], [2, -37, -50, 32], [64, -45, -23, -24], [2, 4, 27, -8], [-13, 49, 11, -27], [43, 19, -8, -3], [14, -1, -17, -19], [-16, 33, 41, -31], [38, 52, 22, -67], [18, 10, -33, 9], [4, -36, 13, 33], [-23, 20, 56, -16], [-20, -23, -16, 35], [-9, 3, -16, 22], [8, -34, 12, 9], [64, -24, -37, -9], [-3, -45, -19, 33], [-41, -30, -26, 38], [14, 9, 3, -65], [-7, 13, 11, -45], [-35, 17, 6, -9], [-56, -2, 23, 30], [-35, -23, 13, 46], [-52, 6, -9, -14], [-30, -31, -30, 35], [-73, 31, 25, 2], [-20, -22, 32, 50], [-42, 31, 50, -1], [-3, 31, 16, -8], [8, -13, 27, 29], [5, 1, -3, 36], [13, -11, -15, -40], [36, -35, -3, -11], [-14, 16, 38, 19], [-19, -21, -9, 26], [45, -2, -36, -15], [6, 14, 26, -41], [-40, -25, -5, 8], [-53, -15, 42, -29], [21, -35, -41, 7], [-67, 17, 19, 21], [50, 21, 5, 0], [-17, -9, 35, -30], [-9, 2, -14, 0], [3, 14, -21, -34], [-12, 22, 29, 9], [34, 4, -15, -1], [21, -13, -24, -22], [17, -17, -32, 21], [3, 20, -16, 26], [-24, -47, 14, 28], [16, -43, -13, 38]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9680_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9680_2_a_cn();".
// 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_9680_2_a_cn(:prec:=4)
    chi := MakeCharacter_9680_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(3169) - 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_9680_2_a_cn();".
// 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_9680_2_a_cn( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9680_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, -5, -6, 0, 1]>,<7,R![31, 23, -11, -3, 1]>,<13,R![139, -7, -25, 1, 1]>,<17,R![19, 32, -20, -1, 1]>],Snew);
    return Vf;
end function;