
// Make newform 8025.2.a.s in Magma, downloaded from the LMFDB on 26 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8025_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_8025_2_a_s();".
// 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_8025_2_a_s();".
// 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_8025_a();"
function MakeCharacter_8025_a()
    N := 8025;
    order := 1;
    char_gens := [5351, 1927, 751];
    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_8025_a_Hecke(Kf)
    return MakeCharacter_8025_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], [1, 0], [0, 0], [2, 0], [-4, 2], [1, 0], [1, -4], [-3, -2], [0, 4], [0, -2], [-6, 0], [-1, 0], [4, -8], [4, -2], [-4, 2], [-8, 2], [0, 8], [7, -12], [-6, 2], [-3, -2], [4, -10], [-8, 12], [4, 4], [-6, 2], [4, -6], [-8, 6], [8, 2], [1, 0], [-10, 8], [-3, 4], [-4, 6], [11, -2], [-2, -10], [-6, 4], [10, -4], [1, -10], [12, -6], [8, -8], [-11, 6], [-5, 0], [-23, -2], [-8, 6], [-13, 2], [2, 8], [-14, 0], [-5, 14], [14, 8], [-1, 10], [-16, -6], [16, -10], [8, -12], [-8, 18], [17, -12], [-8, 2], [-6, -12], [4, 0], [9, -12], [-11, 14], [8, -6], [6, -4], [-19, 2], [-26, 6], [-6, 16], [5, 10], [-1, 16], [18, -20], [19, -22], [-3, 12], [3, -6], [-16, 26], [-14, 20], [-17, -10], [0, 18], [15, 12], [10, -10], [-4, 24], [6, -8], [-10, 24], [-18, 0], [22, 2], [17, -14], [-29, 0], [-6, 6], [10, -18], [-28, -4], [12, -24], [-21, 24], [23, -28], [14, 6], [24, -16], [14, -14], [-9, 18], [-10, -16], [-17, 2], [-8, -10], [-14, 26], [-6, 8], [-1, -12], [-26, 14], [-16, -4], [-29, 2], [-35, 16], [-29, -2], [-32, -6], [-1, 10], [33, 8], [-20, 14], [29, -8], [10, 0], [-32, 10], [-12, -2], [-12, 36], [-23, 24], [10, 14], [22, -10], [-13, -8], [19, -26], [-8, 24], [18, 2], [-36, 16], [-2, 8], [-26, 2], [-22, -4], [-10, 8], [21, 10], [-9, 28], [24, -28], [-15, 18], [13, 18], [18, -26], [16, 6], [34, 8], [12, -22], [4, 6], [4, 12], [34, -24], [14, -40], [12, 12], [-4, -14], [17, -36], [36, 0], [-25, -8], [20, 8], [5, 18], [-32, 2], [-22, 14], [-20, -18], [26, -6], [39, -6], [25, -2], [-6, 34], [20, -36], [-47, 6], [13, -2], [12, -20], [-32, -8], [6, -4], [-13, 24], [1, 4], [-34, -6], [-28, 16], [-22, 32], [11, -18], [-37, -6], [2, 32], [-37, 6], [8, -26], [53, 4], [14, 22], [13, 16], [24, -50], [-12, -26], [-9, -10], [26, -44], [7, -26], [-28, 36], [38, 6], [1, 16], [5, 22], [-12, 42], [16, -34], [31, 14], [18, 8], [-26, 8], [-4, 20], [40, -28], [34, 12], [12, -16], [6, -44], [-8, 24], [-25, 36], [-24, 32], [-16, 24], [20, 0], [-6, -34], [-24, -24], [-4, 18], [38, -16], [-8, -6], [48, -16], [52, -20], [12, 30], [20, 8], [-44, 0], [28, 8], [22, 20], [40, -24], [20, -8], [34, -4], [32, -36], [11, -28], [6, -28], [31, 2], [-50, 6], [-40, 0], [31, 20], [-42, 10], [-19, 12], [48, -10], [44, -14], [-26, 28], [-20, 20], [-57, 20], [4, -4], [-42, 14], [-10, -16], [-44, 16], [-42, 8], [-4, -12], [17, 26], [-23, -4], [-10, 34], [-4, 4], [-34, 12], [49, -18], [-1, 6], [-8, 20], [-10, 4], [46, -18], [20, -40], [-28, -6], [47, -30], [28, -12], [-44, 36], [25, -4], [32, 28], [13, -42], [-43, 26], [-24, 0], [12, -12], [69, 0], [-39, -8], [49, -34], [11, -28], [29, -52], [54, 2], [-14, -20], [24, 4], [-58, 8], [10, -32], [-22, 56], [20, -24], [38, 20], [46, -4], [44, -60], [-38, -26], [-70, 12], [14, -44], [-3, -6], [-2, 0], [-26, 4], [69, -6], [-50, 16], [20, -8], [26, 14], [14, -32], [16, -48], [-16, -20], [49, -16], [42, -50], [-12, -12], [49, -38], [11, -38], [25, 24], [1, -10], [14, 12], [-52, -4], [59, -28], [6, -32], [-29, 0], [21, -12], [-64, 12], [-3, 0], [21, -18], [-2, 32], [-36, 36], [-51, 10], [10, -20], [32, -36], [35, -42], [-32, 10], [23, -20], [36, -52], [3, 50], [-24, -24], [-54, 14], [68, -22], [-30, 12], [17, 22], [8, -24], [-32, -2], [46, -18], [54, -14], [38, 10], [76, -12], [50, 8], [45, 2], [28, -8], [14, -56], [-19, 0], [-38, 20], [-20, -28], [-40, 22], [25, -42], [-42, -28], [0, 10], [-20, -12], [-2, 0], [-27, 6], [-18, 20], [17, -44], [-31, 12], [-33, 66], [44, -16], [-27, -10], [23, -62], [50, -34], [46, -28], [15, 12], [-87, 10], [-8, -12], [49, -72], [-14, -28], [-85, 14], [6, -20], [34, -58], [-64, -16], [-33, 58], [67, -42], [-34, 56], [-36, -2], [15, -8], [-14, 28], [24, 16], [59, -40], [-60, -14], [53, -2], [-24, -32], [1, 44], [-16, 8], [-2, 16], [26, -18], [33, -50], [-60, 38], [52, 2], [19, -24], [-32, 20], [11, 46], [4, 14], [4, -44], [-62, 60], [0, -12], [70, -16], [-15, 46], [64, -32], [20, 12], [-48, -10], [-38, 64], [-18, -42], [10, 16], [4, -38], [-62, -8], [-37, -6], [-24, 44], [-22, 14], [-64, -8], [-54, 0], [-54, -4], [-50, 10], [-38, 22], [-53, 56], [-22, 0], [-99, 2], [8, -6], [50, -50], [32, -46], [49, 30], [3, 28], [-11, 18], [82, 0], [32, -40], [-59, 12], [20, 20], [0, 38], [-26, 44], [-20, -48], [-28, 42], [-66, -18], [62, -32], [2, 4], [6, -48], [15, -36], [54, -16], [56, -20], [25, -64], [48, -28], [-41, -10], [60, 0], [-54, 52], [-54, 16], [-45, 60], [-22, -14], [-56, -20], [39, -66], [-67, 0], [-35, -4], [37, -86], [27, 24], [-8, -24], [-26, -20]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8025_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8025_2_a_s();".
// 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_8025_2_a_s(:prec:=2)
    chi := MakeCharacter_8025_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_8025_2_a_s();".
// 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_8025_2_a_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8025_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, -1, 1]>,<7,R![-2, 1]>,<11,R![4, 6, 1]>,<13,R![-1, 1]>],Snew);
    return Vf;
end function;