
// Make newform 6200.2.a.j in Magma, downloaded from the LMFDB on 11 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_j();".
// 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_j();".
// 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], [1], [0], [0], [0], [2], [-3], [1], [0], [6], [1], [-3], [-11], [-9], [-10], [1], [13], [8], [-2], [3], [7], [2], [-9], [4], [-14], [-3], [-12], [-2], [-5], [4], [-8], [9], [-21], [-10], [13], [-22], [4], [16], [3], [-12], [-12], [-14], [4], [14], [-6], [16], [12], [-11], [6], [6], [4], [-10], [-28], [-2], [-6], [13], [6], [-18], [-19], [-1], [-26], [-14], [16], [-13], [21], [-32], [4], [-11], [8], [15], [10], [24], [3], [-10], [21], [-5], [-10], [14], [28], [-14], [23], [-5], [-3], [-2], [-9], [34], [2], [10], [20], [-28], [-8], [32], [-9], [0], [-10], [-14], [20], [-21], [-3], [10], [24], [-34], [-14], [-4], [38], [-42], [24], [-16], [24], [40], [-14], [15], [-28], [32], [20], [-24], [41], [33], [12], [-23], [9], [11], [-17], [-4], [9], [-2], [-34], [8], [12], [-32], [-50], [11], [20], [-25], [28], [-5], [-46], [28], [-26], [10], [-5], [-20], [19], [-5], [-18], [55], [-12], [-12], [-32], [25], [20], [58], [-5], [-42], [-4], [12], [-11], [-8], [4], [-18], [-15], [47], [-16], [31], [60], [40], [-16], [48], [-24], [34], [-26], [40], [-35], [44], [37], [-54], [37], [-30], [-54], [-8], [-12], [50], [34], [21], [4], [-48], [38], [2], [-56], [63], [30], [42], [-10], [-64], [52], [6], [-20], [-28], [-22], [22], [-45], [42], [-26], [-10], [52], [53], [-41], [15], [27], [-33], [33], [-16], [62], [-2], [-48], [-7], [32], [38], [63], [-2], [38], [-32], [31], [4], [30], [-28], [-66], [-10], [-37], [68], [-29], [20], [13], [16], [20], [-72], [-67], [14], [4], [-14], [-24], [40], [-71], [-20], [11], [-16], [17], [-18], [38], [-66], [10], [75], [64], [77], [32], [-53], [54], [43], [68], [-8], [8], [-8], [-2], [26], [18], [12], [66], [10], [-48], [-2], [29], [-68], [39], [22], [-78], [-38], [-4], [-62], [20], [-52], [-12], [53], [80], [-57], [-70], [66], [-62], [33], [-20], [54], [-39], [-66], [49], [37], [-50], [56], [-26], [-72], [0], [-19], [16], [45], [-52], [36], [-30], [38], [77], [38], [-26], [-2], [39], [-30], [-15], [-59], [-38], [18], [4], [-70], [-14], [-60], [-6], [-22], [-66], [74], [2], [56], [-92], [-70], [-43], [-33], [-31], [48], [-40], [60], [-17], [-30], [48], [-18], [-73], [-55], [-93], [42], [-72], [-38], [30], [-13], [-75], [28], [-78], [-2], [58], [35], [53], [-80], [14], [54], [34], [12], [-39], [24], [-12], [-4], [-75], [-4], [-46], [66], [42], [19], [5], [-84], [-39], [90], [21], [-32], [69], [-66], [0], [36], [-61], [-19], [-78], [-25], [83], [-15], [-28], [32], [75], [57], [-36], [3], [-20], [-21], [36], [-80], [-43], [2], [-48], [31], [-28], [-30], [14], [34], [-50], [-72], [10], [-7], [-50], [-22], [55], [-62], [55], [-66], [-5], [-8], [58], [-81], [-66], [-42], [6], [32], [-28], [37], [-91], [21], [-22], [67], [36], [50], [-78], [-6]];
    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_j();".
// 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_j(: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_j();".
// 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_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6200_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, 1]>,<7,R![0, 1]>,<11,R![0, 1]>],Snew);
    return Vf;
end function;