
// Make newform 4425.2.a.ba in Magma, downloaded from the LMFDB on 14 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4425_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_4425_2_a_ba();".
// 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_4425_2_a_ba();".
// 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, -4, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-1, -4, 0, 1], [-1, 3, 1, -1]];
    Rf_basisdens := [1, 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_4425_a();"
function MakeCharacter_4425_a()
    N := 4425;
    order := 1;
    char_gens := [2951, 2302, 3601];
    v := [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_4425_a_Hecke(Kf)
    return MakeCharacter_4425_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, 1, 0], [-1, 0, 0, 0], [0, 0, 0, 0], [0, 2, 0, 1], [-2, 2, 2, 1], [1, 0, 1, -1], [1, -3, -3, -2], [-1, -2, 0, -2], [-1, -4, -2, 0], [-1, 0, -2, -2], [-5, -3, 0, 2], [4, 1, 4, 3], [2, 0, -1, 0], [0, -4, -5, -3], [1, 2, 4, -1], [9, 0, -2, -1], [-1, 0, 0, 0], [-3, -3, -7, -1], [-11, 0, -2, -1], [-2, 4, -5, -2], [-4, -1, 5, 7], [3, 1, 8, 3], [3, -7, -2, 1], [-4, 1, 6, 3], [-1, -1, 0, -6], [-5, 1, 0, 5], [7, 2, 6, -1], [1, 3, -1, 5], [-1, -5, -7, -4], [0, -5, 2, 2], [-6, -2, -6, 3], [-1, 1, 8, 7], [-4, 1, -6, 3], [-4, -7, -2, -2], [9, 3, -1, -2], [-2, 1, -9, -3], [4, -7, 1, -2], [-3, 6, -1, 3], [1, 5, 6, -3], [10, 1, -2, 1], [-3, -4, -7, -6], [0, -6, -8, 3], [-6, 0, -2, 2], [7, 5, -4, -3], [12, 7, 7, 3], [-14, -4, 3, 1], [-7, -7, 6, -1], [0, 13, 7, -1], [-15, 4, 3, 4], [-10, 3, 1, -1], [-1, -3, -6, 2], [-15, 4, -1, -1], [-1, -7, -3, -7], [4, 9, 2, 5], [0, -6, 0, -12], [10, -6, -6, 1], [9, 3, 7, 8], [-2, -3, -1, -3], [-10, 7, -3, -1], [-7, 12, 13, 16], [-5, -1, -11, 1], [-1, 4, 5, -5], [13, 8, -4, -3], [-11, -1, 5, -8], [-2, 9, 8, -5], [-4, 3, 8, -9], [-3, 9, 9, -2], [1, -8, -4, -7], [14, 7, 9, 0], [2, 14, -1, 3], [3, 5, 6, -10], [-4, -9, -13, -12], [-13, 15, 10, 12], [-20, -7, -3, -4], [-5, 9, 11, 6], [18, 9, 2, -2], [-5, -2, 1, 16], [-2, -1, 7, 10], [-22, -1, 0, -2], [-6, 3, 7, 15], [-7, -8, 0, 3], [16, 3, 4, 4], [-4, -10, -3, -2], [-1, 5, -1, -5], [-7, 1, -7, -10], [-5, -10, 0, 3], [-6, -6, 0, -9], [-2, 5, 6, 11], [22, 9, 15, 4], [-23, 2, 4, 7], [-5, -11, -16, 0], [-25, -11, -6, 3], [-5, 21, 19, 20], [0, 6, -11, 2], [3, 5, 11, -2], [-9, -16, -17, -11], [-26, -7, 2, 10], [8, -14, -1, -5], [-6, 22, 8, -2], [-15, -4, 10, 14], [-4, 13, -5, 4], [15, 4, -6, 13], [-3, -9, -8, -16], [2, -9, -11, -17], [-10, -11, -17, -9], [-23, -4, -2, -8], [-9, -5, 0, -14], [-8, 15, 6, 7], [0, 10, 9, -2], [-18, 4, 0, -7], [-1, 4, 8, 0], [-5, 8, 6, 2], [22, -10, 1, 2], [-6, -16, -12, -3], [-9, -5, -7, 0], [34, 3, 0, 4], [2, -2, -1, 6], [9, 23, 13, -5], [-11, -11, 7, 13], [-11, -3, 15, 1], [-6, -13, -13, 4], [-15, 2, -1, -10], [-11, 12, 15, 7], [-6, 12, -11, 8], [6, 3, -2, -3], [-2, 7, 1, 10], [24, 8, 7, -7], [-8, 21, 2, 11], [2, -12, -2, -3], [-11, -14, -9, -17], [1, 6, -6, 2], [-9, -5, -13, 5], [12, -1, 22, 2], [-5, -1, -3, 2], [10, 0, -9, -17], [-8, -19, 3, -2], [-2, -12, -2, 12], [-10, -6, -9, -8], [-3, 6, 2, 4], [23, 6, 9, -4], [-10, -14, 5, -1], [16, 19, 10, 4], [12, 4, 10, 8], [11, 16, 21, 3], [17, 20, 18, 8], [4, 24, 19, 15], [6, -5, -20, -1], [6, 8, 7, 13], [3, -10, 1, -19], [2, -2, -6, -9], [-16, -8, -19, -3], [5, 29, 30, 1], [-2, -1, -6, -22], [26, 0, 14, 6], [5, 3, 0, 10], [-2, -17, -22, -15], [2, -1, -14, -17], [-15, -3, -16, -2], [21, -2, -1, 4], [-4, -12, 10, -8], [-23, 4, 17, 15], [-10, -8, 3, 3], [-29, 13, 4, 0], [-1, -2, -9, -6], [13, -30, -8, -6], [3, -19, -19, -3], [-1, 10, 8, 14], [15, 16, 21, 12], [19, 1, 2, 1], [-22, -5, -5, -1], [-8, 14, 16, 2], [22, 7, -4, 1], [9, 17, -6, 11], [-18, -23, -16, 13], [-5, -19, 6, -2], [10, 10, 25, 7], [6, -3, 4, -15], [18, 17, 7, 7], [-17, -2, -2, 9], [25, -1, -11, -6], [-12, 6, 2, 15], [-31, 20, 8, 8], [-10, -3, 2, -7], [5, 19, 23, -17], [14, 4, 32, 16], [-9, -1, -7, 3], [0, 20, 4, 18], [19, -2, -13, -7], [-5, -21, -11, 13], [-12, -9, 0, -21], [13, 19, 10, 0], [5, -5, -7, 13], [-4, -22, -16, 0], [15, 4, -2, -3], [-17, -25, -19, -5], [-6, 17, 1, 19], [-15, 10, -8, 7], [-5, -5, -21, 4], [27, -6, -4, 13], [-4, 8, -15, -5], [-21, 10, 14, -4], [7, 11, -23, -9], [-10, 27, -1, 11], [4, 10, 2, -14], [1, -2, 6, -7], [16, -24, -10, -7], [-8, -5, -5, 20], [12, 6, 32, -2], [-25, -9, -20, -8], [32, 9, -9, 18], [2, -2, 24, -1], [-2, -6, -11, -12], [-9, -9, -6, 5], [5, -16, -6, 1], [29, -25, -16, -19], [-1, -3, -2, 23], [-4, -11, 9, 8], [-34, -14, 9, 9], [39, -11, -12, -8], [10, -5, -17, -32], [3, 10, 27, 26], [-23, 29, 16, -3], [11, 4, 2, -23], [5, 9, 6, -8], [-15, -21, -9, 6], [-17, 6, -3, -7], [-32, -4, -9, -9], [-19, 3, -9, -4], [-2, 26, 21, -1], [-20, 25, 14, -3], [13, -10, 7, 16], [9, -7, 15, 0], [-14, -34, -19, 5], [15, 19, 27, 4], [-19, -22, 11, 13], [-15, 23, 2, 3], [-36, 21, 6, 13], [-8, 23, -17, 2], [18, 22, 21, -14], [-8, 20, 25, 14], [-4, -17, 17, 4], [-14, -18, -17, 22], [-12, -8, -10, -8], [-21, 6, -17, 3], [2, 7, -16, 7], [-22, -10, -16, 2], [-33, 6, -15, -1], [-15, -15, 12, -6], [22, -17, -3, 0], [17, 25, 14, -20], [11, -24, 4, 0], [32, 1, -9, -3], [-8, -1, -19, 4], [-37, 11, 14, 18], [8, -5, 18, -6], [21, 10, 14, 2], [-8, -3, -12, 8], [-39, 8, 11, -4], [-14, 4, -7, 21], [14, -17, -11, -20], [9, -37, -38, -33], [-29, 0, -7, -4], [2, -11, 4, 9], [0, 4, -19, -20], [-16, 26, -2, 12], [-45, -4, 5, -14], [22, 22, 6, -10], [-28, -11, -42, -6], [28, -13, 2, -15], [32, 22, -6, -24], [-6, 38, 1, 11], [17, 14, 35, 1], [-16, -8, -7, 27], [16, 35, 14, -10], [12, -38, -30, -9], [-3, 7, 1, 26], [31, -15, 22, 3], [-11, -8, 2, 16], [-20, -36, -44, 4], [-15, -29, -19, -10], [25, -6, -6, -20], [31, 34, 12, -21], [11, -7, -4, 17], [15, 25, 6, -25], [-3, 17, -22, 8], [28, 25, 2, 3], [12, -11, -10, 4], [-18, -3, -2, 23], [2, 4, 4, -3], [-9, -21, 11, -11], [1, -39, -12, -14], [-10, -6, -1, 0], [0, 14, 4, 28], [5, 18, -14, -14], [-10, 30, 29, 32], [20, -40, 0, -14], [5, -22, -9, -13], [15, -20, 19, -9], [-18, 9, 5, -20], [-10, 4, -9, 5], [12, 9, 15, -25], [11, 30, -5, -17], [-18, -8, -33, -28], [24, -12, -4, -14], [13, 7, 14, 4], [-19, -23, -5, -8], [-31, -26, -30, -3], [-3, -5, -4, 0], [31, -9, 18, 7], [1, 16, 13, -3], [-28, -24, -3, -4], [-4, 17, 18, 34], [6, 2, -15, 8], [0, -9, 19, 16], [18, -5, 18, 13], [20, -11, -10, -19], [-6, 0, -10, -5], [-23, 2, -12, 6], [-10, -26, -40, -36], [37, -3, 31, 3], [-5, 26, 11, 2], [-8, 29, 7, 28], [-33, 16, -16, -7], [3, -16, 4, -6], [9, -15, -9, -9], [-31, -16, -7, -9], [-2, 11, -20, -18], [55, -31, -14, -14], [23, 1, 18, 0], [-12, 18, -31, -5], [1, 30, 35, 3], [2, -35, -20, 17], [-73, 2, -6, 5], [-8, 29, -30, 0], [11, -34, -22, -24], [-17, 22, -25, 6], [-27, -26, -40, -15], [53, 9, 21, 8], [-34, -15, -23, 11], [-20, -9, 19, -16], [28, 28, 3, 16], [7, 16, 11, 3], [33, -9, -2, 14], [-26, 35, 6, 7], [-11, 24, 25, 12], [30, -7, -5, 1], [32, -7, 7, -5], [-25, -6, -1, -22], [-34, -27, 14, 6], [20, 24, 47, 12], [2, 12, 22, -7], [-31, -5, -6, -28], [7, 7, -8, -11], [42, 3, -10, -12], [-24, -3, -22, -22], [-23, -35, -11, 4], [25, -17, -17, -29], [-18, -17, -19, -37], [-19, -27, -23, -32], [24, 31, 0, 13], [0, 20, 19, 15], [-8, 13, 24, -7], [-7, -44, -33, -3], [28, -33, -26, -12], [-2, -10, -7, 9], [20, 26, 30, 9], [6, -10, -16, -3], [1, -33, 8, -17], [0, -44, -27, -16], [-32, 9, -5, 15], [26, 2, 39, 20], [17, -30, -29, 13], [4, 7, 3, -28], [-23, -23, -42, -18], [-11, 33, 30, 15], [10, 6, -16, -4], [-51, 7, -20, -9], [2, 15, 3, 16], [24, -34, -27, -16], [-3, 3, 34, 31], [49, -19, -11, -13], [-13, 15, -2, -5], [1, -4, -21, 32], [-45, -27, -50, -16], [-18, 28, -27, 5], [-46, -7, -30, 1], [-8, 8, 2, 26], [-56, -13, -37, -15], [13, 16, 40, 0], [0, -40, -17, -35], [-26, 34, 18, 24], [-24, 23, 8, 12], [10, 23, 36, 15], [44, 1, 25, 7], [-10, -9, 29, -6], [20, -15, -29, -21], [-49, -13, 3, 29], [-19, -31, 0, 4], [3, -23, 17, -9], [-2, 6, 12, -2], [-6, 3, 36, -8], [26, -9, 16, -14], [-26, -30, -31, -5], [21, 2, -19, -42], [-7, 11, -17, -15], [-45, -5, 12, 29], [-10, -26, 27, -1], [29, -27, -26, 1], [37, -29, -15, -23], [-12, 17, -6, 20], [-37, 17, 8, 1], [-1, -14, -8, 17], [-11, -40, -22, -17], [-23, -7, 13, -6], [-8, -56, -40, 11], [36, 13, -13, 14], [-4, 21, 41, 9], [-25, -5, -12, -31], [58, -6, 15, -2], [-38, -4, -3, -12], [-30, -2, 10, -24], [21, -15, -19, 6], [-4, 1, 11, -32], [12, -32, -16, -10], [17, -34, -6, -21], [25, -49, -13, -20], [41, 3, 12, 17], [-19, -44, -43, -23], [14, 1, 16, 30], [-33, 30, 12, 18]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4425_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4425_2_a_ba();".
// 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_4425_2_a_ba(:prec:=4)
    chi := MakeCharacter_4425_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_4425_2_a_ba();".
// 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_4425_2_a_ba( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4425_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![3, -2, -4, 1, 1]>,<7,R![23, -1, -19, -1, 1]>,<11,R![-63, -29, 15, 9, 1]>],Snew);
    return Vf;
end function;