
// Make newform 3480.2.a.k in Magma, downloaded from the LMFDB on 27 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_3480_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_3480_2_a_k();".
// 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_3480_2_a_k();".
// 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_3480_a();"
function MakeCharacter_3480_a()
    N := 3480;
    order := 1;
    char_gens := [871, 1741, 2321, 697, 2641];
    v := [1, 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_3480_a_Hecke( : Kf := Kf)
    return MakeCharacter_3480_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], [1], [-1], [-2], [3], [-6], [4], [-2], [1], [1], [0], [-3], [-5], [-1], [2], [1], [-12], [-12], [2], [-6], [7], [-8], [-9], [-10], [5], [-11], [-14], [4], [-1], [12], [17], [-20], [12], [3], [-6], [-9], [-2], [5], [-8], [-15], [-10], [5], [-13], [-6], [1], [-3], [6], [0], [-3], [18], [-1], [6], [-7], [4], [27], [-24], [18], [14], [-8], [-4], [-14], [16], [25], [-17], [-8], [32], [-8], [-2], [-27], [19], [6], [23], [-23], [-4], [4], [-31], [3], [2], [24], [16], [2], [30], [22], [-5], [-8], [24], [5], [28], [35], [-26], [-14], [0], [-24], [-28], [-40], [-6], [-42], [-14], [-24], [2], [-20], [1], [-42], [-26], [19], [34], [-12], [-14], [-4], [44], [24], [-10], [34], [-10], [40], [21], [12], [15], [18], [-13], [-5], [50], [12], [-15], [-20], [-14], [-5], [36], [-28], [-34], [40], [30], [48], [15], [-4], [-24], [22], [36], [-14], [-21], [33], [-52], [32], [-2], [14], [56], [-5], [41], [-18], [-32], [28], [5], [28], [18], [13], [13], [-20], [12], [-4], [-26], [10], [6], [29], [7], [-23], [-6], [29], [-15], [-43], [18], [-20], [-43], [-28], [1], [-13], [18], [3], [-63], [-33], [-25], [64], [-31], [64], [-33], [-24], [38], [-46], [-7], [52], [-36], [4], [24], [-14], [21], [-22], [-10], [52], [28], [51], [-23], [-61], [5], [-59], [14], [23], [9], [50], [-44], [54], [58], [-37], [50], [-29], [14], [5], [43], [-8], [-29], [-32], [6], [-40], [-19], [-45], [-25], [-17], [-8], [-42], [33], [-44], [-48], [-25], [-4], [68], [-26], [-36], [12], [-14], [-6], [-8], [67], [-60], [29], [-12], [-22], [19], [0], [-38], [0], [33], [-10], [22], [-66], [-14], [-28], [-38], [-60], [-20], [55], [54], [-64], [52], [44], [7], [-79], [-64], [-68], [-13], [19], [-41], [-19], [62], [-60], [70], [-44], [-33], [21], [42], [-30], [60], [-30], [-9], [55], [55], [-14], [-17], [-36], [30], [-40], [-32], [-30], [-44], [-27], [-3], [-20], [-29], [14], [-56], [39], [30], [11], [7], [62], [-14], [-6], [36], [32], [26], [-54], [-14], [62], [-52], [-15], [74], [-2], [-64], [43], [-29], [60], [-84], [-21], [-82], [-30], [-42], [45], [22], [-24], [-29], [-64], [90], [-1], [-20], [26], [73], [-4], [-68], [-1], [66], [36], [58], [-90], [7], [-3], [-59], [-19], [-53], [-65], [20], [28], [7], [42], [-76], [-86], [-54], [8], [-40], [-26], [-9], [-10], [-92], [85], [-58], [12], [30], [32], [76], [71], [0], [-22], [20], [-51], [17], [1], [-29], [-4], [-38], [15], [72], [69], [-60], [-10], [-9], [-77], [-57], [72], [29], [23], [32], [78], [-20], [32], [42], [25], [19], [1], [-95], [-78], [-35], [65], [5], [-41], [61], [24], [0], [23], [90], [-65], [-38], [15], [13], [-90], [84], [-42], [-35], [67], [-73], [-59], [39], [-58], [-18], [24], [104], [37], [-48], [65], [82], [3], [49], [90], [-29], [96]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3480_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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