
// Make newform 9.6.c.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_9_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_9_6_c_a();".
// 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_9_6_c_a();".
// 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 := [7056, 0, 3363, 0, 568, 0, 40, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [84, 1683, 0, 484, 0, 40, 0, 1], [-1644, -3273, -592, -984, -88, -96, -4, -3], [-3108, -4929, -798, -1580, -42, -158, 0, -5], [25116, -7167, 8428, -2592, 868, -276, 28, -9], [-897, 0, -301, 0, -31, 0, -1, 0], [987, -9, 310, 0, 31, 0, 1, 0], [-67452, 51477, -18508, 16368, -1372, 1620, -28, 51]];
    Rf_basisdens := [1, 168, 24, 28, 168, 3, 3, 168];
    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_9_c();"
function MakeCharacter_9_c()
    N := 9;
    order := 3;
    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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_9_c_Hecke();"
function MakeCharacter_9_c_Hecke(Kf)
    N := 9;
    order := 3;
    char_gens := [2];
    char_values := [[0, -1, 0, 0, 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 := 6;
    raw_aps := [[1, -1, 0, 0, 1, 1, 0, 0], [-3, 3, 0, -1, 0, 1, 1, 0], [0, 20, 2, 3, -1, -1, 0, 1], [4, -4, -2, 5, -11, -10, -1, -3], [109, -109, 7, -9, -3, 2, 12, 2], [0, -62, 2, 5, 69, -3, -4, -1], [-531, 0, -19, 51, -35, 41, 3, 16], [119, 0, 39, 45, -3, -123, -81, 42], [0, 2216, -35, -84, -69, 49, 63, 14], [2998, -2998, 21, -72, -56, -86, -9, 51], [0, 478, 29, 98, -711, -69, -109, -40], [-2140, 0, -6, -306, 150, -654, 162, -156], [0, 119, -72, -126, 718, 54, 36, -18], [-1517, 1517, 181, -181, 205, 386, 362, 0], [-188, 188, -190, 81, -991, -1290, -489, 109], [2052, 0, -390, -450, 30, -1038, 810, -420], [0, 1019, 377, 363, -2014, 14, 405, 391], [12532, -12532, -545, 284, 1180, 374, -1351, 261], [0, -1655, -955, -931, -504, -24, -1003, -979], [-7956, 0, 716, -516, 616, 3188, -816, 100], [14699, 0, -873, 1161, -1017, -1845, 729, 144], [-14054, 14054, -392, 1685, 4201, 5102, 509, -1293], [28918, -28918, 846, -765, -1097, -170, 1773, -81], [-56034, 0, -716, -1788, 536, 4948, 1968, -1252], [6691, -6691, 154, -2296, -9200, -11188, -1834, 2142], [85996, -85996, -2281, 4068, -11932, -12426, -2775, -1787], [0, -60596, 449, 524, 10815, -75, 299, 374], [-92853, 0, 651, 3609, -1479, -21111, -2781, 2130], [-51352, 0, 30, 1530, -750, 14934, -810, 780], [0, 33122, -4468, -4749, -3307, 281, -3906, -4187], [21314, 0, -150, -11538, 5694, 15726, 5994, -5844], [0, 107246, 5215, 5640, -15255, -425, 4365, 4790], [-30941, 30941, -3378, 5148, 5548, 3940, -4986, -1770], [0, -1871, 3269, 10781, 7488, -7512, -11755, -4243], [0, -91438, -42, -4383, 5557, 4341, 8640, 4299], [57208, -57208, 2734, -4231, 30529, 31766, 3971, 1497], [0, -207152, 1406, -2437, -501, 3843, 9092, 5249], [-277396, 0, 4584, 8280, -1848, -13560, -11016, 6432], [0, -47770, 893, -2166, -12943, 3059, 7011, 3952], [-206198, 206198, -1595, 11268, 132, 8210, 6483, -9673], [5868, 0, 10376, 12264, -944, -14008, -21696, 11320], [252758, 0, -3624, 3744, -3684, -21768, 3564, 60], [95824, -95824, 2118, -3087, 26233, 27382, 3267, 969], [0, 68707, -10972, -22798, -4182, 11826, 12680, 854], [113796, 0, 5362, -18402, 11882, -15542, 1158, -6520], [88094, 0, -9402, -34326, 12462, 62850, 31266, -21864], [0, -357326, 4259, -1672, -114963, 5931, 16121, 10190], [548644, -548644, -4718, -9967, 50785, 31382, -24121, 14685], [6589, -6589, -365, 11619, -92367, -81478, 10524, -11254], [0, 321670, -14182, -9895, 9753, -4287, -22756, -18469], [457227, 0, -16177, 31929, -24053, 21539, 8301, 7876], [0, 325028, -695, -4692, 108519, 3997, 7299, 3302], [-456233, 456233, -3254, -7900, 96460, 82052, -17662, 11154], [-236259, 0, -10355, -8961, -697, 8071, 20013, -9658], [0, -663163, 13848, 15732, -198764, -1884, 10080, 11964], [268732, -268732, -4342, 18729, 77177, 87222, 5703, -14387], [598320, 0, 36678, 7650, 14514, -20418, -58842, 22164], [-649564, 0, -10764, 30348, -20556, -12708, 972, 9792], [210982, -210982, -4979, 34520, -123896, -99334, 19583, -29541], [-1050542, 1050542, -11285, -8010, -141666, -172246, -41865, 19295], [0, 156106, -33325, -57568, 182805, 24243, 15161, -9082], [0, -655450, 27634, 21633, 119097, 6001, 39636, 33635], [539777, 0, 28881, 51867, -11493, 90603, -69255, 40374], [0, 187364, -46995, -53640, -161177, 6645, -33705, -40350], [-160709, 160709, 24130, -43480, -111080, -106300, 28910, 19350], [-1838402, 1838402, 15653, -54864, -53680, -77238, -7905, 39211], [-760586, 760586, 69406, -95413, 94255, 137654, 112805, 26007], [0, 260353, 44048, 66560, -20352, -22512, -976, 21536], [0, 319493, -6479, 20085, 172020, -26564, -59607, -33043], [732820, -732820, -33053, 74000, 98944, 106838, -25159, -40947], [581581, -581581, 4944, -3996, 252916, 258808, 10836, -948], [-2665314, 0, -1010, 25482, -13246, 2890, -11226, 12236], [502978, -502978, -79544, 95741, -274895, -338242, -142891, -16197], [0, -762002, -19546, 39989, 209217, -59535, -138616, -79081], [583175, 0, -24225, 74781, -49503, 20325, -1053, 25278], [0, 3331010, 51785, 111882, -194947, -60097, -68409, -8312], [500122, -500122, 90049, -57240, -64152, 58706, 212907, -32809], [12620, 0, -64662, -97938, 16638, 393474, 145962, -81300], [0, -904957, -130988, -223086, 264714, 92098, 53208, -38890], [0, 1406071, 29036, -25570, 283086, 54606, 138248, 83642], [0, 3338642, -72093, -104616, 20845, 32523, -7047, -39570], [296752, -296752, -8081, 18872, 337480, 340190, -5371, -10791], [-2944782, 0, -17430, 4446, -10938, -465954, 23922, -6492], [772985, 0, 77889, 11439, 33225, -363075, -122553, 44664], [-2285978, 2285978, -42224, 19121, -47411, -112738, -107551, 23103], [1806895, -1806895, -18935, -68085, 360165, 254210, -124890, 87020], [386217, 0, -88639, -143697, 27529, 732509, 204807, -116168], [1964479, -1964479, 150682, -176308, -74900, 50156, 275738, 25626], [-653750, 653750, 39129, -115848, 298264, 260674, 1539, 76719], [0, 1190854, 56477, 168218, -531423, -111741, -167005, -55264], [1868553, 0, 103465, -74445, 88955, -398381, -117975, 14510], [1942192, -1942192, 53498, -20907, -768451, -682362, 139587, -32591], [-619702, 0, -50262, -331650, 140694, -209346, 241218, -190956], [0, 393437, 16373, -52359, -224740, 68732, 153837, 85105], [0, -3914765, 93941, 161519, 303354, -67578, -41215, 26363], [-2218392, 0, 56744, 242304, -92780, 221144, -206268, 149524], [0, -793852, -35414, 37131, 111, -72545, -180504, -107959], [1336005, 0, -193763, 20523, -107143, 491041, 280383, -86620], [-3343012, 0, 68328, -292464, 180396, 181080, 43740, -112068], [2479628, 0, 98706, -45666, 72186, 622938, -125226, 26520], [-3095357, 3095357, -117275, 148811, 478549, 392810, -203014, -31536], [1522458, 0, 38300, -321492, 179896, 931340, 103296, -141596], [0, 2659205, 105685, 110985, 669588, -5300, 95085, 100385], [2779435, -2779435, -113310, 245448, -151352, -132524, -94482, -132138], [0, 4185019, 163253, 310607, 165906, -147354, -131455, 15899], [-1263877, 0, -86841, 189081, -137961, 816147, 35721, 51120], [-4162373, 4162373, 237101, -319077, -54115, 101010, 392226, 81976], [1964142, 0, 10380, 306396, -148008, 144588, -168768, 158388], [0, 5162366, 49253, 226218, 652649, -176965, -304677, -127712], [-7565099, 7565099, 67516, -175000, -269264, -309232, 27548, 107484], [0, -5714450, -90871, -51034, -386535, -39837, -170545, -130708], [1932968, 0, -221274, -196398, -12438, -557586, 430110, -208836], [0, -8831995, -94136, -114708, 605268, 20572, -52992, -73564], [5893735, -5893735, -17171, 89255, -1064879, -1009966, 37742, -72084], [-752632, 0, 69744, 388224, -159240, -84480, -298728, 228984], [4664035, -4664035, -419578, 512532, -159268, -485892, -746202, -92954], [0, -2238281, -104815, -142729, -785442, 37914, -28987, -66901], [998082, 0, -25758, -752346, 363294, -24282, 414810, -389052], [0, -5746606, -8170, 36273, 902069, -44443, -97056, -52613], [-5362658, 5362658, -102926, 133695, -1274205, -1346362, -175083, -30769], [0, -3425768, 203282, 133439, 550035, 69843, 342968, 273125], [7470886, -7470886, 96331, -321334, 661570, 532898, -32341, 225003], [-9630008, 9630008, 73803, -89316, 980044, 1038334, 132093, 15513], [6146271, 0, -6689, 253749, -130219, -258731, -116841, 123530], [-286070, 286070, -167534, 98315, -1248905, -1485658, -404287, 69219], [3737286, 0, 71232, -229896, 150564, 1798800, 8100, -79332], [-1253120, 1253120, -220133, 513428, -830108, -756946, -146971, -293295], [3119292, 0, 189356, 604068, -207356, 14708, -586068, 396712], [3005572, -3005572, -118934, 352001, 2046529, 2160662, -4801, -233067], [0, 8758198, 28802, 210113, -215991, -181311, -333820, -152509], [-4171345, 0, 24519, -153099, 88809, -621051, 39771, -64290], [0, -3053068, -310575, -360684, -1151801, 50109, -210357, -260466], [0, -5961878, -12463, -165094, 1118469, 152631, 292799, 140168], [-10308814, 0, -279468, -353268, 36900, -952092, 595836, -316368], [0, 4755422, -227380, -668553, 251105, 441173, 654966, 213793], [0, 23590, 301484, 722543, -450327, -421059, -540634, -119575], [-10821510, 0, 43508, 307716, -132104, -1879084, -219120, 175612], [0, 9432226, 291167, 348092, -860019, -56925, 177317, 234242], [0, 15864752, 271578, 396207, -776885, -124629, 22320, 146949], [-15309567, 0, 141705, 1321623, -589959, -2040003, -873369, 731664], [-15711055, 0, 55713, 704907, -324597, -2216013, -436023, 380310], [9145414, -9145414, -35543, 91908, -812028, -791206, -14721, -56365], [0, -1030382, -491479, -1029046, -1248195, 537567, 583655, 46088], [12380724, 0, 30248, 134664, -52208, -1902424, -112704, 82456], [14059694, 0, 138648, -434736, 286692, 2585496, 9396, -148044], [17132554, -17132554, 545376, -556299, -242039, 292414, 1079829, 10923], [-4567622, 4567622, 38005, 346652, 146476, 569138, 460667, -384657], [11219122, -11219122, 260963, -799218, 1198646, 921354, -16329, 538255], [0, -12083453, 366509, 643439, -148326, -276930, -187351, 89579], [-2822904, 0, 18456, -1390824, 704640, 2456808, 667728, -686184], [0, -766484, -1231774, -1454341, 814839, 222567, -786640, -1009207], [-20272050, 0, 6332, 142332, -68000, 1931132, -80664, 74332], [13737989, 0, -520395, 479511, -499953, 1239735, 540837, -20442], [0, 1502930, 565009, 978882, 358557, -413873, -262737, 151136], [14528209, -14528209, -294569, 172475, -1856279, -2272942, -711232, 122094], [1154710, -1154710, -611068, 1507437, 219593, 504894, -325767, -896369], [-7003690, 0, -227898, 748818, -488358, 2164194, -32562, 260460], [-2540618, 2540618, 594667, -943974, 4598994, 4844354, 840027, 349307], [28135766, 0, -50244, 262188, -156216, -1265892, -55728, 105972], [0, 13647368, -527810, -1159005, -2858013, 631195, 734580, 103385], [-29357153, 29357153, -180759, 820395, -759011, -300134, 278118, -639636], [-4235607, 0, -297503, -1466529, 584513, -1152923, 1179519, -882016], [0, -27304136, 124109, 32204, -2297109, 91905, 307919, 216014], [25341012, 0, -614448, 705528, -659988, -1702512, 568908, 45540], [0, 9285779, 376112, 908742, 1629530, -532630, -689148, -156518], [37774, -37774, -13304, -69903, 995037, 898526, -109815, 83207], [7400576, 0, 441216, -627696, 534456, -3613968, -347976, -93240], [10355080, -10355080, -217349, -5092, 19324, -420466, -657139, 222441]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9_6_c_a();".
// 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_9_6_c_a(:prec:=8)
    chi := MakeCharacter_9_c();
    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_9_6_c_a();".
// 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_9_6_c_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;