
// Make newform 2.28.a.b in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2_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_2_28_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_2_28_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_2_a();"
function MakeCharacter_2_a()
    N := 2;
    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_2_a_Hecke(Kf)
    return MakeCharacter_2_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 := 28;
    raw_aps := [[8192], [-1016388], [-3341197410], [-51021361384], [-177413845094508], [-264386643393418], [76811888571465906], [-147764402234885140], [3583628816727527112], [-75208679254256666970], [-131071363974700812448], [-662288183049353372674], [638680458671096629242], [6917115499338769700852], [-30908908867583003138544], [-72917877175183391659218], [-428694162599071555282140], [-308035309306328670786298], [-2019363317538472735190404], [12815663453552821957376472], [-22881210928165048507710118], [53028364881871099261766000], [52517451913599957686712492], [-215234163567542209160339190], [-356303023225402052577970654], [-507244260800605222764847938], [-2076277590211134719695889608], [4522173639150250455889453236], [-3308726876766612280632382570], [2792463932801679162083338962], [17267992327370228401521462656], [-49785201592163793744473618628], [1215248780526032698291640346], [-33255482146331383404675383020], [-202694293228670099205365296050], [-84069309335638452457842027448], [254329675614733630764366102566], [-110806327651185790052929847908], [465221198805646167210746607096], [209199897718472973819091142742], [3186010044066015333491353280460], [581956266640859019828076387502], [987831420508199181093009179712], [-2824237076831261753717248666558], [12233244083155354633147788751326], [8082790033106849788405423075160], [-7638826778217804043052697103828], [32537475602027245217824648506272], [19480005976551380298594817729116], [-9227317445982250118885842985410], [-101729632940958059215864057900998], [198386275447607143421113928757840], [40076109606782948585182199142482], [-380395566828494342615256369787548], [101913282869010116474897687321346], [-16677345017602153505012450084328], [816228468327795898414037477726070], [-990292880382859329649169632967248], [612381409308717108695303744513486], [-1843918033038471816844710674976438], [-1392387335854008409688506528480828], [-1429975324782574290633662960025858], [70137031189263875124444591642956], [5684136567104765023219498636259112], [-2604290318340660484325595963206998], [-9621942335748131400759197675151354], [-12797889393293569559682045802116268], [7782667815075774044446317372611186], [-1402959307317285915833817453436284], [-31320597277573285428117099855442330], [-5535393621743600184282444429098718], [4232666151939544393569320145094200], [21982279761962246737214506206408656], [-1843375184656376549530503637162258], [-72051760384902673983286551116558620], [120962553256937618403465723678337152], [-148947697186729322253360105718348770], [68821935936094592148332304956395766], [-140725279844503808428622968825841358], [-70202182413672450013842285449226550], [160714530208019011811155104935891100], [208803288190138588054929561776316542], [-63695458222366925221710558331986288], [-73505838305819057975012503919545198], [-835560970507154616694334870974901080], [-463649300794657954059716716091416668], [297164464125355690038467504321720130], [-271500024875289170272729120333216294], [223778330635336309289595241519709622], [351209220392410505768617970123432432], [2264356282759781773449114443498796], [-1384802858024644640027082439022410080], [3009803176796116622767636552460622776], [2428996855038034209628352975023781172], [4729569493509060771178836595620683660], [-2733495538230329864795206443253098648], [732140732395208977587867803489369670], [-1857014915826128174112326262527014758], [-8571725360183863300653975382598371948], [-4738421299256681898556338036342293338], [955472899132609719360399643343108636], [9145788325500477860328375336538330326], [-15546920989555898364083149211074868148], [-17665832355564470799524361236838859350], [-3712592459610326687272899665562214108], [-13880681344644700091930304168802095934], [30818379512460101995349454157929426516], [-37795123230547458070254961384839359118], [-34483097353973194831569967400271882360], [45871426580018970889760863943225734922], [46046828313152701101896408245976331296], [36295574055150104262884206820791747262], [29178512566041416370470107236087521466], [-63357943483488928908273619716481292620], [83514345982997039987500018303728286952], [32213896858352175949921341100388471682], [-142226736922731683995404647961046897348], [63269513102928459529923626584659925656], [109947259048634976985280671094845883382], [-57305951184338350945278453707210704020], [-58896433250757650026358025531090658738], [-190956152500391856496410946053106486558], [-179663356876784756850457981118999051394], [315115001759636162318514148474723929972], [-108937454837793313853550989558975740468], [-40253778467409263307861677084557632378], [595422341885398988005345865207714863070], [622975130499956119126314820418467568880], [43671342716057197244675636265531088136], [-8473198823155776657120638563124294938], [-445917325202634500851735846931665876900], [-815216041669333524824687664364828129608], [-692101294972866578437656603143798151088], [239796050017770269992593897376402619246], [-1032407605479464591875937900924942107158], [753584102690870370469188971761738391810], [929980718399368036064014715983185578142], [1343023608590351136861672456610990249196], [-2009494364888964872375126794370523623514], [-168433898555962425942162391480581805830], [2281641460893318628533383398622997250292], [-2299845393035917941510380485231415716818], [1800549631648735002020794037367296050472], [1580806969102929144589284872547038684196], [-123802926731286665891829347695282018810], [-1350108546895564923348964004102016369960], [6400426875110496635949820886512157086862], [-3043240453396247111920229999474751245814], [-3170641776220414181574602079439814367100], [6297520163519651775309595248638511435552], [7673515275206283163887547949175117464726], [8449371481935340639152925971817760938962], [409093478349353737964807406994004986892], [4587320547683064381007392914094632847336], [-5830718803474071353744733345865429046764], [-26382058691868745393205859032960837328], [-13441781500242970314799233818269788965560], [-5329798065042963746736994899649239052830], [14079686739781461862447701067677883620986], [-21526336296703701962484185243478341713578], [-24742932005285241819213270507115713988404], [-13243461913965657332634708432241803747798], [11732272543767814141206967665450403606616], [-18121535899008854121980368050235671518508], [7935147819697408657346853997828497497586], [-33937676568861880757778730966640204896248], [33624534204531658921537592209798402358432], [-4141160444935595949957671116334438512834]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2_28_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_2_28_a_b(:prec:=1)
    chi := MakeCharacter_2_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 28));
    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_2_28_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_2_28_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,28,sign)));
    Vf := Kernel([<3,R![1016388, 1]>],Snew);
    return Vf;
end function;