
// Make newform 6050.2.a.h in Magma, downloaded from the LMFDB on 17 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_6050_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_6050_2_a_h();".
// 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_6050_2_a_h();".
// 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_6050_a();"
function MakeCharacter_6050_a()
    N := 6050;
    order := 1;
    char_gens := [727, 2301];
    v := [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_6050_a_Hecke( : Kf := Kf)
    return MakeCharacter_6050_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], [-1], [0], [2], [0], [-4], [-3], [-5], [-6], [0], [2], [-2], [3], [-4], [-12], [-6], [0], [-2], [13], [12], [11], [10], [-9], [15], [-2], [18], [4], [-3], [10], [9], [2], [-12], [3], [-5], [0], [-2], [-2], [-11], [12], [-24], [-15], [2], [-18], [-19], [-18], [20], [13], [4], [12], [20], [6], [0], [-17], [27], [18], [6], [0], [-2], [32], [18], [11], [6], [17], [-18], [-26], [-12], [17], [-13], [-3], [10], [-6], [-30], [28], [26], [-25], [-6], [30], [28], [-3], [-5], [-15], [-28], [18], [19], [40], [9], [-15], [17], [-12], [4], [-12], [-30], [-2], [-12], [20], [36], [-30], [-3], [41], [-32], [17], [12], [-24], [15], [28], [13], [33], [-9], [30], [13], [32], [-34], [18], [20], [2], [42], [4], [-12], [-6], [-15], [32], [26], [-48], [39], [17], [-12], [20], [-30], [-32], [-4], [-20], [6], [32], [-32], [3], [-5], [24], [-28], [-42], [30], [28], [-42], [4], [-33], [20], [0], [26], [-3], [5], [24], [-28], [-18], [-41], [12], [28], [12], [10], [30], [-13], [-12], [48], [-39], [32], [-3], [-57], [-6], [-58], [-28], [-5], [24], [-15], [2], [18], [11], [-40], [15], [13], [-18], [56], [-50], [28], [-57], [34], [-33], [-36], [-60], [2], [19], [55], [48], [49], [51], [-13], [-18], [-3], [54], [13], [-26], [27], [6], [30], [28], [-32], [-35], [-60], [-42], [50], [36], [-30], [32], [2], [42], [64], [-57], [30], [17], [2], [3], [18], [-66], [-62], [-20], [-15], [34], [57], [10], [9], [0], [-28], [33], [-26], [25], [-2], [33], [64], [-18], [5], [-24], [-45], [12], [39], [-47], [-26], [20], [51], [0], [58], [12], [25], [-24], [32], [-27], [18], [35], [-24], [-15], [32], [-73], [78], [-43], [-34], [27], [40], [-4], [3], [-55], [30], [-18], [41], [-54], [-28], [-47], [-71], [40], [2], [4], [-57], [40], [-62], [63], [36], [-58], [72], [28], [-13], [72], [34], [-48], [80], [30], [42], [-12], [-69], [-27], [-4], [-30], [2], [24], [-60], [-73], [41], [-18], [-80], [-21], [-13], [-17], [-12], [-10], [-30], [-34], [6], [-30], [63], [64], [12], [10], [-75], [-72], [49], [45], [28], [-77], [-12], [-26], [-54], [2], [35], [4], [42], [36], [28], [-42], [10], [21], [-17], [48], [-40], [66], [47], [2], [-56], [63], [-30], [92], [-6], [-60], [-28], [13], [48], [18], [73], [-2], [-18], [-4], [-50], [51], [-60], [63], [-18], [84], [2], [93], [18], [-60], [-47], [-11], [72], [56], [43], [12], [5], [-84], [-60], [-32], [58], [45], [-42], [11], [15], [2], [42], [-81], [-88], [87], [40], [-66], [32], [-32], [56], [-42], [-85], [-36], [-45], [73], [42], [-19], [-20], [-15], [-43], [78], [40], [99], [92], [-57], [0], [88], [-2], [-42], [4], [75], [-49], [-48], [9], [28], [-73], [102], [-30], [-2], [-57], [6], [0], [62], [78], [-15], [-101], [48], [-96], [-75], [17], [-30]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6050_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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