
// Make newform 6480.2.a.r in Magma, downloaded from the LMFDB on 19 January 2026.
// 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_r();".
// 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_r();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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 := 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]];
    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], [1], [0], [-5], [4], [-4], [5], [-6], [-5], [9], [-10], [7], [2], [-2], [8], [1], [-2], [-6], [-1], [-8], [-12], [-6], [-9], [14], [-3], [-2], [6], [-1], [-16], [-16], [-15], [12], [19], [-2], [5], [2], [-8], [-12], [-6], [-23], [-25], [-1], [26], [12], [-16], [-11], [-8], [-4], [6], [6], [16], [-11], [12], [-6], [-10], [-31], [8], [-18], [6], [-6], [18], [-10], [9], [-4], [-2], [21], [-8], [-20], [13], [-18], [27], [-18], [16], [-4], [36], [6], [-38], [30], [14], [-16], [13], [-3], [-26], [29], [-6], [17], [-38], [-15], [6], [-4], [15], [-8], [-43], [-7], [20], [2], [10], [-16], [3], [-28], [-24], [18], [-3], [-5], [-16], [-18], [-14], [17], [-19], [-34], [4], [-24], [28], [17], [3], [-6], [10], [-8], [-44], [25], [42], [6], [-48], [-4], [19], [22], [-27], [-44], [-46], [35], [4], [32], [28], [-27], [5], [18], [-4], [4], [7], [21], [3], [46], [-44], [27], [-13], [0], [32], [-55], [44], [-24], [-25], [52], [-6], [18], [49], [11], [1], [42], [46], [-18], [-16], [40], [27], [-28], [-48], [1], [48], [17], [-20], [-9], [31], [15], [6], [56], [51], [-36], [9], [28], [-29], [-2], [-16], [-44], [34], [30], [-49], [-18], [56], [11], [28], [58], [10], [36], [-37], [66], [16], [-23], [-54], [60], [44], [15], [39], [-60], [-23], [-12], [-12], [37], [-56], [54], [-20], [-58], [-5], [36], [64], [15], [-7], [-22], [45], [-10], [42], [-35], [-5], [-33], [8], [20], [-1], [-30], [32], [-34], [-60], [12], [35], [40], [-34], [-44], [42], [63], [-32], [36], [-51], [-36], [-24], [-34], [54], [36], [-47], [22], [-44], [49], [46], [22], [29], [78], [3], [-74], [0], [43], [-14], [60], [-40], [38], [62], [-19], [12], [30], [35], [26], [-71], [40], [62], [-13], [-16], [-52], [39], [-18], [22], [-30], [9], [-30], [-60], [26], [-64], [62], [54], [-48], [39], [-26], [42], [-11], [78], [55], [-16], [-12], [63], [-28], [-27], [-59], [48], [9], [-62], [-18], [20], [59], [-66], [-67], [-28], [-72], [5], [81], [-48], [-66], [-33], [-27], [-38], [8], [73], [-33], [-57], [-30], [81], [28], [-40], [-13], [-16], [72], [-71], [-23], [26], [0], [-70], [-39], [2], [-89], [8], [7], [14], [35], [58], [5], [-48], [-2], [-26], [45], [12], [-64], [36], [-43], [38], [33], [-8], [63], [60], [10], [-46], [-27], [-30], [29], [93], [-42], [16], [-8], [-67], [-72], [25], [70], [-44], [72], [-66], [-31], [-69], [12], [-14], [-63], [45], [-32], [-41], [-93], [2], [9], [16], [22], [30], [-58], [-14], [-21], [-8], [88], [-10], [-24], [-42], [30], [20], [4], [-86], [-71], [14], [-35], [-18], [68], [15], [67], [72], [-58], [-68], [37], [-40], [-52], [82], [78], [-27], [72], [-42], [16], [-45], [68], [-34], [-37], [14], [-96], [86], [-2], [-14], [-36], [43], [38], [2], [62], [6], [-53], [16]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6480_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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