
// Make newform 7350.2.a.ch 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_ch();".
// 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_ch();".
// 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], [1], [-2], [-7], [-3], [0], [6], [5], [9], [-10], [-13], [1], [-4], [2], [-6], [-2], [4], [-14], [-10], [-10], [8], [-8], [0], [-12], [-18], [-6], [-9], [17], [4], [8], [-6], [-22], [13], [12], [-19], [7], [-11], [2], [-16], [18], [27], [14], [19], [16], [14], [4], [0], [20], [1], [3], [-10], [-24], [-14], [-8], [-2], [-11], [26], [1], [2], [26], [-10], [-2], [-15], [14], [16], [24], [0], [-28], [-37], [-6], [-1], [-9], [6], [-2], [-27], [-10], [-3], [-20], [18], [4], [0], [6], [9], [38], [12], [15], [2], [-8], [-24], [24], [-28], [24], [-14], [15], [12], [4], [14], [39], [30], [-3], [-8], [24], [2], [-34], [-28], [30], [13], [-19], [-30], [-15], [18], [-33], [38], [-1], [-5], [-36], [-40], [-36], [33], [4], [20], [18], [16], [2], [53], [-21], [47], [31], [4], [26], [3], [-51], [-37], [38], [-30], [-9], [-11], [6], [8], [42], [-2], [-2], [-49], [-56], [-36], [-15], [27], [3], [52], [-12], [16], [-6], [56], [-33], [-34], [0], [-12], [24], [24], [-39], [-42], [33], [-36], [-10], [-45], [-9], [40], [-18], [18], [-40], [26], [-26], [-21], [40], [41], [32], [29], [29], [49], [-24], [-23], [10], [-5], [-16], [29], [-18], [48], [4], [45], [12], [-26], [-6], [45], [50], [-38], [-16], [-24], [-34], [-10], [-29], [-20], [-3], [-14], [46], [-15], [27], [-10], [-58], [-28], [-68], [36], [-55], [-25], [-41], [-41], [-57], [-4], [-44], [19], [-25], [44], [44], [6], [-30], [-29], [-12], [-53], [29], [-52], [-39], [-14], [0], [30], [45], [61], [-30], [6], [-17], [-8], [-4], [58], [-38], [49], [-35], [44], [-31], [-14], [37], [61], [-35], [-18], [9], [-24], [-48], [27], [-2], [-9], [-56], [42], [-14], [60], [51], [-18], [65], [-34], [-17], [-8], [-72], [64], [40], [-70], [35], [18], [0], [5], [-81], [13], [-24], [15], [36], [32], [0], [52], [23], [72], [-27], [-42], [30], [-72], [-7], [-47], [-24], [8], [-2], [-41], [2], [-20], [-77], [44], [-50], [4], [-74], [-72], [-10], [-62], [43], [-1], [84], [-46], [-8], [3], [11], [-39], [-12], [4], [-2], [52], [54], [-68], [61], [-72], [61], [11], [-64], [-32], [86], [-6], [78], [16], [-12], [-23], [-12], [-8], [74], [11], [89], [22], [52], [-54], [-52], [6], [-44], [-46], [-10], [-54], [21], [-21], [76], [-62], [75], [-48], [-30], [0], [-84], [86], [-24], [71], [-22], [-36], [71], [-16], [-62], [-45], [25], [7], [-37], [55], [-48], [0], [58], [22], [15], [6], [10], [2], [-20], [-30], [-24], [-39], [2], [31], [-71], [-40], [3], [0], [76], [-34], [-6], [12], [64], [90], [-20], [30], [17], [-81], [-72], [34], [-36], [-53], [-52], [28], [88], [77], [18], [-86], [1], [34], [-10], [34], [13], [-92], [-38], [2], [-27], [-12], [97], [18], [41], [32], [100], [-68], [-3], [22], [87], [-69], [-54], [-82], [81], [-23], [21], [-14], [34], [-10], [-40], [-62], [58], [4], [-19], [-80], [-88], [17], [-30], [46], [23], [-99], [-52], [22], [-96], [-84], [-41], [34], [-28], [22], [-87], [17], [18], [-107], [-50], [-28], [24], [-32], [-106], [52], [70], [6], [-28], [-23], [-30], [-54], [37]];
    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_ch();".
// 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_ch(: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_ch();".
// 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_ch( : 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![-1, 1]>,<17,R![2, 1]>,<19,R![7, 1]>,<23,R![3, 1]>,<31,R![-6, 1]>],Snew);
    return Vf;
end function;