
// Make newform 7280.2.a.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7280_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_7280_2_a_a();".
// 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_7280_2_a_a();".
// 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_7280_a();"
function MakeCharacter_7280_a()
    N := 7280;
    order := 1;
    char_gens := [911, 5461, 1457, 4161, 561];
    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_7280_a_Hecke(Kf)
    return MakeCharacter_7280_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], [-2], [-1], [-1], [-6], [-1], [-2], [-2], [2], [10], [6], [6], [-2], [-10], [0], [14], [2], [2], [-8], [10], [2], [-4], [4], [-2], [14], [-18], [14], [-18], [-10], [-6], [22], [-12], [-10], [-16], [14], [-2], [-22], [-24], [-16], [18], [4], [-22], [8], [22], [18], [-16], [12], [8], [24], [26], [18], [6], [-10], [0], [6], [6], [-10], [18], [-26], [10], [-14], [14], [-12], [-12], [-26], [14], [6], [-6], [22], [-14], [2], [34], [30], [-26], [2], [-32], [-26], [-2], [-6], [-26], [-24], [-26], [10], [-2], [-32], [10], [-22], [-18], [-6], [36], [14], [-34], [-20], [8], [10], [-6], [26], [-10], [6], [30], [22], [14], [-22], [-42], [8], [42], [-24], [-18], [4], [-22], [-10], [-22], [30], [34], [38], [-30], [20], [50], [22], [-40], [-14], [-6], [-46], [-16], [10], [-2], [-18], [-32], [42], [-30], [-26], [24], [20], [-10], [-10], [-10], [6], [-28], [42], [-34], [-14], [30], [-38], [12], [-30], [-18], [14], [38], [-24], [48], [10], [-18], [-18], [22], [26], [8], [4], [6], [30], [42], [4], [-38], [-4], [-12], [2], [12], [24], [-38], [-46], [-6], [-46], [-54], [4], [10], [-24], [-14], [-6], [30], [-34], [-26], [16], [0], [14], [22], [-12], [-22], [54], [-4], [10], [50], [-34], [-20], [36], [50], [34], [6], [26], [6], [18], [18], [-42], [8], [-54], [-50], [-30], [-30], [-14], [34], [26], [16], [26], [-54], [14], [-52], [18], [-42], [-46], [2], [4], [-6], [58], [-34], [26], [8], [6], [58], [54], [12], [-22], [-30], [30], [56], [-14], [-6], [-58], [12], [-10], [6], [12], [0], [12], [-32], [-38], [30], [-18], [-40], [-40], [-10], [26], [-14], [-34], [6], [-56], [58], [2], [30], [42], [-56], [26], [-78], [-38], [-2], [-14], [34], [18], [32], [6], [6], [0], [-10], [70], [-32], [-10], [32], [-74], [-56], [-8], [-74], [42], [48], [-54], [-74], [-82], [-38], [-20], [12], [26], [18], [-50], [-50], [18], [-14], [22], [-58], [22], [-34], [-48], [-78], [-40], [-20], [22], [18], [72], [50], [4], [-30], [-14], [70], [-70], [-58], [50], [-10], [-82], [-38], [-24], [54], [6], [26], [42], [18], [-16], [-86], [34], [-4], [42], [-50], [22], [92], [-26], [-34], [-66], [62], [-4], [-24], [-74], [48], [-26], [-34], [-10], [-78], [-54], [58], [50], [-12], [18], [-60], [-42], [60], [-6], [10], [82], [-10], [46], [46], [-42], [-50], [-66], [82], [42], [-64], [-26], [54], [-78], [2], [94], [10], [82], [-92], [-22], [36], [76], [-84], [-30], [16], [-34], [22], [12], [-50], [46], [-82], [50], [74], [32], [-78], [-30], [-20], [74], [34], [4], [78], [-70], [54], [54], [-78], [30], [-86], [-14], [54], [-92], [-98], [34], [-62], [64], [42], [-86], [0], [-18], [-14], [80], [-54], [14], [14], [-6], [8], [-22], [-18], [-58], [-2], [-94], [38], [34], [74], [60], [0], [-58], [6], [-98], [66], [-34], [68]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7280_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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