
// Make newform 5625.2.a.j in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5625_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_5625_2_a_j();".
// 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_5625_2_a_j();".
// 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, 4, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-2, 0, 1, 0], [0, -3, 0, 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_5625_a();"
function MakeCharacter_5625_a()
    N := 5625;
    order := 1;
    char_gens := [4376, 1252];
    v := [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_5625_a_Hecke(Kf)
    return MakeCharacter_5625_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, 1, 1], [0, 0, 0, 0], [0, 0, 0, 0], [2, 0, 1, 2], [1, 1, 1, 0], [0, 2, 1, -2], [0, 1, 2, -2], [-4, 2, 1, -2], [-3, 2, 0, 0], [6, 1, 1, -1], [-1, -3, 1, 2], [-4, -3, 1, -4], [-1, 3, -3, -2], [-3, 3, -2, -6], [5, 4, -3, -1], [-1, 0, -6, -5], [-4, -1, 3, -5], [-12, 1, -2, -3], [2, 2, -4, -1], [10, -6, -1, 3], [8, -1, 0, 8], [-1, 4, 4, -3], [4, -8, -1, 5], [4, 0, 1, 4], [8, -8, -3, 4], [9, -5, 4, 7], [2, 1, -7, -7], [10, -2, 5, 5], [-7, -1, 2, 6], [9, 1, 1, -2], [2, 2, 4, 3], [2, -2, -1, 1], [-8, -5, 3, 1], [-2, 4, -1, -7], [14, 0, -2, 6], [6, -7, -1, 4], [-2, 6, 2, -8], [3, -6, -3, -3], [3, 0, 6, 4], [-12, 3, -4, -3], [-11, 2, 4, -4], [2, -10, -2, 8], [-7, 5, 3, -3], [2, 3, 0, 9], [10, -4, 3, 4], [-2, -4, 7, 1], [0, 0, -7, -11], [7, -5, -4, -4], [0, -9, -2, -8], [-9, 0, -2, -6], [-6, -9, 10, 4], [-1, 4, -13, -11], [2, 0, -1, 9], [2, 5, 3, -13], [7, -2, -6, -4], [8, -4, 0, 1], [-6, 0, 16, 9], [14, -3, -1, 4], [9, -5, 10, 11], [8, -5, 0, 9], [19, -5, 1, 0], [11, 0, 8, 8], [4, -4, 0, -10], [-19, 9, -3, -8], [10, -8, 0, 4], [-12, 9, 0, -6], [0, 8, -4, 3], [-8, -1, -7, 8], [7, 1, 0, -14], [2, -5, -10, 3], [22, -6, -5, 7], [7, -3, -10, -3], [18, -13, 1, 8], [4, 11, 3, 2], [-3, 3, 5, -7], [15, -3, 7, 4], [2, 7, -17, -4], [-17, 13, -8, -20], [11, -19, 4, 13], [-1, 14, 4, -5], [9, -2, -11, 7], [-5, -1, -3, -20], [7, -5, 23, 18], [-14, 4, -5, -8], [-1, -5, -11, -20], [2, -7, -1, 6], [-15, -2, 11, 1], [7, -4, -4, 5], [-4, -4, -13, -10], [-3, -5, 12, 7], [-2, 16, 3, -11], [-10, -2, 2, 10], [11, -4, 5, 16], [-9, -1, -7, -26], [21, -9, -3, 3], [-5, -4, -5, -6], [-2, 2, -5, -16], [-3, 11, -4, -10], [-13, 16, 8, -7], [-13, 2, -1, -3], [-5, -14, 16, 6], [21, -12, -4, 18], [6, -3, -22, -14], [6, 0, -14, -7], [-13, -1, -8, -5], [-9, -8, 17, 5], [20, -1, 5, 8], [16, 3, 14, 6], [-4, 5, -25, -24], [-11, 22, 11, -10], [16, 4, 7, 21], [-21, -2, -8, -6], [14, 7, -6, 14], [-9, 5, -13, -9], [-1, 10, -4, -3], [13, 7, 3, 21], [-4, 4, 0, 11], [-7, 9, -1, 14], [-6, 2, -5, -19], [-9, 7, 10, -2], [-2, 7, 0, -12], [14, -17, -9, -10], [2, 6, 4, 21], [-23, 14, 2, -26], [1, -24, -7, 2], [-22, 15, 5, -28], [-19, -5, 6, -28], [-13, 5, -14, -14], [4, 8, -13, 0], [-10, 2, 4, -20], [-6, -5, 0, 16], [-26, 9, -12, -28], [-22, -8, 9, 7], [5, 1, 4, -3], [11, -26, -2, 16], [8, -4, -20, 5], [29, 4, 12, 3], [16, -7, 3, -1], [-14, 9, -1, 2], [33, -5, 14, 18], [10, -2, -19, -17], [-1, -2, -9, -27], [5, -12, -6, 12], [15, -15, -12, 3], [9, 12, -7, -2], [-4, 0, 14, 14], [-13, 8, 3, -25], [16, -15, 8, 27], [8, -5, -15, 1], [-33, 11, -15, -30], [14, 4, -6, 7], [9, 10, 7, 17], [-4, 10, 3, 8], [-16, 9, 9, 13], [-10, 3, 4, 20], [3, -26, 7, 13], [-7, -8, 11, 5], [-18, 0, -4, -30], [0, -12, 14, 19], [27, 6, -1, 19], [-12, 15, 1, -13], [-14, 8, -20, -28], [-16, 28, 16, 6], [-15, -8, 19, -2], [3, -18, -11, 13], [-34, 7, -1, -30], [-5, -7, 12, -4], [25, -11, -3, 15], [-7, 3, 3, 24], [20, -12, -4, -4], [-15, 9, -11, -13], [21, -7, -5, 25], [18, 3, -19, -9], [-17, 0, -4, -23], [-2, -8, -3, 7], [14, -7, 7, -4], [34, -11, -4, 18], [18, -10, 2, -11], [-1, 11, 5, 13], [3, 11, 2, 15], [-6, -2, -9, -5], [7, -28, -1, -1], [-1, -6, 6, 14], [-6, -12, 2, 19], [15, -1, 9, -3], [0, 9, 3, -19], [5, -5, -3, 7], [7, -10, -4, -4], [-3, 6, 17, 22], [-42, 9, -3, -3], [6, 9, -4, 14], [24, -9, -9, 28], [22, 13, -22, 6], [1, -1, 10, 21], [15, 6, 8, 36], [-41, -8, 7, -21], [2, -6, -13, -15], [7, -1, -11, -21], [4, -3, -10, 30], [23, -22, -11, 19], [33, 6, -14, 11], [-14, 16, -2, 3], [-35, 10, -4, -4], [-8, 0, -18, 12], [-1, 2, -1, 30], [9, 17, -9, -8], [3, -18, -15, -6], [6, 4, 8, 15], [3, 8, 10, -36], [16, -6, 29, 38], [-30, 27, 8, -23], [6, -19, -9, 7], [9, 13, 32, -17], [-42, 22, -10, -39], [13, -30, -22, 2], [9, 3, 17, 2], [4, -8, 4, -2], [6, 20, 4, 5], [5, -5, -24, 5], [-29, 4, 6, -35], [-6, -3, 15, 6], [26, -4, 9, 11], [-26, 12, 2, 5], [2, 3, 0, -6], [26, 4, -3, 11], [-39, 3, -4, -26], [13, 3, -13, -7], [21, 9, 6, 15], [30, -4, 0, -3], [-17, 6, -5, -3], [-33, 21, 4, -31], [-12, 20, 11, 1], [18, -21, 3, 10], [-10, 11, -17, -17], [24, 3, 25, 18], [20, -10, 1, 12], [-9, 9, 13, 2], [-4, 7, 19, 17], [13, -3, 17, 41], [-3, -15, -9, -12], [14, -1, -5, -21], [30, 13, -17, 0], [5, -2, 17, 18], [-1, -17, 2, -21], [1, 20, -5, -1], [6, -11, 12, 27], [-6, -6, -30, -22], [17, 2, 24, 32], [18, 6, 21, 0], [-28, 8, 6, -22], [10, -2, -1, 51], [11, 14, 5, 18], [8, 10, 9, -12], [14, -12, 37, 26], [-30, -16, 9, -14], [-22, -1, 8, 28], [-4, -24, -12, 20], [29, 7, 6, 38], [-2, 7, 13, 3], [15, -33, -10, 4], [52, 4, -2, 17], [1, 1, -18, -39], [9, -15, 6, 30], [31, -29, -3, 12], [16, -14, -32, -32], [12, 7, 12, 42], [8, -13, -30, -15], [-26, 2, -5, 5], [-43, -6, 0, -4], [-39, 11, 8, 8], [-29, 22, 10, -30], [-30, 1, -22, -4], [24, -9, -6, -14], [11, -21, 14, 10], [12, -17, -6, 24], [41, 2, -14, 4], [34, -9, -10, 8], [1, -10, -3, -17], [-16, 13, 25, 10], [-3, -3, 1, 28], [9, -9, 16, -1], [-3, 25, -14, -16], [16, 3, 25, 31], [3, 12, 24, 32], [-3, 6, -1, -17], [-11, -17, -8, 8], [-19, 16, -6, -25], [-10, 20, 24, -10], [71, -25, 18, 50], [-3, -22, -26, 20], [-20, -2, 29, -7], [6, 1, 24, 38], [-30, 25, 9, 14], [-30, -5, -12, -43], [30, -15, -21, -15], [18, 19, -2, -8], [12, -10, 14, 42], [-34, 4, -2, -26], [-19, 12, -30, -32], [23, 23, -35, -8], [-29, 7, -15, -61], [-23, -9, 6, -17], [17, -10, -20, -32], [-2, 5, 0, 25], [25, 7, 2, 16], [-32, 31, 3, -36], [-11, -17, -8, -1], [17, -5, -8, 22], [47, -19, 25, 40], [-7, 19, -21, -28], [30, -4, 15, 6], [21, 2, 26, 19], [46, -19, 19, 42], [12, -29, -6, 12], [6, -30, 8, 7], [-25, -19, -15, 20], [9, -12, -5, 33], [17, 5, -1, 35], [59, -22, 13, 31], [7, -18, -22, -15], [5, 2, 19, -17], [8, -15, 11, -11], [1, 25, -8, 10], [24, 4, -14, 45], [11, -2, -5, -16], [9, 4, 9, 15], [18, 4, 2, 34], [0, 24, 0, -5], [42, 5, 17, 13], [41, -13, 18, 56], [-36, 2, 26, 28], [-16, -17, 17, -8], [7, -2, -6, -5], [-10, 22, -25, -18], [7, 1, 2, -23], [44, 5, 19, -12], [-50, 7, -14, -30], [-26, 14, -13, 5], [-2, 13, 18, 13], [21, -18, -33, -45], [18, -18, -2, 8], [16, -4, -25, -5], [9, 12, -21, -17], [-5, -8, -27, -29], [14, -19, -37, -6], [28, 4, 23, 17], [-25, -7, 21, 1], [-18, -3, 25, -7], [-12, -6, -20, 8], [3, -12, -30, -28], [-11, -2, 3, -41], [-18, 19, 3, -27], [23, -4, -17, -27], [31, 1, 21, 7], [-27, 23, 8, 16], [-7, -28, -3, -28], [53, 1, -23, -7], [-2, 3, -15, -7], [-32, -3, 18, -22], [24, 0, -3, 63], [-30, 16, 9, -14], [5, 26, -32, -10], [25, 21, 2, -4], [-1, 11, -2, -8], [-14, -7, 11, 23], [9, 27, -23, -25], [-11, 32, 7, -21], [-4, -28, -7, 33], [-69, 24, -19, -65], [45, -1, -5, 30], [26, -22, -2, 22], [17, 6, -37, -19], [5, -4, -2, 25], [-31, -18, 5, -29], [37, -21, 0, 1], [-28, -5, 29, 19], [-16, 2, -5, -40], [16, 3, -16, -8], [-18, -10, 39, 0], [25, -9, -6, -6], [-17, 2, 3, -20], [-11, -23, 10, -18], [2, 17, 48, 2], [-17, -28, 9, 3], [-6, -13, -43, 9], [37, -8, -5, 3], [-34, 7, -5, 15], [-59, 0, 0, -39], [-25, 10, -33, -17], [56, 12, -6, 1], [57, -20, 2, 73], [14, 8, 25, 41], [-2, -11, 16, -23], [-11, 24, 15, 25], [50, 2, 3, -19], [4, 25, 8, -10], [5, -21, 4, -1], [-12, 18, 3, 6], [-47, 4, -12, -3], [-7, 17, -55, -30], [9, -27, -10, 28], [-26, 28, -28, -31], [-10, 10, 25, 0], [10, -2, -3, -10], [-17, 8, -2, -13], [2, -10, 28, 8], [28, -32, 16, 29], [28, -30, -12, 17], [-13, 11, 36, 33], [35, -31, -13, -5], [-4, -13, -4, -50], [-12, 22, -10, 3], [29, -7, -9, 35], [-67, 14, 5, -24], [-5, -13, 11, 33], [-12, -13, -30, 10], [34, 1, 19, 51], [39, -3, 7, -16], [-22, -6, -34, -4], [12, 12, 24, -7], [-29, 40, -18, -43], [24, 3, 4, 77], [46, 30, -2, 3], [45, 9, -24, -18], [21, 25, 15, 6], [41, 11, -20, 21], [-7, -2, -3, 51], [-22, 7, -8, -67], [10, 43, 13, -9], [9, -9, -18, -1]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5625_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5625_2_a_j();".
// 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_5625_2_a_j(:prec:=4)
    chi := MakeCharacter_5625_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_5625_2_a_j();".
// 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_5625_2_a_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5625_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![1, -4, -4, 1, 1]>,<7,R![-5, 10, 0, -5, 1]>],Snew);
    return Vf;
end function;