
// Make newform 7938.2.a.t in Magma, downloaded from the LMFDB on 27 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_7938_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_7938_2_a_t();".
// 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_7938_2_a_t();".
// 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_7938_a();"
function MakeCharacter_7938_a()
    N := 7938;
    order := 1;
    char_gens := [6077, 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_7938_a_Hecke( : Kf := Kf)
    return MakeCharacter_7938_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], [0], [3], [-1], [-3], [-7], [9], [-3], [8], [-1], [-3], [-1], [0], [-3], [0], [2], [-4], [-12], [11], [-16], [9], [-3], [-1], [-3], [-13], [-9], [-13], [9], [-4], [-15], [9], [-7], [9], [-7], [-22], [-19], [15], [6], [21], [2], [0], [14], [-18], [-25], [5], [-1], [3], [-13], [-3], [3], [-13], [-12], [21], [-9], [-15], [5], [-1], [21], [-4], [9], [-28], [24], [-10], [-18], [8], [-13], [-12], [23], [-3], [-9], [17], [-13], [-28], [-15], [-27], [-13], [-27], [-34], [-9], [35], [-27], [2], [8], [-36], [-6], [-10], [9], [41], [3], [3], [-25], [-21], [-25], [24], [9], [-3], [-7], [11], [11], [9], [-12], [18], [32], [-25], [-3], [-39], [24], [-25], [-13], [23], [45], [17], [8], [33], [29], [21], [-15], [-3], [-22], [35], [30], [9], [44], [18], [26], [15], [-13], [-1], [23], [-21], [-13], [-22], [45], [23], [-27], [-28], [21], [33], [20], [42], [-40], [-36], [11], [-15], [-1], [-3], [-25], [51], [47], [18], [20], [33], [-43], [-39], [53], [-18], [26], [6], [-12], [-6], [41], [-33], [30], [15], [-25], [-13], [38], [-3], [-45], [-13], [-39], [-1], [8], [-51], [-25], [9], [56], [26], [8], [57], [11], [-3], [0], [45], [23], [-19], [35], [45], [-25], [-51], [17], [-42], [-27], [6], [-58], [-46], [-39], [51], [-18], [47], [23], [11], [36], [-15], [-43], [21], [9], [56], [35], [-51], [-25], [60], [48], [-10], [68], [21], [3], [-39], [-1], [29], [-63], [-7], [-69], [-37], [-6], [9], [8], [12], [14], [-25], [5], [-30], [23], [-57], [-49], [-51], [15], [-48], [63], [65], [32], [-13], [33], [-12], [-76], [60], [-4], [-12], [11], [-75], [0], [35], [-63], [51], [11], [-43], [6], [-61], [17], [9], [50], [26], [-6], [20], [-42], [-75], [-67], [78], [59], [-73], [-25], [59], [-13], [5], [9], [11], [11], [-24], [-72], [-28], [-63], [-1], [-1], [27], [-13], [57], [53], [42], [69], [-63], [-27], [3], [-49], [-66], [20], [9], [15], [47], [-49], [81], [47], [-57], [11], [-58], [-33], [59], [-3], [11], [72], [69], [-78], [-4], [24], [11], [57], [-72], [-37], [-15], [-19], [23], [-42], [-16], [-27], [35], [17], [-76], [60], [54], [26], [-30], [-37], [51], [-73], [-24], [-22], [-15], [-49], [-55], [11], [69], [57], [71], [-18], [60], [35], [44], [69], [-75], [83], [-25], [-39], [-19], [-13], [66], [-51], [-3], [21], [21], [-73], [-90], [-63], [84], [-85], [14], [-3], [59], [-34], [-69], [53], [45], [-87], [-4], [-49], [-36], [48], [-97], [93], [-37], [-15], [-39], [44], [57], [41], [-15], [77], [-70], [-43], [51], [71], [-6], [-75], [-76], [12], [26], [-37], [-3], [17], [-42], [23], [-15], [-13], [-27], [-75], [-7], [-73], [-3], [-76], [36], [98], [90], [60], [-52], [-97], [69], [-81], [17], [-30], [105], [-75], [47], [-3], [-33], [-34], [30], [-60], [-6], [-25], [75], [-49], [-9], [-13], [0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7938_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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