
// Make newform 4704.2.a.bn in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4704_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_4704_2_a_bn();".
// 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_4704_2_a_bn();".
// 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;
    Rf_num := [[1, 0], [0, 2]];
    Rf_basisdens := [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_4704_a();"
function MakeCharacter_4704_a()
    N := 4704;
    order := 1;
    char_gens := [1471, 1765, 3137, 4609];
    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_4704_a_Hecke(Kf)
    return MakeCharacter_4704_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, 1], [0, 0], [-2, -1], [-2, 0], [-4, -1], [0, -2], [-2, -1], [2, 2], [-4, 2], [-2, 0], [-8, 1], [8, 0], [4, -2], [-2, 0], [-8, -2], [2, -2], [-4, -2], [-6, 1], [-6, 2], [4, -2], [-4, 0], [0, 1], [2, -2], [12, -1], [-4, 2], [-2, 3], [-2, 0], [-6, 4], [4, 2], [12, 0], [-2, 2], [-4, 4], [-18, 0], [-8, 4], [-6, -2], [-4, 2], [-4, 2], [-12, 3], [-6, 1], [6, 0], [-6, 1], [2, -4], [6, 4], [-8, -4], [16, 0], [-24, 0], [-16, 2], [14, -4], [6, -2], [-18, -1], [10, 2], [-16, -2], [-8, 1], [-2, 3], [0, 1], [-4, -2], [14, 4], [6, -2], [-8, 2], [-20, -1], [16, -2], [12, -2], [14, 0], [14, 4], [-24, 0], [-6, -4], [-6, 5], [10, 6], [-12, -1], [10, 5], [8, 0], [30, 0], [8, 0], [8, -8], [-6, -6], [10, 6], [-2, -2], [2, 2], [24, 2], [-18, -4], [-14, -7], [14, -4], [0, -4], [18, -3], [-6, -4], [10, -8], [-4, -9], [-12, 6], [0, -6], [-12, -2], [0, -8], [10, 1], [8, -4], [-16, 0], [16, -7], [-20, 3], [28, 0], [6, 4], [-4, 2], [-18, -4], [40, 2], [-18, 2], [4, 6], [-10, 4], [0, 6], [-12, -1], [18, -3], [-2, 12], [0, -4], [14, -4], [-2, -6], [-4, 0], [-20, 2], [14, 6], [8, 6], [-12, -2], [-14, 2], [-18, -1], [-6, 6], [18, -4], [12, 3], [-6, -7], [-28, 4], [-6, -10], [-10, -8], [0, 4], [28, 2], [22, 8], [44, 2], [-22, -3], [0, 8], [-26, 0], [-24, 1], [-18, -4], [-12, -5], [-4, -8], [4, 3], [-38, 0], [4, 12], [-26, -4], [28, 2], [6, -9], [6, 8], [-4, 2], [-30, -2], [-24, 9], [-32, 2], [6, -1], [22, 4], [-4, -5], [-8, -12], [-20, 2], [16, -8], [2, 9], [40, 0], [-24, -3], [-26, 0], [40, 1], [-2, 7], [-22, 0], [-28, 2], [-12, -4], [-10, -14], [24, 8], [40, 0], [-38, -2], [-14, -12], [-44, -1], [6, 7], [-6, -2], [-30, -3], [18, 8], [-8, 4], [28, -9], [4, -6], [18, -2], [4, -6], [2, -2], [-28, -6], [12, 4], [22, -4], [-28, 3], [-42, -5], [12, -13], [-26, 0], [12, -8], [-14, -8], [0, 4], [-14, -6], [6, 15], [8, 12], [44, 7], [46, -5], [12, -9], [18, 12], [14, -4], [0, 13], [4, -14], [6, 8], [-16, 0], [-10, 4], [10, -10], [-12, 12], [-4, -5], [-32, -8], [30, -1], [-30, 4], [-32, 10], [-14, 8], [-8, 13], [16, 8], [-36, -8], [4, 18], [14, -8], [-40, 0], [-12, -13], [30, 3], [34, 2], [-10, 8], [4, 2], [18, -8], [48, 0], [20, -4], [-2, -8], [16, 1], [-10, 11], [12, -10], [-14, -7], [-18, 0], [24, 6], [-8, -8], [2, -12], [-16, 14], [-32, 0], [18, -10], [30, -8], [-22, 9], [64, 0], [18, 9], [36, -4], [24, -8], [-10, 12], [16, -11], [20, -10], [4, 2], [-48, 2], [-12, -18], [30, -5], [22, 8], [20, 7], [10, -15], [10, -6], [-4, -5], [-10, -9], [-26, -12], [32, 10], [20, -5], [-18, -8], [-36, -10], [10, -11], [-10, -4], [2, -2], [-28, -5], [-28, 8], [-58, 0], [-12, 3], [-12, -6], [18, 14], [-30, 2], [-16, 12], [26, 2], [-56, 4], [-22, 6], [20, -6], [30, 7], [22, 12], [10, 12], [-16, 10], [-16, -8], [44, 10], [-8, 8], [-22, 6], [-4, 8], [-30, -7], [2, 16], [38, -4], [20, 6], [24, 9], [22, -16], [-36, 0], [-18, -6], [-16, 10], [22, 8], [20, -5], [-16, 4], [0, -3], [8, 18], [28, 12], [-10, 4], [42, -2], [-28, 6], [-10, -13], [-44, -10], [10, 4], [-22, -3], [-34, 12], [26, -3], [30, -4], [48, 0], [-30, -10], [46, -2], [-32, 12], [-2, 11], [-38, 2], [52, 8], [6, 15], [34, 2], [-2, 6], [0, 2], [42, 4], [4, -17], [88, 0], [-6, 8], [-46, 6], [-28, 14], [64, -2], [-62, -7], [-22, -6], [-26, -16], [66, 2], [-12, 6], [-8, 2], [-68, -2], [-32, -6], [-10, 4], [72, 1], [2, -2], [52, -2], [-34, 8], [54, -10], [-80, -3], [0, -4], [-22, 6], [6, 11], [62, 4], [-24, 16], [24, -12], [28, 7], [16, 2], [-22, -12], [-42, -8], [0, 8], [14, 0], [60, 7], [48, -4], [-12, 4], [-54, -12], [-6, 13], [-50, 0], [-24, 5], [-30, 1], [-42, -1], [52, -4], [10, 4], [-8, -19], [44, 6], [10, -4], [-22, -7], [-56, -10], [50, -3], [14, -8], [-36, 6], [22, -4], [44, -16], [-10, 3], [86, -4], [-4, -17], [18, 2], [-20, 7], [-22, -8], [32, 4], [-38, 12], [-44, -8], [24, 20], [16, -20], [46, -16], [68, -6], [-44, -10], [26, 16], [-16, -7], [-66, 3], [-8, -10], [-30, 1], [-14, 20], [-40, 4], [36, -9], [20, 10], [2, -2], [-54, -6], [-6, 4], [-36, -6], [-8, 9], [-40, 9], [-64, 0], [-10, -4], [-6, -12], [-4, -12], [8, -6], [-42, -4], [26, -14], [10, -11], [-32, 0], [2, 0], [24, -11], [-18, -5], [-60, -10], [36, -13], [84, 2], [26, -18], [-14, 2], [18, -3], [36, 8], [54, 4], [-20, 3], [2, -15], [46, 10], [-12, -16], [12, 2]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4704_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4704_2_a_bn();".
// 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_4704_2_a_bn(:prec:=2)
    chi := MakeCharacter_4704_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_4704_2_a_bn();".
// 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_4704_2_a_bn( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4704_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-12, 0, 1]>,<11,R![-8, 4, 1]>,<13,R![2, 1]>,<19,R![-48, 0, 1]>,<31,R![-32, 8, 1]>],Snew);
    return Vf;
end function;