
// Make newform 18.6.c.b in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_18_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_18_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_18_6_c_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_18_6_c_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 := [32331, -3585, 3700, -231, 118, -3, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [22035, 16626, -269, 176, 5, -2], [-4096833, 670179, -258101, 35573, -2875, 331], [-168909, 527673, -22229, 30659, -418, 331], [11037819, 769179, 495697, 82325, 3665, 991], [-5840445, 3065883, -636943, 168037, -9461, 1655]];
    Rf_basisdens := [1, 60606, 60606, 30303, 60606, 60606];
    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_18_c();"
function MakeCharacter_18_c()
    N := 18;
    order := 3;
    char_gens := [11];
    v := [2];
    // 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_18_c_Hecke();"
function MakeCharacter_18_c_Hecke(Kf)
    N := 18;
    order := 3;
    char_gens := [11];
    char_values := [[-1, 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 := 6;
    raw_aps := [[0, -4, 0, 0, 0, 0], [1, 1, 1, -1, 0, 0], [-20, 18, 2, 1, 0, 1], [-5, -37, 12, -6, 2, -3], [10, -107, -12, -9, -7, 3], [-228, 260, -8, -31, 6, -13], [458, 13, 38, -2, -13, 1], [358, 1, 20, 34, -1, -17], [-1027, 1050, -35, -4, -3, -13], [-89, -1733, 72, 141, 71, -18], [-2765, 2768, -207, 126, -51, -27], [6576, 50, 130, -40, -50, 20], [1453, -1263, 650, -620, 210, 10], [312, -10619, -468, -117, -195, 117], [-285, 4611, 588, -174, 138, -147], [-16340, 170, 502, -16, -170, 8], [21566, -21411, -1007, 455, -213, -184], [-447, -24785, 984, -381, 201, -246], [-9974, 11087, -933, -669, 45, -534], [-22486, 484, 1358, -188, -484, 94], [-238, -969, -2142, 1530, 969, -765], [-799, 29115, 180, 2082, 754, -45], [-579, 12831, 2532, -2694, -54, -633], [11120, 196, 98, -980, -196, 490], [1946, 12729, -4632, 2268, -788, 1158], [485, -34645, -1056, 393, -221, 264], [65395, -71422, -1833, 7926, -1965, 2031], [-43838, -1555, -3272, 2786, 1555, -1393], [10100, -1410, -4578, -696, 1410, 348], [32076, -31056, 684, -1575, 426, -297], [-111412, 894, 5352, 5340, -894, -2670], [141427, -135972, 6389, -10130, 2961, -1247], [4114, -20927, -11256, 7356, -1300, 2814], [88220, -83941, -5323, -1487, -261, -2270], [-95356, 83820, -8408, 18233, -4986, 3275], [2595, 64855, 2820, -12720, -3300, -705], [161296, -153826, -2766, -6675, 1176, -3147], [237780, 1136, 1744, -3328, -1136, 1664], [155529, -147420, -4881, -6072, 807, -3651], [-7017, 69543, 14544, -4401, 3381, -3636], [-268184, 752, -980, -6472, -752, 3236], [-19716, 6320, 11290, -15340, -6320, 7670], [-7129, -230125, 1788, 18258, 6682, -447], [-268859, 269141, 12222, -7956, 3126, 1422], [337226, -734, -2776, -1148, 734, 574], [319162, -5102, -12766, 5080, 5102, -2540], [177513, -184108, -10721, 14120, -4329, 1133], [1947, -779669, -5892, 4470, -474, 1473], [10530, 79005, -14124, -6873, -6999, 3531], [-623078, 603788, 5802, 18075, -3372, 7959], [-62324, 8639, 32824, 13814, -8639, -6907], [176397, -222186, -13215, 59772, -14751, 15519], [-230, 553157, 26832, -46266, -6478, -6708], [148078, 8171, 7408, -34210, -8171, 17105], [-630735, 650043, 15780, -31584, 8772, -5268], [-3649, 835319, 22452, -28344, -1964, -5613], [1590664, -394, -1430, -496, 394, 248], [44468, -3588, 7044, 35616, 3588, -17808], [34083, -341273, -42576, -27741, -23439, 10644], [-3761, -37037, -46752, 93099, 15449, 11688], [-221705, 274160, 4125, -61590, 14145, -19155], [465086, -395436, -49682, -47305, 4992, -32329], [-978346, 24711, 41544, -65178, -24711, 32589], [377605, -385530, 91289, -48140, 20841, 14383], [-1946, 358253, 16128, -22386, -2086, -4032], [-48097, 878051, 114744, -56511, 19411, -28686], [8057, 839091, -64788, 89208, 8140, 16197], [116165, -138889, -41164, 51292, -15972, 3376], [3491142, -3485685, 31587, -25881, 9261, 1902], [62509, 1491419, -114384, 12645, -33913, 28596], [712, -3355187, 23112, -42582, -6490, -5778], [-473856, 34002, 73716, -56580, -34002, 28290], [-303, -830765, 75780, -131706, -18642, -18945], [-1172544, 1138088, 184624, -76627, 37542, 35999], [-1165704, -14479, -20318, 46238, 14479, -23119], [507577, -517008, -127933, 90568, -34341, -12455], [-59881, 198719, 231312, -225153, 2053, -57828], [3515852, 2418, -16770, -48048, -2418, 24024], [2854489, -2930451, 10178, 79096, -16446, 29758], [-810865, 837797, -24532, -14966, 600, -13166], [-2428011, 2373708, -126837, 140364, -45285, 4509], [98245, -1162729, -186456, 31563, -51631, 46614], [70856, -55226, -158260, 14836, 55226, -7418], [-174634, -54495, -132318, 62334, 54495, -31167], [144957, -1473461, -265452, 29670, -78594, 66363], [-21132, 4660965, 145308, -190893, -15195, -36327], [-1084842, -87711, -245742, 34782, 87711, -17391], [-18978, -1819583, -6216, 67812, 20532, 1554], [69403, -4429085, -242616, 216369, -8749, 60654], [355095, -302200, 147205, -151510, 50025, -1435], [-4479038, -43873, -108500, 46238, 43873, -23119], [-146013, 2942655, 209508, 71400, 93636, -52377], [-2364632, 50422, 95780, -110972, -50422, 55486], [994268, -1070625, 313441, -109999, 59271, 67814], [1811818, -1977139, -19035, 197883, -46089, 59616], [-5187450, 29472, 93114, 9396, -29472, -4698], [3804862, -3573546, -217468, -124313, 3462, -113927], [3558896, -10115, -184168, -307646, 10115, 153823], [3309230, -88536, -184746, 161724, 88536, -80862], [-4844238, -29590, -108248, -38956, 29590, 19478], [79980, 1078633, -28044, -190863, -72969, 7011], [-1249912, -15188, 114302, 319732, 15188, -159866], [-2180730, 1972731, -190221, 352887, -99555, 54222], [58310, -11392099, -102624, 4662, -32654, 25656], [4498988, -4560055, 293663, -114839, 58149, 59608], [-570730, -125433, -173082, 406434, 125433, -203217], [-39904, 550085, 33420, 61227, 31549, -8355], [7968164, 17356, -31738, -167612, -17356, 83806], [-6496183, 6755340, 113191, -362296, 93087, -83035], [-258720, 935725, 670200, -396690, 91170, -167550], [3942977, -4295284, -22129, 410176, -93609, 129349], [2943932, 1038, -211122, -428472, -1038, 214236], [4427527, -4693785, 107882, 232114, -39594, 113332], [217752, 4995409, -216924, -273639, -163521, 54231], [-839580, 57032, 36964, -268264, -57032, 134132], [-147266, -3331283, 173520, 138138, 103886, -43380], [-3920732, 3820445, -309213, 306081, -102375, -1044], [-666600, -40146, 25956, 292788, 40146, -146394], [-1196254, 1509048, -322394, -150397, -2400, -157597], [267113, -5801821, -310212, -258468, -189560, 77553], [-5127500, 4867310, 215502, 158025, -11172, 124509], [-51253, -2702541, 170880, -145281, 8533, -42720], [-224863, 7329539, 740160, -620691, 39823, -185040], [5694594, -94503, -127008, 313002, 94503, -156501], [-63135, -8143457, 230868, -214614, 5418, -57717], [1588156, 7112, -45326, -133324, -7112, 66662], [17345, -6149301, 146640, -308655, -54005, -36660], [-2647056, 42300, 111432, -30936, -42300, 15468], [-342657, 5972647, 424116, 285768, 236628, -106029], [-10820636, 10480808, -403620, 634569, -185862, 76983], [-3246460, -239991, -753378, -66810, 239991, 33405], [7162059, -7632558, -287025, 708702, -189381, 140559], [-13683799, 14348264, -97477, -686600, 141747, -261359], [1292750, -2844, 113232, 243528, 2844, -121764], [5806098, -5143176, -93450, -687381, 142368, -260277], [-3244140, 3238940, -560600, 356225, -141450, -68125], [2617044, 24876, -58182, -265620, -24876, 132810], [4543471, -4707520, 463989, -105438, 74985, 119517], [8443170, -8166102, -27252, -294669, 62454, -107307], [-9054874, -92183, -21958, 509182, 92183, -254591], [6579794, -21321, 136836, 401598, 21321, -200799], [-566305, 3982091, 807384, 285993, 364459, -201846], [-10835469, 10132604, 440917, 515150, -65487, 318689], [5717360, 231568, 406316, -576776, -231568, 288388], [775216, 94792, 93998, -380756, -94792, 190378], [183933, 3672183, -667092, 615612, -17160, 166773], [519363, -7780301, -269832, -1085883, -451905, 67458], [481431, 6227691, -390288, -761289, -383859, 97572], [4819928, -5303959, 1104707, -145907, 155169, 319600], [-4061140, -404336, -1181068, 63880, 404336, -31940], [-2202802, 2383358, -862228, 335767, -170418, -175487], [10637464, -210820, -309758, 645404, 210820, -322702], [17074834, -201341, -471052, 265942, 201341, -132971], [-5908217, 5269620, -587143, 1085386, -306435, 166081], [-154414, 938169, 35580, 400977, 145519, -8895], [-36939, 4617819, -48540, 195762, 49074, 12135], [-23787712, -64830, -264924, -140868, 64830, 70434], [261723, 23970051, -155808, -512505, -222771, 38952], [-10066884, 423308, 852646, -834556, -423308, 417278], [2834108, -3613026, -1498634, 1812929, -569388, 104765], [-220296, 22903929, 1436100, -1852287, -138729, -359025], [-20093466, 469089, 892218, -1030098, -469089, 515049], [17747713, -17074822, 619593, -1144248, 323121, -174885], [-23065950, 42096, 385026, 517476, -42096, -258738], [19540211, -18224367, -884420, -927562, 107856, -603994], [1053581, -3907237, -2122380, 553422, -522986, 530595], [-5226076, -487680, -1431588, 62904, 487680, -31452], [-146319, 20100403, 1166880, -1603083, -145401, -291720]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_18_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_18_6_c_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_18_6_c_b(:prec:=6)
    chi := MakeCharacter_18_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_18_6_c_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_18_6_c_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_18_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![46562734656, 1007927064, 33470577, 179334, 7587, 54, 1]>],Snew);
    return Vf;
end function;