
// Make newform 2960.2.a.l in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2960_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_2960_2_a_l();".
// 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_2960_2_a_l();".
// 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_2960_a();"
function MakeCharacter_2960_a()
    N := 2960;
    order := 1;
    char_gens := [2591, 741, 1777, 2481];
    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_2960_a_Hecke(Kf)
    return MakeCharacter_2960_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], [-2], [0], [-6], [-2], [-6], [4], [-2], [6], [1], [-6], [-8], [6], [-10], [-14], [6], [14], [-8], [-6], [14], [-2], [-6], [2], [-14], [16], [18], [-2], [-18], [-2], [10], [18], [-12], [2], [-4], [-18], [-4], [8], [6], [-2], [26], [10], [2], [6], [-14], [-12], [-14], [12], [6], [-6], [-2], [18], [18], [30], [-18], [10], [8], [-14], [-6], [-4], [-26], [-26], [-18], [26], [-26], [-26], [-6], [24], [10], [2], [-12], [14], [-10], [-8], [20], [6], [-2], [-38], [-22], [16], [-10], [30], [10], [-14], [-22], [-6], [-6], [14], [12], [-12], [6], [-32], [-12], [-26], [-12], [30], [-2], [40], [22], [-32], [-22], [16], [-46], [-44], [30], [-16], [42], [12], [6], [-4], [14], [18], [4], [-2], [-2], [-4], [12], [46], [4], [-34], [10], [-18], [16], [40], [-34], [-2], [-20], [28], [46], [-52], [-10], [20], [22], [26], [10], [6], [-46], [-6], [-38], [4], [-10], [18], [12], [-2], [0], [22], [26], [-22], [-6], [46], [-58], [-12], [-30], [12], [-14], [26], [18], [2], [-46], [20], [-54], [-24], [-20], [34], [22], [30], [-26], [38], [-42], [30], [-34], [46], [-54], [40], [-14], [10], [-30], [-26], [-34], [-28], [42], [-22], [58], [46], [-10], [-58], [16], [-14], [44], [6], [22], [-14], [30], [-42], [66], [18], [-62], [26], [-24], [-18], [-48], [62], [-50], [-16], [18], [-64], [42], [-54], [60], [38], [-2], [68], [-54], [18], [-10], [12], [-46], [-40], [54], [-22], [-48], [-18], [-20], [-10], [-10], [-38], [12], [-14], [-18], [-74], [-56], [-52], [-54], [10], [-42], [-14], [-46], [-62], [-42], [-24], [34], [2], [54], [50], [-2], [-32], [-2], [-44], [24], [2], [-2], [22], [-22], [-18], [4], [-58], [-42], [-66], [-22], [52], [-40], [-58], [-58], [-74], [64], [-54], [-54], [-22], [26], [62], [52], [-10], [50], [26], [66], [54], [22], [74], [-42], [26], [-58], [-26], [-26], [4], [-20], [-26], [14], [-30], [66], [54], [-64], [34], [12], [-42], [62], [-28], [78], [78], [-22], [-70], [-2], [20], [80], [6], [-18], [-16], [-58], [64], [-86], [-66], [18], [-18], [-78], [-12], [-46], [-28], [70], [18], [-22], [-2], [-22], [-42], [-22], [-46], [-46], [0], [60], [52], [22], [-18], [30], [-2], [24], [2], [34], [-50], [-6], [82], [74], [54], [-78], [-2], [34], [-2], [26], [38], [-46], [-2], [78], [56], [-78], [94], [-8], [58], [26], [-54], [22], [18], [-8], [50], [42], [88], [42], [-42], [-22], [82], [72], [-22], [-14], [-14], [-82], [-78], [10], [-74], [0], [24], [-14], [90], [74], [-42], [-34], [-92], [58], [-58], [-18], [-56], [22], [64], [-32], [2], [-26], [-54], [68], [8], [34], [58], [10], [-40], [54], [-30], [2], [68], [42], [30], [-64], [14], [-30], [-30], [-24], [-86], [-34], [84], [-102], [-54], [-14], [0], [38], [-30], [12], [6], [22], [-102], [64], [2], [6], [-94], [106], [88], [34]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2960_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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