
// Make newform 6.13.b.a in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_6_b_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_6_13_b_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_6_13_b_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 := [64518, 500, -499, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [7872, -15712, -96, 64], [985836, 66352, -3936, -88], [-3821082, -596, 15270, -10]];
    Rf_basisdens := [1, 1017, 339, 1017];
    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_6_b();"
function MakeCharacter_6_b()
    N := 6;
    order := 2;
    char_gens := [5];
    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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_6_b_Hecke();"
function MakeCharacter_6_b_Hecke(Kf)
    N := 6;
    order := 2;
    char_gens := [5];
    char_values := [[-1, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 13;
    raw_aps := [[0, -1, 0, 0], [195, -1, 0, -1], [0, 203, 1, -10], [38270, -17, -85, -68], [0, -19129, 121, -1210], [1813250, 500, 2500, 2000], [0, -370412, 3020, -30200], [-30067018, -2935, -14675, -11740], [0, -3667862, -6730, 67300], [0, -7796455, -72245, 722450], [682931918, -43125, -215625, -172500], [-3820030, -10388, -51940, -41552], [0, 27961274, -264146, 2641460], [407279990, 552129, 2760645, 2208516], [0, 97272900, 1009500, -10095000], [0, 40828247, -3483995, 34839950], [0, -1214785349, 2880341, -28803410], [11369266274, 2488380, 12441900, 9953520], [-53358402490, -537123, -2685615, -2148492], [0, 1643647630, 24011570, -240115700], [-63595906270, -6709680, -33548400, -26838720], [77145039758, 7813835, 39069175, 31255340], [0, 1543479261, -31430205, 314302050], [0, 854639446, -2079214, 20792140], [319057118930, -43978444, -219892220, -175913776], [0, -15102055517, 150275753, -1502757530], [792975066590, 35789799, 178948995, 143159196], [0, -20545720081, -113590655, 1135906550], [-664051342750, 173096940, 865484700, 692387760], [0, -15846838452, 70038660, -700386600], [-2958313060690, -144323229, -721616145, -577292916], [0, -46487637007, -209605217, 2096052170], [0, 147425794226, -57402890, 574028900], [-2601195096346, 537401245, 2687006225, 2149604980], [0, -265727002193, 99297197, -992971970], [-14841541283074, -93033345, -465166725, -372133380], [-3319329840190, -898819020, -4494095100, -3595276080], [-6083108380330, 1108624609, 5543123045, 4434498436], [0, -112760487402, 1215388170, -12153881700], [0, 731811429021, -93852105, 938521050], [0, -158740455739, 1033941931, -10339419310], [38341288133858, -1550647820, -7753239100, -6202591280], [0, 1487033321872, -235790128, 2357901280], [33037213733570, 3666774000, 18333870000, 14667096000], [0, -327867851909, 12420988145, -124209881450], [10553326300478, 7344202655, 36721013275, 29376810620], [-38601296003482, -3954612715, -19773063575, -15818450860], [91330425810830, -4269636741, -21348183705, -17078546964], [0, 3790336490073, -3385988985, 33859889850], [-45931637098078, 18756304980, 93781524900, 75025219920], [0, -728334310486, -17947219250, 179472192500], [0, -2670054632748, 9017890572, -90178905720], [-11067073075006, 7559872480, 37799362400, 30239489920], [0, 2741698018571, 19969291861, -199692918610], [0, 1415596048704, -53889470880, 538894708800], [0, 2175702653086, -11328567070, 113285670700], [0, -7553202807883, -1760004353, 17600043530], [-159962455959730, 36405050235, 182025251175, 145620200940], [54103715978690, 32741199948, 163705999740, 130964799792], [0, -2998485045946, -85645479806, 856454798060], [355199507544710, 7230255285, 36151276425, 28921021140], [0, 7939554447955, 70169155385, -701691553850], [476388104683430, 34003405701, 170017028505, 136013622804], [0, -1158923906686, -106279193666, 1062791936660], [666318101189330, 32404393036, 162021965180, 129617572144], [0, -3769769337887, 41183970755, -411839707550], [555625868511782, -168213091795, -841065458975, -672852367180], [-2102008743014830, 28598180932, 142990904660, 114392723728], [0, -3159870086349, -164318927955, 1643189279550], [-2323807893168766, -100580922140, -502904610700, -402323688560], [0, -73444561703944, -35882039000, 358820390000], [0, 34472152447014, 367180946394, -3671809463940], [553116198719630, 329116864107, 1645584320535, 1316467456428], [-737061057961630, -355153429804, -1775767149020, -1420613719216], [1035011699843798, -216224390135, -1081121950675, -864897560540], [0, 54375636445472, -101381236160, 1013812361600], [0, -8911843782101, -129898980511, 1298989805110], [3893657969756450, 158057236284, 790286181420, 632228945136], [0, 81162484402676, 45112174156, -451121741560], [-1831855085593630, 385042153360, 1925210766800, 1540168613440], [0, 50292499108905, 646220646615, -6462206466150], [5210361871493474, -255381942140, -1276909710700, -1021527768560], [0, -89236481726108, 660938641532, -6609386415320], [346775592527570, -221139122364, -1105695611820, -884556489456], [4480611462243902, 272668327215, 1363341636075, 1090673308860], [0, 56622859669083, 389278060005, -3892780600050], [0, -105730268581200, 943441338720, -9434413387200], [9238110984633890, -693793058160, -3468965290800, -2775172232640], [0, -145781988644635, -1336853437265, 13368534372650], [-10153870093866130, 530315562755, 2651577813775, 2121262251020], [0, 102560861353853, -1015061132285, 10150611322850], [0, 200229774545256, -889526188584, 8895261885840], [-5175943773146530, -1287704092537, -6438520462685, -5150816370148], [0, -126790766954609, -305679277759, 3056792777590], [-11714823230695450, 144422101845, 722110509225, 577688407380], [0, -52269531848046, -1396630559250, 13966305592500], [0, -207343630806511, 692505230419, -6925052304190], [0, -583722515465582, -589818744682, 5898187446820], [-7620949267189450, 687907705425, 3439538527125, 2751630821700], [20601577572824738, -1580660245460, -7903301227300, -6322640981840], [-23094882010148650, -1261113502143, -6305567510715, -5044454008572], [0, 142425514179325, 1360997432375, -13609974323750], [0, -164558130926235, 504838343835, -5048383438350], [0, 431552403659950, -5589200677270, 55892006772700], [-24406261493564410, 2539644638965, 12698223194825, 10158578555860], [64147175617725650, -854838270444, -4274191352220, -3419353081776], [0, 698259993206071, 2105347054265, -21053470542650], [0, 704277679179364, 1276866398060, -12768663980600], [0, 881111950122394, 3592758626054, -35927586260540], [-39518236675517470, -297709832880, -1488549164400, -1190839331520], [24122203794227630, -1868170816829, -9340854084145, -7472683267316], [-73076253060238270, -1266776896068, -6333884480340, -5067107584272], [0, 144094056695690, -8709758737010, 87097587370100], [15792391605927782, -7266012878115, -36330064390575, -29064051512460], [27506372588582366, 2493348716695, 12466743583475, 9973394866780], [0, -1783944549394144, 4057367667856, -40573676678560], [45905337648452630, 181347671601, 906738358005, 725390686404], [0, -96562558401858, -14598919910430, 145989199104300], [0, -387918716908523, 13441227101375, -134412271013750], [0, -210720177486515, -13938019429405, 139380194294050], [9184755958437890, -2356414412580, -11782072062900, -9425657650320], [-2475159530717230, -6772446819148, -33862234095740, -27089787276592], [0, 216985593593779, 20288381896985, -202883818969850], [0, -69145462504737, 16939897780545, -169398977805450], [-38735361765161098, 1212855939225, 6064279696125, 4851423756900], [0, 398226434901569, -2673684119741, 26736841197410], [-35326786233123070, 10496133389900, 52480666949500, 41984533559600], [0, 3130295861490108, 12345856299588, -123458562995880], [214203277206981470, 4066611275799, 20333056378995, 16266445103196], [145866371423842370, -8581148941164, -42905744705820, -34324595764656], [-101562533474676730, -18621389846355, -93106949231775, -74485559385420], [0, 2895758770889286, 2766778806810, -27667788068100], [117178531483141550, 6724348800115, 33621744000575, 26897395200460], [-36107772607698910, 12479372406660, 62396862033300, 49917489626640], [0, 368010167197854, 11721922668954, -117219226689540], [18564680700692354, 15476794173920, 77383970869600, 61907176695680], [0, 1242740998703499, -2612271574815, 26122715748150], [-201891736728064330, -15163384069239, -75816920346195, -60653536276956], [0, 333063386328537, -20194108364085, 201941083640850], [0, -402265855494278, 38924293916462, -389242939164620], [-340205107564397194, -1967647779135, -9838238895675, -7870591116540], [0, 6545503658475031, -25490401093819, 254904010938190], [99622808079240350, 26466837856775, 132334189283875, 105867351427100], [0, 7988376455098363, 12737097290165, -127370972901650], [92257904816015042, 26219682407060, 131098412035300, 104878729628240], [0, -6591828013362, -70406227670862, 704062276708620], [10085513634524450, -19535585919708, -97677929598540, -78142343678832], [0, -1096518786984426, 53113418780130, -531134187801300], [-264820910208450154, 24738547924825, 123692739624125, 98954191699300], [0, -367342139929976, 30175985946200, -301759859462000], [61801852546407170, -57094824275372, -285474121376860, -228379297101488], [0, -14156261375424244, 536574763396, -5365747633960], [133360142333087990, -40428271119559, -202141355597795, -161713084478236], [0, -9748628409958222, -54169181621810, 541691816218100], [467810523298856630, 42183648521009, 210918242605045, 168734594084036], [0, 13650913773449292, 33829052450772, -338290524507720], [-305069841467852002, -9934606606905, -49673033034525, -39738426427620], [0, 10596802853286984, 18476993528904, -184769935289040], [81512786403307730, -121380531318020, -606902656590100, -485522125272080], [0, 6435628976609629, -79359123872041, 793591238720410], [0, 19622457372184581, -35258684198325, 352586841983250], [0, 10329173563682958, -65454253541430, 654542535414300], [1153991578612189790, 19669279448103, 98346397240515, 78677117792412], [0, 7768029429612759, 141727379095689, -1417273790956890], [0, -29904296791481276, -28030352485540, 280303524855400], [0, -1811174796505670, -76602773334970, 766027733349700], [269681655917983790, 110431050504675, 552155252523375, 441724202018700], [-178958042746005310, 123755544862044, 618777724310220, 495022179448176]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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