
// Make newform 18.12.a.a in Magma, downloaded from the LMFDB on 09 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_18_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_18_12_a_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_12_a_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_18_a();"
function MakeCharacter_18_a()
    N := 18;
    order := 1;
    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;

function MakeCharacter_18_a_Hecke( : Kf := Kf)
    return MakeCharacter_18_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]];
    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 := 12;
    raw_aps := [[-32], [0], [-3630], [32936], [758748], [-2482858], [-8290386], [-10867300], [-20539272], [-28814550], [150501392], [-319891714], [368008998], [620469572], [-2763110256], [268284258], [-1672894740], [-7787197498], [18706694156], [8346990888], [19641746522], [-5873807200], [-8492558172], [-75527864010], [-82356782494], [41314059858], [-64518289048], [-110218970916], [177778055990], [-78920586642], [-276649479664], [340872108468], [944783919174], [103770279620], [1228518826530], [212465754392], [-1586324491354], [865019758412], [2258018433384], [2159601057498], [-4507858886940], [434052967502], [-867701522112], [186945616322], [-3327984418446], [-1585807747000], [3549580847612], [-5180220241168], [13366451855604], [-2030801797090], [-7133218545402], [-3303627865680], [416938440722], [1919695707468], [-9760312532226], [4048454989128], [11345494153050], [-2352517436608], [-43632679328914], [-27509865726282], [-25781501651788], [-55932366783342], [56805561301916], [67119323976888], [-36668452625878], [-101209787552886], [49661373613892], [-84050826592654], [-17409715189716], [-66091970715610], [174555908736798], [-36048801180600], [-50415069532864], [209366620314542], [295196740486580], [-128923915331712], [-104144969600430], [-115408002381514], [220847231671278], [-85685226492790], [-258945325818060], [109350721448222], [-292179867206832], [95398808587922], [-480574417066600], [315148469982348], [-503692043491170], [-296302309766374], [-100284433145862], [249997836891392], [71627179462884], [-234866310046080], [-989828358666424], [870344599461468], [-538313985518500], [-838817891595432], [597230836744650], [-1367119241161722], [690497403291812], [-448077291674938], [845292601702796], [621109323797274], [2318094820440708], [1549633487555190], [1594075766983892], [1778313010809026], [-298809922584516], [-2130604221793842], [-691981391973000], [1901672192037002], [260367753054896], [-3206828063042818], [-3995201559523386], [-1002766988837020], [-2069507350612168], [100036331563998], [-303785728336468], [-190745837997336], [-1647929555419782], [2628612436916100], [4802412318535502], [-1253250517898398], [1920345440308914], [-612548259695172], [5089895790664892], [1786640230193418], [4181873935406270], [-8025542996498640], [-2938036816387624], [-4423193260679098], [-11173231487779540], [-1986240568363032], [-7635034007095168], [7892408836548686], [11060175620537718], [1666976028534530], [-6925675678057422], [-2997704861135524], [5677939797197514], [-4431592806315930], [-8993226794485948], [-9080128581794142], [-12965358062763208], [5402624946002604], [-797388189729370], [-10231250335335960], [-13301013637965298], [-3384826143344106], [23237585851191380], [-24474289167281952], [21530451830425046], [-27709410869331282], [-8616769617108868], [32265077561004984], [31043636190682916], [-17817306399611952], [29004633876042200], [-10960987666139970], [9138744432893306], [-697286579440422], [2175549006157284], [35967502749858678], [36462492265742216], [10149029320293468], [-29927751302791506], [32359177496667288], [-22858949925002608], [-19978372698505474]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_18_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_18_12_a_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_12_a_a(:prec:=1)
    chi := MakeCharacter_18_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 12));
    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_12_a_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_12_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_18_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<5,R![3630, 1]>],Snew);
    return Vf;
end function;