
// Make newform 4704.2.a.bg in Magma, downloaded from the LMFDB on 20 April 2026.
// 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_bg();".
// 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_bg();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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 := 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]];
    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], [4], [0], [2], [2], [0], [-4], [6], [-10], [-8], [10], [4], [8], [-4], [10], [8], [6], [-4], [-14], [-6], [-4], [-12], [-4], [2], [0], [0], [10], [14], [2], [20], [-20], [6], [4], [-6], [0], [22], [-20], [20], [-24], [6], [-14], [-6], [6], [2], [-8], [-8], [-16], [0], [-14], [-18], [6], [2], [-24], [4], [30], [-12], [-24], [10], [6], [-20], [0], [-12], [-12], [14], [18], [32], [-22], [-2], [14], [8], [-22], [24], [14], [-32], [8], [30], [38], [22], [-22], [16], [-22], [18], [14], [8], [6], [10], [-22], [0], [20], [-8], [-12], [40], [-10], [-24], [24], [36], [0], [-36], [-14], [-12], [-22], [-24], [14], [-20], [6], [48], [24], [10], [-34], [-8], [6], [-18], [36], [-4], [-2], [-12], [12], [-26], [-6], [22], [-34], [-16], [-18], [-28], [-18], [-26], [32], [0], [-38], [-20], [-6], [-16], [-42], [-12], [-34], [-24], [36], [-24], [-14], [20], [2], [4], [26], [-14], [44], [-42], [-28], [-20], [22], [-50], [-48], [8], [-12], [-32], [18], [0], [36], [-2], [-4], [18], [-6], [-12], [-20], [14], [0], [-16], [6], [-2], [8], [-30], [-42], [26], [-26], [8], [-16], [44], [-42], [-16], [-34], [44], [28], [-14], [-8], [-18], [-16], [30], [28], [38], [-24], [26], [26], [-64], [32], [34], [48], [-2], [-38], [-20], [-52], [-54], [-56], [34], [-6], [4], [0], [8], [34], [10], [-20], [50], [12], [24], [12], [20], [54], [-16], [-40], [14], [6], [38], [40], [-30], [-32], [-36], [-22], [-36], [54], [8], [38], [46], [-20], [-32], [66], [4], [64], [-14], [-6], [-66], [-8], [54], [-12], [0], [18], [44], [-44], [-16], [-48], [-68], [-26], [-66], [40], [42], [-54], [-32], [18], [-30], [-52], [-72], [38], [52], [6], [58], [-10], [24], [44], [-62], [-56], [-4], [-42], [46], [-8], [-38], [24], [2], [-24], [-22], [2], [46], [-64], [24], [-4], [-16], [54], [-4], [18], [82], [26], [80], [20], [-6], [12], [-66], [80], [6], [-24], [80], [84], [-24], [4], [-34], [-10], [68], [26], [28], [58], [6], [-30], [42], [-70], [72], [-2], [14], [64], [30], [-70], [-36], [-82], [2], [-66], [36], [-10], [40], [16], [-54], [-70], [36], [60], [-22], [22], [46], [-58], [16], [32], [-20], [-8], [30], [-76], [34], [0], [62], [22], [20], [-80], [38], [42], [42], [8], [56], [-32], [-20], [-10], [10], [72], [78], [0], [0], [60], [98], [-46], [-2], [84], [50], [-94], [20], [-74], [60], [-44], [-50], [-18], [44], [66], [42], [-40], [2], [-36], [-10], [-74], [96], [66], [96], [-46], [-32], [90], [-44], [64], [-72], [-62], [-52], [52], [62], [-76], [42], [28], [26], [66], [-56], [24], [-68], [-10], [38], [18], [44], [36], [92], [32], [-94], [-46], [-60], [32], [14], [-34], [102], [-48], [-26], [92], [-58], [-88], [56], [68], [38], [22], [-38], [-12], [46], [-80], [-90], [-106], [52], [-60]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4704_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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