
// Make newform 2200.2.a.m in Magma, downloaded from the LMFDB on 02 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2200_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_2200_2_a_m();".
// 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_2200_2_a_m();".
// 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 := [-4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_2200_a();"
function MakeCharacter_2200_a()
    N := 2200;
    order := 1;
    char_gens := [551, 1101, 177, 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_2200_a_Hecke(Kf)
    return MakeCharacter_2200_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], [-2, 1], [1, 0], [0, -2], [-4, 1], [4, 1], [-4, 2], [-2, -1], [4, -3], [-2, 5], [-10, 0], [-2, 2], [4, -2], [6, 1], [-4, 6], [-2, 1], [0, 0], [-4, -1], [-8, -2], [4, 2], [-10, 0], [2, -5], [-14, 2], [-10, 4], [8, -4], [-2, 2], [-2, 0], [2, 2], [-2, -6], [-4, -3], [10, -6], [4, -8], [-6, -3], [-4, -2], [2, -7], [-8, -5], [-6, -3], [12, -6], [-4, -8], [2, -8], [8, 4], [-12, 5], [-12, 4], [4, 7], [-4, -3], [20, -2], [18, 0], [6, 8], [-16, -3], [4, 2], [-10, 12], [20, -2], [14, 4], [-26, -1], [-26, -2], [12, 0], [0, 12], [6, -8], [6, -8], [8, -2], [-2, 12], [4, -11], [-10, 4], [2, -1], [4, 4], [4, 7], [-18, 4], [-6, 12], [-10, -4], [4, 8], [28, 0], [20, -6], [12, -10], [8, -14], [-26, 4], [-18, -8], [-14, 5], [-14, 2], [-12, -4], [18, -2], [8, -8], [2, -14], [0, 16], [-20, 0], [-10, 12], [24, -9], [18, -7], [4, 2], [-4, 3], [-12, 0], [28, -4], [-8, 5], [-4, 0], [-26, 2], [-26, 6], [22, 8], [-14, 6], [10, -1], [10, -2], [-4, 2], [2, -4], [-6, -2], [24, -5], [18, -8], [-20, 1], [-8, -10], [-20, -3], [6, -20], [-30, 3], [-12, 10], [-6, -2], [4, 0], [-4, -1], [18, 9], [24, 3], [0, -6], [-18, -5], [16, 7], [-2, 8], [4, -11], [0, -4], [4, 5], [-20, 10], [-10, 17], [42, -4], [-28, 9], [-8, 10], [4, 0], [-28, 12], [30, 1], [20, 1], [14, -8], [2, 0], [6, -16], [-18, -11], [30, 2], [6, 12], [-34, 12], [-48, -1], [26, 4], [0, 12], [-26, -10], [26, -14], [8, 0], [12, -18], [-36, 9], [12, -6], [0, 6], [-36, 2], [-22, 8], [32, 9], [46, -6], [-28, 11], [-12, 19], [-16, -4], [-10, -7], [20, -6], [-30, -1], [-36, 9], [-8, 19], [-6, -9], [-4, -4], [42, -6], [-24, -2], [-40, 8], [12, 16], [30, 0], [30, 5], [16, -11], [-14, 8], [4, 10], [8, 1], [-32, 16], [38, 1], [36, 0], [-18, 10], [2, -13], [2, -7], [-16, -10], [-24, -15], [26, 11], [-48, 9], [-4, -10], [-22, 20], [4, 8], [-16, 12], [-38, 8], [16, -8], [2, 10], [-58, 2], [-4, 18], [46, -6], [10, -10], [-18, 0], [-58, 2], [-30, 0], [-44, -10], [-26, 15], [-26, -1], [0, 2], [14, 15], [-58, 6], [-44, 4], [-30, 1], [48, -8], [-22, -2], [54, 0], [28, 8], [-8, 7], [2, -26], [16, -4], [20, 1], [-4, -16], [-50, 1], [-34, 7], [34, -20], [0, 16], [22, -9], [26, -4], [52, -2], [6, 11], [24, 12], [14, -22], [-22, 5], [26, 0], [12, -5], [14, -14], [16, -4], [30, -12], [-32, 15], [-8, 14], [-2, -8], [32, 4], [-10, 15], [-14, -11], [0, 6], [-52, -8], [-28, 17], [0, -27], [-8, -4], [-8, 8], [18, 0], [-20, 6], [12, -14], [-12, 16], [-28, 18], [32, 17], [-26, 15], [-32, 14], [-6, -22], [16, -6], [-18, 9], [20, 12], [-8, -15], [-46, -2], [2, -24], [14, -8], [0, 3], [-30, 6], [34, 6], [22, -35], [16, 10], [-18, 10], [-12, 0], [-6, -2], [38, -1], [-26, 2], [8, 26], [30, -32], [20, 5], [-14, 34], [16, -14], [-48, 13], [-28, 22], [32, -8], [-14, -8], [-2, 4], [36, 7], [-18, 25], [24, -4], [34, -26], [-14, -3], [26, 2], [-28, -3], [18, -20], [-8, 10], [-68, 3], [34, -4], [-2, 14], [-20, -8], [-56, 1], [-36, 3], [32, -6], [6, -4], [48, 0], [-18, 23], [-4, 16], [38, 0], [0, -25], [-12, -8], [-16, 28], [-24, 36], [-12, -2], [14, -30], [72, 4], [30, 18], [-12, -15], [-44, -4], [-18, 22], [-50, 0], [42, -14], [-20, 7], [42, 13], [-18, 12], [60, -10], [20, -8], [-22, 16], [26, 18], [-4, 27], [-38, 8], [-14, 16], [60, -2], [24, -37], [2, -11], [60, -10], [-20, -16], [-26, -3], [36, -24], [-18, -21], [38, 12], [-28, 12], [2, 20], [12, 9], [8, 31], [-18, 24], [-8, -3], [2, -25], [-34, -3], [54, -20], [-2, -8], [-6, -17], [44, -1], [38, -15], [36, -1], [46, -6], [-8, 29], [40, -16], [-26, 11], [80, 1], [-26, 20], [-38, -14], [2, 11], [-10, 17], [-20, -9], [-44, -15], [-12, 11], [12, -30], [-16, 12], [-24, 2], [10, 34], [-12, 0], [-4, -13], [40, -13], [-54, -2], [-4, -6], [-50, -11], [22, -26], [-4, 24], [-44, -8], [-46, -2], [10, -11], [-48, -6], [6, -40], [4, 24], [4, 6], [-24, -3], [-22, -18], [16, -1], [-42, 6], [62, -16], [6, -26], [-28, -25], [0, -24], [-40, 12], [72, 0], [50, -5], [18, -26], [-24, -10], [10, -9], [46, 11], [-4, -28], [-8, 8], [-32, 24], [20, 14], [0, -22], [-18, -3], [-36, -2], [-26, -7], [2, 23], [42, 0], [-22, 10], [30, 6], [6, 24], [-44, -18], [42, -33], [34, -32], [-44, -3], [36, 6], [-20, -2], [0, -16], [-20, 48], [36, -8], [16, -10], [26, 2], [0, 40], [8, -20], [-50, 4], [-14, -31], [34, 6], [24, 28], [0, 8], [-36, -7], [-50, 20], [-10, 3], [-40, -11], [34, 18], [84, -12], [44, 10]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2200_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2200_2_a_m();".
// 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_2200_2_a_m(:prec:=2)
    chi := MakeCharacter_2200_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_2200_2_a_m();".
// 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_2200_2_a_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2200_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-4, 1, 1]>,<7,R![-2, 3, 1]>,<13,R![-16, 2, 1]>],Snew);
    return Vf;
end function;