
// Make newform 18.8.c.a in Magma, downloaded from the LMFDB on 22 December 2025.
// 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_8_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_18_8_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 := [1872, -660, 709, -99, 52, -3, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [612, 1067, 4, -6, 5, -2], [3132, 517, 2481, -188, 93, 1], [-6036, 5292, -2485, 194, -98, 1], [172896, 25031, 14530, 6282, 113, 184], [13674, -51221, 3239, -6864, 181, -187]];
    Rf_basisdens := [1, 2292, 382, 382, 2292, 1146];
    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 := false)
    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 := ISA(Type(Kf), Fld), 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]];
    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 := [[0, -8, 0, 0, 0, 0], [-14, 19, -1, 0, -1, 0], [18, -18, 8, -1, 1, 2], [0, 70, 0, 21, 5, -5], [0, 2193, 0, 63, -20, 20], [3364, -3364, -100, 149, -149, -298], [-4965, 0, 698, -517, 362, 181], [-22915, 0, -794, 463, -662, -331], [-13218, 13218, -593, -239, 239, 478], [0, 79944, 0, 534, 1939, -1939], [48568, -48568, -2145, 2007, -2007, -4014], [-120064, 0, -8512, 7730, -1564, -782], [362331, -362331, 3116, -226, 226, 452], [0, -99989, 0, -5301, 4710, -4710], [0, 43878, 0, -9951, -12987, 12987], [318192, 0, -22520, 346, -44348, -22174], [834951, -834951, 1699, 17536, -17536, -35072], [0, 2436346, 0, 30318, 3501, -3501], [1144345, -1144345, 22263, -21594, 21594, 43188], [378228, 0, -37780, 9992, -55576, -27788], [-2650291, 0, 62430, -42759, 39342, 19671], [0, 2358976, 0, -84075, 11791, -11791], [0, -3638148, 0, -128877, 11163, -11163], [3966726, 0, 82172, -2104, 160136, 80068], [0, 173119, 0, 286956, -1634, 1634], [0, 1463778, 0, 33654, 60749, -60749], [5087866, -5087866, -79317, 43197, -43197, -86394], [4712505, 0, 176854, -56717, 240274, 120137], [-913012, 0, -62064, -45930, -215988, -107994], [-10128108, 10128108, -77190, -69183, 69183, 138366], [5540942, 0, 567156, -322638, 489036, 244518], [-4474584, 4474584, -23035, 293891, -293891, -587782], [0, 2307039, 0, -505992, -222722, 222722], [-9245519, 9245519, 1005631, -403346, 403346, 806692], [19636644, -19636644, 756280, -357875, 357875, 715750], [0, 1712818, 0, 837753, 288009, -288009], [-18752522, 18752522, -1626636, 297651, -297651, -595302], [7067444, 0, 186704, 281048, 935504, 467752], [-10548336, 10548336, -784977, 287727, -287727, -575454], [0, -46440060, 0, -1248102, 96087, -96087], [-6955500, 0, -288296, 273616, -29360, -14680], [43747646, 0, 182516, -904348, -1443664, -721832], [0, -58128966, 0, 2357553, 923993, -923993], [-31788113, 31788113, -845760, 1102194, -1102194, -2204388], [52914864, 0, 2175500, -1071010, 2208980, 1104490], [48946994, 0, -1929752, 2499058, 1138612, 569306], [-156005372, 156005372, 360305, 314927, -314927, -629854], [0, 85601350, 0, -1102719, 884853, -884853], [0, -183183999, 0, -2775261, -928932, 928932], [184274032, -184274032, 1979244, -77271, 77271, 154542], [65673357, 0, -3714854, 2991301, -1447106, -723553], [9916242, -9916242, -4325565, 578373, -578373, -1156746], [0, -12600821, 0, -1592880, -1208110, 1208110], [-103279593, 0, 515434, -3403163, -5775458, -2887729], [174447933, -174447933, 421488, -1461660, 1461660, 2923320], [0, -107665074, 0, 7397913, 2885189, -2885189], [-129073692, 0, 7006552, -2590922, 8831260, 4415630], [-208413412, 0, 8152608, -3570324, 9164568, 4582284], [0, 338219272, 0, -969690, -2662773, 2662773], [0, 317723748, 0, 1034124, 1502839, -1502839], [239031868, -239031868, -2248911, 486951, -486951, -973902], [-67208784, 67208784, -5221100, 213625, -213625, -427250], [-290016205, 0, 10810578, -12822399, -4023642, -2011821], [115949106, -115949106, 6376415, -1941571, 1941571, 3883142], [0, 29368087, 0, 1469796, 2034782, -2034782], [0, 136257984, 0, -6484050, 915131, -915131], [0, 480807580, 0, 389691, 3193555, -3193555], [500762305, -500762305, -8719904, 1819072, -1819072, -3638144], [-319567539, 319567539, 2210883, 4803882, -4803882, -9607764], [0, -345751094, 0, -7309566, -2437147, 2437147], [0, 76118613, 0, 10310412, 2498044, -2498044], [508285026, 0, -13599708, 14649918, 2100420, 1050210], [0, 312299272, 0, -4225203, 2018535, -2018535], [-951918680, 951918680, 16002896, -14434183, 14434183, 28868366], [-74525251, 0, -13062838, 10934459, -4256758, -2128379], [570758868, -570758868, -12315805, 9842579, -9842579, -19685158], [0, 118113588, 0, -4142178, -6977305, 6977305], [457864040, 0, 36750744, -21048774, 31403940, 15701970], [585182799, -585182799, 9774848, -1956910, 1956910, 3913820], [-627978725, 627978725, -27623336, 14336470, -14336470, -28672940], [-204921948, 204921948, 52071825, -21469329, 21469329, 42938658], [0, -646862258, 0, 11798946, 14868929, -14868929], [-506263074, 0, 15513836, -8835670, 13356332, 6678166], [-421789201, 0, -2627190, -7884225, -21022830, -10511415], [0, -210337532, 0, 38502321, -7284861, 7284861], [0, -32298657, 0, -150981, 33117594, -33117594], [175100463, 0, 3428874, 14967183, 36792114, 18396057], [0, -380974301, 0, 18298752, 2094210, -2094210], [0, 2178242772, 0, -27618210, 14079727, -14079727], [1079505808, -1079505808, -7245457, 12190847, -12190847, -24381694], [158531307, 0, 46283962, -27892223, 36783478, 18391739], [0, -563130006, 0, -45136155, -588063, 588063], [-1442099242, 0, 60192796, -70513718, -20641844, -10320922], [-18764619, 18764619, -10234001, -39222422, 39222422, 78444844], [2545990591, -2545990591, 77053599, -22996224, 22996224, 45992448], [1807602552, 0, 57244524, -35233956, 44021136, 22010568], [-660323502, 660323502, -15321760, 28634351, -28634351, -57268702], [1760599299, 0, -35383378, -18826657, -108420070, -54210035], [515673524, 0, -125604540, 80557716, -90093648, -45046824], [609149336, 0, 90955148, -31804066, 118302164, 59151082], [0, 3044306395, 0, -41947821, 1918254, -1918254], [3203783850, 0, -51223756, 8875976, -84695560, -42347780], [-6133234755, 6133234755, -29781273, 17090850, -17090850, -34181700], [0, 3791868183, 0, 3494484, -11735746, 11735746], [-516566105, 516566105, 17532775, -27778760, 27778760, 55557520], [-5257765411, 0, 17247606, 10409529, 55314270, 27657135], [0, -4816642797, 0, -99484245, 1615694, -1615694], [-4884082026, 0, -77490988, 72428552, -10124872, -5062436], [-1711184568, 1711184568, -82957481, 54829639, -54829639, -109659278], [0, -930743747, 0, 37111656, 69190068, -69190068], [415179208, -415179208, -129697901, 34311583, -34311583, -68623166], [-1458085156, 0, -81648192, 7966926, -147362532, -73681266], [-5955410547, 5955410547, 105369896, -76891612, 76891612, 153783224], [0, 1169485831, 0, 143950695, 89472282, -89472282], [-2345797480, 0, 65383448, -27184984, 76396928, 38198464], [0, 3133045887, 0, -122165880, -151015370, 151015370], [5911213531, -5911213531, -93358845, 101660220, -101660220, -203320440], [2491964478, 0, 43265100, -74345598, -62160996, -31080498], [1056741492, -1056741492, -226558808, 18860893, -18860893, -37721786], [0, -5287690044, 0, 151676223, -10472725, 10472725], [-4482599234, 4482599234, -101370432, 6578499, -6578499, -13156998], [0, -5496388016, 0, 87113832, -83027981, 83027981], [0, 7760078118, 0, -53312538, 21043745, -21043745], [-4042506555, 0, -248779794, 227531511, -42496566, -21248283], [0, -2028551624, 0, -44882469, 59082615, -59082615], [-9336718434, 0, 126477172, -134131316, -15308288, -7654144], [0, 1756308046, 0, -282658482, -140938151, 140938151], [3578029380, 0, -271270200, 130172988, -282194424, -141097212], [0, 3755023318, 0, -122119407, -30882195, 30882195], [470757136, -470757136, 267499620, -125876487, 125876487, 251752974], [8086902005, 0, 353765970, -200071965, 307388010, 153694005], [2495923026, -2495923026, -270229941, 57187173, -57187173, -114374346], [-860156036, 860156036, 347547595, -100891205, 100891205, 201782410], [15055496210, 0, 110271864, -32608020, 155327688, 77663844], [8739381624, -8739381624, 560398242, -187947507, 187947507, 375895014], [-4524667040, 4524667040, -230658190, 73856165, -73856165, -147712330], [1368717930, 0, 398660028, -193115832, 411088392, 205544196], [-2052819068, 2052819068, -395339355, 7483623, -7483623, -14967246], [2218647030, -2218647030, -262460904, -144629253, 144629253, 289258506], [-13745341257, 0, -104776870, 117450959, 25348178, 12674089], [139792115, 0, -122565942, 175427505, 105723126, 52861563], [0, 7236200232, 0, -56174670, 60037187, -60037187], [5224679044, -5224679044, -145285981, 89293139, -89293139, -178586278], [18119303148, 0, 200647448, -116350096, 168594704, 84297352], [-10981216234, 0, 98999068, 25558348, 249114832, 124557416], [0, 14503468368, 0, -183542907, 95144583, -95144583], [0, 4653385012, 0, 532395858, -68483649, 68483649], [0, -1089493980, 0, 166847172, -155178201, 155178201], [1906514479, -1906514479, -42436097, -37648448, 37648448, 75296896], [-21727932792, 0, 89921672, 8425904, 196695152, 98347576], [-551968262, 551968262, 327316840, -326264873, 326264873, 652529746], [15193641750, 0, 169739404, -207728000, -75977192, -37988596], [-18123629761, 0, 300777730, -420508451, -239461442, -119730721], [-9912550716, 9912550716, -439541989, 175296227, -175296227, -350592454], [0, 8039902621, 0, -180837117, -105309632, 105309632], [0, -7005115212, 0, 34538253, -394645437, 394645437], [11415341738, 0, 85918548, 6411366, 184659828, 92329914], [0, -1938936480, 0, -728589960, -396425949, 396425949], [-18172546258, 0, -63568876, 224227448, 321317144, 160658572], [10652895102, -10652895102, -242415260, -137143733, 137143733, 274287466], [0, 2607412863, 0, 248658099, -5703246, 5703246], [-89633169, 0, 636582282, -784434489, -295704414, -147852207], [14114010334, -14114010334, 203476671, -170978415, 170978415, 341956830], [-10015127460, 0, 334577148, -635478924, -601803552, -300901776], [22738348767, -22738348767, -429794060, 291494218, -291494218, -582988436], [0, 9924977772, 0, 292618545, -22642837, 22642837], [-697507216, 0, -773922840, 523316280, -501213120, -250606560], [0, 13928276278, 0, 72593430, 203397201, -203397201]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_18_c_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_18_8_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_18_8_c_a(:prec:=6)
    chi := MakeCharacter_18_c();
    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_18_8_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_18_8_c_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_18_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<5,R![166659897600, 48862653840, 14303890521, 7279794, 122607, -54, 1]>],Snew);
    return Vf;
end function;