
// Make newform 4675.2.a.be in Magma, downloaded from the LMFDB on 11 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4675_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_4675_2_a_be();".
// 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_4675_2_a_be();".
// 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 := [2, 1, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-2, -1, 1, 0], [1, -3, -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_4675_a();"
function MakeCharacter_4675_a()
    N := 4675;
    order := 1;
    char_gens := [4302, 3401, 3301];
    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_4675_a_Hecke(Kf)
    return MakeCharacter_4675_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]];
    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, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0], [0, 1, 0, -1], [-1, 0, 0, 0], [3, -1, -1, 1], [1, 0, 0, 0], [-2, 2, 0, 2], [-2, -1, -1, 2], [2, 2, 1, 1], [0, 2, 2, -2], [1, -1, 3, -1], [2, 0, 0, -3], [0, 3, 2, 2], [6, 1, 0, -3], [6, 3, 2, -5], [1, 2, 5, 0], [-1, -1, 1, -5], [2, -3, 2, 1], [-2, 0, -4, 0], [6, 3, -2, -1], [-4, 5, 0, 2], [-3, 5, -1, 1], [6, -2, 2, -3], [6, -5, 3, -4], [4, -4, -4, 0], [4, -3, 4, -3], [2, -7, -4, 1], [6, -2, -4, 3], [5, -1, -1, -9], [4, 1, 1, 6], [1, 4, -5, 8], [8, 3, 4, -1], [-3, -4, -1, -4], [4, -2, 2, 2], [-4, -6, 0, -2], [2, 3, -6, -1], [2, 3, -3, -4], [0, -2, 8, -8], [8, 1, -8, 3], [8, 4, 1, -7], [0, -6, 4, 4], [8, 5, -3, 2], [-2, 0, -6, 8], [-14, 0, -4, 12], [-8, -8, 2, 0], [10, 2, 1, -5], [6, -8, 4, 6], [-10, 5, 6, -3], [-2, -2, 2, -9], [0, -7, -2, 9], [8, 4, 14, -6], [-6, -6, 1, -3], [4, -3, 6, -10], [10, 5, 2, -3], [-4, 1, -2, -2], [2, 0, -4, -4], [2, -6, -8, 8], [12, 5, 4, -15], [-6, -10, 0, 6], [-8, 2, -10, 0], [6, -3, -8, 2], [4, -7, -9, -4], [-8, -2, 6, -6], [14, 1, 6, 4], [-10, 3, -6, 6], [0, -5, -6, -2], [4, 5, 4, 1], [-6, -1, 10, 1], [-4, 0, 4, 14], [20, -9, -4, 3], [2, 4, 10, -2], [-8, 10, -4, 6], [-6, -6, 0, 6], [-6, 10, 0, -2], [-6, 10, -6, 6], [6, 4, 2, 1], [18, -3, 2, -16], [-2, 16, -2, 0], [-10, 8, 2, -6], [-22, 0, -6, 4], [8, -10, -7, -3], [9, -10, -5, 2], [14, -3, -10, 7], [-12, 7, -6, 9], [12, -8, 2, -8], [-8, -8, -4, 10], [10, 3, -8, 0], [10, -6, -16, 0], [-4, 5, 2, 17], [-2, 15, -4, 9], [-10, 6, -9, -11], [-15, -3, -15, 15], [10, -6, 0, 12], [14, -8, -6, -14], [6, 7, 0, -1], [16, -10, -11, -3], [18, -14, 2, 4], [4, -5, -1, -10], [-2, -12, -1, -3], [6, -12, -4, 2], [-14, -11, 4, 6], [8, -8, 0, -4], [-8, -8, -10, 10], [8, 10, 2, -7], [14, -5, -10, 9], [20, 2, 12, -12], [1, -7, 17, -13], [13, -2, 5, 4], [-14, 11, -7, -2], [22, 6, 6, -10], [-4, 1, -13, 2], [22, -3, -3, 4], [0, 0, -4, -6], [7, -2, 3, -16], [-4, 4, -4, 4], [-13, 5, -13, 11], [14, 13, 8, -19], [6, -15, -10, -2], [4, -12, -14, -2], [-4, 6, 9, -11], [18, -1, 12, -7], [-12, 5, -4, 17], [21, 5, 5, -5], [22, -6, 4, 2], [-2, 18, -4, 6], [-2, 4, 12, 4], [14, 4, -10, -8], [0, -13, -6, 11], [-18, -3, 12, -6], [-10, -16, 0, 8], [-28, 13, 6, 7], [0, -4, 4, 14], [12, 2, -4, -14], [-4, -12, -4, 12], [12, -4, -22, 6], [6, -4, -10, 16], [-2, -9, -16, 5], [6, -10, 8, 8], [2, -5, -2, -15], [-6, 25, 3, -4], [6, 5, 14, -2], [-2, 9, 17, -10], [-10, -17, 4, 1], [12, 7, 27, -8], [-4, 4, -10, 2], [14, 9, 4, -15], [16, -4, 4, -18], [-3, -16, 5, 10], [-6, -2, -12, 6], [-12, -8, 20, -2], [10, -10, -6, 0], [-4, -7, 18, 3], [-10, 4, 14, -2], [-4, -10, 8, -22], [26, 0, -8, 2], [10, -12, 0, -2], [14, 12, -8, 8], [12, -21, -1, 12], [6, 5, -22, -1], [-17, 3, 3, 13], [3, -13, 19, -7], [-12, -11, -14, 0], [0, -12, -16, 12], [26, 3, -20, 9], [-3, -5, -15, 17], [4, 16, 6, 0], [-12, 17, 10, -1], [5, -19, 11, 13], [6, 1, 21, -4], [16, 14, -6, -2], [-19, -10, -17, 22], [-8, -12, -10, 3], [14, 0, -12, 16], [-12, 10, 28, -5], [-8, 0, 10, -6], [15, -24, 5, -4], [8, -20, 6, 18], [-12, 17, 3, 16], [-28, 10, -6, -10], [-4, -2, -12, -24], [27, 8, -3, -4], [-34, 9, 11, -2], [-12, 5, 7, 10], [30, 3, 18, -3], [-24, 13, -11, 4], [4, 18, 4, -6], [-14, 15, 14, 13], [-26, 7, -6, 18], [14, -11, -5, 8], [22, 4, -8, 0], [2, 18, -8, -6], [0, -24, 1, 9], [-32, 2, -5, 11], [20, -28, -12, -4], [1, -13, -21, 7], [9, -4, 13, -14], [-6, 1, 14, 0], [-18, -9, -4, 25], [-8, -3, -31, 2], [25, 1, 11, -11], [36, 7, -10, 1], [-4, 17, -4, -5], [-40, -2, -8, 12], [-12, -15, 10, -9], [6, -18, 2, -12], [-4, 2, -12, 15], [-24, 11, -5, -10], [6, -14, 15, 15], [-32, 24, 8, -5], [-6, -9, -14, 1], [19, -24, 1, -8], [-8, -7, 0, -24], [-2, 5, 14, 21], [-23, -14, -1, 10], [-10, -2, -6, -2], [9, 9, 31, -11], [6, -8, 0, -2], [-20, -1, -24, 18], [-2, -22, 16, 4], [8, -8, 8, 10], [-25, 3, -1, 21], [-5, 20, -3, 0], [8, -7, -4, -10], [32, -7, 14, 0], [-2, 28, -2, 2], [-2, -17, 2, -12], [-52, -4, -2, 4], [0, -23, -6, 8], [-4, 0, 10, -25], [18, -17, 14, -3], [16, -5, 26, -11], [20, 10, 20, -22], [0, -10, 24, -14], [20, -12, -6, -20], [-16, -5, -13, 18], [22, 6, 0, -14], [8, 3, 8, 3], [-16, -6, -12, 12], [-48, -5, 2, 5], [18, -5, 7, 18], [4, 20, 18, -8], [30, 9, -4, -5], [12, 10, 23, -9], [-24, -8, -6, -6], [11, -6, 13, 6], [-24, 9, -8, -12], [20, -2, 12, 10], [-16, -10, 10, -14], [20, 12, 36, -16], [-22, -8, 0, -12], [-22, 15, 21, 10], [28, 9, 0, -23], [6, -8, -20, 18], [12, 15, 7, -12], [-14, -16, -30, 24], [10, -22, -18, 8], [38, 0, 10, -22], [47, -7, 1, -3], [32, 1, -7, -8], [-8, -19, 2, 1], [-13, -27, 5, 21], [6, -15, -10, -17], [-4, -21, 20, -15], [-7, -3, -25, -7], [33, 15, 11, -33], [-15, 23, -11, 21], [24, 4, -19, -5], [0, 17, 26, -5], [13, -33, -3, -3], [-22, -8, -10, -14], [22, -6, -18, -10], [38, -27, -8, -3], [-10, -12, -14, 20], [-2, 29, -8, -12], [-2, -2, 20, -14], [36, 6, 4, -12], [0, 18, -12, 2], [2, 4, 34, -6], [46, -14, -4, 8], [21, -21, 7, 15], [-6, -32, 2, 8], [36, -19, -6, 1], [6, 10, -8, -26], [10, -13, -14, 11], [3, -2, 35, 4], [46, -4, -4, -8], [8, 1, -12, -19], [20, 9, -26, 14], [36, -16, 12, -10], [-10, 2, 12, -2], [38, 11, -11, 8], [28, -15, 9, -16], [20, 14, -2, -9], [-4, -18, 18, -10], [37, 10, 5, -4], [-25, 17, 5, 13], [16, -4, 24, 26], [-19, 5, -11, 3], [-12, -6, 4, 30], [22, 5, 8, 0], [-2, 26, -16, -6], [30, -2, -27, 7], [-56, 10, 4, 6], [-40, -18, -24, 40], [-18, -1, -13, 0], [16, 11, -18, -9], [38, 4, -8, 14], [0, 24, -12, 15], [2, -7, 12, -8], [-30, 19, 2, -15], [36, 8, -2, 12], [11, -9, 5, 7], [52, -18, 4, -20], [12, 3, 5, -24], [16, 12, 12, 12], [-4, -22, 19, -11], [20, -4, 26, -29], [29, 9, 3, 9], [-10, 6, 4, -14], [-56, 3, 8, -10], [2, 7, -2, 14], [40, -22, -12, -6], [-40, 27, 12, 23], [30, 25, 16, -23], [-48, 6, -1, -13], [-28, -6, -18, 36], [-55, 23, 5, -3], [-6, 11, -26, 5], [-40, 11, -10, 13], [-9, -16, 3, -14], [-6, -11, -34, 22], [9, 5, 21, -33], [-13, -5, -7, -13], [20, 11, 6, 21], [7, -17, -25, 13], [49, -9, -7, -7], [-22, -9, -10, 5], [-22, 2, 6, -6], [-63, 21, 3, 25], [22, 13, 10, 13], [16, -43, -8, 13], [-2, 9, -14, 6], [11, -6, 11, 20], [42, 5, -6, -5], [0, 10, 34, 7], [-18, 40, 14, 0], [-8, -17, 10, 29], [-7, 6, 19, 14], [2, 9, -17, 2], [6, 4, -20, -10], [9, -19, -17, -3], [48, -2, 17, 5], [0, -21, 12, -5], [4, 6, 20, 20], [26, -25, -16, -4], [-8, 16, 0, -5], [-46, -8, -9, 27], [22, 24, 10, -28], [-10, 13, 34, -7], [-8, -13, -6, 21], [-15, -14, -7, -8], [12, -9, 4, -5], [-3, 9, -11, -17], [2, 2, -32, 6], [16, 7, 18, -17], [6, 8, 0, 12], [8, -22, -28, 10], [-50, -15, 14, -1], [-68, 0, 8, 1], [-30, 12, -22, -12], [-26, -14, 4, 10], [28, -12, 4, 2], [-28, -12, -10, 18], [-14, -11, 9, -8], [10, 42, 6, -32], [-1, -1, 3, 33], [41, -23, -3, -17], [30, -22, -8, -20], [37, 9, 1, -17], [24, 8, 18, -16], [-16, -9, 0, 41], [28, 9, -20, 17], [-32, 9, 18, 13], [-34, -8, -17, 11], [8, 8, 20, 16], [28, -18, 5, 15], [-24, 19, 2, -3], [-14, 3, -24, 21], [-6, 36, 2, 2], [16, -18, 0, -8], [3, 35, 13, -1], [-52, 3, 2, 5], [22, 28, 20, -30], [0, 8, -23, 17], [-28, -9, 14, -7], [4, -28, -36, 20], [10, -14, 26, -11], [0, -24, 26, -26], [14, -12, -4, -8], [-14, 0, -17, -19], [-14, 17, 8, 37], [-35, 27, 11, -1], [-30, -1, 22, 6], [-2, 18, -8, 36], [-40, 22, -18, -9], [-30, 1, -2, 23], [0, 20, 30, -10], [14, -7, 18, -7], [40, 32, -4, -12], [24, 24, -26, 22], [54, 21, 24, -26], [42, 11, -4, -13], [-22, -20, -11, 1], [-33, -13, -25, 21], [22, 22, 32, -18], [-54, -4, -13, 11], [-2, -7, 1, 22], [-53, 27, 21, 3], [-20, 11, -10, 38], [43, -14, 1, -26], [-20, -18, 22, -22], [20, -35, -8, 8], [-22, 24, 16, -14], [22, -38, 8, -6], [-10, 10, 14, 32], [-28, -4, -8, 12], [22, 39, 5, -34], [-24, -42, -11, 39], [-34, 0, 3, 3]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4675_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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