
// Make newform 400.10.a.r in Magma, downloaded from the LMFDB on 11 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_400_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_400_10_a_r();".
// 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_400_10_a_r();".
// 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 := [-46, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 24]];
    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_400_a();"
function MakeCharacter_400_a()
    N := 400;
    order := 1;
    char_gens := [351, 101, 177];
    v := [1, 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_400_a_Hecke(Kf)
    return MakeCharacter_400_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]];
    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 := [[0, 0], [54, 1], [0, 0], [-454, 13], [-12560, -134], [-73474, -548], [-84634, -44], [12740, 3216], [891374, -4033], [3661670, 22088], [-5338636, -17766], [2875230, 78696], [-3897882, -78844], [8385262, 6001], [7696946, -212795], [29264646, -389340], [-29809132, -505884], [-94081886, 611744], [-52999126, -1153037], [84332796, 1069994], [195106206, 973588], [-233473128, -815332], [164767582, -1072131], [-54167430, -6683096], [-1021529314, -1437700], [44485926, 1345880], [-520181354, -9676725], [-54967710, -1692765], [181986914, -11272680], [-965217978, -1177864], [703191834, 5271673], [5529978000, -4764362], [-2993868626, 8704016], [283096932, -22671204], [2113035034, -15565864], [2937626332, -7334326], [-4110865738, 62922616], [3879628366, 42486013], [16094490570, -3396147], [-3384454234, 1041128], [-17269344148, -23062852], [-16468740394, 6249904], [-16612573924, -53977274], [10259386310, 41512756], [-11353636370, 42828532], [-9106353800, 140254352], [25830117280, -84125226], [21249744254, 250528195], [-16215546942, 315841711], [-37989951506, -2502560], [1431846630, 150413724], [-58532177352, 5172012], [-3862255570, -258490828], [10934558256, 321790546], [-71822999610, 182041400], [82708469046, -200161629], [52480740274, 120868080], [-74146778244, 134044150], [-9230480186, 412381896], [129849094694, -348503764], [-38926856986, -75624907], [-82522226114, -696735152], [-242321408150, 78374363], [-168300980668, 727293326], [186262354582, -411549096], [47314646022, 1465600300], [-23388593208, 1446380830], [74369726270, -1688208664], [-133015438358, 211299279], [-389647933674, -549803696], [-76075746514, -2338673384], [-103948202904, 1585042448], [57735498530, 1750066965], [93550594886, 458173016], [-293142968740, 2417908800], [304588303950, 1246773451], [57802002138, -1132650512], [-39114513154, 3131801052], [-218276719518, -4315956384], [290937277822, 3274529708], [-229521291204, -2901147172], [-201037684038, 1988661784], [805048773932, -1978865122], [-127308220514, -3955539844], [289094349176, 2292763952], [-492756654594, 712531505], [89752484262, 2998121636], [111566989478, 4402419072], [-552219158658, 5097642360], [-199271882058, 603182831], [-258093802550, -6446454213], [1153579973176, 1421707308], [824293974514, 798712201], [403615556784, 2074235170], [-1409533920764, -641353688], [69911341878, 9288822979], [781105108646, -6208889088], [-647131109830, -6669319680], [2145563311654, 1912713789], [-538598259602, -9597250200], [3687146941538, -620078721], [2070998747198, 6638957336], [-2182513015642, -9383114079], [-328408275650, -7341941412], [-3011313249592, 1180617918], [2367792049942, -12821167760], [-523175343390, 13776364803], [-894529286034, -24173566688], [2194270762272, -24083178228], [1975937753494, 18989174556], [168441777186, -10723369259], [1099520949054, 1573000044], [3140113960038, 7490245036], [2101530309100, -23217990136], [-3435689920948, -4230941918], [2393111608206, 959247572], [-1419845437050, 7804820393], [-1745020009662, 5875981825], [-2972386326634, 6738201860], [2329817613564, -13069282812], [1875359341386, 3288359792], [451318684686, 689677252], [875260270510, -10559168868], [-1402757513778, 42033441969], [-2426443091480, 23624164746], [7691702624194, 8658873432], [-1804878136450, 29535750408], [12964506808, 51544252124], [2814307803914, 23927128317], [-2473964446602, 5933498752], [6067634484876, 53824330228], [2354506131822, -26217800113], [2691323893620, 23417266314], [6721889971126, -40613017776], [2966861355498, 56289439776], [-11747242716734, -1131028632], [9138868009374, 49198030404], [-2844301475038, 16170527975], [-7176520602858, -15812647260], [9786429354810, 1411658752], [1447831387072, -9566919294], [-10496113938838, -65091161240], [14261088404494, -50319456193], [725317442922, -71959161185], [-4288114074206, -56347196736], [-7704119161072, 74018111732], [5749612368718, 46777154260], [-28007262347922, 12026238536], [740420980324, -16908494820], [19426414771470, 26174605123], [-23622779271610, 32624791056], [518362321230, 202511471500], [-7722575891002, -59179650207], [-5997342649654, -45506255411], [-1472722383270, 64406742367], [12069686603236, -121136139526], [-1111332879632, -189424495116], [-6960601531018, -40806592796], [-10756669898314, 134207392676], [-10404107595250, -87370112064], [18231675550394, 184207400659], [1684343060550, 8091361344], [-29333019790782, 96066904073], [-18902323376152, 98699283262], [6779611495502, 17709329700], [-2134624361226, -51637594405], [-5817901618124, -149541907886], [3096895194918, -140860759860], [-31130585829646, 160566220600], [19636756560686, -154342248068], [-41604848261092, 151084349248], [34471007937454, 13994169824], [-2847982899580, -89617683034], [-37664134995362, 150630069948], [31853519201296, 163742582560], [-5985041518806, -68589972520], [-34283822650168, 237295222494], [10684672889110, 169989087328], [30484116425950, -184262974481], [17573946710770, 177039292736], [-12576234570142, 284379961885], [-39377791724640, 113071701038], [-20735257866794, 15595067484], [15036878355646, 6541397812], [33688495127134, 259688617155], [-35958538767170, 210565874360], [-21868996089266, 360284333128], [-7982977108090, 343919914441], [7119553679582, 96782483804], [73320740054884, 198712556714], [-63801026783978, -299290983760], [-85979749925586, 112305657665], [-18584153725736, 354368501138], [27287948630530, 350767872176], [1630258639298, -211222607905], [18933569339942, -201623659596], [50804150270190, -405373776420], [-64906033617306, 310444792348], [56188947805214, -341837927552], [-12634491221786, -432136492541], [51796640272230, -650785246088], [49840334833196, -310712687898], [-52782438914858, -114741536820], [-39502229223726, -240647123264], [-36335155015068, -653436745484], [28824201740774, -74461067792], [37432512508064, 764722302152], [-94041670928938, -151627728703], [11837318445306, -976796957624], [16570344962776, 19131971574], [-39098835713914, -450446747732], [-63439727200694, 164657802104], [151563390294806, -48479969253], [84869627521314, -326832816629], [-60751763447216, -611968945236], [5771350733526, -401581527932], [176153872707274, 49210218937], [-172458209238638, 183006546592], [78480590082186, -214030038555], [13788116170798, -1096216421372], [8642714206202, 1104142403536], [9790381101248, -1068445846732], [141613678702802, 833377985992], [267070272940806, 121100574415], [19990934148498, -451719177969], [-153059332117814, 345326424576], [-96979875174274, 87632906892], [-134355128299456, 448551202360], [-9371696473150, -1101624401991], [-98103943317400, -1012472942770], [-185449451550994, -621620868668], [102291674519412, -871412313568], [6570467165836, 615409059726], [165427579442390, 48045636908], [2864179626006, 2108317164757], [-120957792598854, -923852843247], [-115170297314970, -909542187980], [-149399389527402, 390516529868], [10539121054780, 1891029140360], [-4892078433900, -1493181795938], [21809752827086, 175713568533], [-133359011615248, 251509828066], [260616752761630, -91598973129], [-99410760297578, 81967397168], [-7281181136674, 961124905144], [-128972249141080, -361625993176], [-108452737348982, 600626540945], [-159408423766792, 1099094961106], [133042464873380, 1763525231860], [-79844655302666, 141367299983], [215114118157902, -77210122020], [33849244526354, -1812383217376], [-44651619806766, 1095025572329], [-503480131507666, -12749840404], [108312420594278, -310487588304], [-120074161046028, 466357289992], [128998844196710, -1904249964360], [-354864558615654, -658779266569], [-49737342415050, -2195029901624], [44508126822534, 676499855040], [375496698041902, 1107623982083], [4585402509490, 1995496816727], [-486243104299026, -236273083328], [-66665851784786, -2315519614448], [29390361636854, 1418692446636], [-75128427347884, -2953942933992], [-318734789306842, -712384604352], [-219796311046038, 618237588752], [129682941445566, -1963443895375], [-202068417866066, 59218029800], [26020460388830, -1788754338896], [180383444967274, -2353462130613], [534881324663622, 881353089980], [-246555743969648, -98726335024], [-177714583005674, 625580471424], [630338540007662, -559797540217], [-28370288444326, -2988640901673], [-124946480302762, 3217555202408], [346246274722118, 2193250812732], [-98442492325248, -529760644866], [-430426840628706, 2297830519899], [-324739800667116, 451271716374], [-525936313776446, -1529033312463], [-198078691866458, 123624133888], [38106110681842, 2322650918187], [316921675583764, -4173713714054], [-380547888853178, 939945112020], [-207167129045154, -1389772045540], [418467477504912, 2106386008692], [-60781592276874, -3487537427964], [-625878447442318, -1143904738952], [236924905448178, 2219473636591], [261701801290446, 2426017150460], [651683642379840, -705179512406], [539500939487174, 2820696542016], [-191432416486542, 1709631881256], [-46949391009884, -4283614322422], [-215833469090322, 3497424154736], [401580861298108, 4197581522232], [-761098576963398, -1770972383925], [-501389464037874, -2934798947680], [-14369444624682, -5683595067416], [-733493251512008, 3821890287156], [-345117199545818, -1137543694783], [398233786985232, -2736865641070], [-584996605620130, -888635374828], [615307455029130, -1485584040377], [244568509849558, -1777748361848], [36490270442280, 533306199256], [-216196214971682, 5698271516760], [-339343971972610, 5299927352139], [-190315117624578, -4512989446864], [191844553587042, 4039689038288], [810043788632230, 2504217704617], [724919452811098, -3365153059371], [624550942590922, 5042592703128], [402387313854436, -220299856720], [-608938661731548, 2513288125234], [302385618624422, 4121545294712], [-384073897539850, 5095467666724], [1489859396458216, 1676254607370], [107125309026622, -7413666196176], [-570669249663102, 2000796453152], [911902651166470, 658675438863], [-10880043257954, -953193880456], [751922669922942, -4744047437116], [697779940334132, -4829047863608], [-1004507780095570, 6599047539865], [446074596613378, -1819223701067], [-239398217826954, -6074095495348], [523554286503314, 10036617956440], [1204444277687350, -716792196512], [871666863797768, -855116391948], [242994747891758, -9846773988371], [1232559467714816, 4519444955450], [-284868759759966, 4672808267723], [1139481954620306, -4083875547704], [-1774949263132122, -3847649843648], [918668919163126, -7859034414004], [427740147713946, 2334221811881], [67728752464414, -8889686606624], [431999363855382, -8238474117728], [129925586442986, -9415024062072], [-723968919893348, 680958743442], [-1627531880855666, 4095323476504], [-723785091030284, -8358305293432], [1298483197160986, 276409973408], [-1835801049603110, 5905031989471], [-2402130481632492, -3084305577894], [-929157240821778, 2459745648804], [2340428664842432, -1940223804282], [-1369484751997770, 4241505849112], [-104965260605230, -3327971189280], [-997725960638362, 1689571574351], [1054798661588030, 2603333524096], [-1358756657820434, 4558732371044], [951634660133784, 4384980135668], [-136937462285864, 17613868153702], [761919441018670, 975989363124], [219832263770398, 5649188782607], [2185246790970358, 5375445029132], [-457095760154614, -3463531656736], [-467389157165822, -14357354847403], [-585635265931836, -4971241451788], [-307441153471614, -439101367105], [2602845758779478, -1046509410236], [-759924296734626, -798887020], [-238407677263258, 21715663239963], [-456693805068586, 13678508935284], [-285428819515680, 6438230670598], [230003274591292, 8408595599032], [-1967270625147530, -5735751719489], [-2526738352309254, -9155008655288], [979902336437820, 11379561942058], [-1697278621302578, 12965031790796], [-2935219044270348, -524567613752], [-1373236887450652, -1425948992358], [-1081690066097618, -12590221641856], [-980692998187866, 3629603491892], [56373583046782, 15955464384104], [-1113765688532594, -4231447730784], [-2884994440249778, 8246466789672], [926310082125666, -9025494895647], [962339391513966, 6532472080784], [-1525501338955836, 10882443578512], [-591899308059730, 10012648993143], [2737428579881132, -224374668010], [-2919020757912786, 5983764033464], [1769360165292318, -16352645467151], [631729071276386, 10631556997557], [2469816465331606, 9419776493636], [-1866650770251978, -14091895711512], [-883564557919740, 2930956607404], [-2920479093390374, 3864186041635], [354999384123980, 11729190735770], [2400948233754094, -12436217835968], [-4549717543988456, -2690460804308], [-902720159358150, -3671664083328], [979258164886864, 17198767621578], [-1185600370932438, 16085380039792], [1847697147360018, -9493465177448], [-1086145570878906, 24216075410844], [-2283180623627102, 15308068909765], [-2197022926062162, 16932745001152], [-3433157770625862, 10519832910432], [1019754577012956, 26848430474538], [-791746045940602, -29137313719020], [-3707108746517742, 15423519688784], [54697312271230, 25287899851869], [2347851944689884, 15211551722900], [5415265736036078, -1094193050792], [668262637719246, -22171224148952], [1015136530863814, -15086949542667], [3437365192384880, -13003555470570], [-2761118129899186, 8383890301348], [-594662975498466, -10186609270376], [-523903230840224, -38093415437880], [-595900781428358, -11750904991723], [4079899148108478, 14574052546172], [-3986006218663506, 12120099878007], [-1134089409923838, 5136888563088], [989430502120382, -12526112487460], [3275550342291122, 2832385138645], [341658550790692, -30981605232100], [-566429285920650, 25865918458976], [674118027639174, 978047531288], [-4192524228596442, -379028543583], [-3886229250881058, 6191620807004], [-3121703832910040, 2984794993278], [975014328480728, 22512279360776]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_400_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_400_10_a_r();".
// 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_400_10_a_r(:prec:=2)
    chi := MakeCharacter_400_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_400_10_a_r();".
// 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_400_10_a_r( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_400_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<3,R![-23580, -108, 1]>],Snew);
    return Vf;
end function;