
// Make newform 4900.2.a.w 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_w();".
// 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_w();".
// 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], [3], [0], [0], [3], [1], [-5], [8], [-2], [-1], [2], [-10], [6], [4], [11], [-6], [10], [0], [10], [0], [-10], [-7], [12], [-8], [3], [12], [-5], [-8], [-7], [10], [2], [-2], [-4], [-10], [-6], [9], [-18], [-6], [3], [-9], [4], [10], [7], [-8], [-10], [-18], [-3], [19], [27], [26], [-16], [5], [18], [-2], [6], [24], [-2], [0], [14], [15], [-7], [15], [-19], [-12], [-7], [-28], [20], [-22], [-18], [-36], [-9], [28], [19], [-32], [28], [0], [9], [-17], [-27], [-4], [-2], [-23], [-37], [-38], [-26], [-12], [11], [22], [-28], [-4], [-23], [18], [26], [33], [-29], [1], [-26], [-12], [-20], [-25], [8], [-20], [-16], [18], [20], [17], [28], [-3], [-21], [-8], [5], [12], [34], [2], [15], [-26], [-5], [-24], [-36], [39], [-28], [16], [-11], [-40], [-40], [-25], [15], [-2], [28], [41], [-5], [-30], [13], [48], [38], [-16], [-27], [3], [43], [-11], [-6], [45], [18], [22], [-34], [46], [26], [-22], [-24], [-46], [-40], [48], [-4], [12], [-38], [-52], [-55], [18], [7], [40], [-6], [42], [-8], [-18], [60], [13], [-32], [-53], [1], [-26], [-36], [-12], [-17], [-34], [20], [48], [-1], [25], [12], [-20], [-16], [40], [-40], [42], [-44], [18], [42], [-17], [1], [-36], [-34], [12], [25], [-42], [28], [1], [-61], [-6], [-49], [23], [-2], [-28], [-54], [60], [36], [23], [30], [32], [42], [4], [-22], [50], [-30], [-45], [68], [-44], [18], [54], [-12], [-34], [-26], [-8], [45], [36], [-37], [-54], [-21], [-25], [-5], [-12], [16], [-48], [32], [45], [-29], [-9], [26], [60], [-39], [30], [-12], [68], [71], [6], [-27], [24], [-8], [12], [69], [72], [-8], [-48], [-58], [-44], [-42], [67], [38], [32], [9], [65], [-4], [-66], [-22], [29], [-38], [-10], [57], [-28], [18], [-12], [2], [-78], [7], [-16], [30], [-57], [12], [22], [17], [-36], [39], [37], [-32], [-2], [59], [15], [28], [48], [10], [-6], [-39], [-15], [18], [58], [-20], [74], [26], [73], [-36], [-73], [23], [-62], [51], [-36], [61], [74], [68], [4], [-24], [74], [88], [-81], [-30], [-84], [-48], [40], [84], [-5], [-41], [21], [68], [-34], [-50], [22], [-88], [-14], [1], [76], [18], [46], [-26], [30], [-22], [45], [-44], [47], [-27], [-34], [-64], [-49], [74], [74], [-78], [31], [-30], [-8], [-38], [72], [6], [83], [6], [20], [77], [63], [53], [-86], [-64], [-54], [-12], [18], [48], [42], [-34], [35], [-92], [-24], [43], [40], [-51], [39], [28], [66], [99], [80], [44], [52], [-57], [-15], [26], [61], [72], [14], [54], [-42], [-14], [-21], [7], [41], [76], [57], [77], [27], [-35], [-44], [15], [-96], [56], [86], [-61], [26], [24], [-26], [66], [51], [48], [100], [42], [-69], [44], [84], [63], [-60], [-38], [-60], [58], [-24], [-33], [56], [42], [-21], [21], [-46], [-20], [4], [-75], [39], [26], [-6], [-42], [-28]];
    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_w();".
// 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_w(: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_w();".
// 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_w( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4900_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-3, 1]>,<11,R![-3, 1]>,<13,R![-1, 1]>,<19,R![-8, 1]>,<23,R![2, 1]>],Snew);
    return Vf;
end function;