
// Make newform 18.21.b.a in Magma, downloaded from the LMFDB on 26 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_18_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_18_b_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_21_b_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_21_b_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 := [20268006, 8996, -8995, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [4494, -8987, -3, 2], [-19437840, 38874240, 4320, -2880], [-43720560, -9720, 9720, 0]];
    Rf_basisdens := [1, 18009, 667, 1];
    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_b();"
function MakeCharacter_18_b()
    N := 18;
    order := 2;
    char_gens := [11];
    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_18_b_Hecke();"
function MakeCharacter_18_b_Hecke( : Kf := false)
    N := 18;
    order := 2;
    char_gens := [11];
    char_values := [[-1, 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 := 21;
    raw_aps := [[0, 512, 0, 0], [0, 0, 0, 0], [0, -793635, 0, -7], [49153172, 0, -1, 0], [0, 6810154692, 0, -21406], [77861230784, 0, 15463, 0], [0, 627460398927, 0, 461482], [-2697612579664, 0, -2305688, 0], [0, 6945786828444, 0, -26945870], [0, 342570971404707, 0, 132388445], [-316338907527676, 0, -72834069, 0], [-3529300211247418, 0, 2082945788, 0], [0, -9877183417128687, 0, 4309237394], [1702934142855080, 0, -7603967994, 0], [0, -37884032264987220, 0, -21219255078], [0, -114102281892089709, 0, -2406644359], [0, -15306517445178264, 0, 242769013900], [-839036489688545350, 0, -69994446396, 0], [-1487843927213947624, 0, 661573545654, 0], [0, -1701108173064280716, 0, 533169391006], [-632551755051492208, 0, -2548596867012, 0], [8146796095130456156, 0, 2012036773789, 0], [0, 14276648748962493852, 0, 1692432972342], [0, 29502267874529457681, 0, -764971139492], [-10034733651696656608, 0, -37268522292890, 0], [0, 31550646418877497821, 0, -78770856542021], [26630352238813974476, 0, 75968591134065, 0], [0, -58210310081463724800, 0, 48568352999936], [-167174467611557662816, 0, -98809046510979, 0], [0, 54320360340303078897, 0, 81549343815324], [-942092550892471933996, 0, -343664238206625, 0], [0, 1291695399432219238680, 0, -475211530187380], [0, -2450331601219428753, 0, 1287133330808402], [999969631634168271368, 0, -924622827573214, 0], [0, 2875261431647621960355, 0, 401415691015339], [6808022854831443281252, 0, 478162483883427, 0], [7012741839927938340326, 0, -3639023396776404, 0], [-5064504694483325737912, 0, 191400017358326, 0], [0, -6429847787119084477272, 0, -1425471916756860], [0, -13891656113937970680099, 0, -5733867590149251], [0, -22708491872334067017936, 0, -1569601405990576], [-9086062719823951571872, 0, -6754840877249983, 0], [0, -28915404964472376727464, 0, 24151195421697484], [710936830719134050958, 0, 8746867537002168, 0], [0, -7277453096382040373811, 0, -70780554959303273], [-44267215911395007275620, 0, 12068352887383765, 0], [112249889036949237290936, 0, 13355944872641014, 0], [202111242595737495408932, 0, 40200640616035515, 0], [0, -16975165739064821920956, 0, -57720776324696646], [92173438367849265669152, 0, 205621176380404827, 0], [0, -49248755498767331514177, 0, -51398331249261556], [0, 58908040608171949097664, 0, -11802845894424312], [-177478336869224731739248, 0, 42722538654709214, 0], [0, -119683243252233631114164, 0, -650521031015650186], [0, 567293069371440435094047, 0, -516450166011234840], [0, -586817624960068121842728, 0, 429937672834795972], [0, -327262292740118935521747, 0, 538241502535105607], [-653284547124909919921420, 0, 1113403593256462263, 0], [3693285593452678023320864, 0, -111383343938413659, 0], [0, -423870809049665930145279, 0, -1780314868137777832], [4396904509557161557869776, 0, -72648325516330452, 0], [0, -423611463795691716631437, 0, -1840400583558727967], [-2744002623233772218218840, 0, -2096067985792577118, 0], [0, -2130885305713250960760024, 0, 2114709076045443164], [-5304049288855148145657262, 0, 1913890009999008104, 0], [0, -512313545267461050697011, 0, -4022543516473249061], [-9534002646366789590093944, 0, -7608369828939576158, 0], [-15501845599492219711708816, 0, 3106164850776821792, 0], [0, -7698805379880031500816732, 0, -16156853003519413878], [-1201240242787247397847462, 0, 62174068613202308, 0], [0, 11045412056849270138914353, 0, -2656509524158178500], [0, 33103213432577120988420156, 0, -1189696403132629350], [11792695503994297693940948, 0, 15266802113414889135, 0], [-42641993324571688440033670, 0, -7469137291457801708, 0], [80899304462969425095992960, 0, -13210099427952629524, 0], [0, 6076565643979167278224224, 0, 25825019462418031352], [0, -8210953529626285773167565, 0, -39649737574615466333], [40589531445063554889495482, 0, -11320678309403211756, 0], [0, 43616827919398021454380431, 0, -32783899954409542834], [-78617681744488977577714048, 0, -59534302045695735286, 0], [0, -36004269963521751828380196, 0, 53687855371731144774], [-267240662890542391167091840, 0, 2127686415610862141, 0], [0, -127853823577223252692040868, 0, -86841210131470493006], [-72204356100627181583814274, 0, -31301140114512971136, 0], [241269328073882793270356564, 0, -33144852008716373121, 0], [0, -312663959095917674246507796, 0, -44175949711101064290], [0, 243743508679960376612462097, 0, 72380075121027558654], [104904579985875309361402400, 0, -30651531542102454018, 0], [0, -105867037000726630101541533, 0, 184748145103754307551], [417180417876139354130182508, 0, -48508851974368846991, 0], [0, 4759517957859567594101844, 0, -247178600166755407486], [0, -531617648579975435555565732, 0, 47499009081779124954], [-200864689412326707939796708, 0, 48442050378148268317, 0], [0, 251515374434075517285115488, 0, 359819097389915035096], [-469295404601501705949142624, 0, -64783177200078068088, 0], [0, 356279229393625476552888396, 0, 157670689540557810834], [0, 606312437372824809436635171, 0, -762110691137106411247], [0, 154524571993459331023383711, 0, 107538389241730167574], [-372086301539197179485363968, 0, 688785787588472737716, 0], [172326138983259781290499712, 0, -181106512124804418187, 0], [3449977583295700194189225512, 0, 423936210669706846902, 0], [0, 1017561064354363917429595731, 0, -1316797281150879891125], [0, 3452657358605644254787875156, 0, 194719172095675268874], [0, -2482675040500735951473060081, 0, -734802280897248313610], [2186972983659720286362256208, 0, 1413131951282616884228, 0], [1539433692294620267156997746, 0, -1432762332583509405240, 0], [0, -3931951348891864369435929672, 0, 876628879478803733716], [0, 2050990877175712780989484719, 0, -975982001887371623396], [0, -1878181074266441826324654564, 0, -4129641992467641538910], [3005268308088719467642923758, 0, 634748896828787878872, 0], [-522204824713002986143323676, 0, 495921974835139839203, 0], [-4814390142104690136297959206, 0, 3091829795556595245684, 0], [0, -2988465057200622607515949983, 0, -271835401433314553800], [-10125213267838196111896330816, 0, -458139833281626178536, 0], [890240886004456393168797020, 0, -3940412039087084941723, 0], [0, -4328908883194874266660043937, 0, -3732263586539692607158], [-10198857057379414406367489496, 0, -2215024296327533767986, 0], [0, 7911265937478677116205853492, 0, -5423360778090285436602], [0, 4148777647080091771753801629, 0, -7897225039741979159183], [0, 10770777554840547074012874984, 0, -1023703674003745700], [4181197701980737729883740742, 0, -4758215446129398989652, 0], [1506530658388884389202936290, 0, -4565088435480797972048, 0], [0, 1509860851939169173077558045, 0, 3260238918123705773269], [0, 12607238857370359015316677212, 0, -3721641163989567004746], [14123977363873734179329457960, 0, -1908622950719861593602, 0], [0, -21406472200698863850889001325, 0, -915090991747754696791], [3808889843693136542768092352, 0, 1054793802925787463511, 0], [0, 8656241126589417863037273012, 0, -1728148039503266150994], [-22598396392995715397381336596, 0, -9797963407714758955959, 0], [-28315099274531281558606536832, 0, 4199071367291020354239, 0], [-17329261119003428028356517136, 0, -28812724162025119694868, 0], [0, 8952815150876385785101636200, 0, 15987237754766668274724], [-8813714264665747973848556812, 0, 32475086204851753784783, 0], [68344394940476310240032949920, 0, -2351364463076311120809, 0], [0, -61221478285051567905985958751, 0, -23292644031440867071674], [70074892900150471019287580210, 0, 11444043515767854202120, 0], [0, -3170865529366675442893304253, 0, 40659938486398222528677], [-8386377020708772350382083920, 0, -33258790029282514860576, 0], [0, -15340556335024420222075789875, 0, -60954643162184232828927], [0, 27360770147048004174767106513, 0, 42231039024482346710014], [5270830708517599855042979840, 0, 41117758361071315717500, 0], [0, 55036161539611934862546788829, 0, 36253628867348066043919], [-88737935236034008855948959484, 0, -7030525447453762431317, 0], [0, 2665319464549069035158000664, 0, -40712217103770181615604], [-80646155443627140140320064992, 0, 45719366004877724040469, 0], [0, 43716042253116701611484632044, 0, 4870906254069107022498], [-86899355171362310187062317882, 0, 64668091387602122268492, 0], [0, 90907361448265795606884030129, 0, -82628544429442005313662], [-142173444511484178714158142808, 0, 52245986168738953666166, 0], [0, -60972427654932608865194616504, 0, -112649881011153936811004], [-136802538260175605342933100070, 0, 17348988337603283790212, 0], [0, 97259568574387817786150031903, 0, -4098750893590124991352], [241895753355245743231900170392, 0, 3564237833008944063658, 0], [0, 5927545947973593212339407032, 0, 141411608089423907996180], [381686937911200719228035099624, 0, 26637386527471414038022, 0], [0, -186876971382944900019755451288, 0, -196871824894057261656204], [548482033373065602380874907220, 0, -91192671277352212591233, 0], [0, -89333644410901647074179298001, 0, 274815442544807682494718], [672742532078962429923479197694, 0, 113491286101031837841584, 0], [0, 269673412155865369750044625251, 0, -268331472346899917091857], [0, -197398715180952116856977009976, 0, 215965830619223866654620], [0, -63689811365340531027084346209, 0, -68825253204483361719042], [-601081883830016638023950398900, 0, 130635199118903834052201, 0], [0, -343704518215906387432856213556, 0, 305292682478581940022510], [0, 249364140687867583406039441169, 0, -131285543563086545532662], [0, -510126199476244002790775459832, 0, -330994512758295501311924], [-94637599929626674583621879692, 0, 207509496188903349319263, 0], [-532027639121360806006181876902, 0, -255149481647689298793564, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_18_b_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_18_21_b_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_21_b_a(:prec:=4)
    chi := MakeCharacter_18_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 21));
    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_21_b_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_21_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_18_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,21,sign)));
    Vf := Kernel([<5,R![27360283984671775389120562500, 0, 335857739019300, 0, 1]>],Snew);
    return Vf;
end function;