
// Make newform 7800.2.a.y 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_y();".
// 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_y();".
// 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 := [-3, 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], [0, 1], [0, 1], [1, 0], [1, -2], [0, -2], [2, 0], [-3, 4], [-4, -3], [-4, 2], [-6, 2], [2, 4], [2, -5], [-5, -4], [0, 1], [-9, -2], [6, -1], [-4, -6], [0, -2], [14, 0], [12, 1], [4, -4], [-2, 4], [3, 0], [2, -10], [-4, -2], [-6, 2], [10, 0], [-6, 4], [-18, -2], [-4, 4], [-4, -6], [-2, 8], [-4, 7], [1, -6], [4, -6], [0, 10], [-3, 4], [10, -6], [-7, 2], [4, 6], [-2, 2], [-6, 6], [4, 10], [-26, 0], [4, 14], [-4, 1], [2, -12], [6, 8], [-2, 3], [-10, -6], [-6, 6], [5, -14], [6, 10], [-19, 0], [-20, -1], [-14, -4], [6, 4], [-8, 10], [-2, -8], [8, -2], [-4, -2], [5, -4], [-16, 2], [-8, 2], [-17, 8], [-8, 14], [-4, -6], [10, -10], [2, 1], [0, 4], [-11, -6], [10, -3], [12, -2], [6, -8], [-22, 0], [0, -22], [-6, 10], [-6, -10], [-12, 4], [-8, 6], [-6, 4], [-10, 12], [2, 4], [-28, -4], [-6, 10], [-14, 4], [-8, 1], [-12, -8], [-6, -11], [-12, 3], [-20, 10], [-6, 9], [18, -2], [10, -14], [30, 0], [-4, -10], [-8, -6], [-6, -2], [-22, -6], [18, 0], [-5, 14], [-14, -8], [2, -20], [8, 9], [-6, -4], [-2, 18], [-5, 16], [28, -10], [18, -4], [6, -8], [8, 10], [16, 14], [39, 6], [-4, -10], [-20, -16], [-29, -4], [2, 16], [-26, -6], [-25, -8], [6, 20], [24, 11], [-26, -7], [15, -8], [-14, -2], [-10, -2], [-2, 14], [-4, 12], [38, -1], [38, -3], [-2, -8], [-31, -2], [28, 6], [0, 12], [-2, 8], [18, -3], [9, 8], [18, -4], [-14, 9], [24, 2], [-24, 8], [8, 7], [25, -6], [-12, -10], [-28, -12], [-6, 16], [18, -16], [30, -11], [-40, -4], [3, -2], [-28, 4], [18, -12], [0, 0], [6, -4], [-12, -26], [-18, -20], [-11, -20], [28, -14], [16, -5], [5, 14], [-4, -17], [4, -18], [0, -24], [-14, -1], [-22, -16], [1, 26], [-16, 20], [-23, 4], [-20, 10], [-12, 4], [-10, -10], [28, -14], [12, 14], [17, -6], [-10, 7], [30, -12], [-16, 14], [-1, 22], [20, 10], [6, -4], [-26, 4], [28, 0], [-30, 3], [18, 0], [31, 6], [34, 7], [8, -2], [-18, 13], [2, 24], [12, -7], [6, 12], [0, 26], [-16, -2], [-19, -2], [8, 34], [-41, -2], [22, -8], [-12, 2], [48, 2], [4, 4], [-26, 4], [27, -8], [24, -3], [-18, 28], [20, 1], [6, -2], [-56, 0], [2, -2], [35, 0], [10, 16], [-36, 8], [-24, -9], [-38, -9], [40, -4], [8, 6], [45, 6], [66, -3], [32, 20], [-46, -4], [28, -10], [-24, 4], [-32, 11], [-6, -8], [25, 6], [-14, -16], [-32, -2], [30, 2], [12, 17], [-22, -28], [36, 0], [52, 5], [6, 4], [-6, -24], [-20, 30], [-22, 24], [-8, 6], [40, 4], [-36, -20], [40, -6], [-50, 4], [2, 2], [-8, 6], [32, -2], [-6, 26], [16, -10], [-64, -2], [10, 9], [-2, 26], [-40, 8], [48, 14], [24, 22], [21, -12], [-18, 12], [20, 5], [-22, 28], [46, 15], [-19, -24], [2, 40], [-52, -6], [-30, 8], [-12, -24], [-50, 0], [44, 16], [-10, 36], [18, 14], [52, 6], [-10, -31], [-59, -8], [-42, -12], [2, 7], [-10, 8], [10, -26], [41, 12], [8, -25], [-52, -18], [56, 2], [-12, 12], [-12, 2], [-8, -26], [44, -10], [-48, 0], [14, -18], [-22, -7], [-6, 20], [-23, 12], [26, 14], [12, -29], [43, 18], [17, -12], [66, -2], [38, 8], [60, -3], [61, -10], [11, 8], [24, -8], [-54, 8], [26, 16], [-34, 1], [7, -24], [30, -2], [22, -2], [-16, -16], [30, 22], [-8, 26], [-32, -20], [62, -16], [-4, -18], [-21, 34], [42, 0], [0, -12], [13, -18], [-34, 20], [-6, -13], [-54, 8], [0, 39], [-48, -6], [36, 28], [19, -26], [26, -22], [2, 10], [10, -16], [28, -27], [-40, -2], [-13, -40], [26, -1], [-34, 3], [14, 2], [-9, 0], [-26, 20], [30, -12], [6, -14], [-16, 43], [62, -11], [-24, -23], [-74, 0], [-32, 28], [-50, 6], [-52, -6], [-18, 6], [6, -16], [-6, 14], [14, 4], [-60, 6], [12, -40], [23, 38], [26, 13], [18, -11], [25, 20], [-46, 13], [-24, 8], [2, -14], [50, -8], [22, 28], [11, -10], [6, 29], [36, 23], [53, 22], [-10, 5], [12, -36], [34, 16], [-44, -4], [-8, -2], [-4, 26], [-30, -24], [-14, 6], [-4, 13], [-15, -36], [62, -6], [-26, 26], [-32, 22], [-35, 4], [-36, 34], [-15, -42], [12, -21], [-20, -18], [20, 0], [-59, -14], [14, 0], [-6, 6], [80, 4], [-8, -35], [42, -14], [-44, -18], [-36, -30], [40, -27], [-5, 38], [28, -10], [16, -14], [-8, -48], [12, -52], [-12, -35], [28, -30], [22, -11], [85, 0], [4, 25], [27, 42], [16, -18], [-78, -2], [12, 14], [13, -50], [48, -23], [2, 4], [-66, -16], [72, -6], [-26, -20], [-26, -14], [46, 21], [52, 14], [-9, 8], [-9, -24], [54, 26], [-16, -34], [70, -16], [21, -20], [-16, 18], [-76, 0], [-2, 6], [20, 18], [67, -4], [20, 38], [-30, -3], [-12, -8], [80, -6], [44, 10], [48, -20], [-26, -34], [46, -17], [-58, 22], [-30, 30], [-8, -39], [-16, 38], [42, -13], [-80, 2], [-45, 22], [6, -20], [-52, 4], [2, 6], [12, 35], [64, 13], [-32, 36], [2, -8], [12, -36], [-14, 44], [46, -24], [-30, -6], [-10, 7], [-55, -4], [-38, 12], [2, -41], [-38, -37], [28, -42], [20, 30], [-28, -34], [-33, -24], [46, 18], [-64, 16], [-43, 38], [-16, -14], [-40, 0], [4, -17], [76, 4], [5, -6], [-10, -41], [12, -28], [-20, 24], [-24, 26], [-19, 2], [-24, -26], [104, -1], [20, -11], [16, -46], [26, -10]];
    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_y();".
// 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_y(: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_y();".
// 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_y( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7800_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-3, 0, 1]>,<11,R![-3, 0, 1]>,<17,R![-11, -2, 1]>,<19,R![-12, 0, 1]>],Snew);
    return Vf;
end function;