
// Make newform 4400.2.a.bi in Magma, downloaded from the LMFDB on 16 April 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_bi();".
// 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_bi();".
// 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 := [-5, -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], [-3, 1], [1, 0], [1, 0], [2, -1], [-1, -2], [-1, -1], [4, 1], [3, 2], [-3, 2], [-7, 2], [-10, 0], [-7, 2], [-3, -3], [5, 2], [7, -1], [-4, 0], [-6, 6], [5, 1], [-4, 7], [4, -5], [2, -1], [9, -1], [-9, -3], [-8, 5], [3, 6], [-2, -1], [-7, 2], [8, 3], [9, -3], [-8, 7], [7, -6], [-8, 4], [-5, 0], [-6, -4], [-13, -3], [-11, -2], [-3, 6], [3, -9], [5, -3], [-20, 1], [-4, 4], [-7, -7], [10, -3], [-5, 0], [-15, -2], [-8, 7], [-16, 3], [-13, -1], [5, -1], [2, -9], [-8, 7], [-18, 0], [13, 4], [10, -11], [1, -6], [3, 2], [3, -6], [0, -11], [14, -4], [-30, 1], [17, -4], [10, -6], [0, 3], [5, -8], [22, 0], [21, -3], [-9, -2], [-7, -4], [6, 0], [17, -3], [-3, 8], [31, 0], [-18, 0], [-12, 0], [-10, 1], [-26, 4], [17, 0], [-27, 0], [17, 3], [17, -10], [-9, 8], [2, -5], [28, -2], [29, -1], [-5, -3], [9, -12], [-19, 6], [5, 2], [11, -4], [-13, -6], [13, -2], [-1, -5], [22, -2], [-15, 9], [-4, 2], [-14, -4], [-19, 3], [-1, 3], [1, 16], [-15, -9], [5, 5], [9, -13], [2, -5], [2, 5], [17, 2], [-14, -11], [9, 7], [-34, 0], [14, -17], [12, 6], [-23, 6], [7, -9], [-35, 4], [-10, -12], [-1, 8], [4, -11], [-20, 7], [25, 2], [11, 10], [-4, 2], [7, 10], [7, 9], [32, -4], [-4, 12], [27, -12], [2, -9], [19, -18], [-17, -9], [37, 1], [-16, 1], [-15, 8], [8, 8], [-25, -6], [-29, 1], [-1, -6], [2, -13], [-12, -12], [11, 16], [4, 16], [8, 0], [-16, 2], [-24, -5], [-7, 11], [22, -9], [-3, 12], [30, -10], [-5, -8], [-28, 16], [27, -9], [15, 4], [-17, -8], [-12, 16], [-10, 8], [-40, 4], [-3, 6], [-24, -4], [-11, -14], [23, -10], [42, 0], [24, 7], [-5, -5], [9, 6], [-4, -16], [-14, -15], [-32, -3], [-37, 0], [24, -18], [-35, 1], [15, 7], [36, 3], [7, -9], [-11, -12], [6, 12], [-4, 4], [43, 4], [26, -6], [12, -8], [-28, 6], [7, -11], [-35, 6], [18, 0], [47, 2], [1, 4], [-38, 6], [41, 9], [-25, 18], [-52, -4], [36, 5], [-36, 0], [-25, 10], [10, -5], [41, -7], [3, 6], [-16, -6], [-1, 22], [13, -5], [-8, 7], [-19, -13], [-9, 11], [-12, -1], [4, -13], [38, 8], [-37, -1], [20, -8], [1, 16], [2, 8], [19, 3], [13, -12], [-9, 6], [-31, 3], [20, -10], [-35, -2], [-22, 6], [12, -20], [30, -15], [33, 9], [49, -5], [-48, -5], [-11, 0], [4, -8], [2, 3], [15, -6], [-13, 12], [9, -21], [-12, 6], [8, -12], [-10, 29], [-11, -9], [-35, 12], [-3, 8], [3, 12], [10, 5], [3, -12], [30, -2], [47, -1], [-28, -1], [-41, 1], [-41, 16], [10, 6], [10, 2], [23, 0], [6, 18], [-3, -9], [-25, -3], [-7, 5], [-32, 3], [32, 2], [-44, 6], [1, -2], [-38, 10], [-37, 0], [21, 3], [34, 10], [-19, -18], [-61, 0], [-49, -1], [10, -12], [8, -12], [-18, 6], [25, 14], [-4, 25], [-13, 14], [-14, 6], [-15, -24], [-63, 3], [-7, 18], [45, 12], [32, 18], [51, -8], [-8, -18], [-5, 18], [14, -17], [-15, -14], [-12, 0], [-4, 3], [-29, 17], [-35, 16], [2, -19], [52, 0], [19, 19], [23, 12], [-13, 21], [20, -28], [16, -15], [33, 9], [-19, -11], [-10, 23], [-47, -8], [-17, 22], [-48, 12], [-6, 9], [-35, 0], [41, -19], [15, 2], [63, -6], [34, 4], [31, -4], [-39, 2], [6, 12], [-33, -7], [-1, -10], [-38, 15], [-13, 10], [8, -10], [-5, -19], [4, 7], [-57, -4], [-34, -7], [2, 11], [7, 7], [17, -18], [53, -10], [-14, -10], [22, 4], [-18, 6], [48, -22], [27, -15], [47, -5], [-17, -21], [57, 6], [-47, 20], [-14, 25], [58, -16], [-44, 15], [-39, -5], [28, -26], [22, -8], [2, -6], [55, -8], [4, 3], [11, 2], [-50, 6], [-54, 0], [-24, 34], [46, 10], [-29, 5], [41, -21], [-74, -6], [-29, -20], [-25, 26], [-3, 17], [-61, 8], [82, -5], [-26, 11], [-5, -28], [10, -29], [-71, -8], [-11, 3], [-15, 23], [21, -18], [32, 21], [8, 0], [-3, 12], [-14, 4], [-65, 13], [57, -18], [36, 0], [-1, -17], [-47, 22], [-13, 8], [-76, 11], [-15, 7], [-5, 6], [-24, 30], [29, 6], [-28, 24], [52, 7], [68, -8], [-33, 15], [-42, -15], [46, -9], [-3, -16], [15, -9], [-27, 21], [10, 24], [-1, 11], [-73, 1], [-12, 30], [97, -2], [-2, 14], [6, -21], [-33, -4], [48, 9], [-11, -9], [40, 12], [5, -12], [-50, -8], [43, -7], [8, 32], [31, -14], [-16, 30], [-15, -24], [-11, 18], [64, -9], [-6, 18], [-7, -2], [29, -7], [-4, 24], [-23, -11], [-25, 3], [65, -4], [81, -6], [49, -12], [26, -14], [25, 16], [-28, 0], [-56, -14], [-2, 3], [13, -32], [-5, -20], [55, -3], [22, 0], [1, -2], [39, 0], [-92, 5], [-27, 18], [72, -3], [45, 6], [-13, -26], [-3, -24], [-41, 16], [-14, 18], [36, 12], [14, 20], [14, -25], [38, -32], [0, 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_bi();".
// 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_bi(: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_bi();".
// 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_bi( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4400_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-5, 1, 1]>,<7,R![1, 5, 1]>,<13,R![-1, 1]>],Snew);
    return Vf;
end function;