
// Make newform 80.9.p.c in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_80_p();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_80_p_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_9_p_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_9_p_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 := [4608, -3168, 1089, -30, 2, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [-62928, 41631, 790, -10, -22, 39], [27831, -192, -30, 70, 44, 2], [-205824, 1893423, -52930, 670, 1474, 687], [5168544, -1801263, 67330, -34270, 3806, -1647], [2598192, -1703409, 93190, 4390, 858, -1721]];
    Rf_basisdens := [1, 66000, 825, 66000, 66000, 66000];
    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_p();"
function MakeCharacter_80_p()
    N := 80;
    order := 4;
    char_gens := [31, 21, 17];
    v := [4, 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_p_Hecke();"
function MakeCharacter_80_p_Hecke(Kf)
    N := 80;
    order := 4;
    char_gens := [31, 21, 17];
    char_values := [[1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 1, 0, 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 := 9;
    raw_aps := [[0, 0, 0, 0, 0, 0], [12, -12, -1, 0, 1, -1], [31, -33, 18, -4, 3, -1], [371, 371, 56, 7, 0, -56], [-3902, 0, -60, 85, 85, 0], [-19778, 19778, -317, 0, 80, -317], [-44567, -44567, 1416, -466, 0, -1416], [0, 54018, 0, -684, 684, -1614], [-4861, 4861, 1720, 0, -1581, 1720], [0, 432678, 0, 2386, -2386, -13594], [137098, 0, -31380, -3045, -3045, 0], [-77174, -77174, 3015, 1506, 0, -3015], [411182, 0, 36180, -12505, -12505, 0], [-145474, 145474, 45421, 0, -5323, 45421], [2536385, 2536385, 43258, 4263, 0, -43258], [-2296052, 2296052, 137781, 0, -4186, 137781], [0, -1850946, 0, -30152, 30152, -538642], [3894782, 0, 562500, -95625, -95625, 0], [5437022, 5437022, -851, 103661, 0, 851], [2041738, 0, 1027500, -78125, -78125, 0], [18724411, -18724411, -256170, 0, 12756, -256170], [0, -21443688, 0, -122456, 122456, 1191224], [2471480, -2471480, -243037, 0, 212813, -243037], [0, -37413756, 0, -442572, 442572, 224388], [-31155095, -31155095, -724088, 861272, 0, 724088], [-20670358, 0, 1046520, 224930, 224930, 0], [26309687, -26309687, -1273276, 0, 1421251, -1273276], [-86232484, -86232484, 497391, -449663, 0, -497391], [0, -33893334, 0, -447483, 447483, -3632118], [-51774263, 51774263, 29528, 0, 1507590, 29528], [-57660427, -57660427, -10091658, 2163915, 0, 10091658], [276721138, 0, -2842860, -32615, -32615, 0], [214408471, 214408471, 471050, -1735164, 0, -471050], [0, -141641514, 0, -802768, 802768, -15605978], [0, -487898850, 0, 944075, -944075, -7225250], [-86713142, 0, 14799180, 2971995, 2971995, 0], [-283461656, -283461656, 12620489, 4432228, 0, -12620489], [-175710412, 175710412, -11806953, 0, -5454015, -11806953], [-335917213, -335917213, 21228344, 2265971, 0, -21228344], [-401511734, 401511734, -18285305, 0, -6303374, -18285305], [0, -603153918, 0, 3801984, -3801984, 4416114], [664521842, 0, 29163600, 1284900, 1284900, 0], [1098186538, 0, -12606420, 10311595, 10311595, 0], [294163069, -294163069, -20011436, 0, 3519878, -20011436], [-226026350, -226026350, -34500753, 1497002, 0, 34500753], [0, -817485300, 0, 5656200, -5656200, 23268300], [-181561022, 0, -73750620, -1514955, -1514955, 0], [-584261971, 584261971, 94701790, 0, -4044421, 94701790], [517293518, 517293518, -75795923, -24941055, 0, 75795923], [0, -1040798142, 0, -23043554, 23043554, 42490466], [-1340787185, 1340787185, -35830878, 0, 26999042, -35830878], [0, -2223598344, 0, 3277972, -3277972, 26134712], [-1092580978, 0, -10769100, -4925025, -4925025, 0], [-1432032302, 0, 109574100, -11714975, -11714975, 0], [-1418269331, -1418269331, 15088564, -11172722, 0, -15088564], [-2848887577, 2848887577, -71286748, 0, 44864375, -71286748], [0, -1833859998, 0, -38032401, 38032401, -1408446], [6524116378, 0, -1131780, -11894145, -11894145, 0], [2271400522, 2271400522, 37182343, 71123840, 0, -37182343], [4838961902, 0, 278167380, -50236705, -50236705, 0], [-1674005710, 1674005710, -7105207, 0, -20038847, -7105207], [-3163321196, 3163321196, -78912931, 0, -15987732, -78912931], [-778452094, -778452094, -63039639, 80285397, 0, 63039639], [-3986507942, 0, 332269020, -14906945, -14906945, 0], [-6460052573, 6460052573, 57947198, 0, -22244750, 57947198], [-4785055952, -4785055952, 21392561, 6281244, 0, -21392561], [-4169081822, 0, 144261060, 50925165, 50925165, 0], [1760635021, 1760635021, 183218900, -62667464, 0, -183218900], [2308649960, 2308649960, 106233683, -71526187, 0, -106233683], [0, 717569190, 0, -41041270, 41041270, 338588230], [1675878553, -1675878553, 31731496, 0, -96348416, 31731496], [0, 10003222764, 0, -11372532, 11372532, -344033172], [-842116183, -842116183, -618384766, -59138909, 0, 618384766], [3122290156, -3122290156, 572156965, 0, -103268914, 572156965], [0, -15815532978, 0, 50941164, -50941164, 461501694], [6988998005, -6988998005, -804048362, 0, -103840437, -804048362], [0, 5980908414, 0, -95453807, 95453807, -233162722], [-5079409280, -5079409280, 25062657, 182236782, 0, -25062657], [13448109122, 0, -1040622240, 19799840, 19799840, 0], [0, -11194454664, 0, 211899157, -211899157, 998745272], [0, 16532002938, 0, -58270244, 58270244, 288164426], [-13810513378, 0, 1101738180, 162930495, 162930495, 0], [-21853072262, 0, -831373860, 7882135, 7882135, 0], [21520743085, -21520743085, 35798532, 0, 148174272, 35798532], [0, -21522311964, 0, -73799468, 73799468, 624455972], [15483290426, -15483290426, 469361921, 0, -223007023, 469361921], [0, -12072080340, 0, 59009895, -59009895, -296899380], [23906302099, 23906302099, -550276946, 158564498, 0, 550276946], [-4987789078, 0, 702499320, 154900130, 154900130, 0], [-1873324687, 1873324687, 832537322, 0, 62967535, 832537322], [-7807586878, -7807586878, -826050951, 242392561, 0, 826050951], [0, 10814423712, 0, -118992556, 118992556, -3132114176], [11764324619, 11764324619, 424689120, 461142399, 0, -424689120], [29390319298, 0, 13545060, -154753835, -154753835, 0], [0, 35447615730, 0, 320560460, -320560460, -28576190], [58607566667, -58607566667, -295363536, 0, 140489371, -295363536], [0, -67452093354, 0, 20481002, -20481002, -1999550858], [-29984771878, 0, -186165720, -488727730, -488727730, 0], [36615658814, -36615658814, -548218755, 0, -200891631, -548218755], [-52277799958, 0, -3771159240, 373023090, 373023090, 0], [-3941629090, -3941629090, 980066333, 74696113, 0, -980066333], [-18086326136, -18086326136, 2823973449, -376146442, 0, -2823973449], [4421842568, -4421842568, -1294637213, 0, 768291105, -1294637213], [0, -4207011648, 0, -974047901, 974047901, 2278651904], [-18079915742, 0, 1164897060, 184179165, 184179165, 0], [22033422397, 22033422397, -490212732, 1345138590, 0, 490212732], [132685808684, 132685808684, 903311215, -285137091, 0, -903311215], [4979762389, -4979762389, -2103120276, 0, -758728792, -2103120276], [0, 16284690660, 0, 41140720, -41140720, 6166645220], [60689765102, 0, -2209829100, 935064975, 935064975, 0], [-39638317819, -39638317819, -2816255114, 1157665247, 0, 2816255114], [-10307889548, 10307889548, 2552824173, 0, -984996300, 2552824173], [-40251471797, -40251471797, -5015415674, 659815114, 0, 5015415674], [0, -20795006682, 0, -115855184, 115855184, 7236009686], [104584611418, 0, 1311349980, 1301011695, 1301011695, 0], [169834477262, 0, 22468020, 311659055, 311659055, 0], [-87801810124, 87801810124, 2197089671, 0, -617063123, 2197089671], [94804116515, 94804116515, -1440848952, 101212783, 0, 1440848952], [-39736452302, 39736452302, 4959842831, 0, 1308245514, 4959842831], [0, -58834819326, 0, -415774012, 415774012, -10016640302], [-28783278658, 0, 7290999780, -650085105, -650085105, 0], [-13526794199, 13526794199, -1760030200, 0, -1299260984, -1760030200], [-45433993478, -45433993478, 6676812743, -137057910, 0, -6676812743], [-155857804930, 155857804930, -1413218067, 0, -1825454027, -1413218067], [14879287138, 0, -5264842620, -172817955, -172817955, 0], [-81994264738, 0, -8623381020, -723467305, -723467305, 0], [0, 83424669426, 0, 1312600262, -1312600262, -5321203598], [0, 33276476808, 0, 1244960196, -1244960196, 4738057416], [-78355835377, -78355835377, 1823584892, 723559615, 0, -1823584892], [-28732785530, 28732785530, 985628587, 0, -879360838, 985628587], [0, 117364557546, 0, -757312248, 757312248, -6121241958], [156004723151, -156004723151, 4542099196, 0, -1999459473, 4542099196], [385084276138, 0, 340101420, -773347845, -773347845, 0], [-13030067726, -13030067726, 10971666879, 711422448, 0, -10971666879], [71967297122, 0, -8461673280, 2623805480, 2623805480, 0], [0, 44230457952, 0, -813925376, 813925376, 728496704], [-206603302724, 206603302724, -5820224475, 0, -846167884, -5820224475], [70921137434, 70921137434, 979749265, -824901091, 0, -979749265], [-122996812520, -122996812520, -12681200663, 2548340572, 0, 12681200663], [0, -25133960484, 0, -3593637708, 3593637708, 2528923932], [-450519308462, 0, 10697189460, -374646735, -374646735, 0], [-91778820898, 0, 20589082020, -261469945, -261469945, 0], [-255910732501, 255910732501, -5153275600, 0, 3701490259, -5153275600], [-90064426672, -90064426672, 5019140907, 4699653685, 0, -5019140907], [0, -299729439702, 0, -2990371449, 2990371449, -7223880054], [0, -25456472724, 0, -4643806888, 4643806888, -2680760948], [180250321408, -180250321408, -7801905439, 0, -353540996, -7801905439], [52145969539, 52145969539, -2378736226, 1758728508, 0, 2378736226], [0, -786248875026, 0, -610917112, 610917112, -6714208802], [96768983573, -96768983573, 9856720902, 0, -771356225, 9856720902], [-80224176668, -80224176668, -9443944627, -5573900420, 0, 9443944627], [-205148373298, 0, -8669956620, -294607705, -294607705, 0], [43471503800, -43471503800, -22391670477, 0, -1103627007, -22391670477], [-434926725001, -434926725001, 6578151860, -276079081, 0, -6578151860], [581611489076, 581611489076, -2785870729, -2048129423, 0, 2785870729], [210308397898, 0, -5890191060, 557169835, 557169835, 0], [0, 436109513508, 0, -4778404104, 4778404104, -41086816284], [0, -352808441052, 0, 4277860201, -4277860201, -28124950204], [-755486043749, -755486043749, -4353624810, 538685706, 0, 4353624810], [189630993842, 0, 6527404560, 4364033540, 4364033540, 0], [100844918690, 100844918690, -6451492727, 7956041733, 0, 6451492727], [56401398883, -56401398883, 5380064286, 0, 3783866354, 5380064286], [-651190995733, -651190995733, -7839736016, -6392139109, 0, 7839736016], [-170608383182, 0, 26657408340, 6012938185, 6012938185, 0], [191385488077, 191385488077, 8838244708, -1741659440, 0, -8838244708], [-214544937925, 214544937925, -10572183952, 0, -1412522857, -10572183952], [501690449338, 0, -26941322820, 3815586495, 3815586495, 0], [161490790870, 161490790870, 22195613707, -7585544368, 0, -22195613707]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_80_p_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_80_9_p_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_9_p_c(:prec:=6)
    chi := MakeCharacter_80_p();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 9));
    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_9_p_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_9_p_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_80_p();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,9,sign)));
    Vf := Kernel([<3,R![155160150048, -7276369968, 170615844, 383400, 2592, -72, 1]>],Snew);
    return Vf;
end function;