
// Make newform 80.6.n.c in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_80_n();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_80_n_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_80_6_n_c();".
// 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_80_6_n_c();".
// 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 := [1521, 0, -77, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -38, 0, 1], [-3003, 116, 78, -1], [3003, 116, -78, -1]];
    Rf_basisdens := [1, 39, 39, 39];
    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_80_n();"
function MakeCharacter_80_n()
    N := 80;
    order := 4;
    char_gens := [31, 21, 17];
    v := [2, 4, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_80_n_Hecke();"
function MakeCharacter_80_n_Hecke(Kf)
    N := 80;
    order := 4;
    char_gens := [31, 21, 17];
    char_values := [[-1, 0, 0, 0], [1, 0, 0, 0], [0, 1, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 6;
    raw_aps := [[0, 0, 0, 0], [0, 0, -1, 0], [55, 10, 0, 0], [0, 0, 0, -11], [0, 0, 5, -5], [165, -165, 0, 0], [1265, 1265, 0, 0], [0, 0, 110, 110], [0, 0, 43, 0], [0, 2596, 0, 0], [0, 0, -285, 285], [1385, 1385, 0, 0], [2178, 0, 0, 0], [0, 0, 1111, 0], [0, 0, 0, 397], [-23915, 23915, 0, 0], [0, 0, 1090, 1090], [-35882, 0, 0, 0], [0, 0, 0, -2155], [0, 0, 2695, -2695], [-21615, 21615, 0, 0], [0, 0, -880, -880], [0, 0, -3113, 0], [0, -114424, 0, 0], [-615, -615, 0, 0], [146982, 0, 0, 0], [0, 0, 155, 0], [0, 0, 0, 4917], [0, 94204, 0, 0], [11705, -11705, 0, 0], [0, 0, 0, 4917], [0, 0, 9185, -9185], [-243055, -243055, 0, 0], [0, 0, 12210, 12210], [0, -348876, 0, 0], [0, 0, -20185, 20185], [-221935, -221935, 0, 0], [0, 0, 2463, 0], [0, 0, 0, 2013], [-16555, 16555, 0, 0], [0, 0, -3410, -3410], [-114378, 0, 0, 0], [0, 0, -17205, 17205], [-522335, 522335, 0, 0], [301345, 301345, 0, 0], [0, 0, -29580, -29580], [0, 0, -20735, 20735], [0, 0, 29019, 0], [0, 0, 0, 57629], [0, 903276, 0, 0], [703065, -703065, 0, 0], [0, 0, -23320, -23320], [-670582, 0, 0, 0], [0, 0, 49445, -49445], [-599895, -599895, 0, 0], [0, 0, -75581, 0], [0, -1026036, 0, 0], [0, 0, 66275, -66275], [868065, 868065, 0, 0], [-215182, 0, 0, 0], [0, 0, 9295, 0], [1067605, -1067605, 0, 0], [0, 0, 0, 115621], [0, 0, -37345, 37345], [708225, -708225, 0, 0], [-141175, -141175, 0, 0], [0, 0, -74755, 74755], [-472175, -472175, 0, 0], [0, 0, 0, -28259], [0, 821876, 0, 0], [2272225, -2272225, 0, 0], [0, 0, -22220, -22220], [0, 0, 0, -235179], [-444675, 444675, 0, 0], [0, 0, -78750, -78750], [0, 0, 254011, 0], [0, 3040004, 0, 0], [893025, 893025, 0, 0], [1780482, 0, 0, 0], [0, -1980176, 0, 0], [0, 0, 39710, 39710], [-339922, 0, 0, 0], [0, 0, -151965, 151965], [1435785, -1435785, 0, 0], [0, 0, -46420, -46420], [0, 0, -130833, 0], [0, -3446936, 0, 0], [-3659975, -3659975, 0, 0], [-6068018, 0, 0, 0], [0, 0, -221517, 0], [0, 0, 0, -109539], [0, 0, -171160, -171160], [0, 0, 0, 256213], [0, 0, 153725, -153725], [0, 0, -286010, -286010], [0, 0, -310453, 0], [0, -73964, 0, 0], [8644922, 0, 0, 0], [0, 0, 373791, 0], [-459778, 0, 0, 0], [0, 0, 0, -475299], [939785, 939785, 0, 0], [0, 0, -545985, 0], [0, 10578304, 0, 0], [0, 0, -5555, 5555], [2300825, 2300825, 0, 0], [0, 0, 0, -232915], [-2967855, 2967855, 0, 0], [0, 0, -313940, -313940], [8568978, 0, 0, 0], [0, 0, 0, -241395], [4500045, -4500045, 0, 0], [-6726655, -6726655, 0, 0], [0, 0, 231770, 231770], [0, 0, 205535, -205535], [-3858822, 0, 0, 0], [0, 0, 806807, 0], [0, 0, 0, 336885], [2208205, -2208205, 0, 0], [0, 0, 524150, 524150], [-16058722, 0, 0, 0], [7354105, -7354105, 0, 0], [-7182175, -7182175, 0, 0], [0, 0, -560361, 0], [0, 0, -310255, 310255], [6604598, 0, 0, 0], [0, -1650724, 0, 0], [0, 0, -839080, -839080], [0, 0, 0, 631973], [-7350475, 7350475, 0, 0], [0, 0, 682550, 682550], [0, 0, -912285, 0], [0, 0, 1155, -1155], [2572945, 2572945, 0, 0], [1021482, 0, 0, 0], [0, 26975696, 0, 0], [21889165, -21889165, 0, 0], [0, 0, 0, 284933], [15411705, 15411705, 0, 0], [0, -16660424, 0, 0], [0, 0, 838365, -838365], [10596718, 0, 0, 0], [0, 0, 376795, 0], [0, 0, 0, 882365], [0, 15755804, 0, 0], [0, 0, -34420, -34420], [-22314435, 22314435, 0, 0], [-29344975, -29344975, 0, 0], [0, 0, -1609630, -1609630], [0, 0, -238877, 0], [7284145, 7284145, 0, 0], [5539818, 0, 0, 0], [0, 0, -2129953, 0], [0, 0, 0, 1529781], [0, 0, 0, -1262491], [0, 0, -996005, 996005], [0, 0, 883740, 883740], [0, 1027224, 0, 0], [2342065, 2342065, 0, 0], [52552302, 0, 0, 0], [0, 0, 0, -1160347], [6370705, -6370705, 0, 0], [0, 0, 0, 390973], [0, 0, -1746075, 1746075], [-11298695, -11298695, 0, 0], [0, 0, -2724765, 0], [0, 0, 1792515, -1792515], [-18905975, -18905975, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_80_n_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_80_6_n_c();".
// 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_80_6_n_c(:prec:=4)
    chi := MakeCharacter_80_n();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_80_6_n_c();".
// 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_80_6_n_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_80_n();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![96100, 0, 0, 0, 1]>],Snew);
    return Vf;
end function;