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