
// Make newform 5625.2.a.g in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5625_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_5625_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_5625_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 := [-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_5625_a();"
function MakeCharacter_5625_a()
    N := 5625;
    order := 1;
    char_gens := [4376, 1252];
    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_5625_a_Hecke(Kf)
    return MakeCharacter_5625_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], [0, 0], [0, 0], [2, 0], [3, 0], [1, 0], [-1, -2], [3, -6], [7, -1], [2, 1], [-1, 6], [2, 0], [11, -1], [9, -1], [-8, 2], [8, 2], [9, -8], [-1, 6], [-3, 10], [-2, -5], [-6, -6], [-14, 3], [9, 0], [-5, 10], [1, -3], [11, -1], [-5, 12], [-6, 3], [-9, 3], [-7, 2], [9, -14], [-2, 10], [15, -9], [-6, 12], [5, 5], [-5, -1], [-2, 3], [6, -15], [0, 11], [9, -5], [-7, 14], [-6, -4], [-6, -7], [11, 0], [8, -5], [2, 6], [-3, 0], [15, -3], [9, -2], [0, -10], [-6, 10], [-23, 1], [-4, 7], [-15, 21], [-6, 23], [15, -17], [27, -4], [8, -12], [26, -8], [-2, 10], [-12, 6], [5, -7], [-4, -3], [20, -4], [-12, 6], [6, 9], [13, -27], [17, 10], [-12, 15], [4, 2], [-14, 1], [-11, -8], [19, -4], [2, -12], [-12, -1], [18, -8], [22, -14], [9, -4], [-12, -15], [24, -18], [11, -7], [2, -20], [-33, 2], [3, -4], [-11, -13], [0, -12], [11, -17], [-16, 16], [3, 10], [-10, 27], [9, -12], [13, -11], [-15, -1], [-11, -7], [-15, 0], [-25, 13], [-7, -16], [-32, -5], [13, -9], [-36, 6], [-15, -6], [-15, -14], [9, 0], [6, 3], [-9, -18], [-28, 15], [-6, 28], [16, 1], [-15, -15], [-15, -6], [18, 3], [35, -18], [22, 2], [10, 15], [-14, 2], [12, 7], [-14, 5], [2, -13], [7, 14], [-1, 2], [-21, 16], [-5, 32], [-19, -16], [35, -22], [7, 5], [26, 14], [-23, 11], [6, 18], [29, -9], [15, -3], [8, -6], [-23, 4], [25, -6], [-8, -15], [13, -10], [9, -28], [10, -32], [-22, 3], [25, -34], [-7, 29], [18, -32], [7, -8], [14, 9], [15, 21], [-21, -18], [-34, 23], [-33, 33], [22, -8], [-14, 18], [-29, 26], [-14, -18], [-7, -5], [-47, 11], [-4, 29], [17, 0], [11, -16], [-5, 0], [-6, 22], [-9, 12], [-24, -21], [15, -24], [-55, 8], [16, 12], [-4, -16], [-15, -14], [-23, -1], [32, 0], [45, -26], [-34, -12], [-31, 35], [-33, 36], [-17, 33], [-27, 10], [31, 0], [45, -15], [36, 8], [-27, 23], [1, -16], [30, -13], [-29, -12], [23, -42], [8, -5], [-40, 37], [-30, 21], [49, -10], [-45, 10], [-17, 33], [26, -5], [15, 15], [33, 15], [-24, 5], [-18, -1], [-9, 17], [17, -8], [12, 22], [-15, 18], [5, 19], [-31, 34], [13, -5], [-21, 30], [-9, -12], [48, 3], [15, -36], [40, 15], [-54, 3], [1, -11], [27, 6], [-13, -31], [13, -26], [10, 14], [-33, 45], [7, -38], [-13, -2], [41, -31], [-14, -7], [42, -10], [-9, 17], [22, -43], [34, -37], [-21, -30], [-36, 21], [-15, 0], [-2, 29], [23, -54], [22, -43], [21, -12], [-32, 32], [24, 12], [16, -13], [-11, 38], [3, -24], [34, -13], [45, -31], [3, 0], [48, -34], [-54, 4], [3, 39], [-5, -17], [-11, 2], [-57, 30], [21, -29], [-43, 30], [7, 8], [-50, -10], [-19, 26], [-43, 1], [24, 16], [-9, 24], [36, -27], [27, -36], [-36, 26], [3, -30], [58, -5], [14, -18], [-23, 19], [21, -7], [-19, 7], [-8, -25], [-36, 3], [-18, 0], [-27, 46], [0, 1], [-21, 42], [-45, 7], [-30, 11], [-19, 58], [27, 11], [5, -34], [11, 25], [-17, 22], [51, -18], [11, -48], [48, 11], [-43, 36], [38, -32], [-18, 3], [-26, 8], [-13, 16], [40, -31], [-30, 16], [18, -3], [11, 7], [28, 25], [6, 7], [12, -15], [33, -20], [22, -37], [-24, 39], [-6, 27], [1, -22], [27, -18], [11, 29], [-16, 50], [35, -4], [60, 12], [-49, 23], [-38, 15], [40, -22], [-16, 2], [9, -54], [-27, -4], [10, -49], [12, -24], [-49, 16], [33, -2], [-12, -32], [-3, 52], [-2, -1], [-21, -18], [-8, -7], [19, 20], [34, -28], [-49, 64], [-19, 10], [21, 39], [15, 15], [6, -22], [-3, -38], [-72, 6], [-11, 37], [3, -12], [53, -12], [45, -4], [23, -24], [-5, -2], [5, -11], [-46, 22], [-81, 14], [-53, 32], [-36, 0], [-23, -25], [40, -29], [0, 0], [-14, -4], [3, -32], [45, -29], [0, 45], [-7, -8], [39, -9], [-51, 51], [-33, -12], [29, -22], [63, -46], [-63, -15], [48, -18], [-39, 48], [21, -68], [39, 6], [24, -12], [-33, 52], [33, -27], [-58, -5], [-39, 34], [12, -27], [-8, -34], [-21, -30], [37, 1], [28, -20], [-59, 49], [12, 39], [47, -15], [-3, -28], [37, 2], [63, -6], [-43, 70], [-57, 21], [20, -29], [66, -30], [-63, 30], [70, -29], [-6, 27], [65, -22], [60, -30], [-25, 24], [37, 5], [25, -20], [18, 20], [-29, -30], [34, 2], [19, -9], [-7, -35], [3, -48], [-21, 21], [5, -19], [10, 0], [24, -45], [-11, 6], [25, -66], [37, -12], [14, -7], [-46, -8], [-12, 32], [-60, 5], [-14, 62], [-51, 63], [75, 12], [44, 12], [-6, -33], [33, 13], [12, 27], [36, -27], [39, -60], [16, -3], [-6, -22], [38, -16], [-57, 8], [51, 22], [22, -53], [-3, 23], [24, 2], [-12, 41], [68, -10], [-24, -24], [-48, 30], [-76, 6], [40, 31], [69, -33], [27, 0], [26, -16], [42, 34], [24, -58], [-45, 39], [91, -16], [42, 21], [2, 13], [-39, -11], [25, -77], [-56, 67], [-6, 21], [-24, -17]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5625_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5625_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_5625_2_a_g(:prec:=2)
    chi := MakeCharacter_5625_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_5625_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_5625_2_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5625_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, -1, 1]>,<7,R![-2, 1]>],Snew);
    return Vf;
end function;