
// Make newform 7800.2.a.bs in Magma, downloaded from the LMFDB on 20 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_bs();".
// 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_bs();".
// 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 := [19, -13, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-9, 1, 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, 1], [2, -1, 0], [-1, 0, 0], [3, 0, 0], [0, -1, -1], [-2, 1, 1], [-1, -2, 0], [2, -1, 0], [-2, -1, 1], [0, -1, 1], [0, -1, 1], [4, 2, -1], [-1, 1, 1], [4, 2, -1], [3, 2, 0], [8, 1, 0], [0, 3, -1], [0, 3, -1], [4, 1, -1], [-6, 2, 1], [6, -2, 0], [4, 0, 2], [-3, 1, 3], [-2, -1, 1], [8, -4, -2], [6, -3, 1], [0, -2, 0], [10, 3, -1], [0, -1, -1], [-2, 4, 2], [-2, 0, -4], [0, 4, -2], [-14, 2, -1], [-1, 1, 1], [0, 1, -3], [6, 1, -1], [-1, -1, 1], [-6, -3, 3], [9, -3, -1], [6, 0, 0], [-10, 1, -3], [0, 3, 1], [-2, 2, 2], [10, 3, -1], [4, -3, -3], [12, -1, 2], [2, 0, 0], [8, 2, 0], [10, -2, 5], [14, 1, -3], [10, -1, -3], [-13, -3, 1], [-2, 1, -1], [-7, 0, -4], [-10, 4, 1], [-4, 0, -2], [18, 2, 2], [-14, -2, -2], [-2, 4, 0], [-2, -5, 1], [2, -6, 2], [-19, 1, 1], [4, -1, -5], [-8, -5, -1], [1, -1, -7], [22, 4, 0], [14, -1, -3], [16, -5, 1], [6, 2, -1], [12, -4, -4], [-11, 1, -5], [4, 5, -2], [-12, 1, -3], [4, 6, 0], [-20, 2, 4], [14, -7, -5], [12, -7, -5], [22, 1, -1], [4, -6, -2], [24, -3, -3], [-8, 4, 2], [6, -5, 7], [-4, 3, 1], [-8, 2, -6], [0, -5, -3], [14, -6, 2], [-18, 5, 2], [14, -2, 4], [8, 1, -2], [4, 7, 0], [22, 0, 0], [6, 4, 5], [20, 3, -1], [-6, 1, -7], [-14, 4, 0], [-24, 4, 2], [-4, -3, 1], [6, 3, 5], [-6, 1, -3], [10, -7, 1], [-29, 1, -1], [-10, 1, 5], [-8, 8, -2], [12, -1, 6], [6, -2, 6], [0, -7, -3], [7, 5, 1], [-4, -2, 4], [-10, -4, 0], [28, -2, 4], [-2, -7, 3], [-18, -1, -3], [5, -4, 4], [-12, -5, 3], [-6, -6, -4], [-9, 0, 0], [-4, 3, -7], [12, 1, 3], [1, -5, 5], [-30, -2, -2], [-12, -3, -6], [-4, -6, 5], [-15, 6, -8], [8, -1, -3], [-6, 7, 1], [-26, -1, -3], [-8, 6, 2], [14, 5, 2], [36, -3, 2], [2, -5, -5], [-9, 4, 0], [20, -1, 3], [-30, 0, -2], [0, 0, -6], [6, 5, 0], [-9, -4, -6], [-4, -4, -2], [10, 8, 1], [6, 9, 3], [14, -10, 0], [4, 11, 0], [29, 0, 6], [-28, -7, 1], [-16, 4, 8], [-10, 0, 8], [8, -9, 5], [6, -3, 8], [10, -4, -2], [-23, -3, -3], [-26, 8, -2], [16, 13, -1], [-8, -4, -8], [-10, 1, 9], [-12, 2, 0], [-6, 6, 2], [-13, 6, 0], [-24, -3, 5], [0, -9, 4], [25, -1, 1], [0, -7, 2], [0, 2, -4], [-12, 6, 2], [22, -1, -8], [-18, -17, 3], [-23, 8, 10], [-2, 10, -4], [-29, 3, -7], [0, 9, 1], [2, -8, -2], [4, 7, -5], [-22, 3, -7], [10, -4, -4], [-35, -1, 5], [-30, 9, 2], [-4, -10, 4], [-4, 4, -6], [29, 7, -1], [24, 3, -5], [-10, 11, 7], [-8, -8, -6], [-10, -2, -4], [32, 0, -3], [0, 2, 8], [-11, -3, -7], [10, 0, 3], [2, 3, -3], [-6, -5, -10], [38, -4, -4], [6, 16, -5], [-26, -5, -5], [-24, -1, 3], [10, 6, -2], [19, 5, -3], [30, 5, -5], [-31, 9, 1], [-22, 6, 2], [4, 0, 10], [0, -3, -7], [-8, 8, -4], [-2, 6, -10], [-31, -1, 5], [12, -11, -8], [-18, 6, -2], [4, -18, -1], [30, -1, 9], [-24, -10, 2], [4, 13, 5], [-31, 0, 6], [-28, -6, 0], [2, -12, -2], [8, 4, -9], [26, -1, -8], [-22, 10, 0], [2, -10, 10], [9, -9, -3], [12, 10, -3], [24, 6, 6], [-40, 8, 6], [-12, 9, 5], [-32, -2, 2], [16, -6, -7], [24, -5, -11], [3, -14, 6], [2, -16, 4], [-30, 12, 4], [-12, -1, -5], [0, -10, -1], [-10, 6, 10], [26, 0, -6], [-54, 5, 6], [-60, 0, -2], [-2, -1, 3], [20, -3, 5], [-10, 4, -4], [-38, 1, 3], [14, -10, -8], [32, 10, 2], [2, 1, 15], [-16, -1, -3], [54, 1, 3], [-24, 5, -11], [22, -5, 9], [4, 19, -5], [-40, 5, 9], [-38, 9, 7], [-24, 7, 8], [-30, -5, 1], [-8, 0, 0], [14, 5, -9], [-36, -11, 5], [23, -11, -9], [36, -12, -6], [-48, 0, 5], [22, 2, -2], [10, 1, -6], [5, 4, 0], [12, 6, 4], [-18, 14, 2], [4, -9, 1], [14, 14, -4], [-60, 6, 4], [10, -2, -4], [26, 1, -7], [-12, -3, 3], [28, -5, -1], [46, 4, -3], [13, 1, 5], [-52, 8, 6], [34, -2, 9], [8, 8, -6], [8, 17, -3], [27, 9, -5], [-10, 3, -14], [-12, -9, 7], [2, -3, -5], [24, 4, 0], [-6, -6, 6], [-8, -2, -4], [-60, -3, 1], [-22, 8, -14], [-2, -3, 5], [-10, 14, 3], [-6, 5, -7], [17, 4, 0], [24, -5, -11], [4, 7, 4], [-7, -15, 1], [-11, 5, 1], [0, -5, -9], [34, 10, -2], [4, -15, 8], [1, 1, 3], [13, 0, 2], [-6, -8, -2], [-12, -6, -4], [-12, 5, 7], [0, 0, -9], [11, -2, -14], [-12, -5, -11], [-20, -13, -1], [6, -10, 4], [-14, -9, 9], [20, -9, -9], [-30, 10, 4], [-16, -2, -4], [32, -7, -11], [-19, 13, -7], [20, -1, 1], [-16, -4, -4], [-9, 2, -2], [0, 17, -9], [12, -5, 6], [30, -8, 4], [-44, 10, 5], [40, -11, -7], [28, -12, 8], [13, 20, -8], [8, 9, 9], [10, -13, 3], [14, -8, -4], [-22, 12, 3], [36, -9, -9], [17, -4, 6], [0, 2, 11], [4, 0, 5], [-16, 9, -3], [-31, 4, -10], [22, 4, -12], [24, 8, -10], [32, -9, -9], [4, -14, -3], [6, 11, 2], [24, -12, 1], [2, 4, 8], [10, -2, 12], [-4, -3, 7], [-22, -8, -8], [16, -9, 1], [40, -10, -8], [36, 15, -7], [14, 15, -1], [-10, 5, 7], [-28, 4, 4], [-1, 9, -13], [-62, -4, 1], [18, 5, -8], [-43, 8, 4], [26, -3, 0], [2, -6, 0], [-28, -9, -7], [-8, 1, -9], [28, 4, 6], [39, -12, -10], [40, 16, -1], [38, 0, -11], [-3, 17, 3], [14, 0, -3], [38, -6, 0], [-42, -12, 0], [-8, 10, -2], [-20, 7, 15], [-14, 4, -4], [-48, 6, -8], [2, 7, -5], [-4, -16, 13], [41, -1, 3], [24, 3, 11], [14, 19, -3], [-22, 5, -1], [11, -13, -3], [10, 8, -4], [13, -16, -6], [-34, -5, -10], [32, 2, -4], [12, 10, 2], [-17, -7, 5], [-36, 10, 4], [-32, 13, 3], [34, 10, 0], [10, -19, -10], [-38, -1, -1], [-4, -9, 15], [-40, -5, 3], [-2, -3, 18], [1, -16, -8], [20, -21, -5], [26, -6, 2], [4, 6, 6], [-8, -2, -10], [-18, -2, 1], [-2, 10, -10], [8, -2, 1], [47, -8, 2], [-48, 3, -10], [45, -8, -8], [4, 8, -10], [-10, 7, 15], [-20, 17, 13], [27, -2, -2], [-14, -13, -8], [28, 10, -8], [48, -18, -8], [52, 0, 2], [20, 26, 0], [58, -5, -1], [68, -2, 1], [32, 11, -5], [41, -12, -6], [-45, 17, 9], [-24, 7, -1], [24, -18, 4], [-14, 24, 4], [5, 3, -5], [58, 1, -1], [30, 0, -14], [10, 11, -9], [-46, 10, -10], [7, -5, -17], [-18, 11, 9], [20, -10, -11], [4, -10, 10], [2, -5, 17], [-12, -3, 5], [14, 8, -10], [-42, 9, -15], [6, 18, 5], [-34, -9, 5], [16, -19, 3], [0, 3, -2], [12, 12, -6], [24, 21, 0], [12, 7, -5], [7, 23, 1], [4, -2, 16], [-10, 12, 2], [-46, 1, -5], [2, -14, 3], [74, -6, 5], [-10, -18, 0], [-52, 0, 2], [12, -10, 2], [-6, -18, -10], [46, -8, 8], [14, 5, 7], [-4, -1, -14], [63, -7, -1], [58, -2, 10], [78, -4, -1], [-22, -19, 10], [-16, -9, -1], [54, -9, 1], [76, 3, 3], [-25, -20, 4], [-18, -5, -1], [22, 10, -8], [-9, -7, 5], [44, 5, 1], [-50, -6, -4], [38, 4, 5], [46, -4, -6], [15, -4, 16], [6, -12, 7], [-16, -16, 12], [-38, -8, 10], [-48, -9, 3], [-21, 7, -17], [-6, -10, 6], [48, 4, 3], [18, 22, 1], [26, -7, 3], [32, -3, 7]];
    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_bs();".
// 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_bs(: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_bs();".
// 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_bs( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![33, -23, -1, 1]>,<11,R![3, -5, -5, 1]>,<17,R![-3, 1]>,<19,R![60, -36, 2, 1]>],Snew);
    return Vf;
end function;