
// Make newform 2760.2.a.b 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_b();".
// 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_b();".
// 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], [-2], [2], [-1], [6], [-1], [3], [-3], [3], [-7], [0], [0], [-5], [9], [12], [3], [3], [2], [4], [7], [-16], [-6], [7], [8], [15], [-14], [19], [8], [-4], [-2], [15], [20], [4], [-7], [2], [-8], [12], [0], [20], [24], [12], [-2], [10], [13], [22], [12], [-20], [12], [5], [-14], [6], [8], [1], [-15], [-5], [14], [-30], [29], [1], [18], [-24], [1], [0], [1], [2], [-16], [-25], [24], [8], [-23], [-26], [-32], [9], [-14], [8], [2], [-11], [-30], [-10], [-32], [-5], [0], [-12], [11], [29], [14], [-10], [7], [-4], [-16], [-13], [-13], [-11], [-22], [-14], [4], [-10], [0], [-37], [9], [26], [28], [8], [-10], [24], [-16], [3], [28], [14], [-39], [40], [20], [30], [7], [-2], [2], [-30], [-14], [28], [-3], [-16], [12], [-48], [-8], [-3], [-31], [19], [-19], [24], [-22], [-19], [13], [-32], [14], [23], [-35], [31], [5], [-6], [-4], [-3], [-7], [-2], [-42], [-18], [25], [-46], [22], [12], [-20], [-34], [-37], [-12], [-16], [51], [-38], [28], [-12], [10], [20], [-20], [45], [51], [-31], [8], [16], [0], [24], [9], [62], [11], [-48], [36], [52], [15], [13], [46], [22], [36], [10], [-30], [-31], [-26], [38], [-19], [-55], [-17], [38], [14], [-38], [-7], [-24], [37], [-46], [30], [-18], [-34], [52], [44], [18], [-14], [32], [-6], [-68], [22], [-31], [-20], [42], [-18], [-56], [-20], [-23], [-28], [-46], [57], [-63], [18], [-63], [-14], [51], [-31], [46], [-29], [30], [-51], [-4], [63], [30], [38], [-62], [3], [-53], [4], [-20], [26], [29], [35], [23], [37], [38], [-66], [-44], [28], [-4], [26], [26], [-21], [-18], [-6], [-39], [-34], [-6], [-3], [-72], [32], [-54], [-14], [25], [21], [31], [45], [48], [-40], [4], [-30], [-67], [16], [13], [-13], [-53], [34], [60], [34], [-60], [-55], [72], [32], [70], [-72], [-56], [-48], [58], [-53], [-61], [18], [40], [26], [-62], [-15], [56], [20], [-84], [60], [-34], [30], [-13], [86], [13], [-77], [60], [76], [68], [20], [14], [26], [4], [76], [16], [-2], [48], [-8], [-11], [-32], [9], [-3], [11], [78], [20], [-55], [-30], [-54], [-69], [-40], [-20], [-86], [-48], [-87], [-41], [38], [91], [-38], [-12], [-12], [70], [18], [-38], [-13], [-14], [-38], [50], [-48], [-27], [-45], [89], [-14], [-50], [-3], [-49], [-52], [-29], [-19], [-68], [6], [30], [-58], [-22], [-2], [-29], [-91], [18], [64], [-38], [10], [-12], [23], [-76], [-17], [-59], [74], [-20], [-4], [18], [61], [-54], [-25], [-36], [-22], [-18], [-58], [-92], [-82], [-88], [-46], [41], [-84], [-21], [-77], [-34], [18], [39], [-28], [30], [79], [62], [24], [-80], [-3], [-21], [38], [-31], [9], [3], [79], [-51], [-30], [92], [4], [-76], [-42], [-84], [92], [-67], [-30], [0], [-56], [-57], [36], [-34], [14], [-18], [84], [12], [68], [-12], [11], [-76], [47]];
    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_b();".
// 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_b(: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_b();".
// 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_b( : 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![2, 1]>],Snew);
    return Vf;
end function;