
// Make newform 2720.2.a.c in Magma, downloaded from the LMFDB on 19 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_2720_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_2720_2_a_c();".
// 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_2720_2_a_c();".
// 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_2720_a();"
function MakeCharacter_2720_a()
    N := 2720;
    order := 1;
    char_gens := [511, 1701, 2177, 1601];
    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_2720_a_Hecke( : Kf := Kf)
    return MakeCharacter_2720_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], [0], [5], [1], [3], [-2], [-3], [-7], [-8], [-2], [10], [3], [-1], [-1], [11], [14], [13], [-7], [16], [0], [-9], [-5], [18], [0], [4], [11], [-13], [13], [6], [18], [0], [-20], [18], [18], [-16], [-18], [14], [4], [14], [0], [14], [8], [15], [14], [-7], [-19], [-2], [11], [-14], [10], [20], [-2], [15], [-1], [12], [-6], [19], [13], [7], [-4], [24], [2], [-12], [-11], [-23], [7], [-28], [-26], [6], [-14], [-26], [4], [-23], [24], [20], [-24], [5], [-22], [8], [-8], [-18], [8], [-32], [8], [6], [2], [27], [36], [-33], [-38], [-3], [6], [0], [24], [-24], [-38], [2], [31], [-3], [-10], [3], [14], [24], [-22], [-6], [38], [16], [6], [-35], [3], [34], [44], [-26], [-20], [33], [26], [-27], [4], [37], [26], [-45], [8], [32], [-39], [-35], [19], [26], [-23], [-14], [-13], [-31], [-42], [-15], [-2], [31], [-6], [10], [-2], [15], [-14], [-52], [48], [15], [-22], [3], [-45], [16], [-20], [-26], [-10], [-22], [-15], [-16], [-38], [30], [56], [17], [-59], [-24], [8], [15], [28], [-46], [49], [-38], [-48], [34], [63], [50], [-3], [-38], [10], [60], [30], [-27], [-9], [-8], [3], [-6], [40], [64], [56], [8], [-40], [6], [-4], [-12], [6], [21], [67], [-28], [-19], [-6], [-40], [-56], [-35], [9], [-54], [-11], [-38], [-7], [-20], [-2], [-40], [-40], [-8], [-19], [-29], [-12], [44], [-2], [45], [24], [33], [-39], [-18], [57], [-18], [35], [-38], [50], [42], [4], [-57], [-19], [43], [-52], [21], [-18], [22], [5], [26], [56], [-56], [8], [38], [68], [49], [-44], [-32], [-60], [-27], [-33], [54], [-66], [24], [-3], [13], [-20], [-47], [46], [9], [57], [37], [-20], [-14], [34], [-58], [-76], [38], [-48], [39], [60], [18], [-5], [17], [-26], [79], [-48], [80], [32], [26], [47], [-36], [48], [-5], [75], [40], [-63], [30], [-52], [-84], [-42], [11], [-80], [-32], [15], [45], [-33], [-44], [40], [14], [-45], [-26], [-7], [-4], [22], [-52], [43], [-61], [-15], [34], [58], [-22], [-41], [26], [47], [-48], [30], [80], [80], [-71], [35], [57], [-48], [-2], [-81], [4], [-57], [-36], [24], [15], [-7], [-52], [49], [-64], [26], [-10], [-50], [0], [46], [40], [-12], [-30], [42], [14], [-48], [-19], [-50], [25], [2], [-54], [-14], [-14], [74], [73], [62], [-52], [-42], [32], [-26], [-68], [-60], [-4], [-90], [-2], [-31], [-22], [-48], [-60], [92], [-62], [-68], [30], [-1], [-34], [45], [-42], [-78], [30], [-88], [36], [24], [-93], [44], [-85], [-70], [99], [-88], [-30], [65], [44], [34], [-26], [42], [-43], [-92], [16], [24], [-21], [48], [-54], [-90], [28], [-86], [-90], [46], [14], [-14], [-31], [41], [-40], [68], [-75], [2], [42], [2], [97], [-15], [-18], [76], [22], [45], [-64], [30], [-39], [-27], [-62], [48], [-82], [-19], [73], [3], [24], [-74], [-21], [72]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2720_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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