
// Make newform 4900.2.a.o in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4900_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_4900_2_a_o();".
// 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_4900_2_a_o();".
// 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_4900_a();"
function MakeCharacter_4900_a()
    N := 4900;
    order := 1;
    char_gens := [2451, 1177, 101];
    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_4900_a_Hecke(Kf)
    return MakeCharacter_4900_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], [-5], [1], [6], [4], [3], [-2], [-8], [10], [2], [-7], [2], [-14], [8], [-14], [0], [-10], [-11], [-4], [-4], [-3], [10], [-7], [-18], [-11], [-16], [6], [-12], [-16], [-16], [-22], [-3], [-14], [16], [21], [21], [-20], [-10], [3], [12], [18], [22], [17], [29], [9], [-2], [8], [13], [16], [4], [18], [-18], [8], [16], [-20], [-13], [-1], [9], [23], [-14], [-25], [-18], [20], [8], [-8], [22], [9], [-8], [-23], [-12], [8], [-32], [-15], [-23], [-11], [10], [18], [-19], [-33], [-14], [28], [26], [-9], [18], [12], [20], [19], [16], [20], [-15], [-5], [-9], [24], [-30], [16], [-25], [-16], [12], [12], [10], [12], [11], [-44], [23], [35], [22], [-29], [26], [12], [0], [31], [-18], [-15], [-28], [-14], [-37], [4], [-4], [31], [-48], [-28], [-29], [27], [-12], [16], [-33], [3], [18], [13], [-16], [12], [-50], [-21], [-3], [37], [5], [-16], [-3], [-14], [-32], [-46], [0], [46], [-42], [-52], [30], [54], [-16], [56], [8], [-16], [16], [29], [-18], [9], [-40], [54], [-50], [-14], [-2], [54], [-53], [12], [-3], [-47], [38], [-12], [38], [63], [24], [34], [-60], [23], [-7], [4], [52], [20], [12], [-22], [-42], [-56], [12], [22], [53], [45], [12], [-6], [-6], [-27], [-42], [8], [51], [43], [-46], [5], [-27], [6], [2], [10], [-2], [54], [-3], [-20], [-12], [-14], [-44], [26], [-36], [26], [-23], [-46], [-8], [40], [50], [6], [-44], [18], [-10], [-15], [38], [-7], [46], [-63], [51], [37], [24], [12], [2], [8], [-55], [61], [5], [-38], [36], [-75], [68], [-60], [28], [33], [-58], [23], [26], [-48], [2], [-59], [-42], [-42], [-30], [62], [76], [-22], [31], [30], [36], [47], [-57], [-6], [-28], [14], [-45], [2], [-36], [-11], [54], [66], [-6], [-22], [-46], [1], [-64], [-34], [33], [16], [-26], [37], [-14], [69], [33], [32], [-4], [49], [-41], [14], [38], [-26], [-82], [-47], [63], [62], [-74], [2], [18], [-72], [-21], [64], [73], [29], [-80], [35], [-60], [17], [-44], [-30], [-12], [-36], [-26], [44], [-77], [26], [66], [78], [-52], [-6], [-37], [13], [49], [22], [-38], [0], [-26], [-22], [-50], [-19], [-4], [-58], [-34], [-34], [-26], [44], [-81], [-52], [-39], [9], [-42], [70], [65], [44], [78], [-68], [51], [16], [-12], [56], [4], [12], [29], [6], [-52], [93], [-19], [-11], [-54], [26], [12], [-78], [-64], [48], [18], [66], [-49], [28], [46], [-27], [26], [-47], [-45], [60], [14], [-21], [10], [-54], [-20], [-97], [59], [16], [-53], [38], [-4], [22], [-44], [-70], [81], [71], [59], [40], [-9], [25], [5], [-55], [-88], [75], [24], [52], [70], [83], [-10], [84], [6], [-80], [13], [-20], [-78], [12], [47], [-20], [72], [13], [-74], [-36], [-20], [40], [64], [47], [48], [-26], [1], [-3], [-34], [22], [0], [3], [61], [-50], [50], [-50], [84]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4900_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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