
// Make newform 5292.2.a.v in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5292_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_5292_2_a_v();".
// 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_5292_2_a_v();".
// 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, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-3, 1, 1], [2, 2, -1]];
    Rf_basisdens := [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_5292_a();"
function MakeCharacter_5292_a()
    N := 5292;
    order := 1;
    char_gens := [2647, 785, 1081];
    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_5292_a_Hecke(Kf)
    return MakeCharacter_5292_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, 0, 0], [0, 0, 0], [0, 0, 1], [0, 0, 0], [2, -1, 0], [1, 0, 1], [1, 1, 0], [-1, 1, 1], [4, 1, -1], [-2, 1, 0], [1, 0, 1], [1, -1, 2], [-4, -1, -1], [-2, -1, 2], [4, -2, 1], [3, 0, 3], [1, 1, -1], [-1, -2, 2], [-6, 1, -1], [5, -1, 3], [0, -1, -2], [-4, 3, -1], [-6, 0, -1], [-1, 2, -4], [-6, 2, -2], [10, -2, -1], [7, 0, 0], [13, 1, 1], [-2, 2, 0], [3, 0, -4], [-1, 3, -1], [7, 1, 2], [8, 2, -2], [13, 0, -1], [9, -3, 3], [9, 1, 2], [4, 0, -3], [-1, -3, -3], [-11, 4, -1], [6, 3, -2], [8, 2, 5], [-5, 0, -5], [16, 1, 4], [-10, -3, 3], [-6, 0, 1], [7, 0, 0], [11, -3, 0], [-17, 0, -3], [-3, 3, 3], [7, 3, -1], [13, -2, 2], [8, -1, -1], [1, 0, -6], [-3, -3, 0], [1, -2, 4], [13, 1, 1], [20, -1, 0], [-10, 1, -1], [16, -1, 2], [-1, -1, -3], [1, -3, 2], [-9, -3, -3], [0, -1, -2], [-6, 0, -2], [-7, 4, -6], [1, 4, -5], [4, -4, -1], [11, 3, 2], [12, -6, 0], [-12, -4, 1], [4, 4, -5], [14, -1, -2], [-2, -6, 0], [14, 0, 4], [2, 0, 1], [5, -1, -5], [-9, -3, -1], [-2, -6, 7], [2, 5, 5], [2, 7, -5], [-7, -4, 8], [-4, 3, -7], [5, -1, -4], [-13, 7, 1], [-13, 4, 2], [18, -3, -2], [-18, 3, 2], [-22, -3, 1], [-2, 1, 5], [-4, 0, 4], [8, -1, 6], [-1, -4, 1], [1, -1, -4], [14, 5, -4], [3, 1, 8], [-2, 1, -2], [4, 1, -2], [8, -1, 2], [16, -3, 3], [-1, 3, 2], [-11, -1, -5], [-11, 1, -9], [-4, -4, -5], [-17, -5, 1], [-13, -3, -10], [-12, -4, 1], [20, -4, -2], [-19, 2, 5], [-7, 8, 2], [-15, -4, 5], [13, 3, -2], [13, -7, -5], [-6, -6, 10], [-30, 2, -5], [2, 0, 3], [9, 0, -5], [25, 0, -3], [-22, -4, 5], [-14, -5, 4], [1, 7, -13], [6, -10, 7], [10, 2, 2], [7, -8, -2], [-12, 3, -6], [-13, 4, -5], [-9, -6, -7], [-16, 3, 0], [-8, 10, 4], [-30, 2, -5], [22, 3, 7], [17, 3, 5], [30, -3, 3], [8, 0, 2], [7, -4, -2], [-17, 1, -9], [19, -3, -1], [-20, 1, -7], [17, 4, -10], [-8, 10, -2], [-12, 6, -7], [3, -4, -5], [-26, 1, -10], [-18, 4, -1], [14, 2, 11], [-14, 6, 5], [8, 2, 7], [-2, 3, -3], [14, -1, 2], [-2, 3, -3], [-15, 0, -1], [6, -8, 8], [23, 2, -1], [-2, 5, -7], [-4, -4, -4], [8, 6, -10], [19, 1, 7], [-39, -2, 2], [-47, 1, -2], [-22, -2, -5], [-22, -1, 0], [0, 3, -1], [8, 2, -9], [8, 6, -3], [-13, -1, 5], [13, -11, -2], [-30, 3, 0], [-10, 0, 9], [-5, 9, 6], [-16, 3, -9], [-1, -1, 5], [-16, -4, 4], [-3, 11, -2], [7, -2, -11], [38, 0, 5], [-2, -3, -8], [24, -9, 1], [-13, 3, 5], [-26, -2, 5], [1, 3, 0], [20, -8, 4], [11, 9, 5], [18, -3, -4], [27, -2, -7], [-7, -7, 6], [-5, 1, -3], [8, 2, -13], [-11, 5, 10], [-24, -4, -4], [20, 3, -10], [-17, 7, 1], [-11, 0, -4], [21, 0, 0], [-9, -2, 11], [3, 6, 2], [14, -10, 8], [3, -3, 8], [-17, 5, -10], [-21, 7, -10], [24, 0, 3], [2, -4, -7], [-47, 1, 4], [-23, -3, -8], [7, 3, 6], [23, -5, -1], [17, 5, 8], [0, -6, 12], [10, 3, -12], [15, 3, 0], [-17, 1, -8], [-8, -3, 0], [16, -4, 5], [-18, 3, -5], [-14, -4, -2], [-8, -8, -4], [25, 1, -5], [-44, 6, 3], [15, -8, 11], [-16, 8, 7], [0, 9, 4], [-3, 6, -5], [1, 2, 15], [9, -7, 16], [-34, -4, -7], [-21, -5, -7], [4, 4, -11], [32, -3, -3], [-13, 14, -5], [-3, -3, 5], [13, 6, 4], [-14, -2, -11], [-4, 6, -16], [42, -10, 1], [20, -12, -5], [25, 10, -11], [-10, -2, 7], [-20, -2, -17], [10, -3, 11], [13, -8, 4], [-3, -9, 0], [-20, -2, 2], [17, 5, -15], [25, -3, 12], [31, 6, -6], [28, -1, 13], [42, -3, 8], [-41, 7, -5], [-14, 9, 4], [-2, -5, 6], [-10, -6, -6], [38, -1, 8], [-24, 1, -16], [-20, -2, -17], [9, 0, -12], [12, 8, 7], [0, -9, -7], [-13, 2, 12], [-28, 0, 9], [-2, -9, 1], [11, -4, 3], [22, 6, 6], [-1, 9, 13], [13, -11, -9], [-27, -7, 1], [1, -6, -4], [0, 0, 0], [-19, -8, 0], [-51, 3, -3], [0, 9, 4], [-3, 10, -10], [-36, 0, -15], [-17, 0, -17], [5, 3, -6], [10, -6, -2], [35, -3, -3], [0, -4, -8], [-28, -8, 5], [-21, 9, 4], [-13, 3, -16], [2, 9, -5], [4, -2, 1], [-41, -2, 1], [11, 3, -16], [12, -12, 0], [16, -15, 0], [-1, 4, 14], [4, -2, -7], [-19, 3, -1], [-28, 5, 3], [-8, -3, 0], [-32, -2, 1], [1, 7, 1], [23, 5, -13], [51, -6, -3], [14, 5, -9], [-16, 6, -3], [1, -5, -5], [21, 5, -4], [-19, -10, 8], [-11, 7, 4], [-8, 3, -2], [-21, -7, 7], [0, 3, 6], [3, 1, 8], [37, -11, 1], [-38, 2, -16], [-27, -5, -14], [12, 0, -16], [-47, 0, -12], [15, 0, 1], [1, 8, 11], [33, -12, 9], [-8, -14, 6], [50, 5, 4], [20, -3, 12], [9, 12, -16], [20, 4, -14], [-49, 5, 5], [2, -16, 19], [38, 1, -2], [-22, -4, 5], [-29, 3, -9], [-1, 3, 1], [1, 4, -14], [2, -9, 7], [48, -9, 2], [-31, -2, 7], [-31, -3, -12], [-6, 17, -14], [32, -10, -9], [17, 2, 0], [-1, -6, -12], [-24, 0, 4], [-5, 6, -14], [-17, 4, 9], [48, -5, 5], [-19, 2, -3], [25, 5, 19], [13, -2, 8], [-13, 10, -14], [-18, -1, -20], [-21, -5, 13], [35, 2, 11], [-20, -11, -5], [2, 9, -13], [22, 7, 1], [-9, -9, 15], [-8, 0, -15], [2, 3, 18], [-6, -12, 21], [27, -3, 0], [-50, 0, -15], [-13, -6, -9], [20, -16, 2], [-25, 1, 5], [18, -11, -7], [-24, -3, -7], [-37, -4, -3], [-43, 2, -7], [23, 5, -9], [29, 2, 12], [24, -11, -4], [-40, -4, -14], [-10, 14, 4], [-24, 0, -17], [44, -5, 6], [5, 6, 6], [-60, -3, -12], [-37, 3, -1], [-30, 4, -16], [14, 2, -3], [13, -3, -7], [29, -4, 14], [-44, -5, 9], [-38, 3, -4], [25, 2, 0], [47, -1, 17], [-19, 11, -18], [-30, 8, 7], [-22, -16, 16], [19, 6, 3], [-10, -7, 14], [43, 7, 15], [30, 1, -1], [11, 2, 8], [-78, -1, 4], [19, -14, 5], [-61, -3, 0], [57, -1, -8], [-28, 15, -8], [-55, -4, 7], [-17, -7, 5], [1, -5, 19], [-40, 5, -9], [29, -8, -8], [29, 2, -2], [-17, -4, 7], [42, -10, 1], [1, 19, -15], [-13, -12, 17], [40, 4, -1], [-38, -6, -15], [63, 3, 6], [-54, 4, -7], [3, 12, -23], [22, 1, 10], [14, -11, 13], [12, -5, -10], [56, -4, -1], [-47, 0, -12], [7, 13, -9], [9, -1, 7], [25, -11, -4], [25, -20, -1], [58, 5, 1], [7, 11, 2], [88, 1, 6], [-43, -1, -3], [-38, -12, 8], [-33, 3, 3], [21, 12, 10], [-12, 15, -17], [-40, -2, -2], [10, 7, -4], [-23, 13, -2], [13, -3, 21], [0, -12, 22], [30, -3, -4], [-20, 10, -14], [11, 13, 2], [36, 9, -16]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5292_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5292_2_a_v();".
// 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_5292_2_a_v(:prec:=3)
    chi := MakeCharacter_5292_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_5292_2_a_v();".
// 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_5292_2_a_v( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5292_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![9, -12, 1, 1]>,<11,R![63, -12, -5, 1]>,<13,R![21, -11, -2, 1]>,<17,R![-9, -15, -4, 1]>,<19,R![-49, -36, 3, 1]>],Snew);
    return Vf;
end function;