
// Make newform 5290.2.a.g in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5290_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_5290_2_a_g();".
// 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_5290_2_a_g();".
// 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 := [-3, 0, 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_5290_a();"
function MakeCharacter_5290_a()
    N := 5290;
    order := 1;
    char_gens := [2117, 2121];
    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_5290_a_Hecke(Kf)
    return MakeCharacter_5290_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, 0], [0, 1], [1, 0], [1, 1], [-2, -2], [2, 2], [-3, -2], [-2, -1], [0, 0], [-3, -1], [-7, 1], [0, -2], [6, 2], [1, -4], [-1, -7], [3, 1], [-7, 0], [-4, 4], [-1, -4], [3, 7], [0, -1], [-3, 1], [-11, -4], [8, -2], [8, 4], [0, -4], [0, 2], [-10, 0], [7, -3], [3, -2], [9, -1], [-3, 2], [5, -2], [9, -2], [-21, -1], [-4, 2], [-16, 0], [-2, 6], [-11, 5], [21, -1], [-11, -4], [10, -8], [-3, 5], [4, 1], [10, 0], [1, -5], [7, 8], [-14, 8], [-17, 6], [25, 1], [6, 7], [10, -6], [8, -3], [8, 7], [20, 1], [-12, 2], [-8, -12], [6, 4], [1, -17], [-10, 3], [-17, 6], [2, 4], [2, -7], [-9, 1], [-1, 14], [-15, 7], [9, -10], [-7, -2], [8, 5], [18, 6], [18, 5], [-15, 7], [-13, 9], [-11, 5], [-22, 1], [-12, -10], [-20, -2], [-13, 7], [-4, 15], [-13, -6], [-18, 9], [-7, -3], [-4, 4], [2, -4], [-7, -15], [12, 7], [-5, 4], [2, 18], [-28, 6], [6, 0], [16, 10], [21, 5], [-8, -8], [4, -2], [5, 0], [-22, -2], [9, -1], [-38, 0], [16, 6], [-17, -11], [-12, 6], [-15, 13], [-21, 4], [-4, -9], [-16, 13], [-14, -17], [-16, -5], [-28, -1], [15, 13], [-14, 10], [3, 1], [7, 9], [-25, -10], [-8, 20], [-17, 1], [-12, -17], [-12, 10], [20, -4], [-37, 1], [4, 9], [33, -3], [-6, -19], [7, -17], [-16, 1], [-36, -2], [-27, -7], [5, 7], [27, 5], [-26, -10], [-3, -21], [18, -20], [-3, -9], [28, 12], [5, -25], [-37, -10], [4, -10], [8, -12], [5, 2], [-7, 13], [-23, 12], [13, 16], [-6, -6], [29, -3], [-3, 6], [0, -18], [0, 14], [38, 4], [36, -7], [-15, -10], [17, -3], [16, -12], [30, -16], [-28, -13], [-3, -13], [15, -16], [18, -12], [-5, 9], [6, 12], [11, -22], [11, 21], [2, 13], [-16, 8], [20, 6], [0, -21], [-46, 6], [-10, 0], [8, -18], [10, 24], [14, -11], [3, 7], [30, 5], [-8, -2], [-18, 14], [37, 2], [14, 12], [52, 1], [-46, -4], [-10, 4], [-13, -13], [28, 4], [-13, 11], [-64, -1], [17, -5], [40, -4], [-39, 7], [0, 20], [5, -11], [37, 2], [29, -8], [-37, 9], [-44, -7], [-8, -13], [10, 18], [-41, -5], [15, 4], [21, 8], [42, -8], [24, 12], [30, -2], [14, 0], [-18, 4], [-9, 19], [-33, -9], [0, 6], [-44, -15], [2, 16], [-14, -22], [0, 34], [39, 2], [-34, -12], [-8, 7], [45, -1], [37, -11], [24, -26], [14, -10], [36, 17], [14, 30], [23, 28], [-7, -11], [-14, -2], [-22, 10], [1, -17], [21, -12], [-7, -9], [-6, 23], [38, -8], [26, -6], [18, -22], [-28, -8], [-9, -4], [11, -13], [24, 9], [23, 3], [17, -2], [-8, 18], [6, 4], [-18, 23], [17, 23], [12, -24], [-50, 10], [0, 20], [-7, -12], [16, -4], [-26, -12], [-18, 3], [0, 12], [25, -11], [6, 9], [-22, -10], [43, 9], [-3, -13], [-2, 9], [4, 22], [-28, 0], [-1, 25], [31, -24], [10, 30], [45, -10], [-31, -1], [24, 6], [-32, -10], [-9, 34], [15, 9], [34, -12], [0, 21], [-6, 25], [18, -2], [28, -28], [-48, 0], [19, 5], [-47, -15], [-3, 6], [66, -4], [44, -16], [22, -23], [-2, 16], [36, 4], [-26, -12], [26, 29], [-72, 3], [3, -21], [-38, 0], [30, -10], [-28, 0], [46, -5], [37, -1], [22, -20], [12, 24], [-31, -9], [-33, -4], [-36, 4], [-57, 12], [-36, -13], [-18, -3], [13, -23], [21, 11], [-52, -2], [-36, 14], [-23, -18], [8, -6], [-27, 4], [-5, 27], [-35, 21], [-10, 23], [-48, 11], [32, 13], [8, -7], [41, -15], [-8, -8], [6, 34], [-42, -6], [-25, 23], [30, -15], [2, 15], [55, 11], [-2, -29], [12, -34], [-6, 42], [-19, 18], [-39, -2], [-6, -11], [13, 0], [-1, 15], [25, -31], [42, -16], [-36, -15], [-32, 6], [16, 19], [49, -21], [-24, -20], [-22, 30], [-9, -21], [37, -11], [20, -1], [2, -14], [82, 3], [-2, -2], [-1, 18], [-59, -10], [-9, -31], [10, -18], [-21, -2], [-39, -29], [62, -4], [25, 9], [42, -20], [43, -17], [14, 9], [36, -18], [-63, 9], [4, -36], [-18, 39], [65, -15], [-26, 8], [-17, -17], [32, -20], [-11, -23], [-16, -16], [-40, -2], [-75, -11], [46, 12], [-19, -14], [-72, -14], [20, -25], [-24, -9], [-50, -21], [6, -32], [-39, -1], [-52, 21], [22, 12], [-70, -12], [-76, 0], [-67, 7], [9, -15], [-26, -20], [-84, 0], [-3, 29], [-46, 22], [14, 43], [22, -11], [20, 10], [-14, -24], [-31, 15], [-34, -21], [-34, -30], [-14, -12], [1, -53], [-51, -7], [48, 8], [34, -20], [-10, 17], [25, 19], [-13, -4], [-2, -18], [-4, 4], [11, 30], [-13, 13], [-4, -27], [8, 21], [-27, -3], [25, -33], [40, -27], [-37, 17], [-30, 4], [35, -1], [-23, 21], [16, -22], [-13, -34], [35, 22], [-13, -42], [64, 6], [28, 22], [11, -18], [4, -35], [49, -16], [-15, -5], [34, 8], [-23, -15], [59, 8], [-6, 10], [15, -21], [-17, 33], [40, 16], [-3, 18], [96, -6], [-71, -11], [39, 0], [-21, 50], [-35, -16], [54, -2]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5290_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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