
// Make newform 19.8.a.b in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_19_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_19_8_a_b();".
// 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_19_8_a_b();".
// 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 := [-2267712, 7680, 80412, 610, -540, -3, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [-181, -2, 1, 0, 0, 0], [-510288, 454620, 52718, -7416, -249, 23], [-7796880, 775596, 219414, -13016, -805, 43], [407544, -11400, -14854, 718, 59, -3]];
    Rf_basisdens := [1, 1, 1, 11712, 35136, 1464];
    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_19_a();"
function MakeCharacter_19_a()
    N := 19;
    order := 1;
    char_gens := [2];
    v := [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_19_a_Hecke(Kf)
    return MakeCharacter_19_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 := 8;
    raw_aps := [[2, 1, 0, 0, 0, 0], [6, 1, 0, 0, 1, 0], [32, 7, -1, 1, -1, -1], [352, -2, 3, 7, -8, -1], [1314, -223, -15, 15, 49, 41], [1136, -55, -24, -46, 35, -92], [786, 326, 31, -151, 2, -57], [-6859, 0, 0, 0, 0, 0], [758, -1601, 574, 176, -371, -638], [63844, 195, -330, -840, -1315, 10], [42024, 2776, -2148, -980, 748, 812], [173342, 16264, -100, -1100, -1484, 1580], [85598, -10946, -1012, 1960, -5218, -1372], [29502, 8223, 4393, 3087, 3807, -111], [-41010, -4623, -3369, -4251, 4605, -3297], [546984, -9731, 11216, 7174, 55, 3348], [384390, 1473, -6212, 3200, 1465, 15940], [119140, -41363, -14377, -11495, -20987, 2087], [-531006, -34413, 9634, 5046, -16101, -30078], [1173072, -62272, 10718, -3050, 18060, -1130], [-765114, 150924, -11377, -18663, 3600, 11559], [-1362900, -149726, -2812, -8060, 16702, 31508], [-775216, 281862, -2684, 7304, -36814, -17412], [2060330, -248, -26542, 8590, -11452, -13438], [50334, 198490, 71074, 81526, 10, -17758], [5981110, -75748, 3912, -75120, 21420, -58200], [-6252320, -392152, -25938, 25778, 12728, 37486], [-906622, -120593, -23068, 7528, -168577, 52556], [5720820, -689833, 30272, 51890, -80755, -3860], [5353266, 890220, -83212, 1192, -25828, -46276], [6176112, -214680, -52582, -95058, -59724, 21354], [3148930, -60183, -208281, -71055, -251359, 27199], [25494978, -723022, -109201, -46319, 377982, 211687], [-14715410, -759209, 36029, 140155, 36919, 148181], [810660, -119019, 113013, 248175, -197559, 274749], [7299664, -65512, -52106, 77090, 835208, 186502], [-3775802, 546320, 149608, -103708, -117340, 249664], [-40487396, -418460, 111808, -121988, 41344, -226216], [36858756, 868014, -3878, 243458, -50546, 328546], [-25362266, -1844348, 306048, 125052, -599552, 158264], [-43235480, 3471594, 167414, -367010, -679190, -281250], [-17527826, 1040252, -151188, 653600, -117160, -65660], [-28816152, 3244686, -345081, 38835, 1711344, 107091], [46971646, -172410, -124434, -412686, 187650, 384798], [2793122, -1051134, -708184, -788216, -436614, 280648], [-70892944, -4953514, -297961, -101245, 416504, 654691], [-9787842, -8526575, 234024, -296540, -630743, -393232], [9546960, -1550008, 518070, -196570, 2923424, 665470], [-2124726, -5068333, -1176694, -725726, 586011, 68578], [60359912, 1194079, 1363513, 1165495, 1411087, -468967], [-92762680, 11135073, -91769, -656491, 1805237, 613863], [-20140896, -479486, 809539, 569615, 364860, -1200865], [41839038, -4693414, -114248, 737780, -1743022, -687488], [163471806, 6968195, 524919, 169245, -1041473, -294937], [116642650, 4369912, 2309206, -1001866, 3740300, 715278], [37255806, -3946907, 1021779, 1503561, -2570311, -3045413], [142369914, 5918478, -2044946, 41090, 1868458, 538462], [75158110, 10163175, -2070458, -2562000, -2156859, -957846], [63847804, -1351359, -3231675, -918285, 4213353, 1152165], [183477862, -9365354, 274192, -2125120, 705038, -1136688], [-87639166, 15630769, -129063, -656777, -2874119, -320959], [71510180, -20343161, 1999012, 2452778, 1437085, 1163416], [-44113692, 10534356, 2513376, -5076, -734940, -2022072], [73251356, -16762952, -2148955, -479795, -33694, 1443089], [-214667596, -15257299, -544742, -1305238, 1301141, 1770034], [-48017136, -2567363, 2018802, 1789548, -948133, -204314], [113427078, -5366335, 1532470, -1630270, 4824785, -4210250], [-480483334, 4600760, 6080614, 1666646, -7868332, -2570018], [733461318, 3751999, -851145, 332805, -868285, -749705], [-477352544, -13552441, -5299811, -4990285, -3380785, 870205], [76441900, -38450923, -1647802, -2788658, 10990157, 1413374], [125376908, 34386804, -88585, -1435985, -3981702, -3929093], [87896352, -38960140, 3276608, 1326872, -1009204, 3891184], [436096188, -8532181, -4505596, 1547426, 947129, 2660392], [350494942, 1626997, -1789992, -6074540, 2289493, 438752], [258399268, 45636934, 2538776, 5833204, -2487114, 6250048], [934929084, -29899707, 4719735, -1345275, -8016879, -6144081], [-169385612, 11842817, 1473657, -5328817, 18775913, -2933159], [75366658, -2477800, 2539378, -6067750, 10936384, 5112106], [-608639406, 20911644, 9135434, 1206990, -7072440, -13104630], [-843915764, -27922244, -5132816, -5893060, -543496, 1594536], [199616152, 61926117, 4476764, -7657830, -4594449, -3791136], [-397288308, 40807326, 3899444, 2485840, -3757126, 1404716], [-849522102, -19310392, 8284944, 6189536, 16729772, 875632], [576621076, -83002082, 11406386, 8690050, -25609466, -10463734], [203347686, -42786537, -4160009, 7376249, -9716249, -6595697], [936330182, 63861926, 2978826, 8129850, 7656410, 6032530], [-224766222, 59443678, -2820139, 15232219, -9737726, 19376813], [962667228, 73463093, 12834401, -4707125, 6359769, -17201879], [-36963298, -23432343, 12872211, 3972609, -22209027, -5533077], [645194318, -124766825, 4982751, -10149411, -5926677, -4974417], [-978807608, -60875488, 1761108, 1900020, -22135512, 10120452], [892414512, 82265808, -16948910, -2659530, -18978936, 8675010], [-560818372, -4352904, 6971728, -2790520, -9844744, 15671184], [-1932852878, -70679831, -5206789, 18678805, 19124041, 9571859], [-208157298, 78649491, 20062162, 12517388, -3654983, -291434], [1796376034, 81002142, 5986286, 4990870, 40854322, 26072598], [-1431733766, 164004240, 8531534, 10608550, 3055432, -339402], [-588262598, 202895595, -17892460, 1661280, -11084277, -590100], [1233427220, -149674715, 13383575, -3476075, -4370735, -7767745], [94476644, -142741824, 6147136, 13794984, 11176104, -6922032], [1008535572, -151278335, -2617003, 23029123, 24335545, 28504581], [617963152, -138039034, 2540950, 16477670, -11297210, -11144210], [1370969826, -40343840, 36749182, 26660690, -14127864, -16970866], [-2899680260, 38678296, 2475232, -21523280, -39125192, 11632592], [-1839872282, -204893148, -1921175, -16298985, 26680776, 7025745], [-1489953950, 26281853, 9182267, 38651833, 27740873, -8058949], [1781954586, -118878788, -36625268, -20767492, 44082060, 41204876], [-635481264, -28466648, -597620, 13766240, 40999704, -15633004], [-1144506818, -211269886, 42602788, 10927760, -29872378, -30255332], [-2652956492, 60980930, -7101628, 12062168, 16535294, 15602476], [948279904, -158892285, 48588505, -2764605, 14948871, 11901345], [-1729395716, -66743913, -43560943, -30202397, 2446747, 65470401], [1378924200, 384152750, -5836, -7946980, 33681422, -11816732], [1116104858, -40515601, -22672495, 12719795, -70069717, -1534343], [3094253110, 89571886, -23035110, -17600430, 13360282, -15128782], [1201806706, -142861899, 41660801, -2876421, -85449663, -61955247], [-3528085920, -309387066, 5254311, -32281821, 15030744, -54094557], [1938111676, 247329957, 20203313, -22355873, -58060739, -32257071], [1378455338, 181934463, -32319472, -13517780, 41353935, 85890040], [3928026428, -368274693, -12091240, -7401450, 97452009, 44548236], [-1260511050, -224192774, 21000768, -11376968, -61542710, -15732016], [3130709752, 248750585, -17987926, -28874504, -35252833, -22968298], [864960012, -84638704, 22930952, 53630968, -83259528, 73614856], [3684709390, -50104545, -22362277, 1844025, -55577901, -43788789], [-343957254, 51449946, -30638476, 34791460, 36011954, 2844116], [-760557938, 310602832, -74360228, 1675960, 39266140, -17237020], [-2414909128, -67082378, 34184435, -39109865, -29011456, -44308369], [1449999420, 171423368, -8470987, -70966483, -34867366, -61136591], [-1147764510, 643409046, 61140872, 37580268, 22276914, 22896816], [981295206, -644637833, -22802227, -57790745, 60047563, -15141283], [-4531373352, -305279716, -64299048, 36634968, -58331768, 31765016], [-2077534000, 106418240, -18538192, -13088800, 128920424, -31106384], [3013802340, -429114535, -53011177, 32617217, 24284273, 120349639], [-6836919422, -45690326, 20026035, -58789035, 57570958, 16547627], [-3460771110, 17127974, 20979265, 63016175, -42787222, 59503897], [-5751645240, -219750811, -84151058, -45147832, -92621125, 31130706], [-446982022, 544508843, -46374374, -13348486, 119407379, 71891938], [2598183528, -436490319, 125132104, 14582846, 50126203, -15017108], [506446858, -585647078, 92736497, 87563215, -179499450, -30442295], [3602533494, -1016326819, 111037970, 36422090, -185426923, -65522582], [-2400824124, 409880829, -100593447, -30989145, 262962717, 69641193], [-8452735452, 730489056, 16638383, 112646487, -64160058, 72152739], [-5615607470, -855634545, 108288818, 92465302, 81097663, -26995086], [6152909940, -116858941, 48978944, 4830230, -24267055, -164748380], [4122175740, 410146742, -148288594, -39639050, 252706122, 6922438], [355488398, -77243232, 116500276, -855156, -320721816, 32302308], [-2954102874, -42822962, 4182860, 27376660, -9599570, 53696940], [-271981390, 1013058145, -114110155, -81780845, 128529505, 151158605], [7732385656, 815578468, 56746834, 55904846, 138269024, 16263762], [-4922914728, 635331745, 125940942, 86081248, -72868385, -101053054], [-5962466380, -321421241, -80265995, 101531975, -58953197, 224607397], [12774940370, -171404347, 103578117, 30747023, 32910113, -89360699], [-15874042544, 315751544, 112327498, -36368278, 152158780, -94829726], [4976977574, 49042257, -74863190, -63727770, 439880745, -25470150], [6715721908, -405892946, -290214018, -159743370, 16228234, 32483606], [9930096282, 313280169, -82958426, -35426820, 30899235, 232804770], [14101840148, 387617617, -111545550, 40353450, -88270431, 166611546], [6461226198, 1912868044, 47586087, -34442087, -119268248, -180571969], [7393878508, -1412631541, -81427082, 109019180, -92603483, 81539458], [7377343844, 433773424, 3086848, 80195732, -179914388, 167530264], [11697075934, -827546062, 174735986, 106152574, -421625002, -71306302], [-30059942048, 313684056, -5839008, 86533368, 92056032, 3566976], [-5179890564, 672244544, -261416032, -216377840, -65974128, -60831872], [5073932970, -1313416596, -191682498, -261433662, -82334640, 7040526], [-10563938524, -665465242, -39385952, 4162052, 434556858, 140106584], [-13376899596, 299600050, 190767058, 4947790, -44089226, 86429906], [748712452, 902189525, 10200753, -18441913, -279546979, 123354769]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_19_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_19_8_a_b();".
// 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_19_8_a_b(:prec:=6)
    chi := MakeCharacter_19_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 8));
    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_19_8_a_b();".
// 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_19_8_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_19_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<2,R![-1974784, -289800, 64272, 4650, -450, -15, 1]>],Snew);
    return Vf;
end function;