
// Make newform 6080.2.a.g in Magma, downloaded from the LMFDB on 24 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_g();".
// 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_g();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [-1], [-1], [-3], [0], [-5], [-3], [-1], [-7], [1], [-2], [-2], [-10], [-6], [-8], [-9], [5], [-4], [-1], [-12], [-13], [6], [18], [2], [-14], [4], [4], [-7], [-1], [12], [6], [16], [-15], [20], [-16], [-2], [-6], [14], [-10], [-22], [0], [-6], [-1], [14], [6], [-1], [-23], [2], [-17], [-6], [18], [3], [8], [24], [6], [-16], [18], [-29], [-4], [30], [26], [-7], [-28], [7], [-9], [-3], [3], [-2], [22], [18], [-33], [-19], [16], [13], [-11], [36], [-8], [-20], [-30], [-30], [-30], [-19], [-12], [0], [30], [-24], [22], [-13], [-6], [32], [-28], [0], [-18], [-2], [14], [21], [18], [-12], [5], [8], [-36], [28], [-20], [-12], [-2], [17], [-42], [14], [-6], [30], [-2], [-44], [-10], [8], [-16], [-40], [26], [-35], [-12], [-13], [11], [-40], [37], [-4], [18], [-8], [-30], [3], [49], [36], [-14], [6], [-18], [2], [-21], [-7], [-23], [-29], [27], [33], [7], [24], [-13], [-9], [23], [36], [-14], [-24], [36], [-16], [-59], [-30], [-46], [-52], [-43], [12], [-11], [-19], [55], [-7], [-48], [0], [28], [20], [6], [-54], [58], [-38], [-16], [-2], [3], [57], [-48], [37], [26], [-18], [-2], [34], [-22], [-26], [-53], [-29], [38], [-4], [-7], [-18], [57], [-44], [-4], [-57], [56], [-44], [-20], [-61], [32], [-58], [-23], [-8], [37], [-57], [26], [-68], [39], [-66], [34], [-32], [-13], [-33], [-63], [17], [-13], [-48], [40], [-51], [-6], [-20], [13], [-2], [-58], [-58], [-30], [62], [28], [61], [-15], [-10], [14], [16], [-24], [42], [24], [49], [-40], [-34], [-22], [-65], [-14], [6], [22], [14], [4], [56], [-17], [17], [-54], [-48], [-8], [8], [32], [-23], [28], [-57], [-27], [64], [38], [-72], [2], [52], [42], [-62], [66], [-12], [74], [63], [-18], [61], [15], [35], [17], [4], [5], [-19], [63], [-75], [48], [3], [80], [33], [-48], [-60], [-34], [31], [-39], [-59], [-12], [20], [-53], [-26], [21], [18], [4], [40], [-4], [-36], [18], [-10], [58], [38], [-65], [8], [-22], [33], [11], [31], [-34], [-2], [7], [-1], [24], [-8], [24], [48], [84], [-12], [36], [46], [-34], [0], [-79], [-66], [3], [-7], [-75], [56], [57], [40], [-11], [45], [-54], [-46], [68], [-19], [-93], [90], [2], [2], [-45], [4], [-33], [-61], [-43], [-67], [9], [58], [-33], [80], [-34], [-7], [24], [60], [28], [-68], [20], [-16], [-90], [28], [15], [24], [-51], [86], [26], [58], [92], [-11], [28], [22], [-18], [4], [-22], [-50], [-33], [29], [-59], [32], [52], [63], [16], [66], [81], [-90], [74], [-82], [31], [-38], [89], [-22], [37], [26], [-82], [36], [-98], [-15], [2], [-4], [-66], [-10], [58], [-64], [-20], [-62], [-34], [54], [-74], [22], [18], [-37], [8], [-48], [57], [18], [50], [42], [27], [88], [-5], [22], [64], [34], [-55], [-68], [-34], [-15], [-65], [75], [32], [93], [-73], [-41], [-76], [55]];
    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_g();".
// 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_g(:prec:=1)
    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_g();".
// 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_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6080_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![1, 1]>,<7,R![3, 1]>,<11,R![0, 1]>],Snew);
    return Vf;
end function;