
// Make newform 2394.2.a.r in Magma, downloaded from the LMFDB on 21 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_2394_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_2394_2_a_r();".
// 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_2394_2_a_r();".
// 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 := [-2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 2]];
    Rf_basisdens := [1, 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_2394_a();"
function MakeCharacter_2394_a()
    N := 2394;
    order := 1;
    char_gens := [533, 1711, 1009];
    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_2394_a_Hecke( : Kf := Kf)
    return MakeCharacter_2394_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, 1], [1, 0], [-2, 0], [0, 1], [0, 0], [1, 0], [-2, 1], [-2, -2], [4, 1], [2, 3], [2, -2], [8, 0], [0, 1], [-2, 2], [4, 2], [-2, -4], [10, 0], [4, 2], [-6, 2], [-6, 1], [0, -4], [10, 0], [-4, -4], [8, -3], [-4, 3], [4, 0], [-6, -3], [6, 0], [6, -1], [4, -4], [-6, -2], [4, 2], [10, -3], [10, 5], [10, 0], [-8, -4], [0, 0], [14, -2], [4, 0], [12, 3], [-2, 5], [10, -6], [2, 1], [0, 6], [10, 2], [0, -3], [4, -4], [6, 2], [2, 8], [6, -1], [0, -8], [-12, 0], [-18, 0], [2, -5], [14, 0], [8, -4], [6, 0], [14, 4], [12, -2], [-10, 0], [0, 2], [12, -3], [-22, 2], [-14, 6], [-10, -8], [-2, 4], [-14, 0], [18, 0], [24, 2], [2, -3], [16, 0], [-26, 3], [-2, -8], [8, -8], [-2, 7], [10, -10], [-6, -8], [-12, -4], [-4, 6], [6, -1], [-12, -2], [-4, -4], [-12, -3], [6, -4], [14, 0], [-10, 8], [-24, -5], [-16, -4], [-24, -4], [4, 11], [-10, 5], [10, 2], [16, 4], [-20, -3], [-18, 4], [10, 12], [8, -2], [-30, 4], [10, -12], [-14, 1], [4, 14], [-6, -4], [20, -8], [10, 0], [-16, -2], [-28, 2], [-4, 6], [-28, 2], [24, -1], [-2, 10], [-22, -4], [-4, -4], [-36, 2], [38, 4], [-28, 6], [-20, -5], [-34, -3], [-4, -12], [-4, -7], [-18, 6], [26, 4], [0, 12], [-12, -4], [-26, -1], [10, 10], [12, 5], [16, 6], [2, 0], [-12, -8], [16, 0], [-18, -11], [-2, -18], [20, -8], [-6, -14], [-18, 8], [24, -4], [6, 6], [6, -10], [0, -2], [10, -9], [8, -8], [-12, 0], [-8, -9], [40, 0], [-10, 4], [18, 8], [-12, 0], [-16, 0], [10, -9], [-16, 6], [-40, -4], [-40, -2], [-10, -8], [44, -2], [32, -4], [16, -4], [6, 10], [6, 4], [26, -10], [-18, -8], [36, 2], [44, -4], [-22, 0], [-8, -18], [26, 7], [18, 8], [42, 2], [-24, -1], [16, -16], [-4, -1], [-22, 11], [10, -4], [56, -1], [12, -10], [4, -4], [-10, 9], [-24, -11], [6, 8], [4, -14], [20, -14], [-14, -15], [-18, -10], [-46, -1], [0, -1], [-2, -3], [60, 0], [-18, -14], [16, 11], [0, -14], [50, 2], [2, 12], [10, 16], [-30, 8], [-14, -14], [18, -12], [-10, -6], [40, -10], [4, 7], [6, 2], [40, -5], [28, 9], [-40, -2], [0, -2], [-8, 13], [40, -6], [-32, -12], [22, 12], [24, -4], [14, 4], [-32, 5], [-8, 16], [-20, -6], [-32, 4], [-8, 16], [-48, 4], [2, -18], [36, -10], [22, 7], [34, 1], [0, 17], [-14, 0], [-40, 12], [60, -2], [-26, 12], [14, 12], [32, -8], [12, -5], [-30, -4], [2, -8], [0, 0], [22, 1], [-38, -8], [-36, 10], [-16, -9], [10, 14], [-54, 3], [6, 18], [8, -12], [24, 16], [20, -8], [0, -24], [14, 13], [14, 0], [-12, -3], [-8, -6], [4, 14], [14, 14], [10, -23], [18, 4], [-4, -6], [-26, -1], [0, -22], [-12, 7], [38, -4], [42, -10], [4, -6], [10, -8], [30, -6], [-74, -1], [8, 16], [26, 8], [8, -13], [28, 0], [-44, -12], [-26, -10], [-4, -2], [-38, 10], [-50, -1], [-52, 3], [-10, 6], [-6, -18], [44, 2], [-36, 2], [8, 4], [-10, 14], [-2, -3], [-38, -4], [32, -18], [16, 18], [-24, 4], [12, 9], [0, 7], [76, -2], [-14, -15], [30, 0], [6, -20], [-8, -10], [6, -14], [-46, -7], [8, 24], [14, -20], [12, -4], [6, -19], [68, 1], [-12, -5], [-32, -17], [28, 2], [60, 6], [-50, 8], [30, -6], [-36, -6], [-16, 4], [-32, 0], [54, -10], [64, 0], [16, 7], [-2, -9], [-30, 18], [-64, -5], [30, -7], [22, 20], [34, -6], [-58, 3], [44, 10], [24, 8], [12, 18], [-42, 8], [18, 24], [52, 2], [22, 16], [-30, 18], [-14, -21], [-2, -18], [8, -28], [38, 0], [16, 16], [52, -6], [-82, 1], [-30, -8], [18, -20], [0, -6], [-44, 2], [-40, 12], [48, 0], [34, -13], [-46, -10], [-26, 2], [48, -2], [-58, -9], [-78, 2], [18, -8], [30, -13], [2, 20], [-4, -12], [-38, 18], [26, 0], [-56, 0], [72, 5], [-4, 26], [2, 10], [-46, -3], [-24, 21], [-10, 7], [26, 8], [-56, -3], [-4, -4], [-18, -6], [12, -6], [-38, 4], [28, -6], [44, 14], [-8, -28], [-4, 24], [62, -4], [60, -7], [-18, 15], [-22, 6], [-34, -2], [-44, 4], [42, 9], [-86, 0], [48, 8], [42, -6], [28, 4], [62, -11], [-14, -14], [60, -4], [16, 0], [18, 24], [22, -2], [-12, -6], [38, 0], [4, -16], [-32, 14], [44, 18], [-34, 12], [40, 8], [40, 8], [6, 8], [-46, -12], [-38, -18], [12, 10], [8, 0], [-18, 22], [-52, -7], [14, 26], [22, 4], [-2, -9], [-8, 15], [22, 26], [34, 7], [-18, 16], [-2, 24], [16, -6], [14, 20], [-54, -12], [-80, 0], [64, 12], [-44, -2], [70, 3], [-28, -8], [24, 12], [-42, -8], [36, -7], [0, -12], [-48, 3], [-48, -4], [-40, -2], [34, 12], [44, 1], [-46, -5], [-4, 4], [-20, 16], [54, -6], [4, -28], [50, 8], [12, -14], [-56, 3]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2394_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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