
// Make newform 18.14.a.b in Magma, downloaded from the LMFDB on 03 September 2025.
// 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_14_a_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_14_a_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
        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 := 14;
    raw_aps := [[-64], [0], [-15936], [98252], [1630464], [22316306], [-122937984], [-74272984], [-1069509120], [-5607090624], [2162031116], [-5959452922], [21676851840], [-61101030232], [136471948800], [557015616], [-302211949056], [-190535454658], [-918343123024], [-1086593292288], [-77275903210], [2624363498636], [3269608182528], [5922230600448], [5340133325582], [-7400024266944], [-9138097659388], [-6613812905472], [14623620765842], [-29761210864896], [-57960291121468], [31773957113856], [68917595673984], [-118252369967440], [1556540301504], [35542436885324], [153864784408766], [-199640309611480], [-464940036727296], [-376731319361088], [732553762328064], [737496634606922], [220756868510208], [1110506926234370], [1370553456840768], [-976425235502956], [-1131027759532624], [-3495746624401324], [-2165510975865600], [2656912331732954], [1285974108032256], [-3900916117344768], [3930719675457230], [6502669874318592], [-2698019956179456], [5089579280388096], [7062281904405312], [5259515308913108], [13408429326163658], [-1820292353490432], [-4567651141712224], [-13476897955626432], [-3201524864861776], [2271556677061632], [-20356213753573750], [4166807505741888], [41909203235570336], [-10673972739373666], [20436084877566720], [-16402349858684482], [15577450360062720], [-17933860055015424], [48465719778706316], [-36494026151651338], [32538614566583720], [-30349457439475200], [4622204385279168], [4288427204879054], [112464166866254976], [44760713943116678], [139060269376087296], [-46920060962471206], [35764917694871040], [-190804468481573182], [18092274639111188], [-22484984632478976], [-174030620618245248], [239681742746139926], [-48042391883956032], [-234365569467939004], [-301241270059515648], [-106328285420537856], [-555030271305110212], [475552584550649856], [-185876332194980704], [123322390414894080], [-70058743277178048], [863330185654512768], [405622754780154536], [91106823858145058], [-200896285411589320], [-699866181212162112], [-1362109418460485376], [-1393118177145119616], [-708263919512635216], [233945304428336978], [-1116579418498873344], [1281803101147784448], [-688210594455031296], [-933658017324602950], [-416897060082376252], [-483422096935049722], [-1451996749878535680], [1421771198583646880], [-2758966510159477060], [2143776461138353536], [2181886580136725816], [-2206442820347776512], [-1685627084751934272], [-1135816626708065280], [1502914969407564662], [-218720907862480846], [-3226402317753696576], [-2675902577399707392], [3917526441265594664], [3133162264080852288], [-1612106719189214374], [-2041219398112828416], [-1727408128976126020], [-3121831618059511678], [4012319755027717040], [4942134453012487680], [-1938990880335193060], [-450166511475823030], [5485197425215234944], [-6625529179420075006], [-7661421181342178496], [9713013780602567192], [-7055581983294113088], [-7324955136426393216], [10671603475320754328], [16821678465820691520], [-14780808092021232676], [-7196888008193785344], [16609528088847490466], [-2371985372486258688], [-9237843105732737002], [4406799076084411008], [9821194693677259160], [14716761882871021056], [11446826569577679182], [-6446603661201068544], [1620469543797488936], [5242736479717327872], [-2170946828264267080], [-8792672551806743040], [-25160786002602877732], [-1291490630165986176], [25846797750487967738], [-16410932879666964288], [6999921744970983936], [23336285254184361600], [-27177759734018653948], [35269829818854471936], [1345201125615221376], [-10766512245548762112], [6525103879595170172], [29779738341748133894]];
    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_14_a_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_14_a_b(:prec:=1)
    chi := MakeCharacter_18_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 14));
    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_14_a_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_14_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_18_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,14,sign)));
    Vf := Kernel([<5,R![15936, 1]>],Snew);
    return Vf;
end function;