
// Make newform 6050.2.a.dm in Magma, downloaded from the LMFDB on 22 May 2024.
// 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_dm();".
// 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_dm();".
// 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
        poly := [9, 6, -8, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [3, -5, -2, 1], [-5, -1, 1, 0]];
    Rf_basisdens := [1, 1, 3, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
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)
    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+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 := [[1, 0, 0, 0], [0, 1, -1, 0], [0, 0, 0, 0], [-1, 1, -1, 0], [0, 0, 0, 0], [-1, 1, -2, 0], [0, -1, 0, 1], [3, 1, 1, -1], [1, -2, 1, 1], [0, 2, -3, 1], [-2, 2, 0, 1], [0, 2, -2, 0], [2, -1, -1, -1], [-4, 1, 3, 0], [0, 0, 0, 3], [-1, -1, -1, -1], [-1, -3, -1, 1], [10, -2, 3, 1], [-3, 1, 1, 1], [1, 0, -5, 2], [6, 0, 1, 0], [4, 2, 0, 0], [-4, -2, 2, 0], [-5, 2, -2, 0], [-3, 2, 2, -4], [7, -3, 1, -1], [-4, -2, 4, 1], [-4, 4, -4, 0], [6, -2, 0, 2], [13, -5, 4, 1], [12, -3, 4, 0], [11, -2, 2, 3], [10, -3, -2, -1], [-1, 3, -7, 1], [4, -2, -5, 1], [3, -5, 1, 2], [1, 7, -4, 0], [-4, -1, -5, 0], [10, -3, 4, 2], [3, -3, 0, 0], [-3, -4, 6, 1], [11, -5, -3, -1], [6, -6, 0, 0], [-10, 2, 1, -4], [8, 0, 5, 1], [-9, 2, -1, -1], [6, 1, -3, 2], [0, -6, 2, 1], [3, -3, -3, -3], [-7, -3, 7, -1], [-4, -3, 5, 1], [-6, 5, 0, -2], [20, 2, -5, 2], [1, 2, 10, -3], [-2, 3, -8, -1], [-12, 5, 0, -2], [-2, -4, -5, 3], [-2, 3, 4, -4], [-1, -1, -2, -4], [10, 0, 7, 2], [-6, -2, 4, -4], [-3, -7, -3, 1], [0, -1, 5, 4], [-9, 4, 3, -1], [-2, 7, -4, -3], [-6, 2, 9, 1], [10, 5, -1, 2], [-4, -10, 2, 2], [4, 0, -14, 2], [1, 3, 3, -7], [0, 1, 6, -1], [-9, -3, -3, 0], [-6, 0, -10, 1], [3, -1, 0, -2], [1, 0, -4, 7], [-2, -4, -2, 0], [0, -4, 3, -5], [-16, 2, 7, -3], [-3, -2, -6, -4], [16, -7, 1, -3], [9, 0, 6, -3], [-5, 1, -6, 2], [0, 5, 0, 4], [8, 3, 10, -1], [16, 5, -2, 0], [-17, 4, -2, -5], [4, 3, 4, -1], [6, 2, -3, 4], [5, -7, -7, -1], [-11, -10, 3, 1], [14, 1, 5, 0], [1, -3, 1, 2], [-11, 6, -7, -5], [-1, 4, 8, -3], [9, -1, 11, -1], [8, -10, 14, 2], [11, -3, 8, -2], [11, 4, -10, 6], [-5, -8, -4, 7], [3, 5, -2, -2], [7, 3, 7, -7], [-1, -9, -7, 7], [-8, 8, 4, -6], [4, -1, -5, 3], [13, -5, 1, 1], [-17, -3, -4, 1], [-14, -2, 16, -2], [-2, -2, -11, -2], [14, 12, -10, 1], [8, -8, 7, 6], [-12, -3, -6, 0], [-11, -3, 15, -1], [-1, -3, -4, 1], [7, 0, -16, 7], [-17, 2, 3, 1], [5, 4, 2, 0], [-11, -10, 18, -5], [-12, 12, -12, -3], [-3, -3, -9, 3], [-19, -6, 8, 1], [4, -8, 9, -1], [22, 9, 0, -1], [-7, 1, -1, -3], [-3, 4, 0, -1], [16, -7, -1, 8], [2, -6, 5, -5], [-10, 8, 4, 0], [3, 4, -15, -1], [-21, 4, 13, 1], [3, -13, -6, 4], [14, 4, -6, 6], [12, -4, -6, 4], [-15, -2, -13, 3], [-7, -9, 0, 0], [-2, -8, 13, -8], [10, 8, -3, 0], [7, -11, 13, 1], [-7, -4, -2, -7], [20, 0, -1, -5], [-4, -3, -13, 1], [4, -1, 1, 0], [4, -12, 10, 2], [-5, 8, 9, -5], [-16, 19, -1, 0], [-25, -1, 15, 1], [13, 14, -5, 0], [7, -1, 14, 0], [-18, 5, -3, 7], [1, -4, -10, -1], [-11, -6, -11, -1], [-10, 10, -9, 3], [-13, -11, 8, 3], [-13, 10, -6, -7], [-4, 7, -16, 0], [1, 7, 3, -7], [-7, -4, -7, -1], [-1, 17, -1, -4], [8, -3, 8, 7], [-10, 1, -7, 3], [-26, 12, 4, 2], [23, 7, -7, 3], [-10, 4, -22, 0], [-23, 5, 3, 0], [-20, 7, -17, -2], [4, -13, -2, -3], [-31, 6, -1, 4], [22, -6, 0, 3], [-18, 18, -14, 0], [-18, 10, -4, 2], [8, -2, 14, 6], [8, 1, -13, -6], [14, -12, -6, 0], [-3, -9, -9, 0], [42, 2, -5, -2], [-6, 4, 10, -8], [5, 11, -16, 5], [-18, 1, -3, -4], [-23, 9, -2, 8], [-18, 7, 10, -4], [10, 14, -16, 6], [12, -6, -2, -7], [-14, -3, -17, 2], [10, -6, -4, 16], [4, 3, 4, -13], [-28, 12, -4, -2], [18, -14, -3, -1], [-6, -10, 12, 4], [30, -9, -1, -2], [10, 11, -4, 3], [-4, -3, 14, -2], [7, 6, 2, -2], [-19, 0, -10, 1], [-11, 24, 0, -3], [-28, 18, -10, -8], [12, 3, 9, 0], [39, -12, 6, 0], [6, 1, 3, -7], [27, -5, -4, 6], [48, -6, 3, 0], [23, -17, 17, 6], [-11, 13, -14, -8], [-16, 13, 0, -6], [16, -16, 15, 1], [4, -21, 5, 5], [-2, -4, -8, 6], [33, -3, -6, 0], [15, -6, -11, -1], [-25, -4, 20, -1], [-6, 7, 0, -13], [8, 3, 19, -4], [-40, 4, -7, -6], [21, -7, 15, 1], [-5, -6, -7, 1], [27, -6, 12, -3], [-10, -12, -4, 10], [1, 11, -18, 1], [-7, -5, 27, 0], [10, -15, -2, 5], [-27, 8, -21, -2], [-19, -1, 17, -1], [-27, 11, -3, 7], [41, -2, -3, -6], [11, 17, 2, -7], [-9, 4, 5, -6], [19, 3, 1, -7], [20, -22, 13, -1], [23, 4, -10, 6], [17, 6, -7, 7], [-20, 11, 14, 0], [-14, -6, 22, -4], [-13, 9, -11, -7], [13, -9, -3, 5], [-10, -1, 22, -4], [4, -11, -8, 13], [6, 2, 10, 0], [16, -4, 4, 6], [-11, 21, 6, -3], [26, -8, -7, 3], [29, -4, 14, -1], [-45, 8, -3, 1], [18, 1, 9, -4], [12, -4, 2, -2], [-1, -18, 3, 3], [17, -7, 4, 0], [-16, -9, 20, -11], [-2, 4, 22, -2], [-21, 0, 13, 2], [2, -3, -13, -8], [-12, -8, 20, -10], [7, 18, -5, 2], [-38, -6, 3, -1], [-10, 15, 2, -11], [24, -8, 0, -1], [-11, -3, 0, -9], [-26, 0, -2, -4], [-22, -6, 26, -2], [45, -11, 25, 7], [-33, 7, 3, -13], [-3, -3, -18, 12], [4, -1, -3, -9], [9, 1, -25, 2], [25, 2, -14, 3], [7, -5, -18, -2], [19, -5, -3, -5], [9, -2, 6, -4], [15, -5, 17, 9], [19, -9, -5, -7], [-20, -3, -2, 5], [37, 3, -3, 5], [-17, -3, 16, 2], [20, 4, -15, 11], [13, -3, -9, 9], [44, -4, 12, 4], [38, 1, -12, 0], [-12, 5, 12, 1], [7, -2, -7, 12], [4, 3, -17, 8], [11, -5, 18, 0], [-14, 4, -5, -2], [-9, 21, 3, -3], [40, -11, -8, -2], [2, 16, -20, -5], [2, 0, -16, 4], [27, 1, 5, -1], [15, -10, 4, 1], [12, -18, 18, 6], [34, -9, 0, -9], [-4, -12, 5, -5], [-42, 4, -10, -6], [10, 3, 13, -1], [-45, 3, -18, 0], [-15, -8, 0, 5], [-10, -7, -1, 5], [5, 0, 14, 1], [-23, -7, 8, -12], [-23, -17, -14, 10], [-28, 14, -8, -9], [35, -21, 2, -2], [-11, -11, -11, 7], [-16, -18, 28, -8], [-2, -3, -4, -1], [-13, 3, -4, 4], [-23, 2, -7, 6], [20, -15, 11, -2], [-20, -9, 21, -12], [27, -11, -8, 1], [-26, -1, 1, -6], [13, -3, 18, 6], [40, -18, 4, -1], [38, -14, 15, 3], [-7, -7, 11, -10], [36, 6, -9, 3], [-22, 9, 14, 1], [-12, 4, 28, -2], [-27, 5, -3, -8], [42, 16, -15, 2], [52, -9, 1, 2], [2, 4, 2, 0], [-3, -12, 4, 2], [10, -3, 7, -19], [7, 0, -10, -1], [2, -11, 12, -1], [-6, 6, -15, -9], [8, 12, -12, 0], [-18, 6, -12, 6], [16, -1, 2, 5], [28, -9, -9, 0], [-14, 7, -13, 0], [8, 17, 8, -10], [2, 32, -10, -4], [31, -25, 11, 9], [-7, 5, 32, -4], [-22, 7, 6, 6], [-31, 15, -25, -5], [35, -4, 12, -1], [27, 9, -27, 3], [-23, -11, 8, 6], [16, -8, -17, 16], [-19, -2, -6, -4], [-7, -9, -11, -2], [-33, 9, 11, 1], [23, -21, 26, 7], [0, 0, 6, 0], [23, -14, -3, -13], [2, 18, -4, 4], [-24, -7, -3, 4], [-6, 16, -5, 7], [-2, -6, -12, 0], [31, 5, -11, 0], [30, 22, -27, 5], [2, 1, -29, 0], [8, -11, 34, 1], [-1, 1, -19, 9], [-8, 26, 12, -6], [16, 10, -15, 13], [-22, 19, -1, 3], [-20, 14, -2, -6], [-11, 7, -5, -11], [50, -12, -1, -8], [-41, 0, 19, -13], [4, 10, 6, -14], [0, 19, -21, 5], [-44, -12, 10, -4], [11, -26, -4, 9], [-56, 14, 8, 8], [61, 9, -16, 7], [22, 16, -11, 1], [3, -9, -9, 0], [4, 1, -20, 7], [-38, 14, -2, -12], [25, -15, 29, 7], [-14, -2, 28, -8], [-14, -14, -2, -2], [54, -18, 24, 12], [-24, 12, -14, -4], [20, -4, -10, 2], [56, 14, -34, 8], [30, 8, 4, 4], [-8, 9, -23, -7], [12, -20, -5, 2], [4, 0, 4, -10], [-8, 27, -8, 5], [-40, 18, 6, 10], [56, 3, 5, 1], [-33, 12, -20, -3], [-14, 4, 28, -14], [54, 6, 20, -2], [13, 9, -36, 0], [17, -6, 2, 1], [-29, -6, 13, 8], [11, -18, 12, -12], [-9, 3, -15, -9], [14, -1, -31, 8], [51, -18, 10, 11], [10, 18, -26, 5], [-22, 17, -33, -7], [41, 5, -7, -4], [38, -3, 8, 1], [-48, 0, 4, -10], [68, -24, 29, 13], [60, 0, 6, -6], [-19, 0, 14, 10], [5, 7, -11, 12], [39, -17, -6, 5], [34, 14, -26, 12], [-11, -3, 19, -4], [-39, 17, 2, 2], [-16, -3, -16, 1], [20, -23, -3, 2], [38, -9, 5, 10], [-30, 11, 14, -5], [56, -26, 20, 12], [-30, 28, -24, 2], [38, -1, -5, -10], [58, -4, 15, 0], [-3, 31, -18, -4], [7, -13, -11, 6], [-26, 2, -36, -5], [4, 3, 4, -7], [-39, -23, 9, 2], [-8, 14, -23, -3], [-21, 23, 0, -8], [-46, 4, 8, -6], [-15, 39, -21, -3], [-28, -11, 28, 1], [2, 20, 11, -19], [-36, -2, 30, -10], [20, -9, 23, -5], [-25, 3, 9, -21], [-20, 18, 10, -4]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6050_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6050_2_a_dm();".
// 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_dm(:prec:=4)
    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_dm();".
// 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_dm( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6050_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![6, 12, -8, -2, 1]>,<7,R![9, -6, -8, 2, 1]>,<13,R![6, -12, -20, 2, 1]>,<17,R![36, -48, -20, 4, 1]>,<19,R![-552, 72, 64, -16, 1]>],Snew);
    return Vf;
end function;