
// Make newform 6080.2.a.bc in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6080_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_6080_2_a_bc();".
// 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_6080_2_a_bc();".
// 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 := [-4, -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_6080_a();"
function MakeCharacter_6080_a()
    N := 6080;
    order := 1;
    char_gens := [191, 5701, 1217, 1921];
    v := [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_6080_a_Hecke(Kf)
    return MakeCharacter_6080_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, -1], [1, 0], [-2, -1], [-4, 0], [0, -1], [2, -1], [-1, 0], [-2, 3], [6, -1], [0, 2], [-4, 2], [-2, 4], [-2, 0], [2, -2], [-4, -1], [0, 5], [10, -2], [-8, -1], [8, 0], [2, 5], [0, -2], [-14, 0], [-10, 0], [4, -2], [-2, 2], [16, 0], [-4, -3], [-14, 1], [4, -4], [0, 6], [-16, 0], [10, -5], [-8, 4], [2, -2], [-8, -2], [-6, 0], [14, -4], [4, 6], [-8, 2], [4, 4], [-18, 4], [-12, 3], [4, 2], [14, 4], [8, -1], [0, 9], [0, -6], [-12, 3], [-2, 12], [-6, -8], [16, -5], [6, -14], [16, -4], [-16, -6], [-6, 6], [14, 4], [-8, 11], [-6, 10], [14, 4], [-6, 0], [12, -7], [-16, 4], [8, -1], [-2, -11], [-8, 1], [0, -5], [20, -2], [-18, 0], [2, 0], [2, -15], [12, -7], [-30, -2], [12, 5], [16, -3], [4, -12], [-2, -2], [10, -14], [10, -12], [-6, 12], [-28, 2], [14, -13], [0, -8], [-4, 0], [-16, -6], [-14, 10], [-14, 12], [14, 1], [-14, -4], [-14, 14], [6, -14], [24, 0], [-12, -6], [-8, 2], [24, 2], [-2, 15], [2, 0], [2, 2], [4, -7], [22, -2], [-32, 4], [-14, -6], [0, 12], [-6, 2], [12, 6], [-10, 15], [-26, 4], [2, -4], [16, -10], [-18, -12], [4, 2], [26, 6], [-18, 16], [8, -4], [-4, 12], [-2, -2], [-6, 8], [10, 3], [-30, -6], [40, -5], [-2, -7], [-16, -8], [-28, 5], [24, 4], [12, -18], [-6, -2], [26, 0], [-4, 15], [6, 3], [30, -10], [12, 2], [20, 6], [-16, -6], [-18, 12], [26, -3], [10, 11], [8, -11], [-12, -9], [-12, -5], [22, 7], [16, -25], [-10, 2], [18, -15], [-16, -9], [-46, 1], [16, -20], [14, 12], [16, -16], [-36, 12], [12, -24], [12, 5], [-6, -8], [30, -4], [24, 0], [-4, -15], [-8, 12], [8, 5], [18, -9], [-6, 9], [-22, 3], [-18, -6], [0, 20], [-34, -2], [-28, 16], [0, 2], [-4, -10], [-16, -2], [2, -4], [-2, -6], [26, 0], [-16, -5], [-14, 19], [-4, -4], [-10, 3], [-40, 6], [-10, 0], [-40, 2], [-10, -20], [-44, 10], [42, 8], [2, -7], [24, -5], [-12, 18], [0, -12], [38, 3], [-38, 12], [4, -7], [8, 4], [-6, -2], [20, 3], [40, -4], [18, 18], [-20, 24], [-26, -7], [2, 22], [-20, 6], [-6, -21], [-26, 10], [6, 19], [-14, -19], [34, 8], [24, -20], [0, -5], [6, 4], [-8, -6], [26, -10], [28, -9], [32, -17], [-2, 15], [0, -15], [-34, 9], [18, 6], [-14, 6], [-16, 21], [8, -26], [-18, -6], [-18, 23], [34, -12], [8, 6], [38, 0], [-14, -16], [0, -2], [-26, 26], [-2, -25], [-20, 21], [-10, -16], [8, -18], [32, 4], [8, -4], [32, -6], [6, -18], [0, 17], [-24, -8], [-26, -8], [-22, 8], [46, 9], [18, 0], [-50, -4], [40, 6], [32, -22], [32, -12], [40, 4], [2, -3], [-10, 15], [4, 18], [60, -4], [-22, -2], [4, -20], [52, 4], [2, 7], [-66, 2], [-58, 5], [18, 3], [-22, -6], [22, -20], [12, 0], [26, 0], [-28, 0], [24, 18], [54, -12], [-24, 30], [4, 0], [38, -24], [-36, -9], [-46, 4], [-32, -19], [-10, -11], [50, -19], [-48, 17], [22, -6], [-46, -1], [8, -11], [-6, 33], [-28, 1], [-4, -16], [2, -31], [10, -22], [22, -17], [-26, 10], [36, 16], [28, -14], [8, -33], [-30, -1], [-6, -1], [-10, -2], [4, -24], [-42, 1], [-28, 26], [-48, -11], [18, -8], [-2, 2], [2, 6], [52, -12], [-36, -16], [24, 2], [-6, -16], [-8, -6], [-18, 8], [-8, 23], [10, -6], [-2, -12], [-28, 25], [-52, 7], [56, -17], [16, -22], [4, -6], [-48, 15], [-50, -11], [-20, 4], [-26, 34], [-10, -22], [-2, -26], [2, 6], [-32, 4], [-26, -2], [-26, -20], [16, 6], [-48, -12], [38, -1], [30, 0], [-72, 3], [2, -29], [46, 11], [-4, 32], [-62, 11], [-18, 6], [-48, 21], [-52, -15], [24, -10], [10, -20], [-38, 26], [-28, 29], [-60, -9], [38, 4], [-4, -2], [18, -4], [-30, -3], [-48, 12], [-22, 33], [-30, 1], [28, -3], [-46, 7], [42, -5], [-8, 10], [76, -1], [28, 12], [38, 16], [-24, 17], [48, -12], [-14, -14], [-36, 24], [16, 0], [10, -38], [44, 4], [42, -4], [-40, -12], [0, 31], [-8, -24], [58, 7], [-28, 18], [42, 12], [-42, 4], [-36, 28], [16, -11], [30, -14], [4, -2], [10, 12], [-28, 4], [-50, -12], [-28, 42], [8, 15], [-6, -5], [10, -17], [40, -32], [-38, 10], [48, -25], [32, 0], [-46, 24], [66, 3], [-52, -2], [-34, 4], [10, 28], [-10, 1], [42, 16], [8, 1], [8, 26], [0, -3], [26, 20], [-50, -16], [-68, 16], [-30, 4], [-4, 33], [-44, 14], [-42, 10], [24, -22], [56, -2], [-48, 18], [-10, -6], [4, 0], [54, -16], [22, -24], [42, 12], [-20, -6], [-72, -6], [-66, -12], [-76, -1], [58, 2], [42, 6], [4, -19], [4, 2], [56, 6], [14, 12], [32, -29], [-68, -8], [66, -11], [18, -16], [-24, -28], [-56, 22], [26, -5], [-68, 16], [6, -40], [-68, 17], [-34, 33], [40, -37], [-4, 24], [-28, 21], [-4, 3], [-66, -3], [-40, 28], [-20, 11]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6080_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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