
// Make newform 4050.2.a.q in Magma, downloaded from the LMFDB on 17 March 2026.
// 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_q();".
// 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_q();".
// 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_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], [4], [-3], [4], [3], [5], [6], [-6], [2], [4], [3], [-11], [0], [6], [3], [-10], [-5], [-6], [7], [14], [12], [-6], [-11], [12], [4], [-9], [-4], [18], [-2], [-12], [-9], [-1], [0], [-10], [-8], [16], [-18], [-18], [0], [-16], [0], [13], [0], [20], [-4], [22], [-3], [20], [21], [-6], [17], [21], [9], [24], [-6], [-16], [22], [6], [-20], [-18], [7], [6], [1], [24], [-4], [31], [21], [-16], [9], [24], [-8], [10], [29], [12], [-36], [-8], [-33], [-31], [0], [2], [-24], [13], [-10], [3], [15], [1], [0], [-20], [21], [6], [-2], [33], [-31], [6], [12], [3], [-20], [8], [1], [-12], [-3], [39], [29], [7], [39], [-18], [0], [-25], [-8], [-2], [-39], [-19], [-34], [-9], [-23], [6], [42], [36], [32], [-14], [-36], [-21], [8], [-42], [-34], [0], [28], [-32], [29], [-6], [-28], [-38], [-18], [50], [-30], [4], [-48], [39], [35], [48], [4], [-36], [44], [30], [-44], [-18], [-19], [-6], [-2], [-30], [-41], [-42], [-5], [30], [-34], [-30], [10], [-24], [27], [51], [22], [-60], [-9], [36], [20], [-26], [-34], [-42], [-51], [-4], [-18], [-41], [-22], [-6], [41], [12], [16], [-16], [-8], [27], [-32], [33], [12], [-54], [34], [-8], [-55], [54], [31], [-51], [-55], [24], [33], [-51], [-25], [22], [-63], [36], [-36], [-40], [-20], [-1], [33], [-60], [-4], [9], [33], [-49], [-47], [-66], [46], [12], [66], [-55], [10], [-57], [18], [-18], [-10], [-22], [-9], [34], [-33], [44], [42], [-30], [46], [-60], [34], [56], [-10], [-75], [52], [-66], [2], [-36], [51], [-36], [15], [20], [-14], [-34], [-15], [-36], [40], [45], [20], [-6], [-50], [69], [30], [62], [-24], [33], [38], [28], [-48], [61], [-74], [33], [-22], [46], [-42], [-1], [42], [57], [67], [12], [-70], [4], [19], [50], [79], [-2], [-60], [-4], [35], [-15], [30], [14], [12], [-10], [-59], [-6], [-38], [12], [-64], [-3], [-42], [27], [-15], [-45], [46], [-78], [-34], [-6], [36], [76], [25], [-78], [-40], [-12], [-28], [-86], [-36], [-58], [-54], [46], [-78], [24], [-90], [28], [-12], [59], [69], [60], [-77], [-6], [-19], [13], [24], [46], [30], [-67], [-79], [37], [84], [42], [62], [36], [-10], [-75], [29], [48], [38], [-3], [-1], [34], [-2], [-18], [-48], [68], [24], [-45], [2], [-29], [-24], [90], [20], [37], [78], [64], [68], [-54], [66], [-84], [-42], [72], [16], [-63], [-54], [-15], [-53], [31], [-6], [-80], [-43], [48], [-19], [36], [0], [20], [-68], [-69], [60], [-74], [-57], [82], [6], [-69], [22], [-27], [11], [-24], [44], [-8], [-44], [30], [59], [36], [-3], [-35], [-60], [-14], [-52], [39], [35], [-12], [14], [63], [34], [54], [-42], [20], [52], [39], [-23], [-84], [31], [48], [-57], [71], [-38], [0], [30], [-74], [-9], [54], [30], [58], [30], [-9], [70], [0], [-99], [-30], [-16], [36]];
    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_q();".
// 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_q(:prec:=1)
    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_q();".
// 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_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4050_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-4, 1]>,<11,R![3, 1]>,<13,R![-4, 1]>,<17,R![-3, 1]>,<23,R![-6, 1]>,<41,R![-3, 1]>],Snew);
    return Vf;
end function;