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