
// Make newform 4050.2.a.bx in Magma, downloaded from the LMFDB on 24 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_4050_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_4050_2_a_bx();".
// 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_4050_2_a_bx();".
// 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 := [-3, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_4050_a();"
function MakeCharacter_4050_a()
    N := 4050;
    order := 1;
    char_gens := [2351, 3727];
    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_4050_a_Hecke( : Kf := Kf)
    return MakeCharacter_4050_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, 0], [0, 0], [0, 0], [1, 2], [-3, -1], [-5, -1], [0, -1], [-1, -1], [0, -4], [-3, 1], [-4, 2], [1, -3], [-6, -3], [-2, -4], [-6, 1], [-3, 1], [-9, 1], [-4, 6], [1, 3], [0, 6], [-5, 6], [5, 0], [9, 5], [-6, -3], [1, 4], [-12, 2], [10, 0], [-3, 5], [14, -2], [12, -1], [1, -6], [-12, 4], [0, 12], [-4, -6], [15, 3], [-7, 6], [7, -1], [-2, 4], [6, -1], [0, 4], [6, -8], [-1, -13], [-6, -11], [-5, -6], [-9, -5], [5, -8], [-1, 1], [13, -2], [-3, 3], [11, 5], [6, -12], [-18, -7], [5, 8], [-12, 2], [-18, -1], [12, -5], [-18, 8], [5, -12], [10, -8], [6, -1], [-8, -2], [0, 0], [19, -3], [-6, -5], [7, 4], [-18, 4], [-10, 0], [-11, -2], [0, -12], [-7, -3], [-12, 3], [6, 5], [13, 6], [13, 7], [-16, -10], [-12, 5], [-30, -2], [-8, -8], [-12, 15], [-1, -4], [12, -8], [-7, -9], [0, 3], [-14, -10], [14, 0], [-15, -7], [18, 5], [10, 18], [-15, -9], [28, -6], [9, 9], [6, 1], [13, 8], [6, 8], [-22, 6], [-18, 11], [-15, -9], [12, -6], [13, -9], [-28, 4], [25, -3], [15, -3], [-6, 4], [12, -10], [23, 1], [10, 12], [-18, 6], [-6, -8], [0, 9], [-37, -2], [-5, -12], [-14, -6], [24, 3], [-19, -9], [5, 20], [24, -9], [19, -3], [36, -1], [-39, 5], [-18, 16], [5, -9], [-8, -12], [-30, -4], [-21, 5], [35, 3], [30, 2], [5, -13], [36, 0], [1, -18], [-20, 12], [-31, 9], [30, -9], [-25, -12], [1, 21], [-18, -20], [14, -14], [3, -13], [-23, -3], [3, -5], [-12, 21], [-13, 11], [-9, -1], [-29, 2], [0, 22], [-31, -3], [6, 3], [-17, 9], [30, 7], [-4, 0], [-24, 14], [-44, -4], [12, -21], [16, -2], [0, 17], [-5, 9], [24, -9], [-7, -6], [6, 1], [-35, 8], [18, -20], [21, -17], [12, -1], [22, -12], [-27, 7], [30, 3], [-18, -10], [8, 18], [-2, -6], [41, -6], [-9, -19], [33, -5], [-13, -15], [30, 2], [-47, 2], [-19, 4], [-42, 13], [-1, -13], [15, -11], [16, -4], [32, -8], [16, -26], [-3, -23], [-23, 3], [-30, 11], [-36, -7], [-3, -29], [4, -6], [-26, -8], [-1, 2], [12, 11], [-35, 4], [24, 2], [23, 7], [3, 27], [6, 12], [0, 13], [-7, 0], [-8, 18], [18, -4], [0, 19], [12, -8], [-25, 6], [-2, 6], [26, 0], [-15, 3], [-21, 5], [-4, 8], [42, 4], [54, 9], [50, -10], [-26, 10], [-6, 2], [22, -24], [45, -3], [-12, 29], [17, 6], [10, 8], [-12, 25], [12, 14], [-9, 33], [-4, -10], [-19, -24], [-18, 5], [22, -12], [33, -3], [5, -5], [24, -6], [12, -27], [10, 28], [0, -8], [4, -4], [-1, 9], [5, 22], [-54, -8], [61, 3], [-12, -37], [-4, 24], [-3, -33], [39, 3], [-12, 25], [-24, -2], [44, -18], [-20, -24], [-19, -9], [-18, 7], [36, 6], [-14, -32], [-51, -1], [-25, -19], [48, -5], [-5, -9], [-12, -25], [0, 28], [-7, 0], [36, -22], [3, 43], [17, 15], [-14, -6], [0, 8], [13, 0], [4, 4], [-18, 0], [8, 12], [1, 17], [6, 29], [-40, 18], [12, 34], [-12, -6], [16, 12], [-6, -12], [-4, 4], [22, 6], [25, -24], [-13, 24], [1, 40], [22, 24], [-27, 5], [-16, 2], [-1, -28], [-15, -7], [0, 11], [-7, -18], [0, -26], [-4, 30], [-38, 12], [6, 1], [-5, 14], [-51, 19], [-34, 0], [-60, 2], [-42, 6], [-78, 2], [6, 7], [-39, 25], [28, 6], [6, 10], [-13, 20], [-3, 27], [30, 24], [25, -15], [46, -24], [21, 19], [-1, -2], [-36, -6], [2, 6], [-2, -28], [-51, 21], [-7, -27], [24, 12], [-32, 18], [18, -29], [-6, 26], [-18, -4], [46, 10], [-42, 9], [-37, -2], [-18, 2], [-30, -19], [-29, 22], [12, 5], [65, 3], [-5, -4], [-12, 24], [-29, -20], [-18, 33], [-19, -30], [14, -36], [-11, -45], [24, -22], [54, 10], [-55, -15], [-24, -24], [-13, 26], [-15, -27], [-22, -18], [39, 21], [74, 0], [30, 33], [-10, -26], [61, 6], [34, 28], [6, 27], [15, 9], [-49, -2], [24, 16], [66, -8], [47, -15], [-32, 26], [-24, 17], [3, -1], [68, -8], [-26, -18], [-51, 11], [-8, 24], [-22, 6], [30, -28], [-30, 35], [-45, 1], [-12, 37], [30, -9], [-20, -2], [-30, -3], [-30, -27], [84, -4], [-77, -9], [40, -4], [21, 9], [28, 12], [-19, -38], [45, 1], [-22, -26], [-12, -11], [0, -14], [-49, -18], [-44, -2], [-18, 20], [-36, 11], [-65, 2], [-18, -23], [25, -24], [21, -13], [0, -47], [67, 12], [12, 5], [77, -9], [-18, -25], [47, 24], [-35, -9], [19, 3], [18, 33], [-7, -34], [30, 8], [-51, 1], [-47, 25], [48, 15], [-44, 0], [38, 20], [-54, 21], [11, 1], [-3, 7], [-43, 21], [-24, -11], [40, -26], [-24, -22], [6, 28], [56, -6], [34, -8], [-12, -23], [-83, 3], [-45, -21], [-17, -32], [-15, 1], [-6, 16], [-13, 3], [4, -4], [-12, 26], [84, -7], [43, -32], [-6, -1], [12, -5], [-3, 13], [43, 17], [-6, -6], [-30, -32], [13, 30], [45, 21], [18, 24], [30, 23], [20, -12], [30, -2]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4050_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4050_2_a_bx();".
// 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_4050_2_a_bx(:prec:=2)
    chi := MakeCharacter_4050_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_4050_2_a_bx();".
// 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_4050_2_a_bx( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4050_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-11, -2, 1]>,<11,R![6, 6, 1]>,<13,R![22, 10, 1]>,<17,R![-3, 0, 1]>,<23,R![-48, 0, 1]>,<41,R![9, 12, 1]>],Snew);
    return Vf;
end function;