
// Make newform 45.10.a.e in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_45_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_45_10_a_e();".
// 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_45_10_a_e();".
// 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 := [-1182, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_45_a();"
function MakeCharacter_45_a()
    N := 45;
    order := 1;
    char_gens := [11, 37];
    v := [1, 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_45_a_Hecke(Kf)
    return MakeCharacter_45_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 := 10;
    raw_aps := [[-9, -1], [0, 0], [625, 0], [-5908, -56], [-18720, 1952], [72530, -1384], [-191478, -2200], [-202132, 968], [-144336, 64968], [43494, -12416], [-2551432, 75736], [2774162, -174696], [-6870618, -470096], [13798268, 152384], [-47767536, -431368], [32617734, -929872], [-94738272, 1613408], [78168374, -2256688], [20518268, -7444160], [117666048, -7061120], [-13321054, -6480208], [-465304360, -1798040], [-101939532, -3161088], [-116912178, 9306192], [171547778, 44039040], [-179712690, 10351392], [-870671572, -23903736], [-342419796, -39862608], [-1477685482, 8752128], [122396898, 31516232], [-3104830972, 61762280], [1717898496, 66294288], [-5264515734, -7286856], [-175012468, -109011528], [-1079328474, 95881216], [-7034058568, -41782120], [4378265714, 83291496], [957242684, 369358080], [11043572208, -118197624], [-12931282482, 276959232], [14343164520, -88867600], [-4951515922, 249453696], [-5445650280, -338177888], [-6471122038, 13201488], [-2560430970, 414752688], [-18568875016, 357168344], [1433119268, -1095702984], [-18264325660, 379867896], [19306551948, 231603136], [11003834102, 1223574352], [-37204713918, -1014300264], [23208562632, -1162136848], [56754031490, -461796352], [-21018532392, -2290507440], [-49961632926, -11592888], [9291360336, 1335183640], [87821166822, 497468672], [47857254560, -2931878152], [66492167090, 2810356072], [6993044814, 1732391376], [68290784420, 2110595296], [43869496326, -2057660880], [67027144436, 2658536048], [-502188960, 2262689712], [-85979235166, -1153824720], [-64027970706, 4586012752], [40097507252, 1068554680], [10433158010, 4683425072], [-119638815468, -8361924880], [182408858486, 3311404976], [5093478570, -309268296], [-321942926952, -8531803872], [-243480752140, 6863128312], [-382132122742, -8406882616], [44918954540, -11812472440], [-220716176304, -38429640], [544946377638, 5105403648], [228271356026, 10832804408], [-683983301754, 328887168], [447118268762, -13684450368], [-78046714368, 6879525232], [-9884260234, -22837566256], [-454319733888, -11476167456], [5523641594, 23402229680], [65941281080, 26713363640], [760259380980, -15413236416], [-675744868794, -17575974304], [496907453402, 10914413504], [538483242558, -5943751200], [-231838988692, -23694583736], [132202436484, 39043802992], [-1255877364840, 6046064640], [-1880303673292, -12129453960], [1158561333576, -17790773792], [-1327405759732, 8935086488], [48235153080, 29390410264], [880804204518, 17415237248], [1530956853102, -15262434656], [-745153311052, -24497892976], [-402705845482, 26216020096], [425340855332, 28201111904], [-1581592358898, -22553689440], [1885372811628, 13676285712], [419478142062, -18494443488], [611733586340, -43777346472], [2459189434178, -6740865120], [-3581594162196, -57913934448], [-4327146083598, 44257826536], [2647381832856, -36698388704], [3417126700970, 37971257088], [-4114424648692, -46839190600], [2436264027602, 15889158968], [-2377655824494, -111630031656], [-2743466193988, 2037351672], [370875216752, 67802338280], [4877148547902, -65695825776], [-507885343492, -115548111776], [864639203352, -101783796760], [4433380843086, 56123858560], [4333307834160, -2931333280], [-1364847784498, -69197394640], [5261745795386, -71792112368], [-58035845850, 70625923968], [-1199746544724, 56987349840], [-2783308419460, 181350055448], [2540274076326, 32384748448], [-463325471002, 204881394608], [8043151707936, 122189713296], [-4627203009676, -176011281384], [-5546908117222, -146029534776], [-9229794288868, 142838447672], [-4174685522808, -197755768024], [9083602510280, 156315305048], [-1031843789326, -135412753144], [-1366283883666, 452832530016], [-2503066655806, 147918559584], [6471068347926, -60640464240], [-8326751992804, -340403226352], [10306209282174, -236022339008], [-11743506030570, -69481838960], [11353746353612, -266826588680], [13994376498894, -36346010784], [2049771188612, 140385977448], [-279635135628, -6578790880], [-16511132789050, -64647207680], [7545037036200, -407989324160], [-1375017245086, 308030958040], [-18014742761886, 263582826152], [14705600216300, 148711312040], [4534342911192, 216745209736], [4646381591282, -857579906456], [4031406872214, -236858567824], [-7051661977732, 357332712864], [14512183038384, -235713894168], [-18422771920564, 163782947248], [-1168395034032, -227633255440], [-2007409486240, -136964454760], [-16485158934138, 381948719872], [9797037042650, 796069693312], [27984313015182, 97093820704], [9404703957756, 242310797904], [-11811367443990, 87299503544], [9851802644108, 555061904280], [5763833045352, -480902978256], [-22434258462918, 391423723880], [11801755981704, 1291299938088], [29267689446272, 400763981160], [29429634103754, 676079548456], [35683086169730, -280100839680], [4511776726998, 1552873608832], [-29384564553168, 444449327232], [-29412336518866, -123861155968], [-24441327759576, -231318648864], [-11377439535406, 79219560880], [10636259992136, 752563864136], [-8611878113778, -608625074448], [13583860935548, 335270028136], [-37416719032650, 57777432672], [28964786633588, -745791427656], [5526612231470, 1397461760000], [46348786654652, -667133279256], [22313647181040, -110734681568], [-21026006052958, 1503064613768], [-23204134283766, -1047219528248], [41077033894032, -112624676904], [-16994834003610, 1093096556000], [8081427799058, 21474113080], [15605350750700, -496029683344], [-56385058424614, 1490462383296], [-46883094321576, 1844237518016], [-15732152204662, -1694415752176], [-5052250600812, 708455285072], [-40222065516556, -11681913608], [-27996031593090, -2020639353088], [1153012332132, 1507765466400], [1081649414538, -1160894039288], [-21165648380110, 3252753852608], [-49789718561758, -1491560637992], [-32840169882126, 385382945832], [-26629187770104, -2669935421720], [-18947398024434, -983440037664], [53735739819224, -518408114168], [-7541726530630, -904193813768], [-16815584056942, -3872734519072], [-68649820190784, -2670647279184], [15093946647198, 2215191662736], [57293640540488, -2609309097672], [-58548714228564, -1274157374800], [50981376213246, -895064688624], [106687773959636, -136504985016], [-59620948150966, 839186013936], [-67486845537162, 1652214821440], [-70894297429924, 269479745032], [31922155044612, 277802208320], [-27757485834672, 4456493051568], [-54795064221286, 2129239972512], [167063221804004, -1349823123304], [52869675664326, 1735051833888], [-7173533453640, 1911375398008], [-13188364271778, 61218182496], [-40522936379914, -1835144753776], [-80919430708984, 942849102456], [144818989341630, -1032749022960], [-30936427606468, -19818800632], [-107568724488876, -4138391228048], [-184949020421530, 3433247751840], [69335490429066, -910561080120], [-119889057221088, 2055723206032], [-33178801644604, 1408667581928], [137289894983184, 4023019218576], [214748140880786, -2022871896008], [-32071937710492, -2613008066632], [47038360155680, 4553171528568], [203626911617166, 2098679317808], [-161026411308028, 3854817850128], [135175647933192, -5226624244440], [77171113057586, -2847002636864], [71112060076566, -2602829817440], [110528816016912, 3487176529392], [13050575708976, -7298112808512], [-115922295100932, -1716231325968], [-197514653753884, -4269668042696], [-46571919535756, -1502678015800], [139630580942054, -5205912874736], [310812456023466, 1528240005240], [-55398022845552, -2271991825072], [175130730979220, -3552129668328], [319360297172232, -3450691362976], [-108676932746668, 4117692929832], [-123973004395704, -5867930554840], [164785096293722, -2961845564056], [153880196478, -1708950149920], [121725763430208, 881569208856], [-7508200995238, 680770911232], [-114877003039554, 2433605155600], [93967617499344, -7017482938176], [232112894742782, 4337451053600], [-149486042046652, 5967163798800], [-187244529979050, -1114318752912], [-56508568147870, -8419272859248], [69409302944228, 6845250323384], [-176254352325012, -937695012944], [263567112825926, 2174746455696], [164878133641322, 5032762325848], [-18122544867198, 5808897964440], [-157256067060676, -5928013003816], [118202715036222, 4661801369312], [-59741462061354, 9784668002848], [-544500811508524, 3988845169872], [345890589541158, 2503783583552], [198726317923646, -1190813425056], [-369680778645004, 9575401316528], [192369194565554, 16020655336080], [58723948498856, 11231003762536], [106956465666746, -16987358826032], [-256235574142276, 1719286603560], [-214480760210940, 8457340668048], [-146315115670810, 2069516434000], [247580311545770, -12727489253312], [-263674684782528, 11105594813424], [-154978300090296, -8390045498792], [-69426179826904, -16581162865816], [-199989352067592, 4210308352936], [465045761945750, -5538259151072], [206612572350236, -1194316449872], [196321397378472, -9538030758336], [95743007236754, -23614667867680], [181755715353846, 14768520794304], [474251633304536, 11534461444296], [-35037854899650, 18087303738240], [-419313335079810, 8693762414272], [-482781797211516, -5480259285728], [-343864234476174, -12708901297320], [-24753015549696, -14129713275984], [558931309279274, 7576968973560], [511412536639950, 6210850766400], [536367030049352, 12352349797800], [430905328722390, 1787503523184], [290196780710400, 12761556985680], [371599874743844, 6121911299616], [666972655640402, -11410447416272], [358860105602286, -5441542093216], [598220114566976, -9018247611784], [-489157890927852, 9915379360752], [3438766283444, -31019556350968], [-642409323801262, -3333452058240], [-166888560670836, -2009997371808], [146774576206478, -28879569996432], [1142257026676272, -219155842608], [-91219532387782, 11172555548104], [-9931279708248, 19230683749896], [1289580765202782, 3685129218432], [66204459968502, -8276069853216], [-96419518765756, 26905594609680], [-620406354509736, 14081231313112], [323990429023898, -2269443832672], [-429062206691256, 2381781003504], [-79311337538232, 27916016135760], [-96712178479654, 13409870840272], [753604382835294, 23251084711584], [574665216132188, 5732094120456], [-681454452710878, -5718642014736], [-839741765710890, -16196545658848], [644604482566988, 13315344262904], [348251069518482, 39756462693096], [773639623362050, 2441958340928], [1105320245714660, 11060241879480], [-1117043678229076, 4124962184000], [-7318021259904, -30645382127736], [646161634436838, 9928581858272], [-154870390205698, -2365962799280], [-1506094789004898, 10519882617920], [250977213692120, -37624064708520], [-722988329298780, 24940706726224], [-417754897309636, -46656784394808], [167495371205916, 42877194589504], [-952154559624706, 15920904849984], [199064095270938, -21958633950248], [39882367353674, 42345064235232], [-184930360318012, -5839646845880], [-416235890428102, -28083234006136], [-1096751681959422, 25983338063656], [-943200792338322, -31402422268992], [-19478089265368, -6031901836760], [-1372049909803602, 20028175929392], [-93012656933880, -1732791147840], [-112035830494426, 69060162766992], [-1845017799268420, -13752595294528], [1006128317543592, -39806274742896], [478807669187670, 1820521316848], [1380903611006660, 44032516802248], [-373400868799750, -47367121443968], [-623356731559818, 48308398749664], [-505804383973900, 60775398733976], [-533493065673202, -38545506847472], [268349454802098, -75338806059528], [-485184882248208, 32518982829472], [1033434274687344, -46984074173424], [-326341229307150, -73387611852552], [1251740877173568, -22720297525768], [-1875295339218262, -2009321057080], [-193707001723626, -41866062711424], [644675225327280, 66070901514888], [-493234866090432, -48298775353552], [1133608781614556, -50267257517952], [653859370826666, -77856226799488], [-1478419690834338, -26765790919440], [1519790436097052, -38389786966952], [-2333215428539110, 14025813181728], [297352328288664, 83212167383376], [-3600807198604132, 1754511436648], [-2260897100471616, 46735777716248], [-753209341359378, 53103700162752], [2451988646743496, 26256514120504], [-1140890530005478, -14972622408376], [-1856327534410488, 60895967987072], [-749083388235984, 43008472605648], [-1153114320957550, 53908541664096], [-1229683048349994, 3878011827456], [1010761824381146, -35371747731712], [2305476928296078, 47057617444960], [2837380026697962, -5254137429384], [1545595174050380, 33698698635272], [-1457791332382758, 26492096035000], [2818204420817876, -13924763629544], [-1091640827034048, -114993332064904], [3231069742077176, 20232034116504], [3444985692020306, 13916874077928], [-4322884188858052, 26496857048944], [-153201195213816, -112553651410968], [991110606107522, -111379651287488], [195828179853798, 71717599424672], [819916564393104, 21437655764864], [-1438063799623828, -217941913776], [-1051767004569624, 9798524717888], [-443153741986006, 134914243045440], [3748438011946160, -5156595287160], [-2682642739684362, -51596089100112], [2043770237123588, -2614320836344], [-1560209338639146, -58536745210944], [-2027941113999826, 92830891496384], [3924917705895570, -31186257815496], [-894201837048748, -26215867801816], [168330584736378, 157508838395416], [1343710080503742, 110873531744512], [-2212193339394112, 97090593549416], [1973216074661498, -91523644350840], [143184095040390, 22313536799872], [1260390884649404, -5189009664320], [-252510829787472, -48781799758032], [81158428167170, -115398449511104], [-4220187071068266, -61483208633568], [-488250017633316, -49506042973552], [-825278897203780, -103769769607112], [-1552841203440094, 95320363139568], [3562020690353574, -78585571781344], [612204968173152, -93952615935488], [-4181072698705204, -40539593156152], [-491469894408222, -122988208582344], [-2272472971314480, -51123530840696], [561413759607726, -200382429444224], [1995450554147210, -144446562439288], [4654922723145120, 72481839957288], [24014792290728, 146586669668288], [408049384156130, 90758737652496], [-123303719077746, 14000511599792], [-3227117509941996, -277924974272], [-4816336674742650, 1086830706720], [9460498538180, -55534456631832], [1572414853482648, -27534113340832]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_45_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_45_10_a_e();".
// 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_45_10_a_e(:prec:=2)
    chi := MakeCharacter_45_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_45_10_a_e();".
// 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_45_10_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_45_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<2,R![-1092, 19, 1]>],Snew);
    return Vf;
end function;