
// Make newform 9025.2.a.n in Magma, downloaded from the LMFDB on 24 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_n();".
// 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_n();".
// 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 := [[0, -1], [-2, 1], [0, 0], [-3, 0], [0, -1], [1, 0], [-4, 2], [0, 0], [-7, 1], [-2, -1], [-4, -3], [-4, -3], [-3, 0], [5, -3], [-3, 0], [-5, 7], [-11, 7], [-7, -2], [7, 0], [-1, -4], [-7, 6], [-6, 12], [-2, -4], [-11, 2], [-9, -3], [7, -10], [-3, -7], [3, -12], [-13, 6], [-10, 2], [-9, 2], [7, 5], [-1, -4], [-3, 11], [-10, 5], [-13, -5], [13, 3], [-5, 2], [-17, -2], [-6, 4], [9, 2], [12, 0], [11, 2], [-18, 8], [-3, 0], [6, -12], [1, -3], [-11, 14], [3, -12], [-12, -1], [-11, 4], [11, -7], [-13, 10], [7, -20], [12, -20], [2, 8], [19, 7], [6, -3], [8, -12], [-2, -17], [-5, -13], [15, -3], [6, 7], [-10, 14], [0, 7], [-18, 0], [-2, 8], [-12, 18], [6, 12], [13, -21], [16, -25], [-14, 13], [3, 8], [-1, 4], [14, -18], [-2, 1], [-15, 15], [5, 4], [-10, -16], [-18, 6], [4, -8], [-21, -4], [5, 14], [18, -9], [1, -22], [27, -12], [-23, 16], [-10, -6], [8, 8], [-4, -15], [3, 8], [15, 5], [12, -10], [16, -23], [-4, 18], [3, -24], [-19, 13], [-18, 15], [-15, 12], [9, -24], [-20, 29], [17, -10], [-6, 24], [25, -5], [18, -7], [-17, 18], [-27, 18], [9, -6], [9, 12], [30, -6], [-18, 15], [7, 8], [-19, 7], [-19, 18], [-3, 20], [-12, -17], [34, -6], [-1, -4], [9, 9], [26, -32], [-14, 12], [-5, -18], [0, 19], [13, -14], [-23, -10], [17, -35], [36, -12], [26, 13], [-26, 26], [-15, 42], [-25, 0], [-29, 20], [-22, 3], [4, -19], [-21, 16], [-20, 35], [-11, 29], [-38, 0], [30, -6], [-7, -11], [-11, 21], [-24, 47], [-10, 22], [3, -22], [16, -7], [33, -11], [-21, -6], [9, 1], [0, -30], [40, -8], [-28, 10], [-8, 25], [4, 29], [-50, 14], [20, 4], [5, -1], [33, -6], [18, -1], [-26, -9], [33, -27], [10, 14], [-27, 6], [42, -30], [-4, 17], [-43, 20], [-31, -1], [-33, 25], [-30, -6], [24, -38], [29, -1], [-36, -8], [17, 0], [27, -30], [-2, -4], [8, -36], [6, 3], [-3, 30], [36, -8], [15, -3], [51, -12], [17, 0], [8, -32], [17, -2], [5, -31], [-33, 48], [-13, 26], [-3, -20], [-15, 2], [5, -20], [27, 5], [-33, 3], [-3, 23], [-7, 28], [-28, 5], [24, 6], [-19, 25], [-19, 27], [-21, 24], [-5, -26], [-6, -26], [9, 17], [32, -20], [39, -24], [-19, -27], [-8, -4], [-8, 5], [-55, 10], [31, -20], [-27, 54], [42, -35], [-18, -25], [18, -22], [54, -6], [-11, 31], [-16, 7], [40, -36], [24, -4], [18, 23], [0, 19], [43, 16], [-11, 21], [21, -27], [-42, 4], [-42, 21], [9, 1], [7, -39], [-60, 12], [30, 5], [41, -38], [-12, 3], [37, -27], [15, 10], [-45, 9], [46, -13], [23, -24], [-21, 6], [6, -12], [38, 1], [32, -19], [-13, 5], [-11, -1], [-3, 30], [-52, -9], [-36, 2], [-10, -28], [52, -29], [-23, -15], [-43, 35], [-50, 30], [2, -7], [-8, 5], [1, 17], [-60, -6], [3, -16], [58, 1], [-40, 35], [-30, 24], [-65, -6], [17, 20], [-30, -21], [-21, -21], [-43, -10], [-33, 21], [27, -52], [-37, -22], [1, -42], [4, 22], [-15, -36], [-6, 9], [27, -2], [-33, -20], [8, -32], [17, -32], [16, -27], [-6, -24], [-14, 15], [-29, 32], [-41, 57], [14, -24], [27, 5], [-32, 71], [-19, 12], [-22, 23], [-39, 42], [14, -39], [-10, 14], [-14, 0], [51, -8], [-15, -40], [-6, -33], [-33, 45], [-32, -17], [48, 21], [3, -12], [-21, 54], [-12, 9], [2, 45], [40, -68], [-33, 6], [8, -12], [16, -40], [21, -28], [-22, 39], [-4, 35], [45, -6], [-25, -21], [27, 10], [6, 8], [47, 1], [-33, 48], [-37, 16], [-18, -9], [17, -20], [15, -3], [-28, -5], [-3, 31], [31, -17], [-58, 5], [25, -13], [-19, 8], [-25, -26], [6, 2], [78, -12], [-43, -12], [6, 15], [17, 0], [26, -32], [-2, -49], [-20, -41], [-66, 24], [-57, 33], [9, -9], [-26, 12], [63, 6], [2, -15], [-2, 28], [0, 0], [-32, 71], [16, -18], [18, -27], [20, -38], [21, -3], [19, -28], [-10, -36], [-9, -15], [84, 7], [37, -45], [13, 33], [41, -58], [27, -40], [-45, -16], [-50, 9], [-68, 5], [16, -45], [21, 3], [-55, -8], [-48, 61], [68, 8], [-55, -16], [29, -31], [-42, 33], [72, -10], [48, -72], [-25, 5], [5, 34], [15, -48], [-1, 11], [8, -24], [-36, 26], [-48, 10], [-60, 50], [56, 20], [-11, 32], [33, 3], [-76, 1], [71, -7], [68, -32], [-52, 6], [-22, -46], [3, -42], [-33, -20], [-5, 2], [-15, 4], [-54, 42], [28, -36], [-75, 27], [-50, 9], [-27, 18], [-59, 0], [-28, -40], [-33, -29], [9, -66], [60, 15], [11, -18], [22, -35], [-40, 52], [-29, 3], [-44, 43], [-13, 25], [32, -50], [-47, -6], [54, -21], [12, -10], [31, 2], [-84, -12], [-18, 10], [4, -24], [-35, 64], [-33, 8], [48, -66], [85, -18], [57, -75], [17, 8], [-18, -15], [57, -50], [39, -24], [24, -48], [-11, 6], [53, 23], [51, -65], [43, -76], [-6, -24], [43, -47], [75, 0], [-28, -2], [32, 5], [53, 16], [-32, -41], [70, -21], [57, -54]];
    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_n();".
// 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_n(: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_n();".
// 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_n( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9025_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, 1, 1]>,<3,R![1, 3, 1]>,<7,R![3, 1]>,<11,R![-1, 1, 1]>,<29,R![5, 5, 1]>],Snew);
    return Vf;
end function;