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