
// Make newform 1.26.a.a in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1_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_1_26_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_1_26_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_1_a();"
function MakeCharacter_1_a()
    N := 1;
    order := 1;
    char_gens := [];
    v := [];
    // 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_1_a_Hecke(Kf)
    return MakeCharacter_1_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+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 := 26;
    raw_aps := [[-48], [-195804], [-741989850], [39080597192], [8419515299052], [-81651045335314], [-2519900028948078], [-6082056370308940], [-94995280296320424], [-271246959476737410], [4291666067521509152], [20301484446109126982], [-183744249574071224598], [300901824185586335756], [-924361048064704868688], [-990292205554990470954], [13052569416454201837980], [9015451224701414617502], [-26689067808908579702428], [-192390516186217637440248], [42404584838092453858826], [-271681055025772277197360], [-931454457307013524361484], [-1763635518049807316502630], [2829240869926872086187362], [1863424798129100831412102], [4858120128770696114246696], [35830422465487817813321292], [-47779523949713376857525170], [-74647597801541940896262414], [335904534129377492483226752], [-174970523892428305728249948], [618313109745960536292087882], [-484462128637274579929861780], [905568683500101980256093750], [1161895714542448974565531352], [-341504962101535821001216258], [4632019330305293463671472836], [-8264701881776285676276280728], [-6026024708562761758610453874], [24102261500967183004825491540], [-8191932538465314965518627498], [5506016890624536539668892352], [20871590887477398937670272706], [-59936987790338741946487251738], [2240424832787305697791685000], [-75247451459088716712603051148], [-316695888921276124166441057824], [385093867204018424441344878852], [-568261440252719522161661910010], [495586486330457297693292119466], [-144023448037426492352746292880], [-319455938984031179088910841998], [621677267284418547255343836252], [-2294462267947666633683914581758], [773315946921138089280627617736], [3622588130389834818682741628910], [-3627673250121222001463568596848], [-2548076683459664313429095585098], [3598172883135056042267481549402], [3822646294747995463726006273916], [130006531958494180627027636806], [14360214302848177647169534817492], [-22463033920144429698250146067848], [-1379559471136367894001031739014], [-10278651623433080957734662503778], [-5753563965996971662984355822548], [66926793150558778433244186524882], [941781150816541824227585338812], [-33908112195800308067402386538050], [13031284751559498352132220789346], [-130336088347675288184755640431320], [-206294354762653692506037305805328], [246050779873833737919701517205526], [71274301600760314844951680645340], [133051294483218319113126298310016], [240508530175723242636509861314470], [-412136723690212764833398877672338], [-71664659505624898201929474345198], [134430221475968122996297608755930], [-171876160097459082884173044372540], [-827663831782889538482847281783098], [-78383621915046495210172752362448], [633272755307763050690739692591666], [-1482986970040060831209497321814280], [-1209012635333170464590901871190244], [-948861362336468714243755796389950], [1906438015454539953482023226664842], [-45626967057782744498214751298898], [2135214165360682091948455931456336], [-2672252931140078368886189852908428], [1972399217793483382246331331836640], [-396365691342605028028934306158168], [-7226256779485390805843060698858548], [8198301737483581650490339755358100], [4725620603026848328690830213571896], [1969545084859124374313398077691230], [7397816591525737266577846621011402], [17033203938239706662701704149092076], [-12868103727506073374588427568589698], [20662449349768742309415960538527812], [-3287507202857319236737451756367858], [-18080449355994165352055799784337964], [-3059669485707949000126966308019590], [-12988412934313322304448992252392548], [-73149007283437031184593659377598], [51622576954284315296250641988959532], [24070451022895515429903274463421906], [-8306715731833092425485008028093800], [-30040465694002976026741088820368998], [-100962655278660281875479010258127008], [-1024526308514073350808056160507514], [45327063639607885238749699016129322], [124784313486059742429996939685034060], [48333817152455235297360818912551352], [83049407119340498575305771673129602], [52572397212807570140220263990030756], [-203021212934182245316840438243695288], [167656843695783841975546906745288046], [-292520764764077767547034646185916620], [83022703976977790010627770051790902], [-323598217246990900160837490152839774], [77633340760409856063176405173288902], [-249908521900610788265417549767360884], [-85696370131854075386336488795551148], [453463801782936369543916065342799902], [-493253946459830644676925328436697370], [213498713808545388991042502994273360], [512190003491531639219969928363945752], [177366164610548743964253082296616766], [-1135347530077011177037769659346019580], [40374926372477701905735782397977256], [772404884393222923195887199165623152], [331584959148585596040577353957416342], [2022303291728039968865129534892172602], [771193056134021862301167237188337410], [1960602395367194653286888268993426726], [-892654495293574111495131320041147468], [-2354935536386796280810376630649963138], [-1296165763533323698864614991794011670], [2636056416477357054221085357358365452], [-592270505992680220429366303959161898], [476928247666321407950184339078265976], [4177942458006529804074897026301674652], [-3180226070217526507313196970402771810], [-3572695920570651737167056756666687480], [-1754663901382733612982072450161497354], [7103238657301854777597975384261375642], [-7566948942139016552745489201846935620], [5721949004294555145046114270754672736], [3219258509708242534801954541687009102], [-10463253416859950223551856430386179598], [4117448435898373812184041586239319316], [-2529037303097500118008581763261629768], [-4931287778030781014582333390707925908], [-7105476587378448225139854652518494448], [2641548413132821047693879218876582360], [5019344365605312552357640636603350690], [-17018932488743426852986073699646170518], [-15125431526392966776353989505223811698], [1653293258295818493141829726879888212], [27778351805167089272093426013001009146], [3824414748277568577907801195770305672], [-16708665614867499515267004314724420948], [-35437572556504850467887446821661773998], [22675898811191401775988244653815457816], [-1827055282544037157264700582600143648], [23459931419013195552931575066153510662]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1_26_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_1_26_a_a(:prec:=1)
    chi := MakeCharacter_1_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 26));
    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_1_26_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_1_26_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,26,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;