
// Make newform 4025.2.a.l in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4025_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_4025_2_a_l();".
// 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_4025_2_a_l();".
// 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 := [2, 1, -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, -1, 1, 0], [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_4025_a();"
function MakeCharacter_4025_a()
    N := 4025;
    order := 1;
    char_gens := [2577, 1151, 3501];
    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_4025_a_Hecke(Kf)
    return MakeCharacter_4025_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 := [[-1, 1, 0, 0], [-1, 0, 0, -1], [0, 0, 0, 0], [1, 0, 0, 0], [2, -1, 0, 0], [1, -1, -1, 1], [-2, -1, 0, 2], [1, 2, -1, 1], [1, 0, 0, 0], [0, 2, 2, -2], [1, 2, 1, -3], [-2, -1, 2, -2], [-1, -1, -2, 3], [-5, 0, -4, 3], [1, -2, 3, -3], [0, 1, -1, 0], [-1, 3, -1, -3], [-2, -3, -3, 2], [-5, 3, 5, 1], [1, 2, -1, -3], [-2, 1, 5, 2], [-2, -2, 3, -2], [1, -5, -3, -1], [-4, 5, 4, 0], [-3, 1, -6, 1], [-1, 2, 7, -3], [-7, 3, 0, -1], [1, -1, 2, -5], [-4, -3, -1, 0], [-8, -1, 1, 0], [-5, 2, -3, -1], [8, -6, 0, 0], [-11, 5, 0, 1], [-8, 3, 1, 2], [-8, -7, -8, 8], [-1, -3, 0, -7], [2, 0, 9, -4], [-4, -2, -4, 4], [9, -5, 0, -1], [6, 3, -6, 6], [6, -5, 6, -4], [-5, -3, 2, 7], [9, -9, -5, 3], [-5, 1, 9, -5], [-1, -2, 7, 1], [-11, 5, 2, -1], [1, -3, -9, -5], [2, 1, 12, -8], [-2, 5, 7, 4], [-1, 0, 2, -11], [-8, -6, 5, 2], [13, -7, -1, -13], [1, -11, 3, 5], [6, 7, 6, -4], [0, 4, 0, 2], [-16, -3, -9, 2], [-5, 1, 3, 3], [-3, -9, 2, -5], [1, 9, -2, -7], [-16, 12, 5, 2], [-7, -2, -1, 1], [-5, -1, -5, 11], [-11, 6, -4, 1], [8, -10, 0, 4], [-2, -8, -15, 4], [-8, 1, 9, -8], [-9, 5, -4, 13], [-7, 6, -7, 7], [-16, 11, 1, 2], [-6, 3, 5, 2], [2, -2, 3, 12], [-7, 2, -2, -7], [-16, 5, -6, 14], [7, 4, 10, 1], [3, 1, -11, -3], [-4, 5, -4, -14], [0, 6, -6, 14], [18, -4, 3, -4], [1, 13, 3, -11], [-7, 1, -1, 13], [-14, -9, -9, 12], [-10, 1, -2, 6], [15, 4, -3, -1], [-9, -2, -14, 9], [1, 19, -1, -5], [-4, -7, 3, -6], [9, 1, 2, 9], [8, 1, -6, 0], [-1, -2, -9, -3], [-11, 6, 2, -11], [-21, -5, -11, 17], [2, 5, -13, 4], [-5, 4, 7, -5], [8, 15, 0, -2], [-12, 7, 9, -2], [7, 8, 0, -5], [11, 0, -16, 1], [7, 3, -2, 3], [-1, -9, 0, 9], [-12, -14, 11, -2], [23, 1, -6, -3], [24, 4, 9, -14], [-16, 9, 1, -2], [19, -8, 2, 5], [-7, 18, 5, -7], [6, 6, -3, 8], [-9, -2, -18, 11], [13, 11, 8, -11], [-4, -14, 3, 4], [-5, -8, -2, -3], [15, -15, -4, -7], [-13, -10, -6, 9], [13, -1, 5, -15], [1, -15, 12, 7], [-6, 5, 4, 0], [-11, 0, -16, -1], [15, -14, 3, -1], [7, -9, -7, -7], [5, -10, -6, 11], [-4, -4, -14, 8], [-8, 2, -11, -14], [14, -1, -1, 6], [10, 10, -4, 12], [-15, -2, -22, -3], [-5, -14, 9, -5], [-24, 4, -2, 18], [-5, 14, 4, -3], [10, 2, 8, -2], [7, -5, -2, -19], [14, -1, 13, -6], [-10, 19, -7, 0], [5, -14, -7, 9], [-11, 13, 0, 15], [12, -12, -7, -2], [-24, 2, -1, 6], [10, 18, 12, -12], [20, -2, 6, 14], [12, 8, -8, 0], [20, 1, -4, -8], [10, 0, 21, 12], [-37, 1, -8, -7], [-6, 1, -14, -6], [-7, -13, 12, -1], [-9, 1, -1, 1], [-16, -3, -1, -12], [6, 21, 3, -16], [-1, -15, 3, 11], [16, -11, -11, 4], [-10, 9, -3, 12], [-13, 7, -3, -3], [11, -2, -8, 1], [6, -7, 8, 2], [-8, 13, 5, 14], [-14, 6, -8, -10], [-19, -2, 6, -7], [-17, -3, 9, 13], [-17, 3, -17, 1], [27, -19, -1, -9], [8, -9, 19, -16], [-26, -3, 5, -6], [-27, -9, -23, 11], [6, -11, -3, -14], [10, 15, 4, -20], [10, 5, -1, 0], [-4, 16, 0, 6], [-4, -13, 8, -2], [-20, 1, 8, 10], [18, 20, 8, -16], [-17, -4, -21, 13], [-12, 17, -2, 8], [15, -23, 0, -3], [12, 5, -2, -12], [18, -13, -2, 4], [-5, -4, 15, 5], [-13, -4, -10, -1], [-11, 14, -15, 7], [-1, -10, 8, 3], [13, 11, 3, -15], [4, 2, -13, -4], [16, 17, 18, -16], [0, 0, -4, 0], [33, 1, -7, -5], [-7, 12, -18, 11], [43, 12, -3, -3], [2, -15, 12, 8], [-24, -20, -1, 6], [2, -23, -10, 6], [-27, -2, -19, 13], [3, 23, 11, -13], [-2, -4, -16, -2], [-9, -1, -6, 7], [-1, 6, 2, -13], [26, -2, -3, -18], [-34, 15, 9, 14], [-2, -11, -2, 8], [20, -13, -11, -20], [13, 17, 8, -11], [9, -14, 11, -13], [5, -7, 2, -7], [12, 3, -15, -6], [3, -21, -1, 7], [-26, -19, -2, 12], [15, 9, 18, -17], [-4, -7, 15, 4], [13, -2, -11, -11], [-8, 9, -1, 16], [30, 7, 7, -4], [5, -6, 19, -3], [3, 8, 6, -11], [46, -9, 3, 0], [-9, -21, -9, 11], [8, -4, -4, 18], [4, 11, -5, -22], [-45, 26, 9, 3], [2, -14, 11, -14], [20, -22, -4, -18], [1, 18, -10, 9], [-28, -7, -10, 0], [-21, 0, -18, 7], [-24, 20, 0, 22], [24, -8, 6, -14], [-4, -27, -22, 18], [25, -11, 5, -27], [25, -5, -21, 11], [-7, 9, 27, 3], [-5, -16, 12, -23], [8, 0, 8, -22], [-3, -3, 0, -25], [14, -29, 5, -12], [-18, 8, -11, 38], [6, -10, 11, -20], [15, 7, 17, 5], [-41, -15, -13, 21], [18, -1, -1, -2], [30, 14, 24, -26], [4, 11, -11, -6], [47, -6, 3, -15], [0, -23, 0, 12], [12, 6, 7, 8], [-6, 25, -11, 4], [-15, -3, -14, 23], [0, 31, -4, -10], [2, -23, 11, -12], [13, -15, 6, -15], [-7, 12, -6, -9], [-12, -8, 11, 16], [34, -5, -9, -8], [7, -2, 11, 7], [9, 0, 2, 9], [13, 17, 24, -17], [-22, 4, 11, 20], [-20, 5, 3, -20], [32, -9, 6, 2], [-3, -14, 9, 23], [31, -10, -2, -3], [-6, -7, 5, 8], [12, 2, 8, 10], [-15, 0, -19, 29], [-3, -4, 2, 15], [-14, 23, -17, 2], [-16, 24, -1, 20], [-16, -19, 9, 6], [-5, 15, 14, 3], [-43, -10, -7, 15], [21, 0, -28, 3], [10, -4, -15, 2], [28, 5, 9, -24], [2, 8, -5, -20], [-6, -10, -17, -10], [0, 5, 10, -4], [-16, 12, -17, 22], [-24, 15, 7, 18], [8, 5, 26, 8], [-45, -11, -18, 13], [-42, 1, 23, -6], [-36, 15, -3, -14], [-37, 11, -3, 9], [4, 11, 2, 16], [9, -10, 7, 19], [5, -19, 7, 15], [27, -14, 6, -37], [-20, 11, 25, 10], [-7, 2, -4, 17], [3, -21, 9, 7], [-18, 21, 10, 16], [14, 28, -20, 14], [-39, 30, 21, 7], [-39, 14, -10, 23], [-27, 10, 29, -7], [-11, 9, 3, -15], [37, -1, 21, 17], [-37, -16, -23, 23], [-31, -15, 3, 9], [42, 1, 7, 8], [27, -2, 11, -27], [21, -3, 27, -35], [-22, 2, -7, 10], [19, 0, 22, -11], [-24, 5, -14, 26], [32, 3, 16, 14], [-15, -5, -2, -23], [3, 27, 1, -21], [-44, 21, 3, 14], [-11, 37, -9, -25], [36, -1, 24, -6], [12, -1, 9, 20], [-25, -1, 17, -3], [23, -28, -17, 9], [-21, -9, 26, -7], [-31, -7, 12, -15], [16, 15, 24, 2], [37, -1, -10, 5], [-21, 3, 31, -5], [-6, -3, 14, 4], [26, 15, 1, -24], [12, 6, -19, 10], [14, -27, -12, -8], [13, 19, -11, 23], [12, 5, -16, 12], [33, 12, -7, 15], [45, 3, -7, 3], [-62, -14, -13, 28], [10, -1, 31, -14], [-25, -11, 16, -7], [13, 4, -12, 27], [-18, -5, -3, 18], [-26, -22, -6, 14], [22, 27, -16, 4], [-2, 13, 6, 4], [-55, 2, -2, 15], [18, 14, 6, -32], [2, 21, 46, -18], [-13, -19, 20, -27], [-2, -17, 11, 0], [9, 10, -28, 13], [28, -3, -6, -10], [24, -5, -4, 12], [-37, 29, 13, 19], [26, 10, -14, -12], [-12, -19, -25, 30], [40, -12, -14, 6], [-2, 20, 4, 0], [26, -34, 5, -12], [-37, -14, 17, -9], [16, -19, -20, 12], [31, 9, -5, -7], [52, 3, 0, 16], [23, -7, -22, -11], [-23, 0, -20, 13], [-5, -2, 14, -31], [-25, 6, -4, 19], [34, -32, -9, 0], [23, 3, 1, -13], [23, -3, 26, -31], [-8, -30, -2, 14], [-7, 9, 4, -19], [-26, -12, -21, 10], [21, -4, 0, -11], [-24, 2, 21, 10], [-18, -12, -29, 26], [-8, -5, -3, 28], [-36, 39, 22, 4], [23, 5, 18, 17], [9, 19, -15, 7], [31, -43, -3, -15], [7, -7, -20, 3], [41, 0, 15, -41], [11, -10, 17, -33], [-12, -7, -22, 24], [30, -41, -17, 8], [-4, -11, -15, -14], [7, 24, -19, -1], [5, 11, 11, 25], [3, -16, -9, 27], [2, -24, -1, 20], [33, 4, 6, 1], [21, 25, -24, 7], [40, 3, 29, -24], [-43, 15, 26, -7], [27, -12, -16, 1], [9, -10, 7, 15], [20, -6, 22, 10], [10, 9, 30, 0], [5, -33, 9, -15], [15, -25, 19, 13], [23, 6, 0, -33], [-9, 12, -9, -17], [9, 10, -21, -5], [25, 1, -10, -17], [17, 4, -16, -3], [-25, 28, -12, -15], [14, 28, -8, -20], [2, 19, 9, -12], [28, -14, -17, 0], [-42, 3, 25, -4], [-19, 17, -15, 13], [-10, -8, -16, -2], [8, -41, -4, 8], [-6, 1, 7, -8], [1, -4, -9, 35], [1, 5, 0, -11], [-36, -11, 2, 20], [-40, -15, 22, -18], [6, 9, -12, 14], [39, 25, 5, -17], [9, 0, 36, 21], [-22, -16, 8, -8], [19, 29, -9, -1], [1, -22, 8, -27], [9, -17, 12, -5], [15, -14, -16, -31], [12, -34, 11, 2], [-5, 6, -28, -25], [-6, 14, 23, -10], [-47, -1, -29, 13], [-21, -3, 7, 11], [-34, 22, -16, -22], [-22, 27, 9, 32], [-1, -19, -8, -21], [47, -11, 16, -7], [-37, 42, 18, -11], [3, 5, -19, -1], [-38, -24, 1, 14], [13, -34, -11, 5], [-32, -9, -44, 36], [4, 4, 48, -14], [25, 12, 19, -19], [23, -22, -7, -39], [60, -11, 14, -18], [-15, -6, -4, -7]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4025_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4025_2_a_l();".
// 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_4025_2_a_l(:prec:=4)
    chi := MakeCharacter_4025_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_4025_2_a_l();".
// 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_4025_2_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4025_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, -6, -1, 3, 1]>,<3,R![-4, -1, 9, 6, 1]>,<11,R![-4, -5, 14, -7, 1]>],Snew);
    return Vf;
end function;