
// Make newform 7800.2.a.bp in Magma, downloaded from the LMFDB on 17 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7800_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_7800_2_a_bp();".
// 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_7800_2_a_bp();".
// 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, -6, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-4, -1, 1], [3, 3, -1]];
    Rf_basisdens := [1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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_7800_a();"
function MakeCharacter_7800_a()
    N := 7800;
    order := 1;
    char_gens := [1951, 3901, 5201, 7177, 4201];
    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_7800_a_Hecke(Kf)
    return MakeCharacter_7800_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, 0], [1, 0, 0], [0, 0, 0], [0, 0, 0], [-2, -1, 0], [1, 0, 0], [-1, 1, 1], [-1, -1, -1], [-3, 1, 1], [-4, 0, -2], [4, 2, 0], [2, 2, 0], [-3, -2, 1], [1, -1, -1], [-5, 2, 1], [-4, 0, -2], [-2, 3, 0], [1, -1, 1], [-2, 2, -2], [3, 0, 1], [-2, -4, 0], [7, 1, 1], [-1, -2, 1], [-7, -2, 1], [-6, 0, 0], [-10, -2, 0], [-4, 0, 2], [0, -2, 0], [-5, 1, -3], [1, 1, -1], [-11, -1, 1], [2, 0, 2], [-5, 2, 3], [2, -6, -2], [-4, 3, 0], [6, 4, 2], [-11, -5, 1], [-4, 2, 0], [-11, -2, -1], [-2, -4, -4], [6, -2, -2], [0, -6, -2], [-4, 0, -4], [6, 2, 4], [-5, -6, 3], [3, 1, 5], [-3, -1, -1], [-6, 4, 2], [7, 6, 1], [-3, -1, -1], [1, 5, -1], [1, -2, -1], [16, 0, 2], [2, -8, -2], [-13, -1, -3], [-7, 1, -7], [-14, 6, 4], [-2, -2, -6], [1, 3, 1], [7, -2, -5], [0, 4, 4], [-7, 4, -3], [-20, 0, 0], [-12, 2, 4], [-9, 3, 1], [3, 2, 3], [5, 3, 1], [-11, 1, -5], [6, -6, 2], [3, 3, 5], [-3, -4, 5], [11, -6, -3], [-6, -2, 4], [-8, -6, -2], [15, -1, -1], [11, -4, -3], [-14, 0, 0], [0, 4, 6], [-3, 8, -3], [4, -8, 2], [0, 6, 4], [17, 3, -1], [-1, 0, 5], [17, 5, -1], [20, -4, 4], [2, 8, -2], [1, 0, -7], [-20, -2, -2], [0, -1, 0], [-16, 0, 0], [-10, 0, 2], [17, -2, -1], [0, -6, -4], [0, 6, -4], [23, -3, 3], [11, 7, 3], [2, -3, 2], [-2, 6, 0], [-7, -5, -9], [9, -1, 3], [-3, 11, 7], [-21, 2, -9], [-18, -2, 2], [-16, -8, -2], [-3, -13, -1], [16, 4, -2], [9, 10, -1], [-17, 6, 3], [-4, 6, -4], [11, -7, 3], [-22, -2, 0], [4, 4, -2], [-11, -6, -3], [9, 7, -3], [4, -14, -4], [6, -4, 0], [2, -6, 2], [3, 1, -5], [-2, 0, 0], [30, -2, 6], [-3, 9, 7], [10, -10, 2], [-28, -4, 2], [-3, -6, -5], [39, 1, -1], [-34, -4, 0], [-3, 11, -1], [-10, 4, -6], [-7, -1, 5], [2, 0, 4], [-3, -1, -3], [-11, -16, 3], [12, 0, -4], [18, 0, 8], [3, -6, 7], [6, 0, 4], [3, 8, 7], [16, -8, -4], [10, 10, 0], [-10, -2, 8], [23, -1, 3], [10, 11, -2], [-8, 8, -6], [11, -6, -3], [-27, -1, -3], [-1, -4, -3], [8, -4, -2], [-27, 1, -1], [11, 5, -7], [15, 2, 5], [14, -2, 4], [-4, 16, 6], [-2, -2, -6], [37, 3, 1], [10, 6, -2], [-20, -12, 4], [11, 5, 5], [-9, -14, -5], [15, 7, 9], [-16, 3, 4], [17, -14, -9], [-13, -5, 1], [-16, 2, -8], [10, -2, -2], [-11, 4, -7], [17, -4, -1], [-4, 0, 4], [-9, 9, -1], [14, 2, 4], [16, 10, 2], [-4, 1, -2], [1, -3, -5], [-28, 2, 4], [-18, 12, 4], [20, 4, -4], [-8, -2, 2], [3, 5, 7], [-28, 3, -8], [-10, -2, 0], [3, 9, -1], [-14, -6, 2], [-2, 6, -10], [-30, 8, 0], [11, -4, -9], [39, 0, 1], [0, 6, -10], [13, -5, 1], [12, -2, 8], [6, -6, 0], [25, -2, -1], [18, 2, 2], [13, 6, 3], [12, -8, 8], [-40, -5, 4], [0, 8, 4], [-9, -1, 9], [36, -6, -6], [-6, 4, 4], [-9, -16, -5], [-1, -15, 7], [-32, -1, -8], [20, 0, -4], [22, -4, -4], [0, 2, 2], [-10, 3, 0], [-22, -14, 4], [20, -6, 8], [4, 18, 4], [21, 8, -3], [29, 3, -5], [21, -7, 3], [-24, 2, -10], [27, 5, 7], [25, -10, -1], [-15, -10, -9], [16, 2, -6], [-25, -3, 3], [42, 4, 4], [-7, 0, -1], [-13, 14, -1], [-30, 8, 0], [-22, 2, 2], [-17, 0, 7], [-26, 4, -2], [4, -2, -8], [2, 8, 8], [-31, -9, -5], [16, -2, 8], [-39, -9, -3], [-20, 3, -14], [29, -5, 1], [-20, -4, -8], [8, 8, 0], [-4, 2, -2], [-1, -7, -11], [27, -2, 1], [18, 10, 4], [7, -12, -5], [-22, -14, 2], [-30, -2, -10], [19, 6, 5], [-7, 3, 7], [29, -1, 9], [27, -9, 9], [41, 14, -3], [4, -2, 12], [30, -10, 6], [-34, 9, 4], [-9, 3, -9], [7, 15, -5], [-12, -6, -6], [57, 0, 5], [-7, -12, -1], [15, -3, -9], [-22, 4, 0], [42, -1, -4], [21, -9, 13], [18, 0, -6], [14, -10, 4], [-26, -6, 8], [-25, -3, -5], [16, -12, 12], [9, -9, -13], [-23, 7, -15], [-9, 14, 3], [23, 17, -3], [-12, 17, 4], [9, -4, 5], [62, -2, -2], [22, -12, 0], [-9, 13, -5], [2, -6, 2], [-4, 2, -10], [20, -8, 12], [35, -5, 1], [-34, 2, 2], [45, 2, 3], [-3, -19, -1], [64, -2, -2], [16, 10, 0], [11, 9, 7], [-68, -4, 0], [-13, -7, -5], [-1, 7, -11], [-8, 24, 4], [-18, 6, 2], [5, 13, 15], [31, -2, -5], [6, -12, -2], [-12, 12, 6], [-10, 20, 0], [40, -4, -8], [-43, 0, 1], [12, 1, 6], [39, 1, 3], [-36, 2, 6], [8, 4, 16], [36, 8, 2], [-10, 10, 2], [-4, 8, -8], [-6, -2, 6], [-7, 4, 9], [28, 24, -4], [20, 0, 0], [62, -2, 2], [0, -6, 6], [32, -12, 0], [14, -12, 12], [-57, 6, 1], [40, -2, 6], [-19, 1, -15], [46, -1, 6], [-2, -22, -4], [32, 4, 12], [17, 14, 3], [21, -1, -7], [18, -13, -12], [23, -20, -3], [6, 8, 8], [-26, 8, -8], [-24, 8, 12], [50, -2, 4], [20, 14, -6], [-2, 8, -6], [13, 4, -7], [-11, -25, 5], [-7, -3, -11], [-22, -22, 2], [13, -9, 9], [0, 6, 2], [-5, 13, -3], [34, 4, -4], [-7, -5, -1], [-21, 10, 5], [55, -5, 11], [-19, 14, 3], [17, -11, 7], [-27, 0, -3], [4, -16, -14], [-22, 2, 12], [44, -8, -10], [-35, -3, -1], [14, -13, 2], [-24, 8, -16], [-5, -8, 3], [-4, 4, -12], [-21, 1, -13], [2, 4, 2], [-9, 20, 13], [-6, 6, -12], [7, 13, 15], [-6, -12, 4], [42, -11, -2], [-9, -27, -5], [5, 7, 1], [17, 13, -9], [-9, 8, -3], [30, -1, 16], [15, -9, 5], [13, 20, -5], [10, -14, -8], [44, -2, 14], [31, -13, 7], [10, 17, 0], [-49, 1, -3], [28, -12, -8], [-37, 10, -5], [8, 6, -4], [-28, 10, 6], [16, -18, -16], [2, 18, -2], [-47, -8, -9], [18, 4, 8], [-11, 19, 3], [-17, 1, -13], [8, 13, 10], [-32, -8, 8], [-64, 4, -10], [68, -10, -6], [36, -12, -8], [-40, -9, -4], [-13, -12, -5], [12, 16, 16], [-3, 0, -7], [-5, -21, 11], [-9, 0, 9], [16, -16, -8], [6, 20, -4], [-66, 4, -2], [-5, -21, -1], [16, 4, 18], [27, -6, -1], [-84, -5, 2], [-38, -2, -18], [23, -6, -7], [9, -23, 3], [-2, 18, -6], [60, 14, -2], [-59, -5, -5], [-36, 11, 4], [-15, 5, 7], [25, 7, -9], [-4, -12, 8], [-33, -10, 11], [-38, -3, 2], [35, 9, 5], [-20, -18, 6], [5, 16, 21], [14, -10, -18], [12, 15, 10], [4, 4, 8], [16, -20, -14], [-22, 18, 2], [-8, -20, -12], [18, 26, 2], [-24, -2, 2], [-21, 16, 9], [-15, -1, -11], [-5, -24, 7], [-13, -9, -9], [8, 0, -2], [56, 12, 2], [53, -2, -1], [-16, -2, 0], [-16, -12, -10], [-89, 4, 3], [-28, 6, 4], [55, 8, -1], [-63, 1, -7], [8, -4, 8], [0, -8, -10], [-52, 17, 6], [-21, -3, 5], [29, 2, -1], [-22, 2, -12], [2, -18, -12], [28, -24, -14], [-31, 17, 7], [-13, 1, 1], [-32, -2, 4], [-29, -10, -11], [17, 2, 17], [-9, -9, 9], [-22, -4, -2], [8, 18, -6], [11, -3, 9], [21, 31, -9], [15, 0, -7], [-61, -11, 7], [12, -6, -6], [-42, -22, 6], [1, -4, 11], [-39, -6, -9], [23, 20, 11], [-40, 6, 6], [-52, 2, -22], [31, 5, 17], [48, -6, -8], [3, 17, 19], [-41, 4, -13], [16, 16, 12], [-26, 2, -6], [-16, 10, 12], [-37, 17, 15], [-60, 16, 8], [-32, 2, -18], [-61, -7, 5], [23, 26, -7], [28, -22, -10], [-55, 11, -9], [-28, -2, -20], [5, -18, -13], [85, -6, -5], [-20, 12, -6]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7800_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7800_2_a_bp();".
// 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_7800_2_a_bp(:prec:=3)
    chi := MakeCharacter_7800_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(3361) - 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_7800_2_a_bp();".
// 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_7800_2_a_bp( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![0, 1]>,<11,R![-20, 2, 6, 1]>,<17,R![-64, -20, 4, 1]>,<19,R![16, -24, 2, 1]>],Snew);
    return Vf;
end function;