
// Make newform 2025.2.a.y in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2025_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_2025_2_a_y();".
// 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_2025_2_a_y();".
// 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 := [3, 5, -4, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-3, -1, 1, 0], [1, -4, -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_2025_a();"
function MakeCharacter_2025_a()
    N := 2025;
    order := 1;
    char_gens := [326, 1702];
    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_2025_a_Hecke(Kf)
    return MakeCharacter_2025_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], [0, 0, 0, 0], [0, 0, 0, 0], [-1, 0, -1, 1], [0, 0, 1, 1], [1, 1, 2, 0], [3, 0, 1, 1], [1, -2, -1, 0], [2, 1, -2, 1], [-2, 2, -2, 1], [-2, 1, 0, 2], [3, -4, 2, -1], [-2, -1, -2, 1], [-3, 2, 0, -2], [6, 0, 1, -2], [4, -1, -3, 0], [7, -1, 3, -3], [-6, 2, -3, 1], [5, -3, -1, 1], [-1, 1, 3, 0], [-1, 3, 1, 2], [-1, 0, 2, 1], [6, 3, 0, 0], [-6, 3, -3, 3], [-5, -2, -2, 1], [2, -5, -2, -2], [-3, 2, -1, -1], [1, 5, -1, -1], [-5, 1, 1, -2], [-3, 6, -2, 1], [3, -1, 0, -2], [0, -3, 3, -3], [-1, 1, -5, 4], [-1, 6, -3, 0], [-5, -4, -2, 1], [0, 5, 6, 1], [-3, 5, -1, 2], [-8, 4, -5, -2], [11, -5, -2, 1], [5, -5, 1, -5], [4, 2, 6, 0], [-6, 5, 2, 2], [-1, 10, 0, 0], [-2, -2, 1, -2], [8, -5, 1, 1], [9, 2, 6, -5], [-8, 7, -5, 4], [8, -6, 3, 0], [12, 0, 2, -1], [-2, 1, 6, -1], [-4, 1, 1, -2], [-12, 3, -2, -5], [-2, 7, -4, 0], [6, 0, 9, -6], [12, 0, 9, -3], [3, 0, -1, 8], [-12, 0, -2, -2], [4, 1, -7, 0], [7, -5, 12, -1], [10, -4, 2, -1], [-4, 0, -4, 7], [2, -5, 7, -2], [-17, 4, 5, 3], [20, -11, -5, -2], [-8, 1, 4, -5], [-5, 5, -5, 7], [0, -4, 7, -6], [5, 3, -5, -1], [5, 4, 11, 2], [-1, -6, 1, -7], [-10, 1, 7, -2], [7, -7, 5, -4], [-5, -5, 0, 2], [4, -2, 2, -6], [-12, -4, -6, 1], [8, 1, 4, -8], [-11, -4, 8, -1], [-3, -1, -6, 7], [5, 7, -2, 7], [22, -5, 4, -5], [13, -4, 1, 4], [6, -7, 0, 1], [-8, -7, -7, -1], [-1, -3, -5, -1], [6, -10, -6, -2], [-8, 5, -7, 2], [-20, 2, -3, 6], [14, 6, -5, -1], [20, 7, 13, -8], [-5, 13, 3, 5], [10, -10, -2, -2], [-1, -14, -2, 4], [5, 6, -6, 6], [-12, 9, -7, -4], [-4, -9, 4, 2], [20, -2, 12, 3], [-19, 13, -4, 8], [8, 10, -9, 6], [-11, -11, 2, 0], [3, 5, 1, 6], [-16, -3, -14, 2], [1, -7, 2, -7], [19, -13, -4, -4], [-14, 5, -1, -7], [-19, 0, -3, -3], [-3, -10, 5, -10], [8, -5, 13, -5], [-10, -5, -6, 9], [-5, -4, -2, 1], [-5, -2, -11, 10], [0, 14, 6, -8], [10, 4, 8, -9], [-11, -1, -10, -4], [13, -5, 16, -5], [7, -17, 8, -6], [23, -14, -5, -8], [14, -3, -4, 1], [27, 6, 1, -2], [-15, 6, 11, -1], [10, 11, -6, 0], [32, -9, 4, -4], [28, -8, -9, -1], [3, 3, 6, 9], [-3, 9, 0, 3], [-2, -11, -7, 6], [19, -7, 10, 1], [19, -5, 2, -9], [-6, 6, -15, -3], [-4, 9, -15, 0], [17, -21, -9, 0], [7, 10, 2, -3], [10, 2, -3, -3], [21, 2, 9, -2], [-3, 20, 0, -5], [10, -1, 5, 8], [-21, -4, 2, -10], [-10, 10, -11, 4], [-4, 0, 13, -4], [-8, -4, -5, 10], [-7, 16, -6, 6], [21, -4, -5, -3], [22, -4, 14, -4], [-24, -1, -10, -1], [-13, 7, 2, 11], [4, 10, -6, -1], [-5, 5, -2, 7], [2, -6, 2, 4], [31, -10, 6, -12], [12, -7, 12, 4], [35, -2, 12, -12], [5, 9, -4, 7], [-29, 2, -9, 0], [20, -18, -9, 0], [-3, 18, -3, 6], [-11, 13, 12, 5], [-4, 1, 8, 5], [-3, 2, 9, -2], [-2, -10, 1, -5], [-13, 15, 5, -5], [19, 5, -5, -5], [-23, 8, -10, -7], [-4, 4, -1, -13], [11, 9, -3, 3], [-26, 2, -1, -7], [9, -15, 16, -11], [27, -3, 0, 3], [-12, -1, -10, 8], [39, -1, -2, 3], [-9, -4, 2, -16], [-11, 5, -11, -5], [55, -1, 2, -1], [-28, 6, -11, 11], [6, -12, 15, -9], [4, -11, -6, -4], [-21, 8, -6, 1], [2, 10, 19, -5], [-4, -6, -4, 4], [4, -10, 2, -13], [-19, 3, -12, -6], [2, -9, 1, -13], [8, -9, 9, 3], [-34, 7, -6, 3], [-19, -3, -2, -7], [-15, 12, -10, -1], [22, 8, 5, 2], [-11, 23, 0, 0], [-18, -4, -14, 3], [-7, -9, -5, -4], [22, -5, 4, -5], [0, 0, 13, -2], [20, 3, -8, 8], [10, 5, 6, 0], [27, -1, 19, -3], [-12, 3, 7, -2], [-28, -8, -8, 1], [-10, 1, -9, 9], [30, -4, 12, -11], [13, 16, 15, -4], [-27, 15, 3, 0], [17, 4, -15, 3], [-17, -1, -16, -7], [24, -1, 4, -3], [-19, 6, -1, 4], [-26, 19, -4, 18], [43, -7, -4, 2], [-16, -5, -8, 7], [22, -8, 4, -2], [28, 8, 21, -12], [23, -20, -14, -5], [19, -2, 13, -11], [6, -16, -7, 11], [-8, -16, -8, -5], [21, -1, 1, -12], [-28, 13, -10, 8], [0, 9, 6, -15], [19, -11, 4, 7], [-11, -14, -13, 12], [0, 9, -30, 3], [16, -10, 4, -11], [-7, -5, 13, 4], [-34, 6, -17, 5], [-15, 5, 2, -7], [9, -24, -3, 0], [-10, 15, -11, 14], [-11, -13, -2, 10], [0, -13, 5, 8], [-2, -16, -7, 5], [17, -20, -3, 12], [13, -8, 5, -9], [7, -16, 17, -10], [14, 9, 8, -8], [-13, -18, 4, -7], [-5, -5, -29, 1], [-20, -4, 12, -6], [24, 8, -7, 8], [17, 16, -2, 7], [-1, -12, -16, 1], [-35, 14, -2, 16], [15, 0, 12, -12], [-15, 24, -3, 0], [3, -9, 15, -9], [-27, 5, -14, 21], [13, 4, 2, -9], [-30, -1, -26, 12], [-30, 9, -6, 3], [11, -2, 2, -13], [-14, 1, -20, -8], [-5, -22, -6, 0], [-1, 0, 6, -3], [20, -5, -1, -1], [33, -1, 9, -5], [26, -20, -1, 14], [15, -27, 0, -6], [-17, 16, -3, 8], [-31, 16, 6, -3], [-1, 25, -11, 4], [16, 16, 5, -3], [-9, -4, -13, 11], [-4, 4, 13, -14], [21, 5, 29, -1], [-21, 11, -9, -8], [-20, -16, 4, 4], [-3, 11, -10, 23], [16, -11, 9, -13], [-25, 25, 7, -5], [21, -13, -9, 4], [16, -7, 24, -15], [-4, 19, 6, 9], [-1, -12, 12, -6], [-34, -11, 5, -1], [23, 12, 6, 0], [16, -8, -4, -15], [32, -15, 18, -18], [31, -8, 15, -10], [27, -16, 13, -21], [-5, -11, 13, -14], [-20, -4, -7, -7], [37, -8, 27, -10], [8, -6, 20, -17], [-22, -8, -14, -5], [-17, 2, -20, 10], [5, 3, 19, -10], [39, -3, 26, -13], [-12, 5, 4, -21], [-22, 15, -10, 13], [-4, 4, -32, 1], [17, -3, -2, 2], [-43, -2, -8, 1], [-46, 6, 3, -6], [-25, 22, 7, 1], [-20, 11, 7, 4], [-27, 18, -1, 5], [-12, 0, -12, -6], [-29, 2, -1, 8], [-50, 4, -20, 7], [-19, -23, -5, 10], [-28, 0, -27, -12], [-18, -9, -6, 15], [48, -21, -3, -15], [32, -3, 9, -15], [-45, 11, -29, 24], [6, -30, -11, 4], [-17, 25, -7, 3], [-17, -13, -10, 5], [2, -3, 25, -1], [1, -5, 19, 4], [-29, 14, 5, -10], [-26, 22, 13, 13], [20, -5, 37, -2], [-33, 5, -14, -9], [27, 0, 18, -3], [12, -18, -21, 3], [-11, -4, 11, 8], [18, -7, -19, -7], [32, -14, 21, -12], [-14, 4, 5, 3], [-1, -23, -11, 7], [-18, 6, -21, 21], [24, -10, 10, -6], [-49, 7, -5, -5], [-43, 21, 9, 6], [34, -8, 13, -5], [36, -15, 19, -11], [-36, 5, 3, 13], [5, 7, 28, 1], [-2, -26, -10, 18], [6, 8, -1, 5], [-37, -18, -14, 14], [14, 7, -14, 7], [23, -5, 17, -13], [-18, 2, -5, -6], [-37, -2, -22, 2], [14, 12, -6, -3], [24, -30, -10, -1], [-35, 37, 10, 4], [-30, -3, 5, -16], [-14, 16, -8, -11], [-1, -5, -6, -15], [-19, 15, -18, 12], [62, -9, 11, -2], [22, 19, -13, 9], [5, -23, -3, 3], [15, 27, -21, 9], [27, -4, 4, 21], [-31, 1, -19, -13], [31, -7, -1, 5], [-24, 20, -1, -16], [-31, -12, 7, 5], [33, -30, 9, -6], [30, -3, 5, -16], [33, -22, -8, -12], [-10, -6, 17, -5], [-3, -27, 11, 2], [-9, 14, 6, 13], [-9, 8, 31, 3], [16, -1, 29, 2], [-49, 7, -15, 15], [12, -18, -18, -9], [11, 7, -5, 22], [-9, 24, -14, -2], [38, -18, 10, -19], [31, -1, 6, -6], [7, 8, 38, -1], [6, -12, -8, -23], [-37, 15, -24, 21], [-21, 14, 9, 1], [-17, -13, -10, -4], [12, -22, 4, 0], [23, 6, -3, 9], [-29, -7, 5, -19], [4, 1, 0, 17], [29, 13, 2, 14], [-24, 12, -24, 9], [-5, -5, -24, -4], [-49, 0, -41, 14], [-19, -5, -22, -1], [36, 3, 12, 3], [-18, -19, 17, -16], [11, 31, -8, 4], [51, -10, 6, -2], [-12, 21, -25, 17], [9, 6, 15, 3], [-10, -12, -14, 2], [-15, 3, 8, -4], [25, 19, 6, 5], [6, -3, -23, 16], [-17, -11, -17, 1], [19, -20, -29, -11], [-14, 10, 15, 5], [71, -8, 10, 7], [-19, -18, -4, 4], [39, 3, -17, -2], [0, 12, 7, -14], [3, 2, 5, -4], [36, -15, 7, -8], [-34, 9, 15, -6], [-6, 14, 23, 11], [-24, 9, 3, -15], [5, -6, -5, -7], [-2, -13, -4, 20], [20, -12, -5, 2], [19, -22, 11, -13], [-42, 5, 15, -2], [22, -13, 16, -2], [-9, -21, 5, 8], [18, -16, -15, -2], [-7, -3, 0, -24], [-3, 6, -1, -4], [-27, 17, -20, 0], [70, -10, 8, 2], [11, -3, 14, -8], [6, 12, 3, 9], [13, -10, -18, -3], [32, 18, -19, 7], [-28, -18, 6, -12], [0, 0, -2, -2], [-32, -10, -2, -2], [-9, -37, 24, -8], [-51, -3, -21, 3], [47, -5, -3, -12], [35, -20, 3, 12], [-51, 26, 3, -5], [-15, 6, -9, -15], [39, 9, -5, 4], [-14, -8, -23, 1], [43, 11, 6, -9], [-49, 4, -24, 18], [23, 1, -11, 16], [-40, -6, -33, 15], [-7, -2, 29, -1]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2025_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2025_2_a_y();".
// 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_2025_2_a_y(:prec:=4)
    chi := MakeCharacter_2025_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_2025_2_a_y();".
// 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_2025_2_a_y( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2025_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![3, 5, -4, -2, 1]>,<7,R![-9, -24, -12, 1, 1]>,<11,R![-9, 41, -25, 1, 1]>],Snew);
    return Vf;
end function;