
// Make newform 80.10.c.c in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_80_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_80_c_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_10_c_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_10_c_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 := [304, 0, 45, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -51, 0, -3], [0, -74, 0, -2], [1350, 37, 60, 1]];
    Rf_basisdens := [1, 2, 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_80_c();"
function MakeCharacter_80_c()
    N := 80;
    order := 2;
    char_gens := [31, 21, 17];
    v := [2, 2, 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_c_Hecke();"
function MakeCharacter_80_c_Hecke(Kf)
    N := 80;
    order := 2;
    char_gens := [31, 21, 17];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [-1, 0, 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 := 10;
    raw_aps := [[0, 0, 0, 0], [0, 1, 0, 0], [285, -7, 7, 1], [0, -49, -21, 0], [-27492, 0, 10, 20], [0, 110, -507, 0], [0, 1632, -2270, 0], [159220, 0, -238, -476], [0, 5199, -5551, 0], [-882930, 0, -988, -1976], [2646928, 0, 380, 760], [0, 51378, -96687, 0], [-4197138, 0, 12445, 24890], [0, -132643, -146622, 0], [0, 214259, 199463, 0], [0, 259794, -402365, 0], [115207260, 0, 26486, 52972], [90122642, 0, -21575, -43150], [0, 1448953, -2029650, 0], [11902968, 0, 45600, 91200], [0, -90564, -439344, 0], [182010880, 0, 133988, 267976], [0, 1180353, 2889326, 0], [-395675190, 0, 92796, 185592], [0, 1954216, 3208062, 0], [567800502, 0, -452020, -904040], [0, -2238569, -5031735, 0], [0, 4617701, 9006404, 0], [-534190510, 0, -701651, -1403302], [0, -8158280, 5675548, 0], [0, 12947955, 9884421, 0], [-868437372, 0, -2758990, -5517980], [0, 32656548, 8131498, 0], [-3760961060, 0, 1252794, 2505588], [295441050, 0, 3333445, 6666890], [2579341048, 0, 1975620, 3951240], [0, -65546866, 32735751, 0], [0, 21906945, -21314628, 0], [0, 58941063, -102444595, 0], [0, 105145686, -24893669, 0], [7810592580, 0, -7714722, -15429444], [-4345285978, 0, 1654900, 3309800], [-4123722912, 0, 7855720, 15711440], [0, 174939368, 2170122, 0], [0, -107391414, -193794653, 0], [4925548600, 0, 10308240, 20616480], [-15012114092, 0, -12433030, -24866060], [0, 233718899, -352018551, 0], [0, -123402495, 226382996, 0], [-4145569930, 0, -5515748, -11031496], [0, -198194228, -3256376, 0], [70133972640, 0, 7551284, 15102568], [-10747963738, 0, -29140775, -58281550], [-75185487252, 0, -17283750, -34567500], [0, -63190656, 494040256, 0], [0, -266664865, 61363967, 0], [53634804930, 0, -27099567, -54199134], [-39842371232, 0, -51485620, -102971240], [0, 102372970, 168220029, 0], [-123537488178, 0, 16703945, 33407890], [0, -1031645027, 532547436, 0], [0, -720156702, -50107763, 0], [0, -478455999, 611333154, 0], [-148798578792, 0, 74655380, 149310760], [0, 1051745500, 1312762638, 0], [0, 1952104182, 318452605, 0], [-230021907572, 0, 34409190, 68818380], [0, -752580232, -2674247592, 0], [0, 1675687829, 1352686298, 0], [-9582303250, 0, 213229420, 426458840], [0, 2697265984, -1881796820, 0], [-69738875640, 0, 209671356, 419342712], [0, -139794517, 112663365, 0], [0, -3985241734, 3435259821, 0], [-6794088020, 0, 158155658, 316311316], [0, -941730957, 688914821, 0], [-102622727190, 0, -37141219, -74282438], [0, -2127492834, 2962393137, 0], [-292116701598, 0, 124724740, 249449480], [-347638455010, 0, -198167891, -396335782], [137072876820, 0, 114150062, 228300124], [-313152328918, 0, -186069755, -372139510], [-882689283072, 0, 65503260, 131006520], [0, -942022368, 6738688854, 0], [212801146840, 0, -685126396, -1370252792], [0, 1674398877, -1630093912, 0], [-835558180650, 0, 386516145, 773032290], [0, -6519245996, 3292696686, 0], [991786317342, 0, -323668420, -647336840], [0, 2663499235, 6427285167, 0], [0, 3854618313, -1881767320, 0], [188325202080, 0, -32313632, -64627264], [0, -8555972913, 10617383007, 0], [202007035788, 0, 500930990, 1001861980], [-286784207900, 0, 272288630, 544577260], [0, -7462943169, -7888294735, 0], [75222801390, 0, 1090789924, 2181579848], [1656408145482, 0, 625686720, 1251373440], [0, -3394650651, -2172146976, 0], [803429749262, 0, -354626460, -709252920], [0, -502065391, -2787038112, 0], [0, 21763902934, -5687798549, 0], [0, 21590591945, 1222132172, 0], [376799628030, 0, -880772227, -1761544454], [3101021760268, 0, -202887310, -405774620], [0, 9826270800, 22857097644, 0], [0, 27878177997, -14699660038, 0], [0, -3626152632, 5003084572, 0], [2303587797000, 0, -621829720, -1243659440], [-393754646098, 0, 1409345425, 2818690850], [0, -18502025429, 20766418239, 0], [0, -4373133990, -8909054757, 0], [0, -928194948, -7186312460, 0], [-3409283676980, 0, -1393760418, -2787520836], [1307195826328, 0, -1939911580, -3879823160], [5132887401462, 0, -1393494295, -2786988590], [0, -23759718263, 50115138618, 0], [0, -5609002161, 26207905403, 0], [0, 46557715614, 28809765745, 0], [-2191153884540, 0, 263513926, 527027852], [3774024946442, 0, -3030930255, -6061860510], [0, -34759014104, 51665426886, 0], [0, -35756735990, 1496710399, 0], [0, -12147432627, -6416909314, 0], [1532927293588, 0, -1785923230, -3571846460], [3199467371202, 0, 2592448245, 5184896490], [-2203435665610, 0, -4607063436, -9214126872], [1457801997120, 0, 4387055892, 8774111784], [0, 13248594695, -76934436609, 0], [0, 27723171902, -93713437461, 0], [-4320493994060, 0, -4007204026, -8014408052], [0, -4964070433, -55494383917, 0], [4129885808848, 0, 5116075280, 10232150560], [0, 18597765834, 81831960801, 0], [3352326900042, 0, 7746421780, 15492843560], [-9691028355070, 0, 4030489408, 8060978816], [0, 62447981466, 37689561871, 0], [0, -9087906623, 12704634102, 0], [0, -41340058314, -127999736903, 0], [2337513670890, 0, 4461708384, 8923416768], [4224834674908, 0, 1633732290, 3267464580], [-1325100080118, 0, -6313278295, -12626556590], [0, 65410744399, -88265134851, 0], [0, -45209270475, -69869066794, 0], [6924394295570, 0, 6906366297, 13812732594], [14868549756840, 0, -1601992676, -3203985352], [0, 7768642114, 139870514595, 0], [0, 128732145564, -126734615534, 0], [-16827431359940, 0, 1998802166, 3997604332], [0, 173039733915, 83889580907, 0], [0, 36581830310, -29811909801, 0], [-9962935700778, 0, -7841059755, -15682119510], [0, 107912506713, 28064320056, 0], [0, -79363054713, 198720865307, 0], [0, 64380735701, 114994515804, 0], [-16047443942592, 0, -10723186940, -21446373880], [17324007739720, 0, 1910684232, 3821368464], [-14175840998730, 0, -2159108623, -4318217246], [0, 211020404268, 13032319608, 0], [4356304592862, 0, -3959918060, -7919836120], [0, -29960006991, -119999564962, 0], [0, -168305176916, 30849710530, 0], [0, -140213955977, -84867511515, 0], [-20687904094932, 0, 13852232910, 27704465820], [0, 714293680, 326382164734, 0], [0, -155877664857, 188444244071, 0], [-696864118112, 0, -20860744480, -41721488960], [0, -55342550774, -335485589433, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_80_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_80_10_c_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_10_c_c(:prec:=4)
    chi := MakeCharacter_80_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    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_10_c_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_10_c_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_80_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<3,R![45529776, 0, 33552, 0, 1]>],Snew);
    return Vf;
end function;