
// Make newform 4400.2.a.bq in Magma, downloaded from the LMFDB on 12 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4400_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_4400_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_4400_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, -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_4400_a();"
function MakeCharacter_4400_a()
    N := 4400;
    order := 1;
    char_gens := [2751, 3301, 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_4400_a_Hecke(Kf)
    return MakeCharacter_4400_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], [-1, 1], [1, 0], [-1, 2], [0, 3], [-1, 4], [5, -7], [-6, 1], [1, 2], [5, -2], [-5, 8], [2, 4], [-5, 6], [1, -3], [7, -2], [-1, 5], [0, 0], [10, -6], [1, -5], [2, -3], [6, -3], [2, -9], [13, -5], [7, -9], [12, 3], [-1, 8], [-12, 11], [-3, 2], [-2, 1], [7, 5], [8, -1], [7, 0], [-12, 0], [-9, 14], [-2, 12], [17, -1], [9, 0], [11, -16], [5, 5], [5, 5], [12, -1], [0, 8], [-7, -9], [-6, -9], [3, -6], [11, -10], [10, -11], [0, -17], [23, -3], [-13, -5], [4, -13], [12, -3], [14, -8], [-3, 18], [-6, -11], [1, -12], [-3, -8], [1, -20], [-18, 3], [-6, 16], [0, 3], [15, -16], [18, 6], [-20, 15], [-9, -12], [22, -4], [7, -15], [33, -4], [17, 12], [6, 0], [-1, 11], [-5, 6], [-19, 28], [-10, -12], [-24, 4], [-22, -3], [-6, 20], [23, -18], [-25, 16], [5, -5], [1, 0], [19, -32], [-12, -7], [-24, 6], [-19, 31], [19, -9], [11, -18], [-9, -6], [11, 14], [23, -22], [1, -10], [-15, 24], [21, -27], [-34, -2], [1, -23], [-16, -14], [-6, 4], [1, 17], [37, -9], [-5, -6], [-5, -1], [41, -5], [-1, -25], [14, 11], [-22, 15], [19, -16], [-18, -5], [5, -19], [22, -8], [-16, -5], [-16, -2], [31, -6], [5, 17], [-27, 16], [22, -8], [1, 8], [-8, -7], [-14, -11], [9, -22], [9, 4], [-36, 2], [-39, 2], [-19, 11], [12, -4], [-16, 20], [29, 8], [14, 17], [-39, -4], [-15, -13], [-33, 13], [-16, 31], [13, 24], [-12, -16], [17, 8], [-41, 5], [-21, 4], [-22, 11], [8, -12], [-49, 10], [-24, 20], [28, -4], [12, -22], [-32, -1], [35, -7], [-28, -1], [3, -14], [18, -38], [-3, 8], [-36, 4], [-25, 7], [13, -20], [-25, -2], [24, -24], [10, 28], [20, 20], [-7, -10], [48, -8], [-41, 12], [21, -6], [-26, 4], [26, -31], [1, -3], [25, -22], [28, -36], [-34, -9], [-26, 21], [41, 2], [8, -18], [51, -7], [-1, 23], [-18, 41], [-17, 45], [15, -8], [-30, -12], [-40, 8], [19, -16], [42, -18], [0, 28], [-28, -10], [37, -35], [-23, 38], [-46, 24], [-3, -30], [-43, 0], [30, 2], [-29, 31], [9, -36], [32, -4], [-24, 25], [-16, -32], [49, -26], [2, -1], [-29, -7], [35, -18], [44, -38], [-25, -22], [-7, 33], [38, 5], [17, 21], [-43, -1], [36, -37], [-2, 27], [10, -28], [-25, 3], [60, -12], [-39, 38], [-22, 12], [13, -7], [27, -38], [-1, -38], [23, 17], [-4, 6], [33, -4], [10, -10], [-4, -12], [-28, 1], [-13, -21], [-7, -9], [14, -49], [-43, 26], [20, 28], [-2, 41], [23, -8], [45, -42], [-23, 7], [-20, 30], [32, 0], [48, -37], [-7, -9], [37, -26], [-3, -34], [-31, -6], [10, 7], [7, -14], [-54, 6], [-17, 57], [28, -43], [5, -5], [65, 4], [-10, 30], [-46, 38], [-33, 44], [18, 18], [-53, 27], [33, 3], [19, 3], [34, -59], [-4, -18], [-24, 62], [-9, 4], [38, 2], [19, 28], [-19, 37], [-34, -10], [29, -50], [43, -38], [43, -53], [42, -12], [40, -16], [-26, 22], [47, 8], [38, -23], [-17, -10], [-42, -14], [-15, 16], [45, -5], [13, -28], [19, -46], [-32, -22], [21, 24], [60, -10], [7, 40], [24, 3], [15, 6], [4, -8], [34, 15], [-5, -9], [9, -30], [-56, 3], [8, 32], [49, -9], [-19, 54], [45, 9], [-28, 44], [-8, 41], [37, -61], [-53, 11], [44, -53], [-3, 52], [29, -42], [-24, 40], [28, -33], [-5, 38], [-15, 15], [33, -30], [19, 26], [-30, 16], [23, -50], [83, -4], [-30, -36], [17, -39], [5, 6], [-50, -7], [3, 42], [28, -54], [-5, 33], [-28, -35], [1, -2], [-44, 23], [38, 11], [19, -3], [39, -42], [-35, -16], [-26, 30], [-22, 36], [-50, 10], [44, -38], [11, 27], [13, -5], [-9, -33], [15, -36], [7, -12], [28, -67], [2, 4], [-36, 37], [-37, -31], [-12, 34], [50, -28], [6, 30], [35, 32], [14, -23], [3, -28], [-50, 22], [-14, 60], [12, -38], [-42, -10], [-25, 57], [-9, 51], [58, 6], [-49, 16], [1, -24], [-17, -29], [43, -24], [-20, 5], [-42, -17], [45, 0], [-20, 5], [-15, 44], [-33, 31], [-3, 27], [77, -18], [-38, -29], [0, 20], [-25, 54], [34, -8], [-3, 37], [-49, 20], [44, 20], [27, 25], [47, 4], [9, -48], [-14, 29], [11, 5], [3, 30], [40, -38], [57, -32], [44, 0], [4, -7], [60, -40], [-3, -13], [-12, 9], [44, 17], [57, -60], [-43, 41], [-25, 9], [26, -4], [-33, 25], [-5, -21], [24, -42], [-3, -18], [-34, 2], [0, -29], [47, 18], [32, 23], [-9, -39], [-16, -8], [-43, 74], [-58, 20], [-25, -11], [48, -28], [-23, -10], [-40, 10], [63, -20], [-17, 0], [62, -19], [10, -14], [19, -10], [25, -13], [4, -44], [-3, 1], [-7, -17], [9, -44], [-37, 0], [25, 18], [-18, 18], [15, 26], [56, 16], [28, -30], [20, -33], [31, -26], [21, 24], [85, -11], [18, 8], [-67, 58], [19, -6], [56, 19], [49, -50], [54, -49], [-23, -10], [73, -28], [-33, 28], [19, 10], [-6, 62], [16, -16], [46, 16], [0, 15], [86, -16], [6, -27]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4400_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4400_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_4400_2_a_bq(:prec:=2)
    chi := MakeCharacter_4400_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_4400_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_4400_2_a_bq( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4400_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-1, -1, 1]>,<7,R![-1, 1, 1]>,<13,R![-5, 0, 1]>],Snew);
    return Vf;
end function;