
// Make newform 2760.2.a.j in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2760_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_2760_2_a_j();".
// 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_2760_2_a_j();".
// 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_2760_a();"
function MakeCharacter_2760_a()
    N := 2760;
    order := 1;
    char_gens := [2071, 1381, 1841, 1657, 1201];
    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_2760_a_Hecke(Kf)
    return MakeCharacter_2760_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], [1], [1], [-3], [-4], [0], [3], [-4], [1], [1], [1], [1], [3], [-12], [-10], [-9], [-9], [-10], [1], [5], [0], [4], [-9], [-8], [-10], [-15], [0], [11], [0], [-9], [-2], [4], [14], [-5], [2], [16], [3], [10], [22], [8], [-24], [8], [-18], [16], [26], [6], [9], [14], [-4], [8], [-4], [-21], [4], [10], [-26], [-3], [-9], [27], [-2], [-16], [-1], [25], [-4], [-16], [-5], [2], [17], [14], [-12], [11], [2], [-18], [-17], [22], [-8], [-27], [-30], [20], [22], [17], [-36], [8], [-16], [9], [40], [-10], [-15], [-25], [-22], [32], [-13], [-2], [34], [9], [-29], [-7], [-2], [0], [-4], [-18], [-36], [15], [37], [6], [-6], [-4], [2], [18], [20], [-1], [-38], [34], [41], [-4], [26], [12], [-23], [36], [-4], [4], [-18], [-2], [41], [-26], [-8], [-42], [-34], [-9], [-5], [-11], [53], [32], [32], [19], [35], [-42], [-18], [25], [-23], [-27], [17], [-10], [0], [-3], [-47], [34], [14], [14], [-35], [-34], [-14], [26], [22], [30], [49], [-12], [-52], [21], [-42], [-26], [-36], [-26], [42], [-48], [1], [-37], [13], [-48], [4], [6], [-44], [25], [30], [-19], [0], [14], [52], [25], [47], [-8], [32], [26], [-14], [-12], [13], [-24], [40], [-49], [-31], [17], [28], [-42], [48], [-17], [-48], [49], [-64], [26], [2], [-66], [-50], [-16], [16], [0], [-30], [-10], [-14], [-24], [-21], [-8], [-38], [-30], [-16], [28], [51], [-6], [-58], [11], [-27], [12], [-55], [-50], [-59], [67], [32], [39], [54], [51], [4], [45], [-40], [-16], [14], [1], [-43], [60], [-22], [-34], [-73], [25], [-37], [-47], [-70], [-10], [-16], [0], [-62], [-60], [-50], [-49], [-54], [-42], [-3], [22], [56], [27], [62], [56], [-68], [-38], [31], [21], [31], [-45], [12], [34], [-6], [42], [-1], [-48], [-15], [13], [-47], [22], [70], [-16], [-42], [77], [58], [-30], [42], [2], [12], [20], [-44], [13], [-51], [54], [0], [38], [26], [49], [-84], [66], [-10], [-12], [-32], [-48], [9], [82], [19], [39], [-84], [42], [40], [-2], [44], [-22], [54], [2], [60], [-44], [-62], [-44], [29], [18], [-21], [-37], [1], [34], [-66], [3], [-14], [26], [87], [-26], [2], [28], [-64], [-39], [-13], [-12], [71], [-36], [16], [-48], [38], [-78], [18], [-3], [26], [-50], [30], [-90], [21], [-19], [65], [72], [-30], [73], [75], [86], [1], [-49], [34], [14], [-36], [-30], [-4], [34], [-35], [-33], [30], [-8], [26], [-42], [-14], [1], [36], [37], [-43], [74], [-40], [16], [32], [63], [66], [-43], [-36], [14], [-38], [46], [-76], [40], [-52], [-50], [-55], [14], [41], [-17], [68], [-50], [-79], [22], [68], [-11], [-2], [72], [-12], [-57], [19], [-94], [103], [93], [-87], [35], [-101], [78], [-88], [68], [-86], [52], [68], [-8], [63], [-22], [-60], [10], [31], [-80], [-44], [-78], [64], [84], [82], [60], [-32], [-59], [-100], [17]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2760_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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