
// Make newform 7350.2.a.dt in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7350_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_7350_2_a_dt();".
// 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_7350_2_a_dt();".
// 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 := [8, 8, -7, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -4, -1, 1], [-4, -1, 1, 0], [-2, 8, 1, -1]];
    Rf_basisdens := [1, 2, 2, 2];
    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_7350_a();"
function MakeCharacter_7350_a()
    N := 7350;
    order := 1;
    char_gens := [4901, 1177, 2551];
    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_7350_a_Hecke(Kf)
    return MakeCharacter_7350_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, 0, 0], [-1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -1, 1, 0], [0, -1, 2, 0], [-1, 1, -1, 1], [-3, 1, -2, -1], [1, 1, -2, -1], [-2, 1, 1, 2], [-4, 1, -1, 0], [-2, -1, -3, 0], [-3, 0, -2, -1], [1, 2, 1, -1], [-3, -2, 1, -1], [5, 1, -2, -1], [-5, 1, 4, 1], [-3, 0, 0, 3], [-1, 0, 1, 1], [-5, -1, -2, -3], [3, -2, -2, 1], [-2, 2, 4, 2], [-2, 0, 2, -2], [-11, 0, -4, -1], [-5, 2, 4, 1], [-6, -3, 4, -2], [-2, 0, -2, 2], [2, 0, -6, 2], [3, -1, -6, 1], [5, -1, 8, 3], [-8, -2, 6, 0], [-3, -1, 0, -1], [5, -1, 6, 1], [-1, -3, 0, -3], [-1, 0, 7, -1], [1, -1, -4, -1], [3, 4, -4, -3], [-5, -2, -5, -3], [-7, -4, 3, 3], [2, 1, -2, -2], [-6, 1, -15, -2], [-3, 2, 6, 3], [-3, -1, 4, 3], [0, -2, 2, 0], [7, 3, 2, -3], [-14, 1, -3, 2], [0, -2, 6, 4], [0, 2, 2, 0], [-6, -2, 0, 2], [-15, -4, 6, -1], [4, 2, -8, 2], [1, 3, 8, -1], [0, -2, -1, 0], [2, -2, -8, 2], [3, 1, 9, 5], [3, -1, -6, -3], [-7, 6, 0, -1], [-8, 1, -9, -4], [-5, 0, 1, -3], [-17, -1, 6, 1], [1, 5, -6, 3], [16, 3, -4, 0], [0, 0, 8, -4], [6, -2, 8, 2], [3, -2, -6, -7], [5, -1, 0, -1], [-8, 2, -10, -4], [-19, 3, 2, 1], [0, 0, -8, 4], [3, 2, 10, -3], [9, 3, 1, -1], [3, 3, -2, -3], [-2, -6, 12, 2], [-17, -2, -1, 1], [-12, 8, 4, 0], [-5, -4, 13, 1], [8, -3, -13, 0], [17, -2, -12, -1], [-1, 1, 4, 1], [-4, -4, -7, -4], [4, 0, -16, 0], [2, 6, 2, 0], [-19, 1, -2, 3], [7, -6, 8, 5], [-16, 3, 1, 4], [6, -2, 0, -2], [4, -4, 6, 2], [-12, 6, -10, -4], [11, -2, -8, -3], [-8, -4, 20, 0], [-10, 4, 6, -2], [-6, -6, 16, -2], [-14, 0, -14, -2], [-2, -3, 9, 2], [2, -2, 12, 2], [3, 0, -15, 1], [-14, -1, -4, -2], [-7, 4, 8, 3], [-1, -1, 2, 5], [8, 4, -2, 2], [-23, -8, 11, -1], [1, -1, 4, -5], [6, 0, -10, -2], [15, -3, 8, 1], [2, 6, -8, 2], [11, 0, 18, 1], [20, -2, 6, 0], [5, 7, -7, 3], [1, -5, 4, 7], [-8, -6, 1, 0], [-12, 2, -26, -4], [-6, 1, -5, 8], [13, -9, -6, -3], [-5, -1, 6, 1], [3, -7, 4, -3], [7, -7, 4, -7], [17, -3, -6, -5], [5, 4, 7, -1], [-6, 0, 4, 4], [0, -3, 3, 0], [1, -2, -16, -1], [-19, 5, 4, -3], [20, -3, 2, -4], [-4, 2, -2, 8], [-5, -11, 4, 1], [2, 11, -13, -2], [-13, 1, -8, 9], [8, 6, -2, 0], [6, 0, 6, 10], [19, 0, -4, 5], [-2, -2, 4, 6], [0, 12, 0, 0], [-7, 7, 4, -1], [-24, 3, -13, -6], [19, -4, 4, 1], [14, 4, 3, 2], [10, 1, 4, 6], [8, 0, 8, 4], [32, -3, -6, 0], [16, 4, 10, -2], [5, 11, -8, -1], [-3, 8, -7, -7], [-2, -6, -8, -6], [18, -2, 12, 10], [1, 6, -12, -1], [-2, -4, -10, 2], [23, -2, 4, -7], [15, -3, -7, 1], [15, 1, 12, -3], [20, 4, 0, 4], [-2, -7, 7, -4], [-15, -2, -2, -5], [7, 4, 5, 9], [1, -2, 17, -5], [7, 4, -11, 9], [15, 5, -16, 1], [-21, -3, 0, -3], [5, -6, -8, -1], [11, 6, 8, -7], [-2, 9, 0, -6], [16, 6, 2, -4], [8, -2, -6, -8], [-40, 0, -12, 0], [2, 10, 0, 2], [-4, 6, 8, 6], [-1, 2, -17, 5], [-3, 3, 0, -5], [23, 2, 12, 1], [13, 9, -4, 9], [16, 1, 10, 0], [-4, 7, 9, -4], [-5, 2, 2, 5], [9, -13, -4, -1], [21, 7, 2, -11], [12, 1, -17, 0], [5, 6, 4, 7], [-6, -4, -2, 10], [-4, 5, 7, 4], [-6, 8, 6, 6], [35, 2, 0, -3], [-30, 8, -6, -2], [-23, 3, -12, 3], [-10, -9, 9, 4], [23, -3, 11, 1], [5, -7, -6, -5], [-1, 0, 4, 9], [1, 0, 19, -1], [11, 3, -2, -7], [-7, 7, -20, -9], [-4, 2, -18, 4], [-19, 2, -28, -1], [16, -2, 6, -12], [20, 4, -4, 8], [-1, 2, -16, -7], [-14, -4, -18, -6], [21, 3, -23, 3], [-2, -6, 0, 2], [18, -3, 19, 12], [-9, -5, 9, -7], [-17, -4, -7, -3], [17, 0, 17, 9], [-2, -15, 5, -2], [18, 11, -22, 6], [30, 0, -5, -6], [-2, -2, -16, -10], [4, 5, 4, -4], [16, -9, 13, 4], [-26, -2, 4, -2], [4, -2, 0, -10], [13, -9, 8, -1], [-11, -11, -4, 5], [13, 4, 16, 3], [4, 4, -12, -4], [-28, 2, 6, 8], [26, 4, 6, -2], [10, 2, -3, -2], [18, -4, -22, -2], [35, -4, 18, 1], [9, 1, 18, -1], [8, -2, 0, 6], [5, -5, -12, 7], [10, -5, -9, 2], [4, 4, -34, 2], [-20, 10, -10, -4], [-20, 6, -2, 0], [-33, -11, 8, 5], [-15, -1, 7, -9], [11, 5, 12, -3], [-36, -4, -16, 12], [10, 1, -3, 6], [6, -5, 13, 12], [17, -3, 2, 3], [-12, 4, 4, 4], [0, 2, 16, -6], [-8, 12, 8, -4], [-1, 2, -25, -3], [4, 0, 39, 4], [27, 7, -6, -7], [2, -5, -17, -2], [28, 2, -2, 4], [6, 12, -10, 6], [-7, 9, -18, 3], [6, 6, 20, 10], [6, -2, -6, -16], [-43, -1, 7, 3], [24, -2, -6, 0], [-14, -8, 10, -2], [-23, -5, 8, 3], [-4, -6, 26, 8], [-20, -4, 0, 12], [-9, 4, 17, 9], [23, -4, -14, 5], [4, 0, 4, 4], [2, 2, 15, -2], [16, -7, 4, 0], [26, -3, 5, -2], [15, -1, -2, -3], [-31, 5, 6, -5], [2, -5, 4, 14], [5, -4, -12, -9], [-12, 8, -24, 4], [32, 4, -12, -4], [13, 4, -16, 3], [2, 7, -22, 6], [5, -9, 5, -5], [35, -3, -16, 1], [21, 6, -9, -3], [11, 0, 20, 1], [-27, 12, -1, 3], [-36, -12, 18, -10], [5, -2, 22, -5], [3, 14, -29, -3], [-35, -4, 14, 7], [26, -10, -24, -2], [-19, 0, -26, -9], [-2, 10, 0, 2], [-36, -10, -2, 8], [-22, -8, 16, -8], [33, -3, 16, 1], [57, -1, 4, -5], [-7, -2, -31, -5], [-22, -10, 28, -2], [-35, 6, 5, -1], [27, 4, -24, 5], [-15, -15, 6, -5], [13, 13, -14, -5], [-18, 8, 18, 2], [-17, -5, -14, -11], [-8, 9, 7, 20], [1, 10, 0, 11], [21, 2, -5, 13], [-14, -6, 28, 2], [-34, 4, -24, -4], [3, -11, 0, 1], [-5, -2, -29, -11], [38, -3, 16, -6], [36, 1, -5, -8], [12, 1, -2, -12], [-18, -2, -12, -10], [-16, -12, 8, 4], [25, 8, 12, 3], [42, -12, -12, -8], [-8, 8, -12, 0], [2, -12, -6, 2], [4, -4, 16, 0], [-19, -7, -16, 13], [22, -16, -6, -2], [-13, -2, -28, -3], [33, 1, -6, -9], [-5, 6, 11, -3], [-27, 10, 9, 7], [6, -11, 5, 2], [-7, -5, -24, -9], [-3, -8, 23, -5], [-16, -12, 12, -8], [-2, -14, 3, -14], [20, 8, 0, 16], [27, 7, -10, -11], [-21, -10, 4, -7], [1, 21, -10, -1], [5, 7, 36, -1], [-17, -5, -24, -1], [-12, 3, 24, 4], [-14, 2, 12, 6], [8, 2, 38, -8], [20, 0, 15, 4], [-46, -2, -24, 2], [-12, 12, -12, -8], [-8, -8, 12, 0], [16, 16, -14, 2], [-30, -12, 12, 0], [-4, 6, 36, 2], [-2, 9, 13, 14], [0, 0, 4, -12], [4, 2, -10, -8], [-16, 4, -24, 12], [15, -21, 2, 5], [3, -11, 29, 5], [-54, 6, -27, -10], [-12, -16, 20, -4], [-41, 2, 3, 1], [-15, 11, -2, 5], [-34, -1, 20, 2], [-48, 8, -12, 0], [-12, -8, 14, -10], [2, 5, -7, 14], [-3, 6, 2, 3], [1, 0, -13, -17], [-4, -6, 26, -4], [30, 3, -8, 2], [-29, -7, -4, 9], [-14, 8, 14, -2], [-29, -6, 13, -9], [-50, 6, -28, -6], [-20, -8, 14, 6], [5, -1, -11, 3], [22, 0, -2, -14], [8, -12, 16, -4], [-13, -3, -12, -3], [-15, -3, -6, 7], [7, -14, 3, 9], [-7, 2, -50, 3], [-11, -3, -26, 3], [28, -1, -31, -4], [-36, -12, 8, -8], [-29, 5, -2, 7], [6, -7, 34, 10], [22, -4, 34, 10], [-6, 0, -16, 0], [0, 13, 15, 16], [-29, -3, -12, -7], [-31, 1, -6, 15], [9, 0, 5, -3], [-32, 1, -13, -12], [9, -12, 7, -1], [-33, 1, 20, -3], [27, 3, -2, 13], [-3, 18, -20, -1], [-39, 2, 12, 11], [-23, 10, -16, -5], [-25, -2, -4, 1], [-27, 3, -12, -5], [56, -2, 10, -8], [-3, -9, 40, -5], [-63, -1, 0, 11], [-1, 0, 45, 5], [-18, 2, -12, 10], [-17, 8, -4, -7], [-9, 12, 13, 9], [11, 14, -13, -7], [-16, 4, -4, -16], [60, -1, -4, 4], [-8, -1, -19, 0], [-8, 4, 24, -4], [27, 3, 22, 5], [3, 11, -12, -5], [14, -19, 1, -2], [3, -6, -2, -7], [-4, 8, 0, 8], [24, 13, -13, 0], [17, 4, 32, -1], [80, 2, -2, 0], [-8, 6, 26, 0], [13, 13, -29, -5], [-8, -11, 36, 8], [-6, 15, -17, -6], [57, -8, -13, -9], [0, -16, -10, -10], [-37, -5, -14, -7], [5, -13, 16, 15], [-29, -4, 28, 9], [-10, 8, 12, 4], [24, -16, 16, 4], [-2, -12, 42, -2], [37, 7, -14, 5], [-18, 9, -36, -14], [33, -13, 4, 7], [-10, -14, -20, -6], [27, -17, -9, -3], [-17, -2, -25, -19], [-32, 1, -9, 0], [14, 17, -6, -6], [20, 4, -8, -4], [10, -6, -28, -14], [-47, 2, 10, 3], [16, 11, 0, 0], [-24, 20, 4, 12], [-55, 5, -2, 7], [-41, -17, 14, 5], [-10, 4, -34, 2], [-48, 14, 1, 0], [28, 3, -23, 4], [32, 2, 30, -12], [-29, 0, -11, 9], [47, -6, 8, 9], [-29, 4, 34, 1], [-23, -1, -44, -1], [5, 3, 44, -9], [3, -4, -11, -11], [-4, 3, 9, -8], [-26, -8, -22, 14], [27, -9, 34, 5], [37, 7, 24, -9], [41, -17, -16, -9], [30, -20, -3, -6], [-2, -4, 14, 10], [15, -1, 18, 13], [-51, -10, 25, -9], [6, -20, 33, 10], [5, 2, 4, 11], [-3, -14, 37, -5], [-24, 6, 6, 0], [38, 2, 24, 6], [-13, 16, -30, -15], [-4, 0, 36, 4], [-33, -2, 25, 7], [7, -7, -4, -19], [30, 22, -24, -2], [38, -11, -2, 2], [-6, 0, -2, -2], [36, 0, 12, 8], [5, -5, 12, -13], [-4, 1, 19, -12], [-30, 6, -14, 0], [9, 9, -38, -5], [11, -19, -14, -13], [-34, 10, 0, 2], [-58, 14, -4, -2], [27, 9, -16, 5], [-59, -3, 14, -1], [2, 8, 2, 14], [-4, -12, 20, -8], [-72, 14, 18, 8], [25, -7, -16, -3]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7350_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7350_2_a_dt();".
// 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_7350_2_a_dt(:prec:=4)
    chi := MakeCharacter_7350_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(3361) - 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_7350_2_a_dt();".
// 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_7350_2_a_dt( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7350_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![32, -16, -18, 0, 1]>,<13,R![-16, -48, -26, 0, 1]>,<17,R![124, -8, -32, 4, 1]>,<19,R![-448, -224, 12, 12, 1]>,<23,R![128, 0, -36, -4, 1]>,<31,R![64, 128, 78, 16, 1]>],Snew);
    return Vf;
end function;