
// Make newform 7406.2.a.bb in Magma, downloaded from the LMFDB on 06 June 2024.
// 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_bb();".
// 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_bb();".
// 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, -4, -6, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-3, -1, 1, 0], [0, -4, -1, 1]];
    Rf_basisdens := [1, 1, 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_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)
    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, 0, 0, 0], [0, -1, 0, 1], [-1, 0, 1, -1], [1, 0, 0, 0], [-2, 0, 0, -1], [-1, 1, -1, 1], [-1, 0, -1, 1], [-2, 2, 0, -2], [0, 0, 0, 0], [-1, 3, 1, 0], [0, 1, 2, -3], [2, 2, 2, -1], [0, 4, 2, -4], [-2, -4, 2, 2], [0, -3, -2, -1], [0, 4, -2, -1], [2, -1, -2, 3], [-3, 2, -1, -5], [-8, 2, 2, -1], [2, 0, -2, -2], [1, -3, -5, 7], [-4, -2, -6, 1], [5, -1, 1, -1], [-7, -6, -3, 9], [4, -3, -2, 6], [3, -1, -1, -3], [2, -4, -2, 4], [0, -2, 0, 6], [-8, 2, 2, 1], [-10, 0, -2, 1], [-6, 6, -4, -4], [-7, 4, 5, -4], [0, -2, 2, -1], [6, 1, -2, -3], [-4, -6, -6, 11], [8, -8, 2, 4], [-12, -1, 4, -6], [-6, 2, 0, -6], [4, 1, -2, 11], [10, -4, 6, 2], [-4, 2, 10, -10], [-14, 5, 2, -2], [-2, -6, 4, -4], [-4, -2, -2, 6], [0, 0, 4, -4], [-4, -4, 0, 14], [-4, 2, 2, 2], [5, 8, 7, -14], [-18, -2, 0, 0], [-2, 5, -6, -2], [-3, -5, -5, 6], [0, 4, -2, 2], [3, -2, 7, 3], [-12, -2, -6, 2], [0, 6, 6, 0], [6, 0, 4, -5], [10, 6, 2, 0], [9, -4, -1, -8], [3, -9, -3, -2], [0, -10, 0, -3], [-4, -4, 2, 4], [5, 2, -9, 3], [1, -10, 1, -4], [9, 12, -5, -2], [7, 2, 7, 7], [-11, -7, -1, 0], [-10, -4, -2, 16], [-2, 6, -2, -13], [-4, 4, -6, -2], [0, 6, 8, 0], [15, -5, -3, 3], [-10, -4, 8, -3], [-7, -7, 3, -7], [-8, 2, -2, -3], [2, -8, 4, -3], [1, -3, 7, -11], [-18, 0, 4, -3], [-13, -5, 3, 3], [24, -4, 0, 1], [1, 7, 3, -15], [2, -4, -8, 14], [2, -2, 8, -7], [0, 12, 12, -10], [2, -7, 0, -2], [21, 4, 7, -8], [0, -2, -10, 6], [-7, 11, -5, -4], [-18, 4, -4, -9], [4, 0, -8, -4], [12, 0, 8, -4], [-6, 2, 0, 0], [-8, 6, 0, 0], [-8, 4, 4, 14], [6, -10, -2, 8], [-10, -6, -6, 10], [-6, 10, 2, -8], [14, 4, -2, -12], [10, 3, 0, 14], [4, -22, 6, 8], [13, -3, 11, -2], [2, -2, -4, -14], [-14, 12, 8, 7], [-12, 2, 2, 2], [10, -2, -16, 15], [-8, 2, -8, -4], [-5, -9, 5, -7], [-14, -5, 6, -1], [8, 6, 6, 4], [24, -10, 2, 6], [-11, 5, -5, -9], [2, 7, 8, 11], [14, 12, 4, -15], [14, -10, 8, 7], [5, -11, 5, -11], [-14, 0, -8, 3], [0, -4, -10, -5], [-4, 4, -2, 8], [-14, 17, 4, -3], [-22, -4, 12, -8], [12, -6, -10, 4], [5, -2, 11, 3], [-5, 13, -3, -16], [7, 4, 1, 11], [10, -16, 4, 2], [-29, -10, -5, 10], [2, 2, 2, -9], [-4, 8, -2, 7], [-8, -19, -2, 21], [-4, -10, 0, 0], [1, -6, -5, 15], [-14, -16, 2, 8], [-12, -6, -10, 7], [8, -10, -6, 21], [18, 8, 10, -1], [31, 1, 1, -1], [-1, 12, 7, -3], [18, 1, -6, -2], [-23, -7, -11, 7], [18, 3, -2, -6], [4, 10, -6, -10], [11, -16, -13, 0], [-17, 13, -5, 0], [-24, 4, -10, -14], [0, -2, 6, 16], [24, 4, 0, 4], [-7, 7, 7, -5], [-13, -3, 7, -17], [10, 10, -4, 8], [6, 7, 2, 5], [26, -8, 2, -8], [-13, -1, -7, 2], [11, 6, -1, 7], [-4, 22, 2, -8], [-5, -2, -3, 6], [-16, -6, -10, 6], [-2, 12, 4, 3], [-14, 12, -12, -13], [22, -14, -8, -4], [13, -16, -7, 7], [0, 9, 4, -18], [-2, -4, -2, 32], [26, -2, 0, -9], [-38, 4, -4, -6], [-3, 3, 1, -29], [6, -12, -10, 7], [7, -9, -7, 9], [-30, 12, 6, 2], [-10, -16, -2, 8], [-4, 10, 6, 7], [-19, 1, -3, 11], [2, 16, 10, -10], [42, -14, -6, 2], [24, 4, 12, 6], [14, 12, -6, -3], [-8, -9, -2, 9], [-3, -6, 1, 1], [-2, -2, 10, 12], [-18, -16, -12, 12], [-20, 18, -4, -4], [19, -4, -3, 23], [16, -12, 6, -8], [-28, 0, 6, -14], [2, 12, 24, -22], [9, -9, 11, 3], [10, -10, -4, -2], [13, -4, -13, 15], [-5, 17, 15, -4], [-1, 23, -1, -5], [1, 1, -15, 14], [-3, 14, -5, -22], [40, -12, 6, 8], [-6, 18, 10, -20], [6, 12, -16, 12], [-5, -9, -5, 23], [0, -6, -10, 9], [6, 15, 12, -24], [-12, 24, 0, 1], [-20, 6, 0, 13], [-20, -7, -10, -2], [-5, 2, -19, 12], [4, 0, -10, -19], [-14, -7, 16, -25], [22, 18, 6, -32], [4, 5, 10, 6], [12, -6, 2, -4], [-4, 4, 4, -10], [-25, 19, 5, 13], [-36, 8, 6, 8], [17, -13, -17, 20], [-5, -4, 3, 10], [-23, -13, 3, 8], [-3, 15, 33, -29], [4, -2, 6, -25], [10, -4, -4, -30], [-22, 15, 12, -15], [-41, 4, 3, 7], [4, 18, 2, 8], [-21, 3, -7, -25], [-20, 16, 10, -8], [-20, 2, 2, -10], [-4, 0, 4, -4], [-28, 6, 0, -12], [-10, -4, -8, 12], [14, -2, -4, -2], [8, 11, 8, -27], [1, -1, -7, -32], [34, 5, 0, -10], [-16, -16, 2, -8], [5, 19, -1, -21], [-16, -18, -4, 44], [16, -4, -4, -18], [-28, -12, -2, 4], [-4, 6, -10, 17], [-23, 1, -3, -24], [24, 0, 14, 2], [17, -1, 11, 13], [-13, 6, -13, -25], [18, 14, 14, -21], [24, -8, 16, 10], [2, 15, 8, -31], [-2, 8, -6, 22], [-5, -26, 11, 16], [12, -3, 2, 9], [-24, 22, 18, -14], [-28, 2, -10, 0], [52, -9, 10, 11], [-7, 16, 7, -8], [17, 15, -7, 13], [-30, 4, 0, 26], [8, 28, -8, -22], [-20, -16, -16, 29], [10, 11, -4, 32], [8, 10, -2, 7], [25, 12, 9, -7], [-19, -19, 5, -7], [-26, -12, -12, 14], [2, 0, -2, -23], [-6, -2, -16, 22], [6, 0, 18, -16], [-7, -11, -25, 11], [-38, 0, 4, -11], [28, -2, -26, 26], [-18, -6, -10, 22], [1, 0, -21, -3], [-44, -20, -10, 34], [28, -4, 10, 6], [6, 8, 10, -9], [22, -3, -4, -12], [12, 10, -2, -11], [12, -8, 0, 26], [-8, 18, 0, 22], [-10, 4, -12, 5], [23, 14, 3, -35], [8, 6, 6, -11], [-1, -15, -7, 13], [-8, -15, -18, 27], [-2, -4, -18, -14], [-33, 5, -5, -6], [40, -2, -16, 17], [-12, -10, -2, -4], [5, -18, 11, 0], [-14, -22, 8, -10], [39, -11, 9, 13], [32, -3, 8, -10], [-6, 23, -2, -3], [-28, 10, 12, -4], [-16, 16, -12, -15], [6, 0, 20, 11], [13, -18, 3, 30], [7, -7, 9, 13], [-26, 8, 0, 5], [-14, -28, -8, 16], [5, -19, 13, 4], [-35, -15, 17, -17], [-12, -16, 8, -8], [-16, 17, 24, -18], [10, -14, -2, -2], [21, 15, -23, 21], [-18, -27, -6, 35], [22, 11, -2, 11], [-5, 4, -17, -25], [-40, 10, -4, 11], [-6, -6, -6, 8], [16, 26, 28, -32], [-50, -8, 0, 14], [24, -16, 4, 28], [0, 28, 2, -10], [-29, -10, 1, -7], [-26, -14, -2, 10], [28, 12, -24, 20], [-18, 15, -20, -25], [-4, 22, 0, -19], [-2, 28, -2, -9], [8, -26, 4, 26], [34, 16, -4, -5], [-40, -5, 10, -8], [-6, -19, -14, 43], [18, -8, -18, 34], [-8, 19, 2, 2], [26, -10, -22, 4], [-55, 13, -3, 3], [22, -8, 4, 13], [-7, -13, -3, 45], [20, -20, 4, 2], [8, -2, 16, -17], [-12, -5, 18, -6], [-24, -10, 8, 0], [17, 18, -7, -18], [-38, -8, 16, -19], [32, 12, -22, 15], [17, 1, -9, 22], [-14, 34, 2, -14], [28, 9, 22, -5], [-4, -9, 12, -13], [-6, 32, 24, -21], [-24, 7, -8, -7], [-46, -18, 16, -11], [-3, 28, 5, -31], [18, -14, -12, -12], [-53, 5, 9, -1], [-7, 7, -3, 2], [4, -4, -10, 45], [25, -9, -19, 1], [44, 20, 4, -38], [-4, -14, -6, 19], [16, -6, 4, -32], [-23, -1, -7, -9], [24, -14, 0, -16], [8, 22, 20, -10], [-22, 9, 18, -2], [37, 0, -19, 18], [-2, 8, -4, -24], [19, 3, -3, 18], [-39, 17, 7, -23], [-14, -24, 4, -3], [-25, -9, -7, 31], [-23, -3, -1, 7], [-8, -10, -6, 0], [-23, -3, 13, -14], [4, 24, -20, -2], [28, -16, -16, 25], [47, 15, 17, -15], [-12, -32, -16, 32], [-52, -14, 6, 1], [37, -12, -15, 16], [20, 20, 0, 8], [29, 3, -11, 29], [-34, -28, -20, 47], [-28, 22, 4, -13], [24, -18, -14, 4], [2, -41, 6, 1], [-10, 4, -8, 0], [-48, -10, 4, -9], [-1, 31, 5, -9], [-22, 26, 2, -14], [-1, -14, -21, 18], [28, -12, -10, 0], [-48, 23, -2, -16], [70, 7, 4, 4], [34, 8, 4, -10], [-1, -8, -31, 13], [-16, -14, -30, 33], [22, 22, 24, -40], [-4, 18, 10, -28], [-14, -6, 20, 10], [-27, -14, 15, -4], [12, -10, -12, 8], [-44, -4, -20, 10], [2, 20, 16, 9], [-1, -35, 9, 5], [-12, -32, 0, 5], [28, 10, 4, -52], [-34, -12, 16, -6], [6, 7, -26, 15], [46, 12, 0, -11], [8, -6, 16, 5], [-11, -33, 19, -9], [1, -42, 5, 23], [-2, 0, -18, 30], [-19, 19, 25, -40], [-15, -5, -11, 37], [-13, -5, -9, -28], [-18, -12, -8, 39], [35, -6, -5, 5], [-15, -13, 1, 37], [27, -14, 5, 36], [32, 2, -8, -11], [34, 2, -6, 38], [21, -9, -7, -19], [29, 2, 9, 4], [34, -30, 0, -4], [18, 10, 2, -22], [-38, 0, -8, 36], [-8, 14, -6, -8], [-10, 20, -20, -11], [40, 24, -8, -14], [-8, -6, 26, -8], [34, 15, -16, 27], [-16, 7, 6, -30], [-22, 4, -2, -40], [-22, -22, 8, -3], [-30, -3, -14, 10], [2, 0, 24, -10], [-14, 17, 2, -7], [-3, 3, 15, -15], [-39, -11, 9, 5], [-28, 10, -6, 5], [14, -18, 6, -16], [12, -13, 20, 3], [-1, 12, -27, -4]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7406_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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