
// Make newform 9025.2.a.o in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9025_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_9025_2_a_o();".
// 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_9025_2_a_o();".
// 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, 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_9025_a();"
function MakeCharacter_9025_a()
    N := 9025;
    order := 1;
    char_gens := [5777, 3251];
    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_9025_a_Hecke(Kf)
    return MakeCharacter_9025_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, -2], [-2, 0], [0, 0], [0, 2], [4, -2], [0, -3], [0, 1], [0, 0], [2, -4], [4, -5], [-6, 0], [-7, 3], [1, -5], [-2, -4], [-6, -2], [-3, -5], [2, -2], [8, -3], [-2, -4], [-2, 2], [9, -9], [2, 0], [6, -6], [-3, 7], [8, -5], [5, 7], [-4, 6], [-2, -2], [-9, 5], [12, 3], [12, 0], [18, -6], [5, 11], [10, -6], [0, -3], [0, 0], [0, -13], [12, 6], [6, 2], [5, -1], [-16, 8], [14, -12], [-6, -2], [14, 4], [16, -13], [-8, 8], [24, -6], [10, 0], [-16, -4], [13, -21], [-4, 5], [6, 8], [-6, -8], [12, -2], [15, 5], [-14, -10], [8, 11], [6, -14], [11, 1], [-16, 5], [24, -12], [-18, 12], [-18, -4], [16, 2], [13, -21], [-11, -1], [-12, -10], [-1, 21], [-12, 22], [-4, -3], [-20, 17], [18, -6], [-24, 12], [4, 9], [12, -16], [28, -2], [24, -3], [6, 12], [-18, 12], [-11, 15], [12, 12], [15, -11], [-20, -2], [15, 9], [10, 0], [-6, -12], [-20, 25], [-3, -5], [2, 4], [-22, 6], [0, -16], [14, 8], [-24, 2], [12, 0], [-6, 2], [-2, -20], [20, -5], [-12, 9], [4, -12], [24, -3], [6, 2], [26, -4], [-12, -14], [-23, -1], [-12, 6], [-4, 1], [4, 2], [-27, 3], [30, -8], [-6, 0], [28, -12], [11, -15], [6, 20], [-30, 18], [-14, 20], [32, 1], [-12, 0], [-28, 22], [11, -19], [12, 6], [-10, 16], [-21, -3], [-20, 41], [-16, 34], [2, -30], [-3, 3], [24, -31], [14, -28], [18, -18], [-28, 15], [28, 6], [0, 12], [14, -12], [-4, -17], [-10, 16], [-33, -3], [24, -35], [2, -2], [-8, 17], [7, 13], [26, 0], [20, -19], [22, 14], [-6, -24], [-17, 21], [6, -18], [-8, -1], [-36, 3], [30, 12], [4, 8], [-4, 9], [-1, -7], [-10, 16], [-26, 38], [-18, 12], [18, -24], [-8, -4], [8, -37], [6, -28], [-30, -4], [0, 22], [-40, 19], [-26, 42], [-8, -14], [-17, 17], [-12, 42], [-40, 18], [3, 5], [16, -27], [4, 19], [-18, 16], [-18, 36], [48, 6], [-7, -33], [28, -28], [-24, 27], [-36, 30], [-24, 29], [22, -42], [-36, -15], [36, -24], [24, -20], [-16, 21], [11, 5], [2, 20], [45, -5], [1, 15], [-18, -2], [-4, -27], [38, 16], [-29, -15], [26, 2], [-6, 0], [11, -31], [32, -40], [-30, 12], [-44, 3], [-13, 33], [24, -3], [-22, 44], [-44, 11], [-34, 48], [-12, 9], [-20, 45], [2, -34], [-17, -23], [-6, 28], [-20, 20], [-21, 25], [18, -24], [-31, 3], [-15, 11], [-40, 12], [44, 2], [22, 8], [-12, 29], [-8, -18], [32, -19], [16, -34], [39, -27], [26, 0], [62, -2], [-16, 5], [54, -14], [-24, 44], [-19, -5], [24, -25], [-48, 38], [-24, 42], [-10, -14], [58, -24], [64, 6], [6, 42], [22, -4], [18, 24], [-16, 2], [-32, 47], [2, 32], [10, -8], [-10, 20], [22, -32], [-30, 56], [42, 6], [-57, 13], [-36, -21], [32, -2], [12, 12], [60, -20], [-62, 20], [-14, -14], [-5, -15], [-9, 25], [56, -2], [12, -51], [-2, -28], [34, -44], [65, 3], [28, -4], [-6, -20], [-42, 4], [-38, 44], [-12, -34], [34, -4], [46, -24], [32, -31], [6, -34], [-54, -4], [-24, -9], [12, -38], [2, -4], [11, 9], [18, -24], [-28, 37], [6, -30], [-1, 1], [-2, 12], [-4, -10], [19, 9], [28, -3], [0, 20], [-16, -4], [24, 4], [-26, 46], [-64, 3], [-16, 40], [24, -22], [-27, 39], [-8, -11], [22, 14], [-30, -24], [-20, 61], [-6, 48], [-49, 37], [-28, -34], [-40, -3], [-51, 27], [-52, 28], [50, -32], [38, -10], [28, -28], [-39, 15], [36, -55], [12, 36], [0, -12], [-16, 12], [28, -21], [44, 8], [-17, -19], [26, -2], [-9, -35], [-18, -30], [-66, -8], [1, -1], [6, -38], [-52, -10], [16, -15], [-2, 38], [6, -58], [-12, 21], [-73, 5], [28, -60], [-60, 13], [-33, 9], [4, 30], [-39, 51], [60, -11], [12, 6], [30, -2], [44, 2], [12, -45], [-3, 3], [-30, 28], [-36, 64], [-78, 0], [16, -24], [10, -8], [-8, -9], [15, -31], [40, -57], [44, -6], [-30, -20], [-38, 20], [38, -44], [-42, -28], [-68, -7], [-6, 34], [65, -41], [-24, 0], [-30, 14], [-36, 39], [-38, -10], [63, -15], [12, -15], [8, 28], [-8, -9], [63, -27], [28, 20], [-6, -12], [57, -33], [12, -48], [-48, 51], [-32, -17], [30, -30], [-20, 64], [-26, 6], [-4, -29], [-6, 48], [84, -10], [16, 45], [-34, 34], [30, -48], [-36, 32], [30, -12], [-54, 66], [-4, -17], [-42, 30], [12, -18], [28, -3], [-17, 49], [-24, 39], [-4, -1], [57, 3], [52, 12], [41, -1], [-38, 0], [54, 14], [-42, -4], [24, -69], [-10, -26], [68, -14], [36, -35], [37, -17], [-70, 20], [44, -18], [24, -48], [0, -9], [-16, 22], [10, 4], [-10, 0], [-60, 17], [-5, -3], [77, -13], [36, -2], [48, 3], [-45, 69], [72, -40], [0, 43], [36, 21], [52, -76], [42, 18], [-36, 3], [-48, -13], [-54, 4], [-8, -12], [-63, -9], [-2, 44], [-84, 30], [2, 10], [13, 55], [28, -40], [28, -5], [-35, 59], [30, -30], [34, -74], [55, -79], [9, 15], [24, 6], [-49, -23], [36, 26], [26, -82]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9025_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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