
// Make newform 7406.2.a.h in Magma, downloaded from the LMFDB on 03 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_7406_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_7406_2_a_h();".
// 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_7406_2_a_h();".
// 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_7406_a();"
function MakeCharacter_7406_a()
    N := 7406;
    order := 1;
    char_gens := [2117, 3179];
    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_7406_a_Hecke( : Kf := Kf)
    return MakeCharacter_7406_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], [-1], [4], [1], [0], [2], [-5], [7], [0], [8], [-2], [-8], [-2], [3], [0], [6], [-9], [-6], [-5], [-2], [17], [0], [13], [-6], [14], [14], [16], [12], [4], [-17], [-22], [1], [-3], [-7], [-10], [16], [12], [20], [-24], [-6], [-9], [10], [10], [-11], [8], [8], [-3], [-2], [-3], [4], [3], [30], [-21], [27], [-7], [-20], [-24], [30], [-26], [-25], [-21], [-14], [-23], [-8], [11], [2], [1], [27], [3], [-8], [-11], [30], [22], [26], [35], [2], [14], [-32], [25], [-17], [-9], [-30], [12], [-10], [32], [7], [9], [10], [-10], [4], [16], [-20], [36], [4], [15], [-28], [-16], [-42], [24], [-8], [-20], [-6], [-21], [-15], [-13], [-27], [-39], [21], [-12], [2], [24], [6], [-21], [-4], [-20], [45], [4], [26], [-34], [-29], [-10], [1], [-8], [19], [20], [-22], [32], [-30], [-46], [-22], [-20], [30], [26], [-28], [-33], [30], [-38], [-5], [30], [17], [-47], [-22], [-50], [29], [-38], [28], [-36], [-5], [-11], [36], [-34], [30], [11], [0], [-23], [28], [-4], [50], [-19], [6], [27], [-14], [56], [1], [-30], [22], [-30], [-54], [-43], [20], [-31], [-26], [36], [55], [14], [1], [-36], [-28], [22], [14], [-62], [-51], [-16], [18], [6], [28], [-10], [-7], [37], [-10], [-39], [17], [-12], [2], [61], [-23], [14], [8], [-46], [-30], [-64], [-12], [-10], [-18], [-17], [8], [34], [-48], [-41], [-20], [45], [24], [-8], [28], [-32], [3], [-26], [27], [-32], [6], [32], [4], [1], [56], [-47], [-58], [10], [4], [-34], [29], [14], [25], [-74], [31], [12], [-60], [59], [-42], [-40], [30], [-4], [55], [-32], [-14], [-3], [22], [-32], [-21], [4], [16], [-68], [-31], [-46], [-14], [12], [27], [62], [-23], [16], [-38], [6], [-27], [38], [28], [15], [61], [32], [-10], [68], [-60], [-2], [37], [-38], [18], [21], [-46], [-68], [-32], [-13], [-33], [4], [-42], [-76], [-32], [-29], [-58], [10], [-20], [-28], [-35], [42], [25], [3], [-85], [66], [40], [20], [-26], [45], [44], [-49], [30], [40], [-75], [9], [-15], [37], [18], [-54], [2], [-22], [-66], [61], [63], [74], [65], [76], [-74], [-59], [-45], [-35], [-3], [8], [50], [18], [43], [36], [-47], [-78], [78], [-22], [-48], [-72], [15], [-20], [-19], [40], [-63], [89], [-20], [-2], [33], [-12], [6], [-4], [-40], [-46], [73], [-30], [60], [-76], [37], [70], [2], [74], [-86], [30], [-4], [50], [84], [92], [-39], [-84], [-73], [49], [43], [-54], [-48], [25], [84], [12], [-64], [78], [-20], [54], [0], [-34], [-30], [7], [55], [-58], [18], [-94], [15], [36], [28], [-20], [-22], [24], [-36], [87], [-22], [29], [20], [-92], [-79], [38], [-93], [33], [-8], [-50], [21], [-48], [-90], [-10], [-20], [68], [5], [-53], [-15], [62], [54], [-21], [87], [63], [-30], [4], [26], [47], [-18], [84], [98], [-48], [9], [62], [-78], [-45], [99], [99], [84]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7406_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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