
// Make newform 4680.2.a.w in Magma, downloaded from the LMFDB on 03 October 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_4680_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_4680_2_a_w();".
// 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_4680_2_a_w();".
// 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, 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_4680_a();"
function MakeCharacter_4680_a()
    N := 4680;
    order := 1;
    char_gens := [3511, 2341, 2081, 937, 1081];
    v := [1, 1, 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_4680_a_Hecke( : Kf := Kf)
    return MakeCharacter_4680_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], [0, 0], [-1, 0], [-2, 0], [0, -3], [-1, 0], [2, 2], [-4, -3], [2, -5], [4, 4], [0, -1], [-4, 2], [-2, 2], [-6, 3], [-2, 0], [6, -2], [4, 1], [4, -8], [-2, 2], [0, 7], [4, 2], [4, 2], [2, 0], [10, 0], [6, -4], [-2, -4], [10, -1], [2, 5], [6, -8], [6, -2], [6, -7], [8, -8], [-2, 0], [0, 6], [6, -12], [8, -5], [-6, 8], [-14, -6], [2, 8], [18, 2], [0, 8], [12, 8], [16, 4], [-14, 4], [6, -4], [12, -4], [0, 4], [14, 8], [-18, -2], [6, -14], [22, 0], [4, -9], [10, -2], [4, -10], [2, -12], [-18, 3], [6, -16], [0, 7], [-10, 10], [14, 6], [-6, 7], [0, -2], [10, 4], [-4, 10], [-10, 2], [-16, -6], [-8, 5], [-22, -10], [14, -13], [10, 18], [-8, 2], [12, 11], [-10, -9], [10, 0], [12, 3], [-22, 0], [2, 8], [4, -2], [-6, -16], [2, 2], [20, 10], [30, 4], [8, -15], [10, -12], [0, 20], [2, 1], [-22, 10], [-10, -16], [6, 10], [14, 6], [-10, -3], [28, 3], [-2, 6], [-12, 22], [-28, 1], [26, 1], [-26, 6], [24, -8], [6, -21], [6, 6], [-26, -5], [-28, -10], [-2, -11], [20, 8], [-32, -2], [20, 10], [6, 6], [26, 0], [20, 6], [2, -24], [-22, -11], [22, 0], [-2, -4], [12, -17], [0, 9], [-34, -4], [-2, 8], [2, -25], [26, 12], [4, 6], [-26, -12], [14, -14], [6, -10], [-6, 22], [-48, 1], [-2, -16], [6, 18], [-4, -16], [2, 3], [10, -16], [20, 1], [-14, 12], [0, -6], [6, 10], [30, -8], [-14, 4], [-4, 10], [-38, 0], [-10, 28], [36, -4], [0, -7], [-18, -8], [10, 19], [2, 16], [20, 4], [28, -7], [-16, 22], [2, -36], [52, -2], [-14, 28], [-18, 8], [8, 24], [-14, 3], [-6, 17], [-6, -5], [-12, 28], [28, 22], [10, -22], [18, -20], [10, -6], [-30, 12], [-14, -24], [-42, 2], [-16, -16], [-20, 30], [26, -6], [16, -28], [-6, -2], [42, -4], [22, 10], [4, -35], [-10, -26], [16, 14], [16, -26], [0, -32], [-34, 8], [8, -31], [-10, -14], [-26, -23], [-34, 0], [-6, 32], [-8, 18], [-42, -14], [6, 32], [-50, -6], [-24, 8], [-6, 4], [-10, 36], [-6, 6], [8, 33], [18, -14], [-30, -20], [24, 24], [-26, 0], [-22, -17], [-10, -4], [26, 18], [-30, -12], [-8, 14], [-6, -23], [-42, -2], [52, -12], [-42, 0], [-12, -12], [-12, -1], [-6, 38], [12, 13], [10, -7], [-2, 24], [-28, 6], [-22, -4], [-20, 8], [14, -25], [-18, 24], [12, -39], [-10, 18], [46, -9], [34, 24], [-10, -6], [30, -16], [36, 8], [20, 31], [10, 0], [2, 20], [-26, 5], [12, 4], [58, 4], [40, -2], [-14, -13], [-8, -9], [-2, 8], [-12, 42], [-56, 5], [26, -4], [-42, 15], [-22, -10], [-14, 18], [32, 18], [0, 44], [48, 0], [-26, 8], [16, -26], [22, -25], [30, 26], [-2, 28], [-8, 16], [-46, 20], [32, -7], [-36, 19], [30, 5], [-12, -42], [-18, 16], [34, -28], [18, -24], [18, 28], [12, -23], [24, -12], [22, 38], [-38, -28], [44, -2], [-2, 25], [-2, -37], [-6, 50], [42, -6], [-24, -26], [8, 14], [-30, 10], [54, -4], [-6, -14], [14, -2], [-22, 28], [2, 34], [58, 12], [28, 12], [-10, 18], [70, -4], [-34, -10], [-10, -30], [-10, -2], [-16, -6], [-14, 9], [0, 21], [-26, 35], [6, -18], [10, -24], [24, 14], [-30, 16], [50, -20], [12, -15], [-68, -8], [-4, 0], [50, 13], [10, -8], [24, -7], [-10, 36], [26, 24], [36, -24], [-26, -8], [48, 14], [6, 24], [-6, 12], [66, -4], [-4, 8], [18, 25], [-20, -28], [-28, 22], [22, 13], [2, -12], [52, 5], [38, -16], [30, -5], [-6, -2], [24, -8], [42, -11], [-6, -4], [12, 12], [28, -25], [24, 19], [20, -42], [-6, 16], [4, 30], [4, -30], [36, -8], [22, -6], [60, -10], [28, -44], [60, -1], [-66, 12], [-14, 23], [34, 24], [-18, 40], [-6, 24], [-44, -6], [-34, -2], [8, -17], [50, 18], [-6, 20], [10, 44], [10, 54], [38, 13], [26, -4], [46, -10], [38, 12], [36, 34], [30, 28], [40, -20], [-6, 16], [-18, -24], [24, -39], [-46, -36], [-88, 1], [58, 12], [22, 4], [18, -41], [-66, 8], [46, -18], [-28, 17], [-40, 27], [18, -12], [-58, 16], [-8, 26], [52, 8], [50, -3], [-28, 21], [46, 17], [30, 10], [66, 4], [-2, -6], [-38, -4], [16, 0], [-20, 44], [-10, 34], [8, -28], [-12, 40], [-82, -10], [52, -33], [44, 22], [-26, -32], [-8, -28], [18, 34], [22, 42], [-68, 10], [-18, -12], [36, -6], [20, -7], [50, -6], [-40, 15], [14, 38], [-26, -24], [22, 15], [-26, 14], [68, -10], [36, 29], [-18, -1], [-16, -59], [-10, -4], [12, -11], [-24, 12], [-20, 32], [22, 20], [26, 12], [-6, 38], [-22, 0], [-8, -2], [-46, 0], [56, 0], [-24, -38], [-46, 4], [26, 46], [4, 5], [-14, 44], [-26, 6], [-42, -5], [4, -10], [-42, -20], [-6, 0], [12, 31], [58, 33], [24, -6], [-2, 5], [-20, -28], [26, -40], [58, 14], [52, -6], [14, -56], [8, 34], [22, -47], [-26, -2], [40, 5], [-52, 2]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4680_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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