
// Make newform 7800.2.a.bb in Magma, downloaded from the LMFDB on 24 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_bb();".
// 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_bb();".
// 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 := [-8, -1, 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_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], [1, 0], [0, 0], [0, -1], [0, -1], [1, 0], [-2, 1], [0, -2], [4, -1], [-2, 0], [0, 2], [-2, -1], [2, -1], [4, 0], [8, -2], [6, 1], [-8, 0], [-2, 3], [4, 0], [-8, -1], [2, 4], [0, -5], [12, 0], [10, 1], [-6, 1], [-2, 2], [4, 0], [12, -1], [2, 2], [6, 0], [-4, 6], [-12, -2], [2, -4], [4, 1], [10, 1], [0, 0], [-2, 0], [4, -1], [0, 0], [6, -4], [4, 6], [-2, -1], [-8, 0], [-6, -1], [-10, 6], [8, 4], [-4, 8], [8, -8], [12, 2], [2, 0], [22, -1], [8, -9], [2, -8], [4, 4], [-10, 0], [4, 4], [6, 2], [24, -2], [-2, 8], [-14, 8], [-20, 0], [22, -2], [-12, -1], [0, 0], [6, 0], [-2, 6], [-8, -4], [-2, 6], [-4, -5], [18, -6], [-14, 0], [8, 0], [-4, 4], [22, -2], [8, 2], [-16, 2], [6, 6], [6, -9], [10, 0], [-14, 8], [-12, -6], [-6, 10], [-8, 8], [14, -6], [24, -7], [12, -9], [2, -1], [-30, -3], [10, -9], [8, 7], [20, -9], [24, -3], [8, -3], [12, 0], [-8, -2], [-4, 8], [18, 5], [10, 4], [-28, 0], [10, 4], [20, -8], [14, -8], [-12, 3], [10, -10], [-4, -9], [-30, -3], [-4, 2], [18, -2], [-8, 4], [-14, -7], [-28, 0], [-2, 5], [-6, -12], [8, 10], [-32, 4], [2, 6], [-4, 3], [-12, 5], [30, 0], [-28, 4], [-14, -6], [22, -4], [14, 1], [-28, 8], [0, -10], [-10, -2], [-46, 2], [24, 8], [4, 2], [6, 11], [8, 6], [-8, 6], [-8, 5], [46, -2], [-14, 4], [-14, 6], [-10, -2], [-20, 8], [14, -1], [-6, 12], [16, 4], [2, 11], [44, 0], [12, 6], [6, -8], [-8, -1], [14, -3], [-2, 7], [-20, -3], [-40, -2], [14, -8], [18, 0], [-20, 8], [20, 9], [-44, 2], [-24, 0], [-32, -5], [34, -7], [-10, 4], [34, 1], [20, 8], [30, 9], [-8, -8], [20, -4], [-54, -2], [8, -4], [8, -7], [-10, 10], [18, -8], [22, 5], [-32, -4], [-22, 0], [32, 8], [2, 5], [0, -11], [-38, 10], [16, 6], [-6, -15], [4, -8], [-42, 8], [16, 3], [-12, -8], [14, 4], [-22, 16], [-16, 2], [30, 2], [-34, 6], [-20, 5], [-46, -6], [24, 9], [6, -6], [-44, -6], [-44, 3], [34, 3], [20, 8], [-10, 13], [26, -4], [-18, 0], [2, -6], [4, 7], [18, -4], [-8, -17], [-2, 9], [-6, 11], [-16, 1], [54, -5], [16, 6], [28, -8], [26, -7], [4, 5], [-66, 2], [-2, -8], [28, -4], [-36, -10], [-24, 12], [42, -6], [52, 4], [2, -8], [-40, 2], [-2, -4], [6, -15], [-40, 10], [-14, 12], [-8, 20], [28, -5], [38, 3], [-34, 15], [-24, -2], [4, -6], [0, 19], [-18, 6], [20, -7], [-24, 4], [10, 6], [44, -2], [-40, -10], [-38, -6], [-26, -8], [28, -10], [8, -16], [-12, 12], [20, 9], [-12, 0], [-6, -14], [26, 2], [16, -12], [-40, 8], [32, 11], [-8, -20], [-52, -4], [-2, 20], [18, 12], [-8, 22], [-14, -1], [-18, 3], [-24, 17], [14, 8], [-20, 3], [30, -12], [-38, 17], [-12, -10], [60, -3], [-46, 6], [-58, -2], [-14, -12], [-28, -9], [42, 1], [2, -7], [4, 17], [-58, 8], [38, -8], [-52, 9], [2, -3], [0, 0], [-42, -8], [64, 1], [20, 8], [58, 2], [-46, 14], [-4, -2], [-12, -9], [-40, -8], [28, -12], [-46, 4], [-28, -4], [0, -12], [-58, 6], [6, -6], [-40, -6], [-78, -2], [-26, 22], [12, -8], [18, 18], [64, 4], [6, 16], [30, -12], [-8, 24], [14, -17], [-44, 4], [44, 3], [22, -20], [62, 2], [-8, 27], [44, -3], [-20, 12], [-30, -1], [60, -3], [14, 5], [-40, 8], [-10, -18], [-52, -1], [-30, -12], [-46, 0], [-28, 4], [-48, 12], [-14, 19], [-72, 1], [16, -21], [10, 16], [-46, -2], [-52, 0], [2, 20], [-74, 0], [-56, 3], [18, 12], [-6, -3], [0, 2], [-4, -25], [44, -5], [-34, 4], [18, 0], [38, 3], [32, -8], [-44, 8], [48, -8], [12, 2], [-30, 4], [34, 6], [-30, 20], [-4, 18], [-66, 5], [14, 23], [2, 17], [-8, -12], [-18, -16], [-4, 8], [46, -9], [12, 23], [-8, 16], [-34, -1], [-16, 2], [58, -1], [-38, -13], [20, -14], [-34, 9], [-2, -20], [0, -17], [-8, 28], [30, 8], [40, -6], [38, 4], [26, -6], [20, -24], [-16, -4], [-12, -2], [-18, 10], [46, 10], [-8, -21], [-14, -21], [-36, 18], [76, -8], [64, 8], [54, 12], [48, 1], [-58, 6], [-32, 13], [48, 6], [18, 5], [-78, 6], [-18, 32], [-22, 8], [18, -20], [48, -8], [-22, -8], [16, 24], [-24, 0], [8, 14], [62, -10], [36, -12], [-28, -1], [18, 10], [-26, -8], [-48, -5], [-52, 16], [16, -17], [30, -16], [-24, -2], [-22, 20], [36, -11], [-6, 0], [66, 0], [14, 7], [64, -11], [26, -10], [26, -1], [48, 9], [-2, -24], [-54, 4], [20, -3], [-8, -19], [-26, 28], [54, 11], [-12, 31], [-28, -19], [46, -8], [-2, 12], [-16, -3], [52, -2], [66, -2], [28, -11], [22, -16], [30, -29], [-24, -12], [36, -12], [2, -4], [-34, 22], [-12, 3], [-30, 19], [32, 6], [-72, -6], [-30, 16], [48, -13], [84, -5], [-24, 2], [22, -27], [-46, -4], [18, -16], [10, 0], [28, -8], [40, -12], [20, -12], [-62, -3], [-38, -6], [-24, 6], [50, -4], [-2, 0], [-4, -6], [-48, -2], [34, -8], [-2, -16], [20, 3], [-32, 16], [52, -2], [34, 12], [34, 15], [-18, 18], [-46, 12], [28, -18], [-10, -16], [-38, 4], [44, 3], [0, 20], [36, 4], [38, -21], [-12, -9], [18, 11], [8, -15], [52, -10], [66, 4], [52, 4], [64, -16], [-28, 14], [-24, -21], [-70, 14]];
    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_bb();".
// 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_bb(:prec:=2)
    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_bb();".
// 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_bb( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-8, 1, 1]>,<11,R![-8, 1, 1]>,<17,R![-6, 3, 1]>,<19,R![-32, 2, 1]>],Snew);
    return Vf;
end function;