
// Make newform 7800.2.a.ba in Magma, downloaded from the LMFDB on 23 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_ba();".
// 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_ba();".
// 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, 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_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], [-1, 1], [-1, -1], [1, 0], [-1, 2], [-2, 0], [-2, -2], [-3, 4], [3, -1], [2, -4], [0, -4], [2, -6], [-5, -5], [3, -2], [-5, 1], [1, 2], [-5, -3], [-2, 4], [2, 8], [-6, 2], [-1, 9], [0, 0], [2, 12], [-9, -2], [0, 0], [-10, 6], [-8, 8], [2, -8], [-14, -2], [-12, 4], [0, -12], [-6, -2], [6, -8], [-3, 3], [7, -8], [14, 8], [-14, 8], [5, 6], [-4, 0], [-9, -4], [6, -6], [-4, 0], [4, 0], [2, 2], [2, -6], [18, -4], [-13, -1], [-10, -4], [-10, 0], [-1, 3], [-4, 0], [-8, 0], [-1, 0], [-8, -8], [1, -8], [5, 7], [-2, -8], [-14, 0], [-2, 18], [6, 8], [-2, 0], [-10, 6], [17, -2], [14, 12], [2, -12], [-1, -6], [-22, -6], [2, 4], [-12, -8], [-11, -7], [4, -4], [27, -4], [-7, -5], [2, 4], [6, 16], [-6, 20], [-18, 8], [8, -8], [8, 4], [0, 8], [-10, -12], [14, -8], [-10, 6], [2, 18], [0, 0], [24, -4], [-2, 0], [11, -9], [-28, 0], [-3, -17], [-3, -3], [-14, 6], [-23, 1], [8, 20], [-8, 0], [-18, 0], [-2, 6], [-18, 0], [0, 16], [16, 0], [-2, 6], [33, 8], [-10, 6], [14, -20], [-1, -9], [6, 16], [0, 4], [-13, 10], [-2, 10], [30, 4], [22, -12], [-22, 16], [14, 0], [-27, -6], [18, -16], [-12, -24], [-29, -4], [-18, -10], [12, -24], [7, 10], [2, 0], [5, -27], [5, -3], [-21, 8], [12, -16], [-20, 16], [-12, -8], [40, 8], [19, -11], [17, -1], [42, -6], [11, -14], [14, 0], [-12, 4], [6, -16], [-15, -13], [-11, -4], [30, -8], [41, 9], [22, -8], [-16, 24], [1, 13], [-1, 2], [2, -4], [24, 4], [10, 16], [-42, -2], [-31, -1], [20, 4], [-15, 28], [-8, -8], [-6, -2], [0, 24], [-18, 2], [-2, -14], [42, 0], [-7, 28], [34, -8], [-19, 1], [-29, 4], [17, 29], [-26, 2], [-16, 12], [-13, -3], [30, 10], [39, -14], [-12, -8], [-7, 14], [14, -16], [48, -4], [20, 20], [-14, 4], [6, -30], [11, 16], [-5, 5], [18, 24], [2, -34], [17, 8], [14, 12], [-2, -42], [10, 16], [12, -28], [-37, 7], [-22, 16], [17, -12], [-5, 39], [26, 8], [-15, -13], [26, 0], [-1, 13], [14, -10], [30, -4], [-30, 14], [-45, -4], [-10, -8], [57, -4], [6, -20], [2, -30], [6, -24], [40, 20], [10, 8], [-29, 10], [35, 7], [2, 40], [-29, 21], [28, -16], [24, -20], [-8, 16], [3, -28], [18, -24], [-28, 4], [5, 11], [-5, -11], [-12, -24], [10, -34], [19, 4], [25, 13], [-12, -16], [46, 0], [2, 28], [-12, 8], [-43, -17], [-18, -26], [-5, -34], [-46, -16], [-38, 26], [16, -8], [-25, 9], [-10, 0], [4, 44], [35, 3], [10, -24], [-34, 2], [34, -12], [2, 16], [-46, 4], [12, -28], [0, -8], [50, -8], [6, -14], [44, 16], [-54, -12], [-30, 24], [-12, 8], [-10, 12], [-10, -28], [-27, -5], [-24, 36], [-16, -16], [10, 20], [6, -28], [41, 10], [26, 0], [-5, -23], [62, 8], [35, 5], [17, -24], [42, -12], [-6, 34], [14, -18], [-20, 20], [6, 40], [28, 36], [-10, -14], [20, 44], [38, 8], [29, -15], [-15, 10], [-6, 32], [27, 11], [-58, 0], [-8, 24], [-11, 2], [45, 17], [-62, 8], [-10, 16], [0, -20], [18, 2], [-54, -6], [2, -20], [16, 4], [40, -20], [17, -11], [2, 50], [-35, -36], [-44, 24], [-11, 13], [21, -16], [25, -18], [0, 20], [6, 12], [7, 7], [47, 8], [7, 36], [16, 20], [-6, 48], [22, -22], [-19, 25], [15, 4], [8, 8], [44, -4], [-32, 0], [4, 8], [22, -12], [4, -12], [-26, 0], [2, 20], [-15, -40], [46, -10], [-36, -4], [-13, 22], [-34, -34], [7, -31], [2, -16], [21, 39], [10, 16], [-8, 20], [25, -30], [4, 52], [-40, 20], [58, 8], [7, 5], [-38, -8], [-29, -28], [-21, -45], [-21, 27], [8, 28], [-29, 12], [-6, 44], [-30, 8], [40, -8], [33, 11], [-27, -9], [35, 21], [22, 40], [-76, 0], [48, 12], [-30, -18], [32, -40], [62, 0], [-68, 0], [6, -18], [-2, 20], [28, -24], [-23, -24], [61, -19], [-59, 7], [9, 28], [65, -13], [-16, 4], [40, 20], [-2, -14], [-30, 0], [9, 14], [-35, 17], [-39, -13], [-21, 8], [-19, -7], [56, -16], [-30, -16], [16, 16], [-18, 32], [2, -10], [-46, -8], [20, 16], [23, 21], [-43, -14], [-16, 8], [56, -12], [6, -4], [13, -50], [-62, 14], [51, 22], [1, 41], [-10, -30], [-68, -4], [-73, -8], [-26, -8], [36, -20], [-52, -8], [-17, 19], [32, -4], [18, -32], [22, -44], [-25, -21], [-3, 18], [18, 0], [-26, -14], [32, 20], [56, -16], [51, 5], [-14, 2], [-67, -19], [61, 28], [-17, -29], [-3, 6], [-14, -58], [-20, 16], [-10, -60], [-5, -26], [3, 19], [-66, 16], [-42, 12], [6, -46], [26, -40], [-20, -28], [-31, -15], [26, -8], [-57, 4], [-37, -46], [88, 8], [18, -6], [-90, 0], [29, 18], [-22, -48], [-20, 36], [-40, -40], [-6, -14], [3, -14], [6, 0], [41, -19], [68, -4], [6, 12], [10, -40], [-12, 24], [-8, -20], [23, -21], [-84, 0], [-28, -20], [-1, -9], [66, 6], [-9, -3], [-34, -20], [-23, -4], [34, -32], [-40, -4], [-24, -20], [1, 63], [79, 5], [-36, 24], [-38, 24], [-24, 16], [-42, -32], [-26, 8], [12, -40], [-33, 5], [61, -14], [62, -16], [3, 31], [-57, 37], [74, -16], [-2, 24], [-10, 56], [3, -56], [-76, -12], [-40, 16], [7, -52], [30, -32], [0, 48], [-35, 47], [-48, 8], [-5, -34], [71, -1], [-24, -12], [84, -12], [34, 20], [-1, 44], [-38, 46], [17, -33], [-77, 5], [10, -48], [28, 12]];
    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_ba();".
// 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_ba(: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_ba();".
// 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_ba( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-1, 2, 1]>,<11,R![-1, 2, 1]>,<17,R![-7, 2, 1]>,<19,R![2, 1]>],Snew);
    return Vf;
end function;