
// Make newform 2760.2.a.q 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_q();".
// 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_q();".
// 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
        poly := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
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, 0], [1, 0], [1, 0], [-1, 0], [-2, 3], [-4, -1], [-3, -1], [0, -5], [-1, 0], [-3, 3], [-5, -4], [-3, 0], [-3, 1], [2, 0], [4, 1], [-5, -1], [-5, -5], [-6, 5], [5, 4], [-5, 5], [0, 11], [0, 4], [9, 5], [-8, -2], [-4, 2], [7, -3], [-2, -6], [-1, 3], [0, -13], [-5, 3], [10, 1], [0, 4], [8, -6], [11, -6], [-12, 1], [-6, 4], [-7, 6], [2, 4], [-4, -5], [0, -8], [-18, 4], [8, -10], [-4, -7], [16, -6], [-6, 14], [-2, 18], [13, -2], [-10, -12], [20, 0], [4, 2], [-24, 4], [1, -5], [8, -3], [10, -4], [0, -9], [17, 9], [-17, -1], [7, 12], [-6, -4], [2, 5], [1, -18], [-9, -17], [-4, -13], [-4, -12], [19, 0], [-12, 11], [11, 14], [2, 4], [16, -2], [-9, -2], [-20, 3], [-16, 3], [-5, -10], [-8, -12], [-12, -4], [19, 5], [-22, -10], [-16, 0], [-6, -6], [-3, -18], [18, 13], [-12, 19], [-8, 2], [27, -2], [-22, 14], [-8, -5], [-19, -9], [19, 0], [10, 6], [4, 17], [-9, -1], [0, -7], [-2, 5], [15, 7], [-7, -2], [-5, 21], [-4, 14], [2, -5], [36, -4], [36, 6], [-20, 8], [27, -1], [1, -3], [-10, 10], [18, 9], [12, -24], [14, 0], [0, -19], [0, -6], [-11, 8], [10, -17], [26, 16], [19, 7], [-4, 0], [-22, -7], [-14, -5], [29, 2], [-30, -9], [6, 31], [-6, -21], [10, 6], [6, 19], [1, -7], [32, 9], [22, -16], [0, -21], [30, 5], [-1, 1], [5, -10], [-27, 2], [11, -10], [-4, -16], [-24, -9], [-47, 0], [-21, 7], [-18, 1], [-6, -22], [9, 26], [5, -23], [7, -1], [-27, 2], [8, 22], [-16, -16], [-7, -17], [-21, 14], [-46, 4], [2, -6], [-26, 4], [9, 18], [-22, 10], [10, 2], [24, 1], [-2, 13], [-6, 6], [-15, 12], [-12, 12], [-4, 24], [-39, 13], [48, -2], [20, 11], [24, -18], [-46, -8], [-2, -23], [28, 18], [11, 21], [5, -3], [-27, 2], [8, -34], [0, 16], [-8, 23], [4, 32], [17, -8], [-18, -4], [11, 8], [-24, 4], [-4, -15], [-54, 6], [-7, -23], [-1, -8], [12, 13], [-36, -1], [-4, 15], [46, 10], [-10, 25], [-7, 1], [-2, -11], [12, 7], [-25, -20], [-41, 14], [-1, 25], [-24, -13], [10, -32], [12, -27], [25, 15], [42, -4], [-43, -15], [32, 13], [28, -14], [2, 8], [18, 8], [-4, -11], [-18, -28], [-4, -27], [4, 11], [12, -3], [18, -18], [-14, -13], [-2, -21], [-11, -35], [-58, -4], [-50, -10], [-22, -26], [18, -2], [-6, 28], [-25, 21], [18, -15], [-6, -18], [17, 29], [-35, 5], [2, 9], [-37, -18], [14, -38], [-11, -15], [-21, 0], [46, -1], [-17, -6], [-30, -6], [-31, 3], [-60, 4], [-1, -45], [-12, 3], [20, 25], [10, 6], [-51, 15], [-31, 30], [14, 8], [2, -5], [-14, 36], [11, 37], [9, -45], [-3, 11], [7, 20], [-14, 14], [36, 14], [12, 24], [-56, 2], [-22, 21], [-34, -3], [38, 10], [-11, 31], [-8, 42], [30, -28], [27, -27], [22, -6], [-42, 1], [-33, -9], [-2, 37], [-24, 4], [54, -7], [-58, 12], [-9, 2], [-15, 3], [-51, -10], [-23, 20], [44, 2], [42, -7], [16, -41], [-10, 24], [13, -18], [-36, -12], [-9, -28], [-3, -42], [-11, -16], [22, -24], [2, 37], [8, -13], [-8, -41], [-5, -32], [-14, -29], [16, -33], [6, -28], [-6, 35], [-40, 22], [-48, 4], [-8, 5], [13, -15], [-45, -12], [70, -4], [-6, 2], [-42, -18], [-14, 18], [-5, -21], [60, -10], [36, 7], [-38, 1], [8, -8], [-16, 25], [34, 19], [1, -9], [10, 12], [-19, -40], [-19, 7], [-32, 18], [-52, 21], [8, -4], [6, 3], [26, 11], [14, 52], [-32, 15], [-34, -27], [32, -20], [6, 53], [-8, -27], [-56, 8], [-13, 19], [50, 9], [7, 17], [13, -37], [27, 10], [48, 14], [38, 11], [-45, 4], [-2, 60], [42, -12], [-21, 43], [2, 39], [34, -21], [-60, 3], [36, 0], [-17, 3], [27, -14], [18, 3], [53, 16], [-18, -25], [4, -24], [-48, 0], [-18, 34], [34, -22], [24, -2], [41, 2], [-30, -14], [58, -24], [10, -34], [38, 29], [-27, -21], [31, 29], [-21, 38], [-20, 27], [42, -32], [-5, 1], [9, -32], [-14, 35], [35, 7], [31, 28], [42, 33], [-82, 0], [-38, 15], [10, -48], [10, -43], [-42, 18], [-27, 18], [-43, -7], [22, -10], [20, 38], [10, 42], [34, -6], [92, 5], [-23, 34], [28, -4], [-15, -13], [-1, -22], [-46, 28], [-20, -2], [12, 8], [48, 25], [-1, -15], [-30, -42], [-5, 14], [-44, 2], [18, 30], [38, 30], [-54, 6], [56, 0], [-10, 37], [-20, -2], [-50, -28], [-23, -20], [-50, -17], [55, 14], [37, -9], [72, -11], [18, -2], [31, -43], [-34, -7], [-6, -17], [-21, 50], [26, -6], [-32, 10], [-12, -8], [-7, 45], [51, 16], [-34, -24], [25, -36], [35, 25], [55, -9], [-39, 4], [27, 6], [26, -42], [-2, 32], [28, -24], [82, -1], [-46, 21], [44, -36], [0, 58], [13, -54], [-38, 12], [32, 22], [-30, 11], [-19, -7], [48, -18], [34, -15], [24, -18], [78, 17], [-32, 44], [2, -29], [-8, -32], [-60, 6], [-57, -15], [18, -6], [5, 37]];
    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_q();".
// 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_q(:prec:=2)
    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_q();".
// 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_q( : 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![-14, 4, 1]>],Snew);
    return Vf;
end function;