
// Make newform 7350.2.a.bb in Magma, downloaded from the LMFDB on 25 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_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_7350_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [1], [0], [0], [0], [-4], [3], [2], [3], [0], [-1], [-10], [-9], [-10], [-3], [-6], [-6], [8], [-4], [3], [14], [11], [0], [-15], [-7], [18], [5], [-18], [2], [21], [-16], [-12], [-9], [2], [-6], [8], [8], [8], [-24], [-18], [-6], [8], [-21], [17], [-12], [11], [14], [-19], [-6], [-4], [-30], [15], [14], [12], [30], [9], [-6], [-7], [-28], [9], [-4], [-24], [-28], [9], [5], [-18], [-10], [11], [-36], [26], [-15], [12], [8], [-4], [-16], [21], [6], [-22], [18], [5], [18], [-40], [-27], [29], [5], [-6], [-21], [2], [-12], [5], [12], [-27], [-31], [-6], [32], [-36], [-36], [15], [32], [-16], [26], [6], [-30], [27], [32], [14], [42], [21], [-3], [-10], [-7], [-16], [-15], [20], [-37], [-33], [38], [24], [0], [-36], [-10], [-19], [-12], [6], [20], [-12], [-34], [-27], [-37], [14], [2], [-51], [-16], [-16], [27], [26], [18], [-22], [0], [6], [56], [-54], [32], [48], [2], [27], [26], [54], [-4], [-15], [38], [-3], [38], [48], [-16], [39], [-19], [18], [26], [30], [-48], [6], [-49], [-36], [27], [-12], [59], [-40], [5], [-24], [-30], [38], [48], [35], [-31], [-39], [-16], [30], [56], [8], [-4], [6], [-34], [-54], [33], [-30], [50], [14], [-31], [-12], [38], [36], [-10], [-12], [-24], [-6], [50], [-10], [42], [24], [-24], [29], [-40], [-1], [30], [-48], [-31], [24], [-15], [-52], [65], [-42], [-7], [-18], [-21], [-55], [35], [6], [-24], [-18], [-4], [-31], [-21], [65], [54], [-46], [21], [-15], [-49], [48], [68], [56], [23], [-39], [-4], [15], [50], [60], [36], [-15], [54], [2], [32], [-4], [-27], [33], [-61], [-60], [14], [21], [-16], [18], [9], [-10], [12], [54], [-4], [-28], [42], [-7], [44], [66], [-22], [-64], [15], [44], [-78], [-30], [14], [-48], [68], [2], [-1], [5], [50], [-25], [-18], [20], [-25], [-54], [33], [41], [75], [44], [62], [45], [-7], [12], [8], [-63], [-12], [-30], [57], [-18], [62], [84], [-28], [-42], [-54], [2], [5], [42], [-31], [30], [74], [29], [-18], [-40], [-72], [2], [-81], [24], [-66], [8], [-33], [74], [-6], [63], [-1], [33], [-52], [26], [18], [-16], [-33], [-46], [-64], [-64], [27], [54], [-46], [-78], [59], [18], [62], [-12], [2], [9], [14], [-1], [-82], [3], [54], [8], [-66], [-54], [-34], [20], [24], [36], [-34], [29], [-12], [-85], [32], [-15], [15], [54], [39], [-36], [-16], [42], [51], [-24], [14], [-58], [0], [5], [2], [78], [80], [3], [-60], [77], [-52], [60], [-24], [-25], [-57], [-55], [0], [-66], [-16], [18], [14], [99], [-55], [-22], [20], [-69], [71], [-6], [72], [-46], [15], [5], [80], [-42], [-76], [18], [86], [6], [-67], [-42], [-48], [77], [38], [3], [-76], [24], [-46], [0], [-24], [38], [47], [18], [72], [53], [3], [-48], [-12], [56], [-12], [30], [-43], [42], [-42], [42], [44], [-51], [77], [96], [32], [81], [86], [-69], [-25], [50], [62], [-13], [54], [21], [-10], [57], [-97], [105], [26], [-27], [-46], [-88], [-112], [-9], [54], [-69], [71], [-78], [-88], [-78], [32], [-3], [38], [-85], [102], [-46], [98], [11], [47], [90], [-9], [-52], [-52], [-90], [9], [-13]];
    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_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_7350_2_a_bb(:prec:=1)
    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_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_7350_2_a_bb( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7350_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![0, 1]>,<13,R![4, 1]>,<17,R![-3, 1]>,<19,R![-2, 1]>,<23,R![-3, 1]>,<31,R![1, 1]>],Snew);
    return Vf;
end function;