
// Make newform 5775.2.a.bz in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5775_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_5775_2_a_bz();".
// 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_5775_2_a_bz();".
// 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, -7, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-4, 0, 1, 0], [0, -6, 0, 1]];
    Rf_basisdens := [1, 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_5775_a();"
function MakeCharacter_5775_a()
    N := 5775;
    order := 1;
    char_gens := [3851, 4852, 4126, 3676];
    v := [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_5775_a_Hecke(Kf)
    return MakeCharacter_5775_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, 1, 0, 0], [-1, 0, 0, 0], [0, 0, 0, 0], [1, 0, 0, 0], [-1, 0, 0, 0], [-2, 1, 0, 1], [1, 0, 1, 0], [3, -2, 1, 2], [1, 0, 1, -2], [-1, 1, -1, 1], [6, -1, 0, 1], [-2, -3, 0, 1], [0, 3, 0, -3], [-1, -3, 1, 1], [-2, -3, -2, 1], [-3, 2, 1, 2], [-1, -1, -1, 1], [1, 4, -1, -2], [2, -4, 0, 2], [0, 1, 0, 1], [0, 2, 2, 2], [0, -1, 0, -1], [-1, 0, 1, -4], [5, 5, 1, -3], [3, 1, 3, -3], [2, 0, 2, 2], [3, 1, 1, -3], [6, 5, -2, 1], [10, -1, 0, 3], [-5, -2, -1, -2], [-3, 3, -1, -1], [-6, 3, 2, 3], [-4, 0, -2, 0], [14, 4, 2, -4], [-2, -6, 0, 2], [-2, 4, -2, 0], [-3, 3, -3, -1], [-2, -5, 4, 1], [-2, -4, -2, 0], [-4, 0, -6, 0], [0, -3, 0, 1], [-2, 0, -4, 4], [12, 4, 4, -4], [-2, 2, 2, -4], [-8, 2, 0, 4], [4, -8, -2, -2], [-10, -2, -2, -2], [-7, -3, -1, 5], [1, -6, 3, 2], [6, 5, -4, 1], [4, 3, -4, 1], [-1, -7, 1, 1], [8, -6, 4, 4], [0, -4, -2, -2], [4, 3, -2, -5], [16, -2, 0, 2], [11, -5, -5, -1], [15, 2, -3, 2], [0, -2, -4, 0], [-12, 6, -2, -2], [6, 5, -2, -3], [3, -4, 3, -4], [-2, 6, 2, 2], [4, 2, 2, -8], [11, 3, -5, -1], [-4, -10, -2, 2], [3, 2, -3, -2], [15, -5, -3, 1], [4, -2, -4, -2], [-1, -4, 1, 6], [-10, 2, -4, 2], [-7, 7, 3, 3], [-11, 3, -1, -9], [9, -7, -1, -1], [5, 6, -1, -2], [0, -1, 0, 7], [-2, -1, 0, -9], [0, 6, 2, 2], [4, -15, -2, 1], [4, -2, 0, 0], [3, -11, -1, -5], [-5, 0, 3, 0], [-12, -2, 0, 2], [10, -2, 4, 10], [-1, 8, -3, 0], [18, 4, 0, -2], [16, -1, 2, 7], [15, -1, -3, 5], [14, -6, 2, 0], [-6, -2, -4, -4], [8, -10, 0, 2], [6, -5, -6, -5], [-10, 6, -4, 0], [-11, 17, 3, -3], [-21, -8, 1, 0], [15, -4, 5, 8], [15, -7, -1, 5], [13, -1, -3, 3], [-8, -6, 0, -2], [10, 15, -4, -1], [19, -9, 1, 7], [-10, -6, -6, 4], [-2, -2, -2, -2], [-7, 1, 5, -3], [-20, -3, -4, 1], [-2, -4, 0, 8], [-8, -3, 0, 1], [4, 2, 2, -2], [-10, -10, -6, 6], [7, 6, 5, -8], [10, -2, 2, 2], [6, 8, 6, -6], [-4, -2, 6, -2], [-6, -4, 4, 2], [1, -18, -1, 6], [-6, 0, 0, 8], [-7, -11, -1, 1], [-20, -10, 0, 2], [-9, 6, 7, -2], [-19, -9, -1, -1], [10, -7, -4, 1], [31, 5, 5, -5], [-15, 0, -7, 4], [0, 4, -2, -6], [14, -8, 4, 2], [-3, -1, 1, -1], [13, 8, 1, -8], [-9, -5, 3, -3], [3, -11, 1, -7], [-6, -14, -4, 2], [-10, 6, 6, -2], [6, 6, 2, 10], [19, 6, 9, -6], [-18, 10, -4, -6], [10, -4, 6, -2], [-9, 4, 9, 2], [-6, -6, -4, -6], [-12, 4, 0, 12], [2, 2, 4, -6], [2, -14, 4, 6], [-12, 0, -4, 8], [7, 3, 3, 15], [30, 1, 8, -1], [8, -18, 0, 6], [22, -10, 0, -2], [-11, -5, -7, 1], [0, -11, -6, 1], [-26, 0, 0, 4], [-10, -11, 0, -5], [11, 2, 7, 8], [-19, 9, -9, -5], [13, 3, -3, -1], [-8, 6, -2, -8], [1, -14, -1, 10], [18, -1, 0, -3], [20, 2, 8, 6], [-10, 12, 2, -4], [20, 14, -2, -6], [8, -9, -2, -5], [10, -9, 6, 13], [1, -2, 9, 8], [26, -4, 2, 6], [3, -15, 5, 9], [-7, -3, 1, 3], [-15, 6, 1, -10], [18, -10, 2, 10], [1, -4, -1, -12], [6, -4, 4, 0], [0, 1, 6, -3], [8, 13, 6, -3], [-35, -9, 3, 3], [10, -3, -4, -11], [-13, -1, -3, -9], [11, -5, -3, 5], [-10, -6, -8, 12], [14, -2, 12, 2], [16, 17, -4, 1], [-20, 0, -6, -8], [6, 10, -2, -10], [24, 2, 8, -4], [0, -12, 2, 6], [-8, 2, 4, 2], [2, -10, -8, 6], [17, 12, 5, -8], [15, 2, -1, -4], [-1, 13, -1, -7], [-9, 15, 9, -3], [23, -9, -3, 7], [10, -3, -4, 1], [0, -1, -12, 3], [6, -12, -8, -8], [6, 8, -6, -8], [6, 8, -6, -4], [1, 23, -7, -9], [12, 3, 8, -1], [4, -4, -2, -12], [12, 0, 6, 16], [-6, 17, 4, 5], [23, -8, 3, 0], [6, -8, -6, 0], [-11, 9, -3, -11], [-5, 26, 1, -6], [13, -3, -11, 1], [32, 12, -8, 2], [1, 11, 5, -3], [-16, -8, -10, 0], [14, 11, -4, 1], [-10, -16, 6, 4], [-21, 5, -5, 9], [-6, 9, 4, -9], [1, -11, -1, -9], [39, -9, 7, 11], [-4, -2, 2, -4], [36, 5, 8, -3], [-32, -20, 8, -4], [-14, -2, -8, 6], [-27, 7, -1, -13], [-14, 6, -2, -8], [-14, 16, -8, -10], [-39, 0, -3, 0], [16, 4, -10, 4], [-10, 6, 10, 2], [-4, -3, -2, 5], [-18, 1, 0, 15], [7, 0, 9, 4], [-8, -9, -6, -5], [18, -3, 0, 13], [-12, -17, 4, -1], [12, -6, 12, 2], [-21, -1, -7, 7], [22, 9, -4, 1], [38, -10, 6, 10], [4, -15, 0, -11], [9, 17, 5, -3], [41, 3, 3, -5], [-15, -10, 3, 2], [8, 5, -2, 9], [0, 18, 4, 0], [-6, -10, -2, 2], [-16, 2, -10, -8], [-2, 26, -8, -8], [33, 16, -1, 0], [-10, 4, -6, -12], [43, 14, -5, -2], [27, -10, 3, 2], [2, 5, 2, 9], [0, -8, 0, 16], [-11, -23, -3, 15], [-20, 9, -16, -7], [-20, -2, -4, -6], [-6, -8, 2, 2], [8, -11, 0, -9], [48, 0, 2, -2], [-18, -5, 4, -13], [-27, 2, -3, -10], [-15, -7, -1, -19], [13, 0, 17, 0], [4, 19, 4, -1], [30, 7, 0, 7], [22, 6, 12, -10], [9, 9, -1, 1], [-8, -16, 8, -8], [37, -4, 11, 6], [-20, -1, -14, -1], [4, -5, -10, -5], [32, 9, -6, 3], [28, -12, 2, 12], [-25, -3, -5, 9], [-7, 27, -1, -9], [0, 13, -8, -1], [2, 12, -4, -12], [2, -28, 0, 10], [1, 19, -3, -17], [6, -5, 18, -5], [-2, 7, 0, 11], [6, 20, 2, -20], [-1, -18, -5, -8], [12, -12, -10, -8], [10, 7, -12, 3], [36, 0, 4, -12], [1, 4, 11, 8], [18, 0, 14, 0], [4, -16, -8, 4], [-27, -4, -5, 6], [2, 1, 6, -3], [-10, -3, 6, -7], [20, -1, 14, 3], [28, 4, 0, -14], [14, 0, 8, -14], [0, -5, 4, 1], [40, 0, -2, 0], [-40, -1, -4, 7], [-20, -15, -4, 23], [20, -16, -4, -4], [18, 0, 2, -6], [24, -4, -8, 2], [12, -2, -2, 12], [-12, 11, -6, -5], [-16, -4, 0, -16], [-36, 4, 0, 4], [14, 10, 8, -10], [24, -5, -12, -7], [-40, 9, 4, -3], [25, -12, 9, 6], [9, 20, 3, -4], [-4, 21, 2, 13], [-33, 0, -5, -14], [-12, 33, 2, -7], [-20, -5, 8, -1], [-27, 15, 11, -3], [22, 18, 10, -14], [28, -17, 10, 7], [47, -1, 7, -5], [16, -1, -14, 5], [-22, 9, 2, -7], [-15, -2, 7, 4], [0, 18, -2, -4], [-19, 19, 7, 7], [18, -6, -4, -2], [-11, 5, -7, -7], [8, -8, 12, -4], [-8, 15, -6, -5], [-10, -8, -2, 2], [-10, 21, 4, 15], [16, 2, -12, -4], [-52, 18, 6, 2], [-10, 6, 2, 10], [11, -17, -3, 11], [10, -15, 6, 5], [36, -3, 8, -5], [-38, -7, 0, -3], [-28, -24, -2, 12], [29, -14, 15, 18], [4, -4, -8, -4], [-26, 10, -6, 6], [8, -4, -4, 4], [49, -16, 5, 16], [-36, 2, -6, 14], [4, -9, 6, 15], [20, 5, 8, -7], [12, 13, -10, -3], [37, 6, 1, 2], [-16, 35, 4, -11], [-34, -10, -2, 18], [-33, -14, 7, 2], [-19, 9, 15, 1], [-4, 9, 14, 13], [4, 7, 2, 9], [-44, -20, 0, 8], [-10, 17, -8, 1], [43, 22, 1, -14], [12, -30, -6, 10], [-18, -17, 0, -17], [-30, 15, 2, 11], [20, 12, 6, -16], [3, -2, -1, 6], [-6, 8, 0, 10], [22, -21, -2, 11], [-10, 2, -2, 28], [-3, -26, 5, 4], [-7, 13, -13, -9], [6, 0, 14, 6], [18, -4, 0, 10], [-13, -25, 5, 3], [-11, -11, -9, -3], [-38, 8, 0, -12], [-5, 14, -5, 6], [31, 9, 5, 13], [-14, -17, 12, -5], [-4, 22, 0, -2], [12, -14, -2, -12], [0, 2, 0, -26], [13, 1, 1, -23], [-59, 4, -1, 4], [46, -11, -4, -3], [46, 0, 0, -6], [15, 13, -7, 21], [24, 16, 2, 0], [2, -11, -14, 3], [18, 19, 8, 3], [25, -25, 1, 7], [-31, 6, -11, -22], [-12, -28, -12, 12], [66, 11, 6, -7], [-13, 6, 9, -6], [6, -15, 6, -3], [-41, 8, -7, 0], [-27, -1, 13, -5], [8, 14, -8, -14], [-8, -10, -8, 6], [-9, -22, -13, 10], [-22, 30, -4, -18], [-16, 9, -8, -3], [5, -1, -21, 3], [-10, -16, -10, 20], [23, 23, 1, -15], [6, 4, -2, -4], [-14, -18, -4, 22], [7, -30, -7, -2], [25, -1, -11, 7], [33, 2, -5, 16], [-41, 14, -5, -10], [-7, -13, -17, 3], [48, 5, 2, 5], [18, 11, -6, 5], [-3, 10, -5, 22], [12, -15, 6, 1], [6, -8, 4, 0], [21, -9, -5, -5], [75, 3, 3, -3], [-4, -16, -6, 20], [18, 1, -2, 3], [-34, 6, 4, 0], [12, -5, -8, -13], [-14, 6, -6, -12], [-23, -5, 9, 11], [-47, -1, -5, 3], [5, 3, -1, 7], [0, -21, 2, 3], [-22, 4, -10, -12], [36, 27, -14, 3], [62, -2, 4, 10], [-31, -12, -7, 2], [-12, -29, -12, 15], [15, 7, 7, -13], [36, -21, 2, 11], [-1, 6, -9, -4], [-35, -7, 1, 5], [-50, 4, -4, -2], [10, -3, -10, -3]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5775_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5775_2_a_bz();".
// 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_5775_2_a_bz(:prec:=4)
    chi := MakeCharacter_5775_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(2999) - 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_5775_2_a_bz();".
// 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_5775_2_a_bz( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5775_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![2, 0, -7, 0, 1]>,<13,R![40, -72, -2, 8, 1]>,<17,R![-10, -1, 1]>],Snew);
    return Vf;
end function;