
// Make newform 6080.2.a.br in Magma, downloaded from the LMFDB on 14 May 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_br();".
// 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_br();".
// 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, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-3, 0, 1]];
    Rf_basisdens := [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_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], [0, -1, 0], [1, 0, 0], [1, -2, 1], [0, 0, 2], [4, -1, 2], [-1, 0, 1], [1, 0, 0], [3, 0, -1], [1, 4, -1], [-2, 0, 2], [7, -1, 1], [-8, 2, 2], [-2, -4, 2], [0, 0, 4], [0, 7, -2], [5, -4, -3], [6, -2, -2], [0, -1, 4], [0, 0, 0], [-3, 4, 3], [-8, -2, 0], [-4, -2, 0], [-4, 6, -6], [3, -1, -3], [2, -2, 2], [-3, 3, 1], [-4, 5, 0], [1, -6, -1], [-5, 5, -3], [-5, 3, -5], [-8, 0, -4], [7, -4, -3], [4, 0, -2], [-2, -2, 6], [-8, 6, -8], [16, 2, -2], [2, 8, -6], [9, 1, 1], [-5, -1, -3], [6, 2, 2], [6, 8, -4], [3, -6, 7], [-1, -9, 1], [-2, -8, 4], [-5, 2, -1], [5, -8, 1], [-3, -3, -3], [-10, 9, -6], [0, 2, 4], [2, 0, 4], [-9, -6, 3], [-2, -6, 0], [4, 0, 8], [5, -3, -9], [6, 10, -6], [14, 0, 0], [-1, -2, 5], [2, 10, 0], [0, 6, -2], [-12, 6, 4], [-2, -5, -4], [-15, 7, -7], [11, 6, 1], [3, 2, 1], [2, -5, -8], [23, 0, 3], [-3, 5, 7], [-12, 2, 0], [-10, 4, 0], [13, -8, -1], [5, -2, -5], [-8, 0, -4], [2, -5, -8], [-9, 2, -1], [11, 5, -1], [4, -4, 2], [6, -10, 0], [2, -8, 12], [-10, -8, 4], [-2, -12, 10], [9, -8, 7], [18, 2, -2], [-5, 13, -3], [8, -14, 4], [-6, 10, 2], [-22, -8, 0], [19, -10, 5], [14, -8, 12], [-6, 14, 2], [30, -6, 2], [-4, -8, -2], [11, -5, -1], [-6, 4, -10], [-22, 8, -8], [-5, 4, -1], [-4, 10, -10], [8, 12, -10], [-4, -15, 4], [-10, 2, -6], [-5, 13, 7], [-6, -18, 8], [-11, -5, 1], [-8, -12, 2], [-10, 16, 0], [21, -2, 3], [0, 6, 4], [-2, 8, 12], [20, 2, 8], [12, -2, -10], [-33, -5, 3], [2, 14, -8], [4, 2, -2], [4, 8, -2], [-16, -4, -6], [-6, -22, 12], [12, -14, 16], [7, 16, -5], [-30, 2, 0], [11, -4, -1], [-17, 0, 5], [13, -1, -9], [34, -5, 0], [-15, 15, -11], [14, 8, 0], [18, -10, 14], [-14, 4, 4], [-25, 6, 1], [9, -6, 1], [-20, 4, -10], [6, -12, -6], [-9, -5, -1], [-36, 2, -8], [34, 4, 0], [-7, 4, 9], [-9, 0, -1], [-6, -9, 0], [24, -13, 8], [-12, 7, -14], [5, -18, 3], [-3, 14, 1], [-24, 0, 6], [-13, 14, -5], [-34, 9, 6], [33, -6, 7], [2, -14, 2], [2, 4, -8], [23, 1, 1], [-4, 16, 0], [1, 11, 1], [38, -9, 12], [12, -14, -4], [6, 4, -6], [31, -7, -5], [0, -3, -12], [-2, 6, 10], [-7, -2, -3], [-31, -10, -1], [-31, 4, -1], [-1, -2, 1], [42, -10, -6], [-33, 1, -7], [22, -10, 10], [-20, 16, 0], [-1, -9, 17], [-23, 1, -3], [0, 6, 8], [-4, 14, -2], [-2, 18, 4], [-12, 2, 6], [-27, -6, -7], [-17, -2, -15], [8, 4, -18], [-23, 6, -1], [-14, 16, -14], [-8, 10, -4], [30, -12, -6], [4, 18, -12], [-9, 7, -17], [-12, 6, -8], [29, 12, 1], [9, -10, -7], [-19, 1, -1], [1, -13, -13], [31, -12, -9], [6, -4, 12], [16, 25, -10], [17, 15, -3], [-20, -12, -2], [35, 2, -1], [-29, -7, 5], [18, -18, -2], [12, 0, 0], [19, -12, 13], [12, -16, -8], [-3, 1, -9], [1, 18, -9], [16, 0, 6], [-15, -2, -9], [-25, -2, -13], [-16, -10, 10], [-22, 10, -14], [4, 11, -6], [8, 6, -14], [-30, 4, -16], [-38, 14, -4], [11, 10, -7], [10, -11, 6], [17, -22, 15], [-13, -6, 3], [-25, -6, 1], [10, -18, 2], [-50, 10, 6], [-8, -3, 8], [34, -12, 6], [26, 18, -8], [25, -18, 5], [14, 4, 16], [-9, -21, -1], [-2, -20, 16], [-32, 6, -10], [10, 24, -14], [-18, -14, -4], [15, 0, 11], [4, -3, 0], [2, 8, -20], [-29, 15, 5], [-8, 12, 0], [-1, 1, 3], [-22, -24, 14], [-8, 12, -22], [-9, 6, -13], [-18, 6, 18], [-24, 26, -10], [-12, -6, -12], [-1, -10, 11], [12, 2, -8], [-6, 0, 8], [34, -8, 8], [-12, 22, 0], [11, 13, -13], [16, -8, 4], [7, 6, 11], [5, 8, 7], [-37, -13, 5], [-20, 12, 20], [24, 0, 4], [-30, 6, 10], [4, 28, 0], [-11, 14, -7], [-12, -12, -2], [3, -6, -11], [7, 0, -13], [16, -12, 22], [10, 16, -12], [48, 8, 4], [-6, -16, 4], [-5, 13, -13], [-11, 5, -25], [16, -6, 2], [11, 23, -1], [5, 11, 1], [-28, -6, 4], [40, 7, 6], [38, 8, -4], [17, 40, -15], [-5, -8, -19], [-35, 8, 9], [48, -15, 20], [28, -20, 18], [7, 2, 17], [-32, 21, -8], [21, 8, 7], [21, -18, -9], [-3, 31, -9], [3, 6, 15], [-12, -24, 4], [-7, 12, -5], [18, 10, -4], [-12, 24, 2], [-23, 25, 5], [35, 14, -3], [39, 12, -5], [15, -30, 5], [18, 6, -22], [-40, 16, -18], [23, -22, 29], [5, 1, -1], [-27, 2, 9], [-30, -8, 12], [-4, 32, -14], [-32, 16, 16], [-11, -21, 7], [18, 18, -6], [-21, -17, -3], [-20, -26, 8], [-22, -16, 14], [6, -8, 0], [17, 18, -19], [36, -16, -8], [-20, -2, -22], [-40, 17, 14], [23, 22, -15], [-36, 11, -12], [-10, 16, -14], [-15, 1, 19], [-30, 13, -30], [67, -8, 9], [-20, 4, 4], [16, 12, -2], [32, 0, 8], [26, -34, -6], [-4, -12, -2], [-7, -41, 13], [-46, 2, -10], [24, 30, -6], [-6, -16, -8], [38, -2, 10], [-3, 22, 15], [14, 0, -8], [17, -2, 9], [-17, -4, -3], [25, -32, 3], [43, -19, -9], [23, -20, -11], [10, 10, 0], [41, 8, -15], [0, 5, 24], [-1, 31, -17], [32, 22, -6], [6, 6, 14], [28, -31, -6], [15, -10, 21], [22, 24, -2], [-38, 24, -20], [-42, 16, -14], [9, -2, 23], [-25, 5, -7], [43, 2, 9], [-11, 44, -7], [52, -7, 18], [3, 28, -23], [3, -30, 13], [-62, -4, 10], [24, 23, -18], [26, -2, 14], [26, 40, -12], [28, -19, -20], [16, 0, 0], [18, -14, 8], [-12, 8, 4], [29, -9, 23], [-18, 6, 14], [15, -27, 3], [20, -10, -2], [25, -17, 27], [-5, -14, -17], [-56, 4, 4], [15, 16, -15], [-9, 7, 15], [16, 22, -22], [-84, 2, 0], [49, -21, -3], [-1, 10, 19], [14, 10, 10], [65, 5, 3], [20, -10, -2], [-13, -35, 15], [16, -22, -2], [38, 8, -16], [-57, 20, 3], [-3, -38, 21], [15, 34, -7], [-8, 8, 0], [38, -6, -16], [9, -6, 21], [-16, -24, 0], [-6, 32, -12], [-35, 30, 15], [39, -29, 1], [22, -16, 12], [-50, 0, -8], [-21, 2, -17], [46, 12, -16], [-39, -12, 1], [-45, 11, -1], [69, -10, -9], [-8, -10, 30], [2, -20, -2], [25, -25, 21], [30, -20, -28], [64, 1, 6], [34, -32, -10], [26, -14, -6], [0, -34, 16], [-33, 19, 25], [52, -10, 20], [-14, 22, 8], [40, -4, -16], [-6, 8, 20], [-22, 8, 0], [58, -4, 12], [49, -19, 17], [31, -29, -15], [26, 4, 0], [-9, 2, 3], [6, -30, 24], [-76, 8, 10], [-8, -23, -8], [10, -12, 6], [1, 1, -21], [10, 20, -24], [-26, 13, 18], [52, -24, -10], [1, 16, -17], [42, 16, 4], [38, -22, -18], [-57, 15, 7], [3, -8, 1], [-57, 13, -5], [46, 12, 8], [-14, 31, -32], [-1, -10, -13], [-43, 2, -11], [39, -27, -15], [4, 1, -22], [-38, -11, 10], [25, -8, -3], [8, -48, 20], [27, -26, 17]];
    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_br();".
// 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_br(:prec:=3)
    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_br();".
// 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_br( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6080_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-2, -4, 1, 1]>,<7,R![-16, -16, -1, 1]>,<11,R![16, -28, 0, 1]>],Snew);
    return Vf;
end function;