
// Make newform 2142.2.a.m in Magma, downloaded from the LMFDB on 10 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_2142_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_2142_2_a_m();".
// 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_2142_2_a_m();".
// 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_2142_a();"
function MakeCharacter_2142_a()
    N := 2142;
    order := 1;
    char_gens := [1667, 1837, 1261];
    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_2142_a_Hecke( : Kf := Kf)
    return MakeCharacter_2142_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], [-3], [1], [-3], [5], [1], [2], [0], [0], [2], [-1], [0], [5], [6], [3], [12], [8], [11], [12], [-7], [-7], [3], [9], [17], [-6], [-13], [-12], [2], [9], [-4], [12], [-12], [-13], [-9], [-16], [14], [-10], [-3], [-6], [0], [20], [-15], [-16], [-18], [8], [26], [8], [6], [23], [-27], [-9], [-22], [-15], [15], [9], [-18], [-7], [-22], [-12], [11], [0], [2], [33], [-10], [-6], [-1], [-4], [3], [-13], [-15], [24], [-28], [14], [-10], [18], [30], [20], [18], [-16], [6], [26], [30], [14], [-28], [12], [21], [-37], [-24], [32], [-12], [27], [11], [0], [20], [0], [-12], [-18], [-22], [-25], [2], [-18], [39], [0], [-4], [-10], [-33], [-42], [0], [38], [-22], [-22], [21], [-7], [20], [9], [-1], [-24], [30], [36], [-22], [-28], [-27], [-24], [5], [33], [-25], [0], [23], [2], [-28], [-6], [-40], [20], [-45], [-40], [18], [17], [-6], [54], [11], [18], [41], [33], [-7], [-21], [44], [18], [-22], [9], [29], [-48], [56], [-33], [-10], [-12], [38], [-30], [8], [39], [-36], [6], [-46], [51], [-24], [24], [-31], [20], [-46], [-3], [-24], [23], [48], [-55], [56], [-54], [-52], [-42], [8], [14], [-10], [0], [26], [-6], [57], [36], [47], [44], [-40], [-57], [29], [15], [47], [42], [-3], [30], [14], [41], [-30], [60], [-12], [-52], [-55], [2], [-45], [-24], [-61], [-12], [-42], [-4], [38], [18], [5], [45], [15], [62], [50], [-33], [-6], [-9], [-70], [32], [54], [29], [-3], [-10], [6], [-24], [-37], [-60], [-4], [-16], [44], [-24], [-40], [-48], [23], [-54], [60], [72], [-21], [56], [5], [-46], [12], [9], [8], [-48], [-49], [75], [-52], [-60], [36], [41], [60], [-6], [-43], [-52], [-15], [56], [-1], [-6], [-34], [-28], [-60], [-28], [-30], [-51], [-58], [-51], [32], [29], [14], [-70], [-40], [11], [12], [20], [5], [-15], [54], [23], [-57], [77], [-7], [-33], [86], [72], [-40], [-21], [-12], [-6], [-54], [-36], [-55], [63], [-43], [-66], [6], [68], [-52], [-87], [-43], [-15], [-16], [-16], [18], [-58], [72], [-16], [-36], [-24], [-15], [20], [9], [-28], [-60], [-12], [2], [36], [-1], [-40], [6], [-10], [-66], [14], [38], [17], [-24], [-42], [-19], [-36], [80], [-69], [8], [-78], [-94], [18], [-55], [65], [56], [-60], [-33], [-64], [81], [-33], [2], [-37], [51], [-27], [56], [-70], [-87], [80], [14], [15], [-12], [36], [30], [63], [-67], [-36], [-9], [-57], [68], [95], [69], [-22], [-4], [-30], [80], [60], [75], [32], [62], [-30], [-54], [-88], [57], [-10], [3], [0], [-43], [57], [-19], [-33], [86], [-58], [38], [-12], [20], [87], [30], [20], [-75], [8], [-49], [-6], [92], [-33], [-58], [30], [-94], [24], [84], [14], [20], [12], [-64], [12], [53], [-3], [-48], [44], [14], [-57], [-6], [-46], [60], [-36], [-69], [32], [-78], [9], [11], [42], [57], [-54], [38], [-24]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2142_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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