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