
// Make newform 4200.2.a.bq in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4200_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_4200_2_a_bq();".
// 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_4200_2_a_bq();".
// 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
        poly := [1, -3, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-1, 2, 0], [-4, -2, 2]];
    Rf_basisdens := [1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_4200_a();"
function MakeCharacter_4200_a()
    N := 4200;
    order := 1;
    char_gens := [3151, 2101, 2801, 1177, 3601];
    v := [1, 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_4200_a_Hecke(Kf)
    return MakeCharacter_4200_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, 0, 0], [1, 0, 0], [0, 0, 0], [1, 0, 0], [1, 1, 1], [1, 1, 0], [0, 0, 1], [1, 1, 0], [3, 1, 0], [0, -2, -2], [-1, -1, 0], [-2, -2, 0], [5, 1, 0], [4, 0, 2], [2, -2, -2], [5, 1, -2], [2, -2, -2], [0, -2, 2], [0, 0, 0], [-3, -3, -1], [1, -3, -2], [-6, 2, 0], [2, -2, -2], [1, 1, 2], [-5, -1, -2], [11, 3, -2], [8, 0, 2], [7, 1, 4], [-4, -2, -2], [7, -1, -2], [8, 4, -2], [-4, 0, 0], [1, 1, 4], [-5, -1, 2], [-2, -4, 2], [-16, 0, -2], [3, 3, 2], [6, -2, -2], [0, 4, 0], [6, -2, 3], [-3, -3, 1], [2, 0, 2], [-5, 3, 1], [6, 2, 0], [7, -5, -2], [-11, 1, 2], [-6, -2, -6], [8, 0, 4], [-4, -4, 2], [-6, 4, -2], [15, -1, 0], [5, 5, -1], [4, -6, -4], [6, 2, -2], [6, 6, -3], [-7, -5, -4], [13, 1, 2], [-19, -3, 0], [-2, -2, 0], [8, -2, 4], [4, 0, -6], [-2, -2, 1], [4, 0, 2], [-8, 0, 6], [11, -1, 4], [9, 5, -2], [-18, 2, 2], [16, 0, 0], [-13, -3, 0], [-4, 2, -6], [12, 4, 3], [-9, -1, 1], [-12, -4, 0], [-6, -2, -8], [-4, 0, 2], [-6, 2, 4], [8, 2, 2], [-7, -7, -6], [0, -6, -4], [-8, -6, 0], [16, -4, -2], [8, 2, 6], [-31, 1, -1], [-1, 3, 0], [-19, 1, -2], [-5, 5, 0], [6, 4, -8], [10, 2, 4], [19, -9, -4], [4, -8, -6], [4, 4, -2], [-8, 0, -10], [-10, 6, 6], [13, 5, 9], [-16, -4, -2], [-18, -2, 4], [-1, 3, 2], [25, 1, 4], [20, 0, -4], [8, 6, 2], [-4, 4, 0], [9, -3, -6], [-6, 10, 4], [24, 2, 0], [-24, 4, 0], [11, 7, -4], [-10, 6, 0], [-12, -4, 1], [-21, 3, 1], [22, 0, -4], [24, 0, 4], [-28, 0, 4], [3, -5, 0], [3, -1, -2], [2, 2, 0], [-12, 2, 8], [-4, 0, -2], [-16, 4, -4], [-13, -9, 4], [27, -5, -1], [8, 6, -2], [0, -12, 0], [6, 6, 7], [-13, -3, 4], [-7, -3, -2], [4, 2, 10], [-6, 0, 8], [-2, -2, 4], [-4, -4, -10], [1, 9, -4], [-12, 8, 4], [-37, 1, 0], [-10, -10, -6], [10, -2, 4], [7, 7, -10], [-10, -8, 4], [22, -2, -3], [-16, -4, 4], [-2, 6, 3], [-10, -8, -12], [27, -1, 2], [18, 4, -6], [-12, 0, -6], [-17, 9, 8], [10, 8, 10], [-6, 2, 10], [-19, -3, -10], [2, -6, 1], [11, -13, -8], [-9, -11, -4], [-24, 4, 4], [-5, 7, 2], [-10, 2, 8], [-10, 2, 6], [-10, 2, -8], [35, 3, 1], [-2, 6, -10], [-17, -9, 2], [5, 9, 8], [29, -3, -4], [9, -1, -8], [11, 11, -2], [-30, -2, 4], [-18, 2, 0], [-1, -9, -8], [-28, -4, -2], [-26, 6, 2], [-3, -3, -10], [-2, 4, 8], [-10, 6, -7], [21, 5, -7], [20, -2, -2], [-7, 9, 7], [-14, -2, 0], [-21, -9, -6], [7, -1, 8], [-2, -14, -4], [-52, -2, 2], [24, 8, 6], [-16, 2, -6], [-2, 2, -8], [54, 2, 0], [0, 0, -8], [-32, 0, 7], [-3, 15, 4], [5, -3, -2], [-28, 0, -4], [0, 12, 12], [-10, -8, 0], [-22, 2, 4], [-5, -17, -2], [-13, 13, 0], [-20, -16, 6], [-3, 9, 4], [-3, 3, 4], [-16, -8, -7], [-42, -4, 0], [-28, 4, 8], [-22, 10, 5], [-20, -8, -12], [-10, 8, 2], [-3, 1, 10], [-25, -9, 4], [12, 10, 0], [34, 6, 8], [30, -10, -1], [-13, -1, 6], [3, -3, -8], [-10, -8, 0], [39, -1, -4], [-22, -6, 0], [-5, 15, 10], [0, 0, -12], [14, -6, -2], [-10, -2, 2], [-14, 4, -4], [10, -6, 6], [21, -7, 6], [-7, 3, 8], [31, 3, 0], [-30, 8, 0], [-17, -1, 0], [-14, 4, -4], [0, 0, 0], [32, -12, -4], [2, -8, -8], [-22, -6, -15], [-37, -5, 1], [12, -4, 10], [5, 5, -3], [-50, -6, 4], [37, -3, -4], [16, 8, -6], [-50, 0, 0], [16, -12, -2], [-4, 4, 2], [4, 14, 12], [3, -1, -2], [-3, -11, -11], [6, 6, -12], [17, -1, 8], [7, 3, -14], [-4, 4, -8], [10, 4, -4], [-14, -6, 5], [6, -10, -2], [28, 4, 2], [-4, -8, -2], [14, 2, 8], [-17, -11, -8], [16, 4, 4], [-47, -3, -2], [21, 7, 4], [20, 6, 8], [50, -6, -3], [1, -7, 5], [-34, -4, -12], [0, 20, 6], [14, -10, -7], [27, 15, 0], [0, -12, -2], [-57, 1, 0], [6, 16, 2], [19, 11, 10], [-24, 0, -3], [29, 1, 2], [-22, 12, 2], [49, -7, -4], [32, 0, 12], [23, -5, 8], [0, 2, 14], [0, 4, -2], [3, 15, 10], [14, 6, 18], [23, 11, 10], [48, 0, -2], [-17, 1, 0], [12, -2, 6], [4, -6, 6], [14, -6, -2], [40, 0, -2], [-26, -2, -4], [20, 4, 18], [-4, -2, -2], [36, 8, 8], [-13, 3, -7], [18, 2, 4], [53, 1, 6], [3, -5, 4], [-25, -1, -10], [-10, 0, -18], [30, 2, -6], [-1, -9, 0], [52, -8, -2], [62, 2, 0], [-5, -17, -8], [-1, -5, -18], [36, -12, -3], [-10, 2, 6], [12, -24, -8], [37, 1, 0], [-9, -5, -16], [4, -12, -4], [-7, -1, 0], [28, 8, -4], [12, -4, 0], [5, -5, -12], [46, 8, 10], [-31, 1, -1], [-12, 12, -4], [12, 12, 10], [-28, -6, 10], [4, 6, 8], [6, 10, -8], [-37, 1, -8], [4, -6, -12], [20, 0, -4], [3, 3, 9], [19, -1, -10], [-32, -6, 12], [39, -1, 12], [-40, -4, 8], [-27, 1, 4], [4, -4, 0], [45, -3, -6], [-16, -10, -16], [36, 0, -4], [12, -8, -6], [37, -1, 4], [41, -3, 0], [24, -2, -6], [71, 3, -4], [-11, 5, 0], [-2, -18, -8], [-2, -6, -4], [-6, 2, -8], [2, -12, -12], [2, -14, 3], [20, 10, 4], [28, 4, -10], [-50, -6, -8], [3, 3, -4], [-7, 13, 10], [16, 8, 14], [35, -1, -4], [-1, 15, 3], [-18, -8, 2], [-18, 26, 12], [22, 6, 24], [-2, -18, -3], [9, 9, 12], [40, 4, 20], [-6, 4, -2], [-20, -4, -8], [-36, -14, 10], [-40, 0, -1], [2, 10, -16], [-32, -4, -16], [-41, -9, -2], [-17, 13, 12], [46, -6, 0], [31, -5, -8], [-17, -11, -12], [27, -5, -9], [-28, 8, 0], [32, 20, 0], [40, 8, -5], [-46, -2, 0], [28, 2, 6], [53, -3, 9], [-13, -13, 4], [7, -11, 0], [6, 12, 6], [17, 9, 0], [-26, -18, 0], [-4, 0, -4], [-13, -21, -3], [-17, 11, -4], [-31, 1, 0], [-19, -15, -18], [83, 3, -2], [-25, -17, 10], [-50, -10, 2], [-11, -19, 2], [47, -5, -6], [-22, -14, 8], [-30, 10, 6], [-19, -19, 0], [-32, 8, 0], [10, -18, -10], [30, 8, 16], [-32, 24, 13], [-1, -17, 7], [28, -8, 2], [5, -11, -1], [40, 16, 0], [23, 3, 22], [23, 3, -14], [-24, -12, 4], [-28, 18, 6], [48, 10, -6], [-9, 7, -14], [-2, 10, -4], [-10, 30, 11], [-7, 9, 0], [-1, -21, 2], [-14, 2, 8], [-18, 4, -8], [-36, 8, 8], [-30, 22, 10], [65, 5, 12], [17, -3, 8], [-49, 1, 8], [34, 22, -14], [34, 6, -8], [1, -3, 18], [-31, -7, 3], [-48, 0, -2], [-44, 4, -1], [-26, 18, 10], [-32, -6, 14], [-35, 5, -6], [-13, 17, 8], [-30, -10, -8], [-49, -13, 0], [38, 6, 13], [45, 3, -4], [24, -6, 8], [-11, 1, -22], [-18, -18, -2]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4200_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4200_2_a_bq();".
// 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_4200_2_a_bq(:prec:=3)
    chi := MakeCharacter_4200_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_4200_2_a_bq();".
// 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_4200_2_a_bq( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4200_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![8, -20, -2, 1]>,<13,R![8, -12, -2, 1]>,<17,R![16, -16, 0, 1]>,<19,R![8, -12, -2, 1]>,<23,R![16, 8, -8, 1]>],Snew);
    return Vf;
end function;