
// Make newform 4732.2.a.c in Magma, downloaded from the LMFDB on 27 December 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4732_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_4732_2_a_c();".
// 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_4732_2_a_c();".
// 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_4732_a();"
function MakeCharacter_4732_a()
    N := 4732;
    order := 1;
    char_gens := [2367, 2705, 4565];
    v := [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_4732_a_Hecke(Kf)
    return MakeCharacter_4732_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], [0], [-1], [-1], [-2], [0], [-3], [-6], [-4], [-7], [4], [9], [9], [10], [-2], [9], [14], [-5], [-8], [10], [-7], [2], [-6], [6], [2], [-17], [-14], [2], [-14], [11], [-14], [14], [15], [-14], [-3], [18], [11], [2], [18], [2], [0], [15], [-8], [11], [-18], [14], [8], [6], [-12], [-6], [-26], [-6], [-3], [30], [-3], [-18], [-6], [10], [-3], [7], [-2], [31], [-4], [-12], [2], [-3], [14], [-25], [0], [-14], [1], [0], [20], [29], [16], [30], [9], [14], [15], [1], [36], [25], [24], [1], [-34], [-36], [-26], [-17], [-21], [-14], [14], [12], [-16], [16], [40], [-2], [-29], [21], [-12], [-7], [-8], [-3], [-10], [22], [12], [-27], [44], [29], [34], [-35], [18], [17], [-41], [-2], [-32], [-41], [20], [46], [6], [36], [-13], [-41], [-30], [-2], [-20], [-18], [-43], [14], [52], [-1], [-36], [16], [-6], [6], [-6], [18], [2], [-52], [-6], [15], [-40], [-10], [48], [-6], [55], [26], [-5], [37], [-16], [10], [21], [57], [16], [16], [-18], [-12], [-18], [-27], [33], [10], [60], [-58], [32], [-6], [-33], [2], [36], [59], [-10], [-13], [36], [39], [-62], [-29], [12], [13], [-10], [25], [64], [26], [48], [40], [-11], [50], [-44], [-17], [46], [6], [-61], [60], [-11], [48], [-56], [50], [-2], [-6], [-13], [-35], [-43], [-14], [57], [-10], [11], [13], [-26], [3], [-14], [42], [-57], [-24], [-37], [-30], [-10], [-50], [-6], [-35], [-44], [65], [52], [-30], [25], [14], [27], [-32], [60], [-19], [-67], [48], [-14], [-12], [1], [4], [-60], [31], [56], [-10], [-50], [49], [54], [-10], [60], [52], [-36], [-31], [-7], [-30], [44], [-20], [26], [-30], [14], [26], [16], [53], [46], [40], [-42], [8], [-6], [61], [64], [0], [-37], [43], [-63], [-68], [-14], [-55], [-42], [-39], [31], [-32], [-3], [-22], [-82], [36], [38], [45], [-41], [66], [-40], [54], [26], [-13], [12], [-62], [47], [53], [56], [-7], [66], [-40], [15], [80], [-26], [-81], [-42], [71], [-56], [-52], [41], [29], [12], [-4], [10], [23], [4], [3], [-2], [9], [12], [-58], [15], [46], [2], [-55], [-24], [-76], [74], [47], [44], [-26], [75], [8], [38], [-11], [-86], [30], [-14], [17], [1], [-7], [-22], [66], [80], [-22], [-55], [74], [9], [-94], [54], [-33], [-29], [-38], [14], [-50], [7], [44], [44], [-6], [-8], [-38], [57], [-4], [-39], [9], [48], [48], [-45], [42], [73], [-39], [-46], [-70], [20], [-74], [66], [22], [-45], [-42], [4], [74], [9], [0], [-15], [66], [-6], [-34], [17], [61], [90], [-61], [6], [-2], [-14], [18], [-78], [98], [-28], [-28], [39], [-29], [-6], [62], [-30], [22], [-102], [-58], [18], [-3], [94], [-34], [88], [-83], [-21], [8], [-74], [-33], [-2], [72], [49], [-27], [32], [46], [-13], [63], [-6], [-44], [90], [-78], [-67], [55], [72], [36], [74], [43], [-34], [87], [-2], [16]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4732_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4732_2_a_c();".
// 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_4732_2_a_c(:prec:=1)
    chi := MakeCharacter_4732_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_4732_2_a_c();".
// 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_4732_2_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4732_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![0, 1]>,<5,R![1, 1]>,<11,R![2, 1]>],Snew);
    return Vf;
end function;