
// Make newform 3.26.a.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3_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_3_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_3_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
        poly := [-321750, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-6, 12]];
    Rf_basisdens := [1, 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_3_a();"
function MakeCharacter_3_a()
    N := 3;
    order := 1;
    char_gens := [2];
    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_3_a_Hecke(Kf)
    return MakeCharacter_3_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 := [[-162, -1], [-531441, 0], [285430878, 22912], [-14843692864, 5152896], [-9093892809276, -983057152], [-52571818339618, 8456327424], [-228493682174718, -310973856000], [6948719247673532, 1780077627648], [69671149450176888, -20198378016512], [-1251016745130354906, -126217146058624], [537736051246227656, -1052676722058624], [-985735474619156314, 295504419926016], [-209581677851994798534, 5221410776755456], [19465197949129913540, 45176076103631616], [-369203088922474907520, -9934991015089408], [-4247001400980921362082, 15631770768985728], [4216038737213096999748, -397484438615856128], [-12139563991870563165730, 2464520538925757952], [-67843054021039258521028, -7885549958339957760], [60201534566364999577992, 18643323271852842240], [42489004798930952398538, -13385360579839137792], [630380976638854108378040, -27385251957433054080], [-438740250914925392850756, 42027911871325874432], [1065394046187937914347322, 133735101954765715968], [-2797058648649902610696958, -71593944273965145600], [-405722082835205847095346, -938445958366534356352], [-17158406996559890240221360, -136693900379065440384], [-19835498676087621061937100, 333584725685830221312], [16519124684733990878359262, -201405355740742010112], [5924741367598180368494994, -1735501975077263195648], [-22637597896505689409723848, 21805635625829140717440], [298448097949394678287349820, -9089452005028014123008], [68082948895393668620341818, -15268995828792234055936], [143570976011907305768509748, -48075816355959997698048], [-1358521990972762450813180434, 125444527032883310264704], [614917052594206467753133232, 257006633008699809728640], [1288575917835403410362191838, 20854231946819923544064], [-1107629451457610268261514804, -693140419986311165748480], [-4398320951910896404125216744, 714082855272328468519936], [-1638428993657522285572066266, -2437643430764507637862528], [3824346094782246212487125580, 1998516939242636799575040], [6470182809150674916158045606, 3243664820736820228237056], [-4724936117283123011591686656, -3894566657536567200627712], [-14718657789240516732222359806, -2663947195073687016880128], [-23465857745601970708905343026, 8824471385876839348188288], [61936302664939941025834469456, 935868759048192220216704], [70002720151378306873956229676, 8402356901048623763383296], [170375702673502902530612150072, -7686379223342309202754176], [326151065444064305077251225036, -16087310174395615298209024], [51579336922993522417998090038, -29131347138353069042965248], [39954089555798137584503641290, 57860497184687351621700096], [587066327403554103278991094512, 5508743792884467730974208], [-386310469844621106150149378926, -63438028869857129999811072], [750341493957098143348802003412, -112745702879008460623614720], [431358143567696230482697043970, 33030264795014191415406592], [254562882594877008912936011256, 357940875900965556399380480], [-2627753431191465363927432361578, -225651764406192477762621312], [334096546153167714317001082184, 15421146588155478088833408], [-3733927031923128542296545776506, 417616337285799225071632128], [3114512881382400140061655101018, -90606732107281631595636736], [308846121001035962203031081252, 274466453188097764268642304], [-133350112104241522465593578034, -240951290188413548751896960], [-7385535850211232392140640984500, -1419688773669694811016619008], [6557119934317809683346166610664, 61068021391858736756259328], [9513969565141904753297400590906, 191542150966262864287887360], [-3032739747044484427494217549530, 1994007999139994895754858112], [-31318540635157505454238512719788, -148897384115310812905136640], [-11317129960325582499238720142446, -2063175397030549178874611712], [-47732900114721210049338387003468, 7853033648623660000426604800], [-21962957443685609042857126632706, -4458074801536415106255849984], [-695548510633503573322899445758, -16007201686474701019072155136], [-52131789386285021326895093332632, 9657279157799055240641064192], [-107076055600366404665329020300616, 6746600283855767849180884608], [140646508054895028904462402202390, 1491202336178924841156973056], [-52425971550148001735538075539500, -23254456135474885812545744640], [106850623105741894001870427426816, 13691326029311730013351383040], [41138235839139003618787127335518, 17458040887205393477940513152], [-375646722744679518212977686370450, 2646902693477871596892436992], [309441912880659573870844318548450, -16169067733117059834095207168], [68122684055548555926567747558458, -16259959329024178128094806528], [178744116139724794067206615803852, -2033884903108284434973362432], [-248826078489245912020924515797482, -85853318823890978357017057536], [-148551935525683772839257618029664, -75822957732552215481275652864], [-771935528973595159448456881923214, 43804545766569967297692994560], [441542707184828372596807166884160, -26599721051312894032935765120], [821682233732196249824307204141012, 76561372257725829252367618304], [627509213089337578294253323829106, -132769377506538277488621655296], [-1253238331491030189955581941036374, 173066511333001738415402912256], [392117272978175620958203089390342, 246290990106094126472832191360], [281591251644417977957009915234120, 253149750989196195671422805376], [1169221228475434127393418880445340, -38840297803158643799672195328], [-3229051347514249472923871561197200, 184883928778788743609307188480], [2854922800022787763596642323487392, 600350256883689606115044480], [-4279685004832068481889242170575820, 183351065466386705834483994112], [-2283231555424603231083044775102388, -592827617103741679823594422272], [-7870145475443700787849849452220008, -100555429341196543365464983296], [1669775094248080574384941847361318, 321087310741220965484545677952], [3444625773377953013279573290296666, 1760655262065628517177801369856], [-3964404167950234109173263888394300, -301304636635532938089604740864], [-239111635068701773564546328173234, 878873400835902948363409426176], [-4318151376017472540125418894005524, 2372326932505009460983667041536], [13099034453883169497319716211197702, -65371195215608909742053151360], [-14647684100911649058671234292637476, -419200569608211820209068396288], [23848752113483681669493051457053642, 940282028810776336479725673728], [-24620878366396420394339086377445276, -308016097225079681364761405952], [2767192735543793554492868685212162, 2071798232740580027534291804160], [-28165519551642895836570274904092140, -219006919226419662775739227648], [29801806220433840071331079326936690, -2913167192650813328221696679424], [-6070598123458170698422055530435944, -1699711861360850040433510758656], [34105496824089035379664958441553434, 24226892511003252610710432768], [61986313231432772473810699879021592, 3141992001064063586624221334400], [-22296323009300091303639082710448186, 2712338616239953241070813230592], [-9908392010516579700026480491427862, -1433859710338200497003985038336], [36873326024919262768274510423301908, -14803763306534589221590765206528], [33418378347561929243015550808966352, 1933968410842413331623034673280], [-78897971411188256033632927693909134, 20938423615267749543691446331136], [100863356196443363125384791015443660, 774903564019309127862315591936], [-178312125610243172097635567590192248, -4669101207565864721141440055040], [-77405162714592244406767106632174554, -25659354087588533430875563740800], [-165875233545487059705712958434214580, -12913166613931813505475309544960], [-54814701083353694431956589541361898, 5903134845565507147908859392000], [-278502927655900959966593761147437022, -16592457853630293531617265610752], [53872567935224936313593005019893854, 400714991054697208977120894848], [-49726472964383341178764509374563644, 24393935260037775975168723797760], [209780912126807040010768721221453244, 16274253146772073396606268467968], [145016955255782731144695912749738790, 60592518269534746614555365000832], [-26086500623957870067687457919490538, 21970560896622456422387842061568], [-428816707927190336194531295331240864, 31437572851695511817948888488704], [-543375751664823931103281826357358352, -27088481138361301484237487263616], [296480904299097063843446057613112430, -60616160162656535334442913673984], [75232166738594465957517223100227388, -56592800394327625055327509160448], [-864455912452553541400345080603503880, -33952169102136483917213986947584], [524151879169464644353252188456236504, -54810753050503839151931359324032], [-1434719356960005676497060182789347642, 32560116160273172627787559298304], [845974919965745986569923248121817258, -105727143165431866423282662738176], [636854190363632929913444290862601986, 207251654293548012188826734183424], [-402197728887256589791687816576766514, 247980820444929220061863088146560], [1494589997902737658033934525994722780, -101844712263936126028398527685888], [1302144871882074808466015871169239990, 58576221418013570957796999836032], [913258600806099459461842019744144730, -387186944526800731424518183952640], [765053378774519075749909631873053892, 137397387442703217368552235313920], [-4647022174148232524967433850041271682, 79241326671861950991587986815104], [-361416451808403216564492428234157136, -535435582081972670563523916279168], [-3618827262245394137118656988707249628, 186942924976616305220018233367040], [-999003423576588352589836994002136530, 532349941468667440593203367217920], [3014133288163027912969654593754195560, 504535968282151106508258984815360], [-2183016975462987187965864837143058154, -947512336969853999246386484259840], [13831109103327225039988502695773930, 326174313442451095505636353494272], [1535551447461131198781725607487904180, -131646056747497277067065373408000], [2213546533898013534831673533511235040, 323543395423059859077352911830016], [-10547496093074120528531837116885184434, 107830968594364956599603212571136], [101205022227445841377231944393282738, 618601631861764515595258312633344], [-2646023976025746815881257702710362180, 320726761798705012509603905246976], [1580805013139450398080703330818890760, -868909016006190176662232451104768], [12005477736253449227681897689086755780, 885055783907735930489201680972032], [4651367027690337571085821138102681872, -1458720254897913901303813102374400], [-4742288711862238563310845127783524400, -1757871211715333444069217389024640], [3375644928649475541123590811407039922, -942067817185875200902858522001152], [11301981745116429019712015216103469034, -644902947082985268780077430085632], [581748167921206238159826413460756006, -2175775589831928001535985063899264], [2067550230894561675122410760004050508, -1286789035846029575658789178878976], [23838005759894536927760928373781670282, -499809959479762196725975294891776], [-14987100523157724088987999673163963088, -1108327894346023869109567229228160], [-10348868769552815341113095927968975644, -227940468663720269795273474229504], [-8102305769397411497304141159412213278, 1744477717502461285571795107682560], [-1975031378434191246101410851922764312, 4380299621329570882736586622665728], [13990897883231395487390012405063860712, -1123205622435204785251421487269760], [2796578351030742971554559105992422278, -5491035563166426312251766780857856]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3_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_3_26_a_a(:prec:=2)
    chi := MakeCharacter_3_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_3_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_3_26_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,26,sign)));
    Vf := Kernel([<2,R![-46305792, 324, 1]>],Snew);
    return Vf;
end function;