
// Make newform 6480.2.a.bd in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6480_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_6480_2_a_bd();".
// 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_6480_2_a_bd();".
// 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 := [-8, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_6480_a();"
function MakeCharacter_6480_a()
    N := 6480;
    order := 1;
    char_gens := [2431, 1621, 6401, 1297];
    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_6480_a_Hecke(Kf)
    return MakeCharacter_6480_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], [-1, 0], [0, -1], [-1, 1], [0, -1], [0, 2], [-1, 0], [2, 1], [1, -1], [-1, -3], [6, 0], [-7, 2], [-2, 2], [-6, -1], [0, -3], [5, 0], [6, 2], [-6, 2], [-1, -1], [8, 2], [-4, 2], [-10, 0], [1, 1], [2, -2], [-1, 5], [-10, 3], [-6, 0], [11, -3], [-8, -2], [-4, 5], [13, -2], [12, -2], [-15, 0], [-6, -4], [-21, -1], [6, 5], [4, -4], [-12, 0], [2, -5], [-11, 2], [3, -5], [-9, 1], [-6, 2], [4, -1], [0, -4], [-17, 0], [-12, -4], [-4, -4], [-10, -2], [-6, 6], [0, -6], [13, -7], [4, -5], [-14, 4], [-6, 3], [-5, 3], [16, -2], [-10, 3], [-14, -1], [-10, -2], [-2, 5], [6, -2], [1, 5], [-4, 0], [14, -1], [-17, 1], [-4, -2], [-16, 6], [-23, 1], [-6, 8], [-13, -1], [10, 6], [-4, -2], [-4, 9], [-16, -1], [-14, -2], [34, 0], [-6, -9], [-18, -1], [8, 8], [25, 1], [13, -1], [6, -14], [-5, 11], [-2, -8], [-1, -10], [-26, 6], [-21, -3], [10, -5], [-4, 6], [-17, 3], [4, -7], [1, -8], [-13, -2], [-16, 8], [38, 0], [-10, 3], [20, 6], [-17, 9], [40, 0], [8, 7], [10, -6], [-29, 6], [-7, 3], [4, -4], [30, 0], [2, 8], [-15, 9], [13, 0], [38, 2], [-12, 9], [20, -10], [36, -1], [39, 1], [-19, -7], [-26, -2], [2, -10], [20, -2], [-12, 15], [-19, 11], [-10, -4], [14, -3], [24, -6], [-20, 9], [1, -3], [-10, -12], [-27, -7], [40, -3], [-10, 8], [1, -5], [-20, 4], [24, -6], [20, -3], [3, -6], [-11, 9], [-18, 0], [8, 10], [0, 6], [1, -14], [7, 9], [-39, 1], [30, -2], [8, -16], [7, -15], [-5, -7], [4, 2], [40, -2], [-29, 9], [-28, -7], [16, 3], [-23, 1], [-20, -6], [-30, 5], [26, -4], [9, -19], [-35, 3], [-9, -5], [38, -2], [2, 12], [42, 2], [12, 0], [28, 4], [15, 10], [-32, -6], [4, 4], [-1, 1], [-12, -9], [-39, -2], [24, -7], [3, -14], [27, -7], [7, -13], [-22, -6], [32, -2], [53, -4], [-4, 3], [-13, 7], [-20, -4], [-9, -13], [6, 2], [32, -7], [-4, -3], [-2, -10], [38, -3], [-27, -7], [-2, -7], [0, 2], [19, 2], [12, -10], [-18, 4], [-26, 4], [-12, 8], [33, -7], [2, -2], [4, 0], [9, 0], [-10, 5], [24, 2], [-20, -7], [13, -11], [-31, 15], [32, 3], [1, 16], [-20, -8], [24, -1], [-5, 11], [20, 10], [34, 4], [-44, 0], [-6, -4], [-15, -1], [-44, 9], [8, 8], [31, -3], [-23, 10], [34, -10], [11, -5], [-30, 3], [10, 8], [9, 13], [-11, -7], [-15, 10], [-64, -1], [24, -12], [-5, 21], [46, 0], [0, -2], [-2, -21], [52, 5], [48, -1], [-31, -4], [40, 0], [10, 11], [32, -4], [-30, 15], [7, -2], [28, -14], [60, -1], [13, -5], [-56, 0], [-24, 7], [2, 9], [6, -4], [0, -10], [-47, 5], [-18, 7], [12, 19], [-21, -8], [-42, -2], [18, -12], [-5, -4], [-14, -2], [-5, -16], [34, 3], [16, -5], [-25, -9], [22, -2], [-16, 5], [0, 12], [-30, 19], [54, -8], [1, 19], [28, -19], [-50, 6], [-7, 18], [14, -12], [23, -4], [4, -20], [-30, 13], [15, -5], [-4, 12], [-32, -2], [9, 11], [50, -12], [-22, -14], [-26, 6], [-11, 5], [50, -9], [-12, -15], [-18, -15], [24, 12], [14, -27], [-10, -2], [20, 0], [-1, 13], [-22, 12], [-38, -11], [-21, -3], [-30, 12], [-3, 1], [20, -4], [4, -14], [19, -23], [16, 9], [-9, -9], [27, -13], [4, -26], [13, 0], [-18, 0], [10, 10], [44, -1], [-11, 3], [6, -8], [-25, 14], [20, -2], [20, 2], [17, 1], [25, 13], [8, -18], [22, 6], [5, 5], [-13, 14], [58, -10], [20, -12], [1, 0], [27, 8], [-17, 1], [26, -2], [63, 7], [28, -9], [-4, 12], [41, -13], [-4, -12], [-12, 10], [-7, -10], [-21, 25], [30, -10], [16, 11], [-2, 7], [-27, 13], [-2, -7], [-7, 9], [-72, 2], [-11, -10], [-26, 10], [-9, 19], [2, 2], [-3, 8], [40, -5], [-2, -19], [-10, -10], [-25, -3], [52, -6], [-44, -7], [-60, 8], [9, 17], [-38, 8], [-39, 9], [-60, 3], [5, -24], [8, 2], [38, -6], [-46, -11], [-15, -5], [-18, 4], [-19, 11], [-31, 10], [-22, 12], [48, -11], [84, -2], [-5, 8], [12, -5], [53, 2], [58, 4], [-12, 8], [-8, -23], [-38, 18], [41, -6], [55, 4], [20, -5], [-50, 11], [-29, 1], [-5, -17], [12, 1], [43, 4], [35, -9], [-30, -2], [-49, 11], [12, 4], [58, 0], [50, 6], [54, 3], [-50, -8], [-23, 7], [-32, 3], [16, -4], [-2, -5], [32, -22], [-38, -15], [54, -16], [-36, 27], [28, -8], [-14, 8], [1, 29], [-14, -4], [35, -17], [-78, 9], [-20, -9], [-11, 7], [-17, 1], [0, -18], [22, -7], [20, 8], [-33, -21], [24, 6], [-68, -3], [-10, -1], [-22, 0], [-55, -13], [48, -10], [-58, 8], [20, 24], [-7, 0], [-36, 8], [10, 10], [-77, 9], [-18, -14], [4, -14], [-54, 6], [18, 6], [-58, -11], [48, 17], [-57, 20], [34, 10], [-2, -23], [42, -18], [2, -7], [-47, 3], [40, 8]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6480_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6480_2_a_bd();".
// 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_6480_2_a_bd(:prec:=2)
    chi := MakeCharacter_6480_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_6480_2_a_bd();".
// 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_6480_2_a_bd( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6480_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-8, 1, 1]>,<11,R![-8, 1, 1]>,<13,R![-8, 1, 1]>,<17,R![-32, -2, 1]>,<19,R![1, 1]>,<23,R![-2, -5, 1]>],Snew);
    return Vf;
end function;