
// Make newform 5950.2.a.c in Magma, downloaded from the LMFDB on 02 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_5950_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_5950_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_5950_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_5950_a();"
function MakeCharacter_5950_a()
    N := 5950;
    order := 1;
    char_gens := [477, 2551, 2451];
    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_5950_a_Hecke( : Kf := Kf)
    return MakeCharacter_5950_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 := [[-1], [-2], [0], [1], [3], [2], [1], [5], [6], [9], [5], [2], [3], [-10], [0], [-12], [9], [8], [8], [12], [-1], [2], [-9], [-6], [-1], [-15], [2], [15], [14], [12], [-13], [-6], [9], [-16], [6], [-13], [17], [-16], [-15], [0], [-18], [2], [-15], [-4], [-3], [-25], [-25], [14], [24], [26], [-30], [21], [-1], [12], [30], [-12], [0], [20], [-13], [15], [2], [-9], [-7], [0], [-1], [21], [-28], [-22], [12], [-1], [6], [33], [8], [-16], [-31], [36], [0], [20], [-18], [-10], [24], [8], [-30], [-16], [20], [30], [30], [17], [-9], [-28], [-36], [-21], [-16], [0], [20], [-12], [-3], [21], [29], [17], [-1], [6], [36], [-6], [-37], [20], [-12], [42], [3], [-37], [35], [2], [30], [-10], [41], [-12], [-10], [-48], [18], [-48], [14], [8], [12], [-12], [14], [-12], [5], [0], [32], [-7], [-28], [12], [-4], [2], [42], [14], [-9], [-34], [-21], [42], [-16], [-3], [-28], [-24], [-49], [-45], [26], [-30], [-4], [24], [-10], [51], [-46], [3], [41], [0], [-16], [-30], [2], [-6], [-57], [-33], [-37], [21], [42], [21], [2], [20], [-34], [54], [-42], [59], [42], [-1], [-46], [-3], [44], [42], [-34], [-37], [-19], [-36], [-22], [6], [-39], [-57], [5], [8], [-40], [3], [-13], [-9], [38], [-51], [-9], [-54], [-4], [-37], [57], [30], [9], [-7], [23], [8], [45], [-9], [-52], [24], [12], [-37], [8], [-57], [8], [-27], [51], [14], [-19], [36], [-48], [42], [-40], [-28], [3], [2], [-39], [-70], [-9], [72], [8], [12], [-46], [-16], [-13], [39], [-37], [18], [65], [-27], [36], [6], [-21], [-52], [56], [20], [18], [36], [47], [-36], [-10], [3], [38], [75], [9], [-34], [15], [0], [11], [2], [24], [38], [14], [-24], [-4], [56], [18], [-37], [-6], [-6], [-40], [6], [20], [-70], [68], [-19], [56], [38], [18], [44], [-7], [-21], [-66], [-76], [9], [-70], [-76], [12], [2], [-75], [-10], [-6], [-9], [48], [-51], [-84], [-79], [6], [62], [66], [-42], [80], [14], [-6], [20], [39], [-4], [50], [6], [-76], [-3], [86], [3], [30], [-12], [8], [-51], [-16], [12], [60], [-37], [9], [44], [-22], [78], [-1], [-36], [-40], [29], [-34], [90], [-90], [50], [-57], [53], [69], [47], [-60], [26], [87], [-85], [38], [62], [-27], [-54], [59], [24], [12], [-58], [-10], [72], [-24], [-28], [2], [0], [-37], [-70], [-66], [42], [72], [-18], [9], [29], [-30], [3], [15], [41], [-25], [48], [-67], [62], [12], [-88], [36], [-90], [56], [83], [-42], [-18], [-40], [66], [62], [66], [-21], [92], [-90], [86], [-3], [5], [-49], [-73], [-90], [26], [78], [36], [8], [9], [38], [8], [-6], [65], [36], [-4], [15], [92], [42], [6], [32], [32], [39], [-31], [-18], [77], [-6], [-12], [-79], [77], [-18], [-66], [-43], [-33], [-18], [-18], [56], [-48], [-21], [47], [18], [-75], [-42], [23], [45]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5950_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5950_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_5950_2_a_c(:prec:=1)
    chi := MakeCharacter_5950_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_5950_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_5950_2_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5950_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![2, 1]>,<11,R![-3, 1]>,<13,R![-2, 1]>,<19,R![-5, 1]>],Snew);
    return Vf;
end function;