
// Make newform 2808.2.a.q in Magma, downloaded from the LMFDB on 06 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2808_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_2808_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_2808_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 := [-6, 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_2808_a();"
function MakeCharacter_2808_a()
    N := 2808;
    order := 1;
    char_gens := [703, 1405, 2081, 1081];
    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_2808_a_Hecke(Kf)
    return MakeCharacter_2808_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]];
    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], [0, 0], [-1, 1], [2, 0], [-2, 0], [-1, 0], [0, -2], [-2, -2], [-2, 0], [-6, 0], [2, 2], [2, -2], [-4, -2], [-1, -2], [-3, -1], [0, 0], [-9, 1], [-3, 2], [0, 2], [1, 5], [4, 0], [0, 4], [5, 1], [5, -3], [-4, 6], [4, 6], [13, -2], [-10, -2], [-8, 4], [2, -2], [7, 0], [-12, -2], [-12, -2], [9, 2], [-13, -1], [4, 4], [-11, 0], [4, 8], [-7, 5], [0, 4], [-6, -6], [-11, -4], [4, -2], [-8, 2], [-7, 5], [3, -4], [13, 0], [4, -6], [-1, -1], [-6, 6], [4, 2], [6, -8], [-16, -4], [2, 2], [-22, 0], [20, -4], [-2, 2], [-4, 6], [3, -4], [5, -5], [1, -8], [-24, -2], [-2, 0], [-4, 4], [3, 10], [28, 2], [-6, 8], [3, -10], [6, 0], [-6, -2], [17, 7], [-15, 9], [24, -4], [-13, -10], [-6, -8], [-6, -4], [18, 2], [-20, 2], [9, -7], [14, -10], [0, 2], [-10, 2], [19, -3], [-2, 4], [1, 14], [30, 0], [3, 9], [16, -6], [-3, -11], [-12, 2], [4, -10], [3, 1], [-34, 4], [-12, -6], [12, 8], [8, 6], [-19, 1], [12, 2], [-19, 2], [-24, 2], [-24, 4], [4, 6], [-12, 6], [-8, -8], [7, -8], [34, 0], [6, -8], [-4, -10], [28, -2], [-21, -2], [-16, 0], [24, 0], [-7, 11], [4, -4], [6, -8], [2, -8], [28, -2], [-30, 2], [24, -8], [10, -2], [-4, 6], [3, -4], [12, -6], [33, -7], [-2, -2], [20, 10], [-14, 6], [24, 10], [-8, 4], [-20, 2], [-2, -12], [-31, -7], [8, -12], [2, -4], [-3, 7], [-2, 20], [15, -1], [36, -4], [2, -10], [-12, 16], [-16, 0], [16, 6], [-11, 14], [-22, -12], [-3, -10], [-21, 11], [-14, -4], [18, 4], [20, 0], [23, 3], [-16, -8], [-36, 8], [-12, -12], [0, -16], [-35, 4], [32, -2], [-15, 0], [-8, 18], [13, -6], [20, -10], [-21, 9], [42, -4], [-28, -6], [6, -16], [-21, -3], [-22, -8], [25, -6], [-1, 16], [14, -10], [6, -6], [-9, -9], [-42, -4], [34, 4], [24, 6], [-1, 2], [6, 16], [-22, -10], [-21, 11], [-23, 2], [-38, -8], [-20, -8], [50, 4], [-25, -10], [-23, 13], [-15, -5], [-42, -2], [5, 12], [-4, 6], [6, 4], [-6, -20], [23, 12], [-35, -9], [-1, 6], [-35, -5], [2, 24], [-42, 0], [32, 2], [11, 22], [-63, 1], [-8, 12], [7, -11], [1, 18], [-14, 12], [35, 0], [-37, -13], [-6, -24], [-8, -6], [-10, 4], [-33, -3], [41, -4], [38, -4], [32, 8], [39, 8], [-11, -9], [15, -11], [40, -2], [8, 0], [24, 16], [-42, -4], [-45, -1], [17, 8], [-26, -6], [52, 2], [10, 4], [-24, 4], [-18, -12], [8, 8], [-2, 12], [-41, 0], [-29, 3], [6, -12], [-13, 2], [0, 22], [42, -2], [-7, -14], [-10, -8], [-44, -10], [57, 3], [24, -8], [-6, 18], [21, -21], [-28, -12], [-16, -20], [4, 20], [-36, -10], [6, -10], [44, -6], [43, -3], [20, -18], [-64, 2], [32, -4], [-12, -6], [10, 24], [14, 24], [-12, 22], [-19, 5], [-7, -6], [-54, -2], [-20, 12], [-42, -4], [65, -4], [-54, 2], [6, -16], [2, -12], [-31, -19], [7, 12], [24, -18], [15, 15], [54, -4], [-6, 24], [50, 8], [-38, -6], [6, 2], [-5, -22], [73, 2], [16, -8], [-9, -13], [6, -20], [14, 10], [-42, -12], [-6, 32], [-40, 12], [18, -6], [-8, -4], [-34, 2], [42, -12], [-37, -14], [7, 3], [24, 12], [30, -14], [36, 0], [0, 8], [-4, -2], [-2, 20], [10, 16], [36, -10], [64, -4], [-42, -6], [-28, 4], [14, 18], [-43, 8], [-3, 5], [-9, 6], [30, 12], [-53, -2], [-10, -2], [-16, 26], [-10, 24], [-6, 32], [-26, -16], [-6, 0], [-68, -6], [48, -10], [9, -8], [-23, -5], [-47, -14], [-18, 4], [75, -5], [-4, -26], [0, -6], [1, 22], [46, 2], [48, 10], [8, 18], [-39, -15], [-17, 6], [68, -8], [-12, 8], [60, 2], [38, -6], [4, 18], [-18, 0], [64, -4], [-30, -20], [-14, -12], [10, 0], [-54, -10], [-9, 15], [-22, 6], [16, -8], [-58, -4], [-42, -10], [5, 11], [3, -22], [16, 10], [40, -12], [-59, -2], [-42, 10], [6, -24], [-14, 14], [14, 0], [10, -2], [59, -1], [7, 0], [11, -2], [-28, -16], [-23, -3], [31, 13], [46, -14], [43, 1], [20, -22], [78, 6], [-42, -4], [15, 17], [36, 4], [-59, -8], [-64, -10], [6, -18], [-29, -16], [74, 2], [67, -6], [-34, -12], [32, 12], [7, -28], [-11, 12], [21, 5], [22, 12], [6, -18], [-6, 10], [25, -12], [0, 30], [-19, -5], [-4, -10], [15, 17], [82, -6], [58, -12], [24, 6], [33, -14], [26, -22], [-14, 2], [18, -22], [51, -17], [26, -12], [37, 8], [41, 19], [30, 16], [50, 14], [60, -10], [-1, 12], [45, -15], [-52, -16], [-10, -12], [-20, -32], [-72, 6], [-24, 18], [32, 12], [80, 8], [-25, -3], [50, 10], [-47, -17], [-67, -8], [16, -22], [24, 10], [64, -12], [27, 4], [-20, 2], [17, 21], [11, 20], [27, 25], [-12, -30], [80, -6], [-16, -2], [9, 39], [-42, 18], [-82, -6], [0, -14], [-20, 6], [-5, -7], [34, 20], [18, -22]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2808_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2808_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_2808_2_a_q(:prec:=2)
    chi := MakeCharacter_2808_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_2808_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_2808_2_a_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2808_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-5, 2, 1]>,<7,R![-2, 1]>,<11,R![2, 1]>],Snew);
    return Vf;
end function;