
// Make newform 7350.2.a.cf in Magma, downloaded from the LMFDB on 17 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_cf();".
// 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_cf();".
// 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], [6], [-6], [0], [-4], [0], [-8], [2], [-4], [-10], [6], [2], [-10], [-4], [14], [-14], [8], [-6], [-8], [8], [-18], [-2], [-14], [12], [-4], [6], [-6], [-4], [12], [-10], [8], [0], [-8], [14], [-2], [18], [6], [2], [10], [-20], [-22], [-6], [-18], [12], [-16], [-20], [-14], [10], [-4], [-28], [-20], [8], [32], [22], [-18], [8], [6], [-28], [-22], [20], [-12], [-26], [-10], [-20], [26], [28], [2], [-4], [-24], [4], [8], [16], [14], [24], [14], [2], [-16], [12], [-34], [0], [-18], [10], [12], [-10], [-38], [-2], [-8], [0], [-36], [-12], [-22], [-32], [-6], [34], [-2], [44], [18], [-30], [-2], [-24], [26], [-4], [14], [-32], [16], [44], [12], [40], [-36], [-42], [20], [-40], [18], [4], [46], [-14], [-6], [-18], [14], [22], [24], [40], [24], [2], [-16], [32], [46], [-40], [0], [40], [40], [-6], [40], [26], [-20], [-18], [-18], [-16], [0], [24], [24], [22], [-44], [22], [0], [16], [32], [32], [18], [-14], [-26], [10], [12], [-8], [42], [-30], [2], [48], [6], [48], [-4], [-54], [42], [8], [-42], [46], [-18], [6], [2], [4], [-54], [22], [42], [-56], [24], [-24], [6], [20], [12], [16], [-24], [-40], [-18], [44], [-4], [-38], [0], [-2], [-36], [0], [6], [8], [40], [-34], [-4], [0], [-10], [4], [38], [-22], [64], [4], [-22], [-50], [-16], [50], [8], [-2], [22], [-32], [-24], [-44], [0], [-60], [-50], [24], [18], [58], [-10], [-10], [28], [-64], [18], [24], [12], [-32], [-46], [12], [-44], [24], [-22], [68], [-42], [64], [18], [34], [44], [4], [28], [-64], [-46], [52], [24], [-8], [60], [4], [32], [0], [-50], [8], [-4], [66], [-6], [38], [-44], [-30], [22], [-64], [4], [-50], [2], [-12], [-8], [12], [-18], [14], [58], [42], [10], [14], [8], [46], [-4], [12], [-22], [-10], [-36], [-6], [64], [30], [-50], [20], [-24], [-54], [6], [-6], [2], [-12], [-36], [-6], [-84], [28], [-14], [-2], [78], [36], [28], [-70], [-38], [24], [56], [68], [-66], [-68], [38], [48], [80], [-38], [-24], [74], [2], [48], [0], [12], [16], [-10], [46], [80], [22], [-78], [40], [-18], [-52], [44], [-4], [64], [-26], [-2], [-46], [26], [-44], [-32], [-52], [-46], [-20], [-24], [-52], [-56], [54], [-6], [0], [58], [-2], [50], [-82], [12], [26], [0], [-14], [-56], [-88], [10], [44], [8], [-52], [18], [64], [-8], [-6], [-48], [66], [-28], [-78], [86], [4], [-30], [62], [0], [48], [36], [38], [-8], [36], [40], [78], [70], [-62], [-34], [-86], [44], [82], [-16], [30], [-64], [70], [-46], [-42], [-34], [-30], [-62], [-76], [24], [46], [-62], [50], [-24], [-84], [-26], [-34], [-92], [-84], [-6], [-22], [-40], [102], [-28], [60], [34], [-42], [-84], [56], [-78], [18], [60], [-44], [-36], [78], [-48], [42], [-88], [-12], [-34], [-70], [24], [6], [-68], [-20], [-80], [50], [-40], [-42], [-74], [-18], [66], [-2], [62], [22], [-40], [-18], [-54], [-60], [-68], [-18], [-36], [10], [16], [-34], [66], [0], [-44], [78], [54], [76], [-82], [44], [42], [22], [52], [-72], [-30], [-98], [100], [-30], [0], [84], [-86], [-68], [-4], [8], [-40], [-74]];
    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_cf();".
// 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_cf(: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_cf();".
// 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_cf( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7350_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![-6, 1]>,<13,R![6, 1]>,<17,R![0, 1]>,<19,R![4, 1]>,<23,R![0, 1]>,<31,R![-2, 1]>],Snew);
    return Vf;
end function;