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