
// Make newform 5175.2.a.bw in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5175_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_5175_2_a_bw();".
// 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_5175_2_a_bw();".
// 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, -2, -5, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-1, -5, 0, 1], [-1, 4, 1, -1]];
    Rf_basisdens := [1, 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_5175_a();"
function MakeCharacter_5175_a()
    N := 5175;
    order := 1;
    char_gens := [4601, 3727, 2926];
    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_5175_a_Hecke(Kf)
    return MakeCharacter_5175_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, 0, 0], [0, 0, 0, 0], [1, 0, 1, 1], [-1, 0, 1, -1], [3, 1, 1, 0], [-4, -1, 1, 0], [-1, -1, 0, -1], [1, 0, 0, 0], [-1, 0, 0, 2], [-1, -2, 2, 2], [1, -4, -1, -1], [3, -4, -2, 2], [-1, 3, 4, -1], [1, 3, -3, 0], [-2, 2, 2, 4], [0, 2, 0, 0], [-3, -1, 2, -3], [-1, 0, 1, 1], [7, 4, -2, -2], [5, 1, -1, 4], [5, -1, 2, 1], [0, 5, 3, -4], [1, -3, 2, -1], [9, 2, -1, -3], [2, -2, 2, 0], [2, 1, -3, -2], [1, -1, 4, -1], [1, 3, 0, -1], [1, 0, 1, 1], [11, -7, -3, -4], [-1, 4, 6, 6], [8, -2, -2, 4], [-11, 6, 2, 0], [2, 2, -2, -4], [1, 4, 0, 2], [7, 7, 0, -1], [-7, -1, 1, -2], [10, -6, -2, -2], [2, 0, -6, -4], [7, 4, 2, -4], [-5, 6, 3, 3], [-2, -5, -5, 4], [19, -3, -3, -2], [5, 7, -1, 2], [5, 4, -1, -7], [2, 2, -2, 0], [-4, 0, 2, -6], [-3, -6, -5, -7], [13, -7, 2, -1], [-5, -5, -3, 0], [7, -4, -6, 4], [-10, 5, 5, 0], [-2, -1, 9, 2], [3, -3, -7, -4], [-9, 5, 8, 5], [-5, 4, 2, 6], [10, -2, -8, 6], [11, -1, 3, -4], [-1, 0, -5, -3], [-2, -5, -3, 0], [4, -2, 2, 4], [-4, -8, -10, -8], [5, 4, 0, 6], [22, -4, -2, -2], [14, -2, 0, 0], [-7, -8, 6, -2], [9, 1, -4, 1], [4, 0, -2, -6], [-3, -8, -8, -8], [-5, -1, -7, 0], [7, -3, -6, -9], [-6, 9, 9, 10], [12, 11, -9, -6], [-8, 0, -8, -8], [19, 5, -2, -1], [-8, 0, 4, 4], [11, 7, -7, -10], [-4, 5, -1, -6], [-7, 6, -2, 4], [-1, -5, -6, -11], [15, 2, 1, 5], [-7, -1, 0, 7], [-4, 3, 11, -2], [-13, 4, 4, 8], [3, -7, 7, 0], [-18, 6, 6, 10], [0, -7, -5, 0], [5, 14, 10, -2], [-2, -2, -6, 4], [4, 6, 0, 6], [-18, 11, 1, 2], [-1, 13, -1, 8], [-7, 4, 2, -2], [7, 4, -2, 8], [0, 6, 0, 6], [25, 6, 2, 2], [-12, -4, -12, -8], [1, 12, 1, 9], [11, 8, -8, 4], [-7, 9, 11, -8], [9, -3, 12, 1], [12, -14, -10, -8], [-18, 15, 11, 4], [18, -3, -5, -10], [9, 13, 7, -2], [5, -3, -3, -8], [10, 6, 2, 8], [4, -4, 6, 0], [-3, -2, -18, -10], [0, 4, 4, -2], [-6, -5, 15, 6], [-9, -7, 0, -7], [-10, -14, 4, -10], [-19, 11, 12, -5], [-3, 1, 6, -9], [2, 5, -1, -16], [-15, 9, 15, 6], [-1, -5, -1, -12], [-10, -5, -11, -14], [12, -12, -14, -6], [21, 7, 1, 16], [-20, 2, 12, 2], [7, 11, 9, -2], [2, 14, 8, -2], [21, 6, 3, -1], [11, -2, -3, -11], [-6, -6, 0, 14], [4, -7, -7, 10], [12, 3, -11, 4], [-1, 10, -12, -2], [-4, 5, -1, -4], [-9, 11, 6, -3], [-7, -6, 1, -9], [-1, -4, -6, -2], [6, 7, -13, 0], [-5, 13, 6, -1], [-14, -4, 10, 2], [-7, 3, -4, -1], [6, -12, -20, -8], [13, 6, 0, 16], [-14, 10, 4, 6], [-7, 11, 19, 12], [-32, 6, -2, -4], [-20, 12, 2, 6], [13, -20, -15, -13], [18, 2, 6, 6], [-19, 21, 15, 4], [-17, -4, 14, 4], [-25, -13, -1, 8], [4, -12, -12, 2], [-8, -9, 11, 4], [-2, -8, -2, -12], [-5, -1, -9, -2], [-29, -1, -10, 1], [-29, 17, 6, -1], [27, 4, -5, 1], [-9, 2, 4, -6], [11, -2, 15, 5], [8, -15, -15, 8], [9, -7, -9, 2], [12, -4, -6, -2], [1, 23, 3, 0], [-20, -16, 6, 2], [-11, -10, -23, -9], [-8, -14, 4, 2], [4, 6, 0, -6], [8, 2, -8, 4], [-35, 7, 10, 1], [17, 5, 9, -2], [9, 6, -19, 1], [15, 10, 2, 4], [0, -1, 7, 0], [4, -4, 20, 8], [5, -6, 6, 4], [3, -2, 5, 5], [-13, -14, 6, 12], [15, 4, 0, -2], [-7, 19, 16, 15], [16, -21, -13, 0], [-3, -11, -5, 10], [-3, 1, 6, 3], [7, -15, -9, 12], [-36, 2, 4, -4], [-6, -15, -17, -16], [12, 15, -13, -4], [-26, 20, 16, 12], [13, 7, -12, 11], [3, -22, -4, -2], [32, -6, -12, -10], [21, 3, 1, -6], [-16, 4, 12, 6], [18, 3, -5, 0], [18, -6, 0, 6], [-26, 11, 13, 8], [29, 11, -6, -7], [-7, -16, 3, -15], [-26, -20, 10, 10], [-8, 10, 10, 8], [27, 9, 3, 8], [-2, -2, -16, -18], [-4, 0, -6, -4], [-9, 3, 3, 8], [9, -24, -25, -7], [-12, -8, 12, 12], [21, -11, -13, 4], [-1, -6, -17, -1], [5, -15, -13, -8], [13, 6, 10, 20], [-37, 2, 10, 14], [19, 1, -9, 10], [-19, 4, 20, -4], [-3, -3, -4, -15], [-32, -6, 0, 6], [-26, 8, 18, 8], [1, 3, 0, 23], [-5, -9, 1, 4], [19, -2, 2, -14], [8, -15, -19, -6], [25, -19, -15, -8], [43, -16, -10, 4], [5, 14, 13, 5], [-7, 18, 22, 16], [-1, -10, -7, -9], [23, -7, 13, 6], [13, 12, -10, -4], [-9, 16, -19, 1], [1, 2, 8, 8], [2, -26, 2, 0], [-40, -6, 2, 2], [-40, 28, 8, 8], [-1, -6, -7, 5], [-12, -15, -9, 6], [6, -8, -22, -16], [26, -2, 12, 6], [-1, 24, 7, -1], [-16, 10, 18, 0], [41, 12, 3, -1], [7, -28, 14, -4], [-25, 20, 18, 14], [-30, 0, -2, -6], [-1, 14, 0, 0], [25, 11, -13, -10], [-11, -12, -6, 18], [4, 2, 18, 6], [-19, -22, -2, -2], [21, -15, 1, 10], [12, 26, -12, -2], [-24, -14, -4, -14], [-22, 15, -11, -4], [0, 3, -27, -12], [-32, -7, 7, -6], [18, 12, -12, -4], [-19, -2, -9, 3], [8, -22, -2, 10], [13, 0, 0, -16], [-29, 8, 5, -13], [4, 5, -7, -22], [-29, -9, 7, 12], [5, -5, 7, 0], [26, -10, -8, 14], [15, 15, -8, 15], [-16, -16, 6, 8], [19, -8, -13, -5], [-10, 18, 6, -12], [3, 17, 26, -5], [29, -30, -7, 1], [23, 15, -18, -15], [-19, -29, 8, 3], [-15, 1, 1, 12], [-5, 20, 34, 6], [-24, 22, 20, 26], [-15, -3, 0, -11], [11, -24, -21, -7], [25, -9, -3, -8], [-13, -17, 11, 6], [-8, 10, 14, 32], [-4, -22, 8, -10], [8, -7, -17, 6], [-30, 12, 6, -10], [29, -1, -9, 26], [-4, -1, 21, 10], [-11, -10, -7, 19], [8, -2, 4, 30], [-8, -2, 2, 8], [20, 14, 22, 12], [26, -14, -22, 16], [37, 3, 8, -5], [10, -10, -10, 20], [-16, 28, 22, -6], [20, 2, 0, 26], [6, -19, -27, -22], [-8, -16, -8, -20], [15, -29, -20, 3], [-29, 9, 21, 2], [-38, -10, 2, 0], [38, -23, -21, -2], [-21, 25, 29, 12], [11, -6, -24, 2], [-1, -13, 11, 14], [15, -24, -29, 11], [49, 9, -14, -21], [-18, 27, -7, -2], [-1, -3, 5, 0], [-20, -12, -20, -4], [27, -17, -7, 8], [8, 8, 20, -4], [40, 12, -12, 4], [12, -15, -33, -34], [-36, 20, 4, 12], [-3, -15, -23, 4], [11, 9, 30, -1], [32, 13, 9, -12], [7, 1, -15, 2], [-1, -5, -18, -3], [-9, -20, -1, 21], [-13, -18, -8, -18], [23, 20, -8, -10], [-12, 34, 2, 8], [13, 12, -6, -8], [3, 23, 18, -3], [15, 20, 7, -21], [-37, 12, -8, 4], [14, -14, -18, -18], [-4, 25, 21, 6], [-28, 12, 20, -4], [-18, 17, 1, 0], [-35, 27, 23, 12], [55, -4, -3, 13], [20, -1, -3, 24], [-23, 26, 28, 18], [35, 9, -1, 4], [-5, -6, -6, -18], [-17, 23, 15, 2], [-19, 1, -8, 5], [39, 15, -17, -10], [30, 31, -9, -16], [35, -4, 11, -1], [-13, -18, -10, 8], [35, 19, 8, -9], [-43, -17, 1, -12], [31, -1, -20, 19], [12, 0, -26, -22], [10, 24, 0, 20], [-26, 41, 27, -12], [28, -18, -22, 16], [15, 14, -2, -20], [0, -26, -16, 0], [-42, 14, -6, 0], [0, -11, -11, -10], [17, 14, 6, 0], [31, 11, -3, 20], [2, -20, 6, -4], [34, 4, -20, -12], [0, 3, -13, -28], [-4, -2, 0, 4], [4, -1, 15, 0], [24, -19, -17, -18], [11, 7, 17, 8], [0, 20, 24, 2], [28, -7, -23, 6], [13, -20, -6, 12], [-63, 1, 5, 4], [42, 1, -11, -12], [25, -3, -5, 0], [23, 3, -13, -30], [37, -29, -27, 0], [-17, 6, -9, 5], [4, 16, 26, -6], [1, 0, -22, -10], [-32, -12, -12, -12], [31, 19, 9, 18], [38, 29, -5, -14], [-2, -28, -30, 2], [1, -9, -21, -20], [25, 6, -20, 12], [17, 24, -1, -23], [58, -14, -2, -4], [-26, -18, 8, -6], [37, 15, -11, 0], [28, 17, 19, 18], [5, -3, 14, 23], [-22, 2, 10, 4], [-9, 9, 5, 6], [-7, -18, 7, -5], [31, -13, -11, 0], [1, 4, -10, -24], [28, -46, -18, 6], [24, 17, -7, -14], [-40, -13, -3, -12], [20, -1, -1, 24], [-4, -6, 10, -26], [-15, -20, -24, 2], [-38, 0, 8, -18], [-33, -14, -7, 17], [34, -15, 3, 0], [-5, -11, 28, -3], [-9, -6, 13, 17], [-62, -9, -3, -22], [52, -12, -6, 2], [-9, -22, -14, 10], [17, -23, 11, 0], [-15, -14, 3, -15], [40, -37, -27, -8], [31, 4, -14, -24], [1, 20, 0, 8], [17, -21, -4, 7], [29, -40, -8, -14], [-21, 18, 29, -1], [-12, -30, 6, -14], [47, 1, 17, 2], [-3, 1, -21, -12], [7, -14, -37, -15], [8, 24, -2, -6], [31, -19, -20, 17], [29, -8, -12, 0], [36, 22, -26, -2], [32, -8, 6, 0], [-1, -17, 8, 11], [1, 13, -12, -11], [-5, -28, -13, -7], [-17, -27, -18, -13], [-28, -20, 22, 6], [4, 2, -4, 26], [23, -43, -23, -2], [-35, -3, -11, 2], [-29, 23, -2, 13], [-2, -14, -8, 16], [-11, 24, 14, 12], [43, 8, 4, 10]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5175_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5175_2_a_bw();".
// 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_5175_2_a_bw(:prec:=4)
    chi := MakeCharacter_5175_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_5175_2_a_bw();".
// 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_5175_2_a_bw( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5175_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![1, 2, -5, 0, 1]>,<7,R![-4, 12, 4, -6, 1]>,<11,R![-28, -44, -16, 2, 1]>],Snew);
    return Vf;
end function;