
// Make newform 9025.2.a.u in Magma, downloaded from the LMFDB on 26 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_u();".
// 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_u();".
// 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, 1], [1, -2], [0, 0], [1, 2], [-1, 4], [-2, 0], [0, 3], [0, 0], [-2, 2], [-6, 0], [-3, 3], [9, -3], [8, -1], [4, -9], [6, 1], [-8, 1], [6, -2], [9, -9], [1, -6], [11, -4], [1, 6], [-1, 0], [7, -5], [6, -6], [9, -1], [8, -13], [2, -2], [-15, -3], [5, -8], [2, -7], [-4, 3], [-12, 0], [6, 2], [-14, 0], [-3, -4], [12, -11], [-18, 10], [6, -2], [-2, -2], [-3, 14], [5, -10], [9, 6], [-5, -8], [-1, 15], [1, 4], [0, 12], [9, 2], [-7, 16], [8, 4], [-2, 14], [23, -4], [-9, 6], [13, 0], [14, -5], [22, -11], [21, 1], [7, -10], [0, -7], [-12, 0], [-3, -1], [-27, 2], [-7, -4], [-18, -9], [13, 2], [7, 8], [-2, 8], [-1, 9], [5, -6], [27, 4], [15, -26], [-23, 4], [13, -22], [6, 4], [18, -3], [-12, 30], [20, -26], [2, -4], [-12, 13], [-20, 16], [-31, 9], [-16, 4], [15, 0], [-12, 14], [1, 20], [-9, -17], [24, -7], [-7, -11], [9, -9], [13, -13], [18, -37], [27, -15], [3, -19], [19, -18], [-31, 2], [25, -22], [-12, 19], [8, -13], [-17, -2], [4, -1], [30, -14], [-13, 12], [-15, -17], [-19, 22], [-15, -6], [-14, 36], [-2, -28], [39, -7], [23, -22], [-1, 26], [25, -27], [-7, 21], [-20, 17], [18, -17], [9, 17], [0, -21], [-27, 6], [7, -28], [-6, 17], [15, -18], [27, -26], [9, 12], [19, -10], [28, 5], [19, 11], [15, -14], [-36, -8], [-30, 24], [-9, -2], [3, -27], [0, 31], [-13, 9], [12, -2], [-42, 9], [19, -16], [29, -1], [-9, 15], [27, 13], [-8, -22], [-32, 37], [1, -2], [8, 1], [-19, 29], [6, 19], [27, -36], [-1, 0], [-51, -2], [42, 3], [-41, 10], [20, -5], [-15, 29], [-24, -13], [1, 4], [30, -32], [24, 8], [-29, 42], [-18, -3], [-3, -17], [19, 4], [-12, 24], [-29, -19], [6, -27], [-6, 12], [-2, 5], [37, -11], [5, -23], [21, -21], [-4, 12], [24, -19], [-10, -15], [-17, 11], [-21, 18], [7, -40], [29, 14], [-33, 3], [-4, -3], [1, -7], [0, -29], [8, 17], [-31, -17], [-4, -5], [19, -9], [2, 13], [-29, -15], [11, -41], [26, 8], [28, -13], [36, -36], [-6, -10], [12, -9], [7, 1], [9, 10], [-33, 42], [-35, 51], [34, -32], [-33, -12], [17, -11], [12, 27], [-33, 45], [-31, 26], [41, -5], [43, -7], [-21, -25], [30, -36], [-32, -9], [-15, 0], [-56, 16], [17, -36], [33, 10], [21, -45], [-9, -12], [-7, 0], [0, 5], [-34, -8], [21, -14], [24, 28], [-12, -12], [24, 0], [-21, -7], [-2, -5], [46, -43], [30, 1], [-10, 15], [-31, 11], [24, -20], [10, -26], [33, -3], [-31, 14], [24, -5], [5, -24], [-57, 24], [-26, 26], [-2, 0], [27, -15], [18, 6], [30, -8], [5, -13], [52, -3], [36, -10], [-47, 22], [-11, 25], [3, 29], [3, 16], [-4, 4], [30, 19], [9, -15], [6, 3], [28, 9], [-5, 1], [7, -48], [0, 30], [25, -4], [-67, 10], [43, -2], [32, -23], [3, -7], [48, -36], [1, -9], [7, 0], [-12, 1], [4, 3], [-26, 9], [46, 7], [2, 33], [3, -36], [20, -53], [-32, 33], [-41, 28], [-45, 11], [52, -21], [18, 24], [-50, -9], [-3, 2], [18, -24], [-44, -7], [-40, 34], [-51, 15], [-11, -28], [36, -24], [19, -6], [-28, -10], [-66, 5], [-36, 12], [21, -7], [24, 10], [18, -28], [-15, 9], [-40, 1], [-11, 19], [-55, 4], [2, 7], [50, -4], [46, 20], [-7, 32], [-43, 50], [9, -18], [8, 20], [-15, 21], [-18, 36], [-56, -2], [-55, 31], [0, -30], [-54, 18], [33, 6], [57, -36], [33, 7], [-8, -4], [0, -3], [-18, 1], [39, -26], [-11, -24], [39, -44], [28, -8], [-68, -8], [-39, 4], [36, -9], [-30, 66], [-7, -34], [46, -17], [14, -2], [2, 43], [-1, -24], [-9, -6], [-38, 10], [45, -14], [45, -63], [-9, 40], [-34, 63], [7, 18], [-28, 20], [-3, -42], [14, 34], [45, -48], [15, -6], [-18, 27], [41, 4], [-37, 40], [-20, -21], [-54, 48], [-25, -36], [23, -18], [-13, 54], [49, -56], [47, 20], [-36, 24], [24, 0], [9, 33], [-68, 20], [-25, -11], [5, 55], [-24, 42], [-56, 41], [-26, -6], [-15, -8], [25, -48], [-17, -19], [-11, 34], [25, -1], [5, -25], [25, 22], [20, -4], [39, -14], [3, 12], [-34, -31], [-40, 22], [-15, 42], [-34, 30], [6, 0], [19, -31], [6, -62], [9, -19], [33, -57], [19, -32], [60, -32], [72, -6], [28, 6], [65, 4], [-11, 68], [6, 6], [-14, 13], [-12, 22], [-23, 52], [51, -41], [-53, 21], [5, -26], [36, 9], [18, -11], [12, 25], [39, 8], [19, 2], [52, -43], [27, -25], [39, 1], [28, 38], [42, -49], [9, 9], [66, -46], [83, 6], [-74, 7], [-43, 34], [18, 11], [-36, 24], [45, -17], [17, -74], [55, 14], [-42, 42], [55, -18], [-82, 9], [-8, 56], [66, -15], [-6, 2], [32, 36], [60, 19], [-70, 16], [-48, -9], [20, -32], [9, -49], [75, 2], [59, 12], [99, -9], [-63, 34], [14, 28], [-5, 21], [-57, 29], [-19, -7], [38, -54], [-99, 15], [15, -42], [91, -29], [-38, -15], [-61, 65]];
    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_u();".
// 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_u(: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_u();".
// 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_u( : 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, -3, 1]>,<3,R![-5, 0, 1]>,<7,R![-1, -4, 1]>,<11,R![-19, -2, 1]>,<29,R![6, 1]>],Snew);
    return Vf;
end function;