
// Make newform 4680.2.a.bb in Magma, downloaded from the LMFDB on 25 April 2024.
// 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_bb();".
// 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_bb();".
// 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 := [-10, -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_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)
    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+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, 0], [0, 0], [1, 0], [0, -1], [2, 1], [-1, 0], [-2, -1], [-2, 0], [-4, 1], [-4, 2], [-4, 2], [-4, 1], [-8, 1], [4, 0], [-4, -2], [-8, 1], [4, -4], [0, -1], [-4, 0], [-2, 5], [8, -2], [2, -1], [-4, 0], [0, 3], [10, -3], [-4, -4], [12, 0], [-10, 3], [0, -4], [-12, -2], [-8, 2], [2, -4], [-18, 0], [-2, 1], [-4, -1], [0, 0], [-2, -4], [14, 1], [12, -4], [2, 0], [22, 0], [-4, -1], [0, 0], [-14, 3], [-2, -6], [-8, -4], [20, 0], [-2, -2], [16, 2], [-20, 2], [2, -3], [-2, -3], [2, 0], [2, -6], [-4, 6], [-10, -2], [4, -4], [-12, -2], [-2, -4], [-10, 0], [20, 0], [-10, 2], [-22, -3], [-8, 0], [6, -4], [2, 6], [2, 6], [10, 6], [2, 3], [-24, 4], [-2, 4], [0, -8], [12, 4], [-14, -2], [-6, -8], [0, -2], [-4, 8], [-20, 1], [10, 4], [6, 4], [-6, 8], [-4, 8], [16, 0], [18, 2], [-10, -3], [2, -9], [-12, -3], [10, 1], [-28, -3], [4, 3], [-10, 3], [26, -1], [-12, 9], [-10, -6], [26, 4], [-26, 2], [8, -9], [-30, 0], [20, 0], [24, -6], [-4, 8], [-2, 0], [-14, 3], [22, -2], [2, -9], [-18, 5], [8, -6], [-2, -2], [32, -4], [12, 1], [-20, 8], [-16, 11], [-2, 0], [18, -8], [20, 0], [-6, -6], [34, 1], [-12, 3], [6, 8], [22, -2], [-12, 0], [-14, -4], [-4, -3], [-28, 0], [-10, 0], [4, -8], [32, -4], [-20, -4], [-4, 2], [12, -11], [2, 4], [16, 2], [-18, 9], [-42, 2], [10, 0], [46, -2], [38, 2], [16, 4], [12, -1], [-10, -4], [2, 6], [16, 5], [4, 0], [-40, -2], [-26, 8], [-10, 13], [8, 11], [-10, 1], [34, 1], [-8, 2], [18, 8], [2, -4], [4, 8], [-32, -5], [0, 6], [4, 4], [26, 7], [0, 3], [42, -4], [52, -1], [-12, -8], [14, 7], [2, -14], [-30, 10], [-10, 6], [20, 0], [-2, -11], [-46, 2], [-14, 16], [16, 5], [8, 4], [44, 2], [20, 4], [-26, 5], [6, 9], [-42, 2], [6, 8], [-12, -9], [-40, 4], [10, -4], [-32, 3], [-10, -6], [34, -4], [26, 8], [0, -2], [24, 8], [-2, -6], [-10, -9], [10, -10], [10, -5], [-2, 6], [24, 10], [-50, -1], [-8, -11], [8, -4], [50, -1], [6, 16], [46, 4], [-26, 10], [-16, -3], [6, -12], [-6, 11], [-36, -5], [32, -5], [30, -1], [-24, 7], [28, 6], [-48, -4], [-28, -1], [2, 1], [10, 10], [-12, 18], [-48, 8], [16, -10], [40, -4], [-18, 18], [-24, -8], [10, -4], [56, -2], [-10, -4], [-32, 9], [-48, -2], [-14, 16], [-6, -10], [10, -5], [12, -13], [10, -19], [-48, -2], [-44, 2], [-14, 21], [10, 6], [-6, 5], [8, -12], [-10, 6], [8, -14], [-32, -6], [-6, -2], [-18, 16], [22, -8], [-4, -4], [36, 4], [10, -11], [-24, -4], [36, 0], [30, -6], [40, 4], [-26, 6], [38, 1], [-14, -2], [-18, 6], [14, 16], [54, 4], [-4, -10], [-36, -5], [20, 3], [-14, 11], [-2, 8], [-34, 13], [2, 0], [-6, -3], [-28, 14], [2, -15], [24, -16], [-10, 2], [10, 12], [18, -17], [-40, -5], [-40, -5], [46, 3], [-26, -8], [26, -4], [-62, 7], [-26, -3], [16, 0], [-30, -8], [-20, 13], [36, 8], [36, -8], [-14, 10], [22, 16], [-48, -3], [36, 4], [-10, 22], [-4, -2], [-12, 20], [-28, -8], [26, -18], [-2, -18], [8, -2], [34, -14], [-40, 12], [-4, 8], [-18, -6], [-56, -4], [2, -8], [-40, -6], [-24, 8], [-48, 3], [30, -2], [30, -19], [-34, 8], [-2, -10], [-38, -1], [-26, 21], [36, -4], [2, -21], [10, 9], [16, -3], [8, -8], [22, 10], [-36, -7], [-50, 4], [-30, -4], [-28, 4], [-48, -4], [-44, -1], [30, -9], [22, 17], [-24, -14], [26, -6], [-64, 4], [8, -2], [-24, -2], [12, 7], [-22, 4], [-36, 5], [-6, 0], [-6, -3], [-48, 1], [34, 0], [8, -10], [8, -1], [32, -8], [20, -16], [18, -6], [32, -6], [8, 10], [50, -6], [30, 0], [0, -18], [20, -17], [14, 9], [-52, -9], [48, -12], [-6, -4], [-34, -6], [-56, 3], [18, -11], [-32, 8], [-32, 19], [34, 8], [42, 11], [48, -11], [4, -22], [0, 9], [-16, -10], [54, -11], [-44, -8], [-40, 2], [52, 2], [2, -20], [-38, 22], [-58, 10], [-56, 4], [8, 10], [-6, 2], [54, -2], [4, -9], [-12, 7], [-46, -8], [8, -12], [-52, -4], [28, 14], [-66, 5], [-34, 2], [-6, 7], [-68, -6], [-66, 13], [6, 14], [-50, -4], [-22, -4], [6, -8], [-2, -10], [34, -16], [22, -2], [32, -8], [-40, 18], [78, -6], [-36, -12], [-40, 13], [-74, 2], [-26, -16], [-38, -11], [36, -8], [38, -11], [-26, 20], [20, -2], [-42, 12], [-54, -7], [22, -16], [56, 6], [-10, 1], [80, 5], [-2, 22], [-12, 21], [38, 5], [-34, 4], [30, -20], [34, 3], [90, -1], [-10, 8], [-44, -13], [-54, -1], [30, -27], [18, 0], [4, 6], [34, 15], [8, 18], [-2, 14], [28, 19], [20, 2], [-48, 9], [64, -4], [-22, -14], [72, 6], [18, 14], [6, -9], [28, -7], [50, -12], [-60, 6]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4680_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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