
// Make newform 2760.2.a.f in Magma, downloaded from the LMFDB on 25 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_f();".
// 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_f();".
// 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], [1], [0], [-4], [-1], [0], [1], [-7], [-7], [-3], [-5], [12], [-6], [3], [7], [2], [-3], [-3], [-4], [-12], [3], [0], [-18], [-15], [16], [15], [4], [3], [-6], [12], [-2], [-21], [6], [0], [7], [-6], [-6], [-24], [-8], [-8], [-6], [-16], [-6], [-10], [-7], [-10], [-20], [-24], [12], [11], [0], [2], [-6], [17], [15], [11], [-2], [20], [27], [21], [8], [-24], [-9], [6], [25], [-2], [-12], [-29], [30], [2], [-5], [-10], [0], [9], [26], [36], [-10], [17], [-24], [28], [8], [-19], [-16], [42], [1], [-21], [18], [4], [15], [-14], [22], [17], [-5], [21], [-34], [28], [4], [-26], [-28], [19], [33], [6], [-18], [28], [-30], [6], [20], [-33], [-10], [34], [29], [44], [-34], [32], [37], [-8], [16], [-8], [-10], [-38], [-3], [-14], [8], [18], [-14], [-25], [39], [49], [21], [16], [20], [-25], [27], [-14], [-10], [-11], [-11], [-11], [41], [-42], [0], [9], [-15], [-22], [-42], [-10], [-43], [-34], [-38], [46], [42], [-18], [37], [-36], [-4], [37], [30], [34], [-4], [6], [-34], [-24], [-11], [-49], [-19], [32], [52], [-6], [36], [49], [-10], [-7], [-64], [-38], [-20], [17], [19], [-20], [28], [14], [-30], [-40], [-63], [-28], [28], [-5], [25], [-47], [32], [14], [-52], [23], [-40], [-19], [-4], [-14], [34], [54], [-6], [48], [4], [4], [30], [-66], [-34], [28], [59], [8], [2], [10], [16], [-28], [3], [22], [-2], [27], [-31], [-8], [-15], [-50], [45], [-25], [-52], [39], [-18], [-45], [-36], [-27], [-44], [-36], [22], [9], [-47], [-12], [-10], [30], [-1], [9], [23], [25], [18], [-18], [-56], [0], [22], [-56], [30], [51], [66], [-18], [33], [14], [-36], [75], [26], [48], [-48], [-30], [59], [-79], [-33], [47], [-12], [46], [38], [-78], [19], [-24], [-63], [-47], [-11], [-2], [-14], [-28], [-14], [-27], [-10], [38], [26], [-10], [36], [-12], [8], [13], [73], [-74], [-24], [30], [10], [45], [-52], [-58], [10], [60], [-28], [-36], [9], [42], [-57], [-53], [-12], [-34], [-16], [58], [-48], [18], [-54], [-26], [-36], [-24], [62], [52], [9], [-10], [59], [3], [-19], [50], [2], [-17], [-14], [34], [51], [10], [-34], [64], [0], [69], [35], [-40], [55], [0], [56], [16], [78], [-70], [-38], [1], [-46], [-18], [-58], [50], [-55], [93], [25], [-52], [-54], [29], [59], [58], [-79], [-53], [22], [-50], [8], [-86], [-64], [2], [25], [55], [-10], [-8], [2], [-34], [54], [45], [-92], [-51], [-35], [10], [-88], [32], [-60], [95], [2], [-31], [100], [-34], [-70], [6], [68], [4], [76], [46], [-23], [-6], [101], [-13], [-24], [46], [9], [-46], [-24], [-63], [-66], [-72], [-4], [-33], [-13], [90], [67], [-71], [25], [19], [-57], [6], [32], [76], [-98], [-88], [68], [-56], [59], [90], [4], [22], [-21], [-88], [-72], [74], [76], [60], [-34], [-68], [40], [45], [-12], [97]];
    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_f();".
// 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_f(: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_f();".
// 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_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2760_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-1, 1]>,<11,R![0, 1]>],Snew);
    return Vf;
end function;