
// Make newform 9200.2.a.y in Magma, downloaded from the LMFDB on 13 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9200_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_9200_2_a_y();".
// 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_9200_2_a_y();".
// 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_9200_a();"
function MakeCharacter_9200_a()
    N := 9200;
    order := 1;
    char_gens := [1151, 6901, 2577, 1201];
    v := [1, 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_9200_a_Hecke(Kf)
    return MakeCharacter_9200_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 := [[0], [1], [0], [-4], [6], [1], [0], [-2], [1], [9], [-5], [-2], [-9], [-4], [-3], [6], [0], [2], [-10], [3], [7], [10], [-12], [0], [-8], [-6], [-4], [-18], [20], [-12], [11], [15], [12], [-23], [6], [-5], [4], [-1], [-24], [-6], [-15], [2], [18], [19], [-21], [-14], [-20], [-16], [-24], [8], [9], [3], [-22], [-12], [-3], [-6], [-27], [16], [31], [-12], [26], [-24], [32], [-21], [-32], [-18], [-35], [-8], [-36], [-19], [3], [6], [-28], [-26], [-8], [24], [0], [-23], [6], [-19], [-12], [-28], [12], [-14], [-11], [9], [6], [28], [21], [32], [-18], [-12], [-13], [9], [19], [-6], [-3], [12], [-16], [-7], [-1], [24], [12], [-42], [-8], [43], [33], [42], [0], [5], [-4], [16], [42], [40], [40], [24], [14], [21], [9], [12], [14], [1], [-42], [3], [28], [-12], [32], [0], [-10], [40], [25], [12], [4], [34], [-27], [-46], [-24], [-4], [6], [-30], [19], [-30], [-31], [48], [2], [-48], [-38], [-39], [-5], [-45], [-14], [48], [20], [-3], [-10], [18], [-32], [39], [22], [-12], [33], [18], [23], [-42], [-18], [54], [16], [10], [14], [-15], [30], [53], [12], [-8], [-11], [0], [-23], [-45], [14], [-52], [-13], [0], [-41], [30], [-30], [48], [34], [-10], [53], [48], [1], [-12], [22], [-6], [18], [24], [-22], [64], [-24], [-45], [36], [-8], [67], [26], [-12], [3], [-62], [21], [-9], [-35], [-47], [-33], [-28], [-54], [-24], [-28], [17], [-27], [42], [21], [-49], [-38], [-3], [-52], [-27], [-1], [-54], [-15], [-22], [-36], [-2], [-20], [58], [-54], [-28], [24], [-40], [42], [39], [-51], [24], [55], [65], [-49], [18], [27], [-19], [-18], [-26], [54], [-32], [42], [30], [32], [30], [-63], [50], [-10], [-57], [43], [68], [0], [-22], [28], [42], [-26], [-6], [72], [-22], [51], [53], [38], [28], [4], [-5], [29], [-12], [-70], [38], [-72], [-9], [-14], [-66], [38], [32], [72], [-26], [54], [-80], [-66], [-30], [48], [-66], [-18], [-29], [-30], [40], [57], [21], [35], [40], [-78], [64], [-33], [76], [13], [-36], [20], [66], [-2], [57], [42], [36], [-1], [42], [-52], [9], [-21], [-32], [-57], [28], [-80], [27], [-16], [30], [56], [-62], [23], [-42], [60], [-67], [-3], [61], [-33], [-50], [-33], [62], [36], [71], [56], [-59], [12], [6], [-14], [30], [12], [35], [-28], [66], [42], [31], [-65], [-18], [-70], [44], [-66], [-24], [-42], [63], [-36], [22], [45], [27], [30], [-97], [19], [-27], [2], [-22], [45], [-20], [-63], [48], [-32], [-47], [21], [-90], [-62], [36], [37], [78], [30], [-52], [-3], [4], [-9], [13], [-14], [-34], [36], [-16], [-6], [15], [-52], [72], [-74], [-8], [-36], [64], [54], [59], [-9], [32], [24], [15], [7], [-98], [-99], [-52], [36], [-11], [-87], [-42], [-14], [-14], [-39], [24], [20], [60], [0], [-48], [-20], [24], [-36], [-65], [45], [102], [6], [-29], [39]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9200_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9200_2_a_y();".
// 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_9200_2_a_y(:prec:=1)
    chi := MakeCharacter_9200_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(2999) - 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_9200_2_a_y();".
// 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_9200_2_a_y( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9200_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, 1]>,<7,R![4, 1]>,<11,R![-6, 1]>],Snew);
    return Vf;
end function;