
// Make newform 6200.2.a.l in Magma, downloaded from the LMFDB on 12 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6200_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_6200_2_a_l();".
// 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_6200_2_a_l();".
// 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_6200_a();"
function MakeCharacter_6200_a()
    N := 6200;
    order := 1;
    char_gens := [1551, 3101, 2977, 1801];
    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_6200_a_Hecke(Kf)
    return MakeCharacter_6200_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]];
    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], [2], [0], [3], [-2], [2], [6], [1], [6], [4], [-1], [2], [7], [-4], [-8], [-8], [3], [-6], [12], [3], [10], [-12], [-2], [-16], [7], [17], [-19], [11], [-1], [-9], [10], [-4], [22], [18], [6], [20], [17], [23], [4], [-18], [-10], [2], [13], [-13], [12], [-18], [-5], [4], [12], [26], [-21], [-12], [10], [-20], [-25], [6], [0], [-4], [28], [1], [20], [-6], [-13], [-13], [-2], [-13], [-26], [24], [-26], [-10], [-24], [-13], [-14], [25], [-4], [10], [0], [27], [-24], [14], [-9], [37], [0], [4], [11], [3], [-30], [-40], [38], [14], [-27], [-27], [-22], [0], [6], [9], [-24], [-26], [-18], [35], [31], [-12], [-31], [0], [-10], [-30], [-36], [21], [-11], [28], [4], [2], [38], [20], [-6], [4], [-34], [-44], [-38], [7], [-37], [24], [14], [15], [-33], [3], [-4], [-24], [29], [-49], [28], [24], [-5], [-24], [-14], [21], [24], [4], [0], [8], [-20], [36], [-54], [-34], [2], [0], [-14], [30], [-20], [-4], [31], [-24], [-28], [31], [-27], [0], [-28], [36], [14], [-6], [-42], [22], [0], [36], [-3], [-30], [-38], [-3], [0], [-24], [-10], [-10], [8], [3], [57], [-46], [-35], [-13], [56], [60], [49], [36], [49], [28], [-45], [-24], [-22], [7], [-64], [-41], [24], [-51], [-32], [-48], [60], [46], [6], [34], [-7], [21], [21], [-14], [50], [25], [-52], [58], [-47], [8], [-3], [-41], [-40], [32], [4], [61], [-12], [-41], [-52], [27], [-6], [-57], [4], [13], [21], [-59], [-33], [10], [-3], [48], [-26], [-32], [-4], [-5], [-9], [18], [60], [-40], [41], [-34], [-46], [22], [-44], [56], [10], [-24], [-40], [-16], [2], [-8], [76], [64], [-55], [-57], [-14], [-11], [53], [-68], [3], [-46], [-3], [-53], [44], [-78], [-44], [47], [36], [-3], [45], [6], [-36], [51], [-14], [-52], [-54], [28], [-37], [13], [7], [-80], [8], [0], [-65], [1], [21], [-5], [-85], [-42], [38], [-18], [40], [30], [-57], [63], [-34], [44], [-18], [-78], [-16], [86], [-4], [20], [54], [-36], [28], [-76], [-44], [54], [54], [-53], [-42], [67], [2], [-10], [-47], [44], [51], [-52], [-60], [-38], [-29], [-18], [70], [48], [49], [-65], [-26], [0], [29], [-11], [78], [-4], [3], [73], [9], [-66], [-3], [19], [74], [34], [-43], [32], [0], [-66], [-30], [62], [-34], [75], [50], [74], [-18], [-41], [0], [66], [27], [18], [11], [48], [22], [34], [58], [-9], [-81], [40], [62], [-33], [37], [48], [33], [16], [-86], [-84], [24], [-40], [-59], [35], [-6], [20], [95], [53], [30], [-38], [56], [-36], [82], [-84], [-28], [-15], [65], [46], [94], [-56], [24], [66], [71], [40], [-4], [-58], [-8], [-83], [-52], [42], [-32], [43], [16], [-27], [70], [23], [-82], [-20], [90], [-70], [-6], [77], [14], [-10], [97], [63], [60], [9], [-22], [-1], [48], [-54], [-50], [-89], [1], [-16], [-4], [24], [56], [-20]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6200_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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