
// Make newform 7406.2.a.r in Magma, downloaded from the LMFDB on 06 May 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_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_7406_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;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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+1)]];
    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], [2, 0], [0, -2], [1, 0], [-4, -1], [0, -4], [6, 1], [2, 1], [0, 0], [-2, -4], [-6, 2], [0, -2], [4, -2], [4, 1], [6, 2], [0, -4], [4, -6], [-4, 8], [8, -1], [-8, -4], [2, 8], [8, -2], [2, 9], [-2, -5], [10, -5], [-8, 0], [-12, 2], [-8, -1], [0, -10], [4, 7], [4, 4], [-12, -2], [12, 1], [0, 10], [0, -2], [-8, -4], [12, 0], [18, 0], [6, 2], [12, 4], [-2, 8], [8, -2], [8, 8], [8, -12], [-2, -8], [20, 2], [-12, 8], [14, -6], [2, -5], [16, -6], [14, -8], [-8, 4], [-14, 1], [10, 7], [-4, 18], [-16, 0], [12, 12], [-18, 6], [-2, 12], [-12, 13], [26, -5], [4, 0], [-10, 4], [-14, 6], [2, 9], [-2, 12], [-12, 4], [8, -13], [6, -8], [8, 0], [-20, 6], [-8, 8], [-20, 2], [-8, -10], [12, 1], [24, -8], [-16, -10], [4, 8], [-16, -11], [-4, -6], [-22, -5], [8, 4], [0, -2], [10, -3], [10, 2], [6, 8], [-36, 0], [12, -3], [0, -24], [36, 0], [-10, 3], [12, 18], [12, -16], [6, 0], [-10, 16], [16, -4], [-40, 0], [-14, -7], [-6, -23], [22, 4], [-4, -4], [0, -16], [34, -3], [24, 7], [-4, 7], [-2, 16], [8, 6], [-12, 2], [12, 8], [6, -16], [-2, 2], [0, 18], [-16, -23], [-2, 5], [0, 4], [24, 9], [-6, -7], [2, 18], [10, -8], [-4, -5], [4, 20], [28, 12], [-20, 12], [-28, 16], [-8, 2], [-32, 4], [-16, 6], [-6, 18], [12, 10], [4, 20], [-26, -8], [-16, 22], [8, 6], [0, 2], [-28, -10], [-26, 13], [20, 4], [6, 13], [8, -22], [0, -36], [-4, -2], [-38, -12], [24, 4], [24, 19], [4, -8], [0, -24], [24, -4], [2, 0], [-50, 4], [28, -12], [2, -12], [18, -3], [-4, 0], [22, -6], [56, -1], [24, 8], [-8, -10], [-28, 18], [14, 1], [-8, -14], [6, 0], [8, 13], [-4, -8], [-6, -21], [-4, 29], [-40, 12], [16, 12], [12, -16], [-12, 15], [-12, 16], [-32, -3], [-16, 0], [0, -2], [12, -17], [2, -42], [-14, 25], [34, 8], [-22, 16], [40, -4], [0, 14], [12, -4], [26, 19], [-30, -24], [-44, -10], [-32, -22], [-40, -2], [30, 12], [-10, 13], [30, 8], [-6, 30], [-20, 2], [-20, 0], [8, 27], [20, -24], [16, -3], [-26, 17], [24, 1], [-48, 8], [10, 39], [-46, -10], [-8, -22], [-18, -14], [4, -32], [18, -13], [30, -11], [32, -12], [-24, 8], [12, 12], [4, 36], [-2, -36], [0, 8], [8, -24], [16, 18], [-58, -3], [46, 6], [34, 13], [0, 40], [12, 26], [-24, 18], [62, 0], [-26, -16], [-32, 12], [-12, -40], [-40, -8], [14, -8], [6, 4], [26, 1], [36, 20], [28, -6], [38, -16], [38, 24], [26, -31], [-32, 24], [26, -16], [22, 37], [20, -6], [30, 3], [-8, -6], [-20, -24], [-18, 6], [-52, -15], [26, 0], [-14, -26], [-42, 24], [2, 24], [-6, -6], [6, -18], [6, -29], [-52, 11], [-40, -18], [48, 10], [-2, 45], [-40, 12], [-14, -15], [0, 16], [10, 16], [-24, -26], [-2, 5], [16, -4], [52, -14], [48, 10], [4, 35], [0, -12], [24, -22], [-10, -16], [-30, -7], [-24, 24], [6, 17], [16, -21], [-38, 0], [-24, 16], [-12, -23], [38, -15], [0, 18], [-20, 6], [-2, 22], [-28, -20], [26, 20], [-12, -15], [26, -17], [-6, -2], [-32, 2], [-8, -20], [-24, 18], [-50, 4], [-8, 20], [-56, -9], [24, 8], [2, 46], [70, 8], [-16, 10], [-14, -3], [42, -8], [-22, 15], [-6, -24], [60, 0], [40, 12], [-8, 36], [30, -12], [-28, -22], [18, 1], [-32, 30], [0, 24], [36, 12], [12, -11], [6, 0], [22, 16], [12, -40], [-8, 8], [-54, -16], [2, 46], [-16, 24], [20, -43], [4, -20], [-16, 22], [10, -3], [26, 20], [8, -12], [14, 37], [-4, 12], [14, -21], [-20, 15], [0, 32], [16, -32], [12, -23], [-42, 21], [-4, 5], [-48, 26], [-72, 10], [24, 20], [-6, 20], [38, -16], [-14, 22], [36, -18], [0, -15], [-18, 20], [48, 2], [-66, 15], [-30, -16], [-56, -20], [10, 12], [48, 7], [-68, 0], [0, -4], [-8, 42], [-34, 24], [-52, 0], [22, -32], [-40, -8], [4, 28], [10, -56], [18, 32], [-10, 28], [-16, 40], [-24, -4], [20, 10], [48, 4], [-18, 19], [16, 32], [8, 40], [40, -38], [-18, 48], [36, -32], [-16, 41], [-36, -22], [62, 16], [-60, 16], [-32, -28], [-12, -11], [54, -16], [2, 12], [32, -24], [8, -44], [-12, -18], [-46, 0], [-40, -26], [16, 42], [22, 43], [2, 11], [26, -32], [0, -2], [84, 3], [-24, 12], [-60, -16], [14, -7], [-2, -14], [28, -4], [4, -40], [24, -27], [-40, 12], [-8, -31], [-48, 12], [-20, -32], [-8, 30], [8, -8], [-28, -15], [-40, -12], [2, -1], [-40, 13], [-22, 36], [12, 44], [-62, -24], [24, 42], [-38, -29], [-24, -20], [-54, 26], [0, 16], [-58, 0], [-26, -37], [26, 52], [-4, 34], [-6, -16], [12, 47], [32, -7], [4, -5], [48, 32], [32, -24], [30, -10], [-22, -1], [32, 8], [56, -24], [4, -48], [16, 0], [36, 2], [28, -10], [28, 28], [-44, 17], [50, -16], [-80, -2], [-54, 38]];
    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_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_7406_2_a_r(:prec:=2)
    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_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_7406_2_a_r( : 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, 1]>,<5,R![-8, 0, 1]>,<11,R![14, 8, 1]>],Snew);
    return Vf;
end function;