
// Make newform 50.22.b.e in Magma, downloaded from the LMFDB on 10 February 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_50_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_50_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_50_22_b_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_50_22_b_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 := [86973087744, 0, 589825, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 294913, 0, 1], [0, 4423685, 0, 5], [141558000, 0, 480, 0]];
    Rf_basisdens := [1, 147456, 12288, 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_50_b();"
function MakeCharacter_50_b()
    N := 50;
    order := 2;
    char_gens := [27];
    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_50_b_Hecke();"
function MakeCharacter_50_b_Hecke(Kf)
    N := 50;
    order := 2;
    char_gens := [27];
    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]];
    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 := 22;
    raw_aps := [[0, -512, 0, 0], [0, 7743, 1, 0], [0, 0, 0, 0], [0, 109989839, 123, 0], [52595888592, 0, 0, 370611], [0, 77114162233, 2571252, 0], [0, -4598499025101, 28650372, 0], [-11910608357900, 0, 0, 88677864], [0, -20646510744717, 454003431, 0], [83519444223210, 0, 0, 10502558028], [2686542499072892, 0, 0, 5990086347], [0, -20931271031978041, -119562962808, 0], [-31611187502757018, 0, 0, -13492837542], [0, -28458960477791237, -1574613777567, 0], [0, -3313387250306541, -780913279437, 0], [0, -361437755935976187, -13478118580788, 0], [408530059465716420, 0, 0, -2389203736494], [-2290498584912924718, 0, 0, 22761577848144], [0, 7202007917193302639, -23530616787411, 0], [25570478866008057492, 0, 0, -4456798947981], [0, 3698080628020580353, -373045748127108, 0], [-12538883438762516360, 0, 0, -214235631444066], [0, -30022580474446518717, 1529581110859965, 0], [-52114234068633422490, 0, 0, 1752924118973820], [0, 65223380128807477199, 6049970082567180, 0], [765397554080084729142, 0, 0, -1501238274298212], [0, 883487886233707512823, -2582284765774605, 0], [0, -183380355666569565741, 4751862469368429, 0], [-10479700490018589650, 0, 0, 6792148185310212], [0, -202430658032716937187, -30818501144532504, 0], [0, 342594820096407562319, 126660017833919199, 0], [-24976296466342735819728, 0, 0, -25340265907728987], [0, -11002665177790862456121, -114679016334424752, 0], [22771793246686480185940, 0, 0, -42115013406711474], [31998579428511342014550, 0, 0, -95318777745146460], [90966236203534632438452, 0, 0, -162953018803644765], [0, -15117998778439258944061, -352235972712277032, 0], [0, 90952029242576586692443, 470228190464537085, 0], [0, 73195437068221154570439, -1666025914469431461, 0], [0, 114569946889826504019813, -2270076131086851720, 0], [36628621475951419312380, 0, 0, -1501641916702441218], [438951469253004930962342, 0, 0, 97790453022928632], [475350026009208887893812, 0, 0, 1528384551886563429], [0, 630797148730066682313853, 73995593608418460, 0], [0, -122491446621234433086321, 5034500969108644164, 0], [1696986400257447086305240, 0, 0, 2960572536088171368], [-1496525341942913801977888, 0, 0, -1936944234472568235], [0, -2282087705446949710365557, -4331342374249326981, 0], [0, 261093281360544694072179, 44586825725255248977, 0], [1083161935341254159800450, 0, 0, 98028293575196496], [0, 3104878923134093515586493, -33620355447507846252, 0], [-16268644234948319775961320, 0, 0, 3596568430900819974], [-2907753995845178152894258, 0, 0, 55242523303461893490], [9741914440985307496871952, 0, 0, 73037790253946926215], [0, -5213684147746808870803581, -8475608228145329448, 0], [0, -6817526090370208786309977, 115763667906843647979, 0], [-42776116063774027076504610, 0, 0, -71356062459108964248], [-55090123155809976585666988, 0, 0, -39151132070113932627], [0, 10401680772675999729438299, 38655095340661341288, 0], [25614021266152724259770982, 0, 0, -262576378349617282530], [0, -4638069045368535228802937, 267367347393483279909, 0], [0, 27559635728421489768500553, 194172427765368117360, 0], [0, -30718405070197180625981521, -823179307877476380315, 0], [-139485569961030377949116628, 0, 0, -34781078784324523983], [0, 15828729458229906652211653, -1816271345576696887032, 0], [0, -69710225654866647775021461, 79263036209169817884, 0], [-29110403475145162300242088, 0, 0, -5606659053048370719], [0, 23263047292445989532478719, 512714361883347996360, 0], [0, -73116372418717133882005281, 933822217960959918081, 0], [308454107679525309293225530, 0, 0, -977966164222423277064], [0, 486834276504055186470043113, -252459370968866054328, 0], [-552505608190499905115913720, 0, 0, 1906128918797553042408], [0, 282811393542927942273663899, 499368593209033135107, 0], [0, 263831386382466309994546213, -154324450884978168120, 0], [1129097043726319564308074860, 0, 0, -529532526148026970272], [0, 42155310323342775310106643, 4533866789286179745603, 0], [748665729234105035428971990, 0, 0, -2733314287445081936664], [0, 569365558771544019123176519, -18949926217893239982324, 0], [-1029578629731313192416719838, 0, 0, -3808976086747442486928], [1618839086564667125952883330, 0, 0, -2960133689190481286622], [-3385731452677261234779629940, 0, 0, 12524111795049860471406], [-789109155125882873663132278, 0, 0, -5201630770599648780420], [-1511107604078203754177143068, 0, 0, -19296831279910404293895], [0, -865281230858081562584343407, -25200456465976810519692, 0], [-2707168366572068537586770600, 0, 0, 11034542974414937469048], [0, -1944517074960204133571763357, 22459969310029376138337, 0], [-1149841861800260060668876230, 0, 0, -19528878396055805910666], [0, -818261292753965506258155421, -14453609609789428907520, 0], [-9244753727962884853481665938, 0, 0, -10911538581410419864020], [0, 2575646108803649135952964183, 46127839626599291879367, 0], [0, 3325301533708468240913508639, -44921258151157439727771, 0], [6033944418036787057839396120, 0, 0, 60290273786568322901670], [0, -277773974310636652893775741, -39734297717953375664673, 0], [2141781090588421717433255952, 0, 0, 90556335349110797585727], [-9183803549707369232371763660, 0, 0, 67725215509722667361748], [0, 1267078270174074359996161383, 29035509159195204201483, 0], [22565715607841969699072928810, 0, 0, -5169054830440414485696], [16996972404051853975216237722, 0, 0, 17291034536390835202560], [0, -11292549175804730692031155577, 352755665954954604430413, 0], [-8731777898736749090698240738, 0, 0, -293219809837570724260476], [0, 11025576959821527883258379939, 41188747499454581203137, 0], [0, -46908795133025918981136383001, 1397622186337512978936, 0], [0, 13333626603579353989422467703, -195725156908646806514367, 0], [-62439974986810958570830515390, 0, 0, -201910262410993562589654], [23338234348898765196412259672, 0, 0, -80660195423169828695535], [0, 13049596674684402590395875179, -1002200795900041429086288, 0], [0, 45585623110893319981606381299, -227929265705286792171411, 0], [0, 4744432470711758304732506793, 313954531220050482669792, 0], [-41006887620500775917034947040, 0, 0, 561754176867462457590582], [-124066279158620900589478907818, 0, 0, 542969498088877796959926], [0, 45600180243094267751523382619, -1088895454859179729409853, 0], [0, -46604817670726629864348711287, -308611213222320984448284, 0], [0, -42188742938300862820915350141, -1342947110127282096362820, 0], [-78528486996217894434264778820, 0, 0, 283970360729897899389060], [-267297027711342306359529389308, 0, 0, 154131770009858251384887], [380654712249165314322651644142, 0, 0, -177694345373291609630910], [0, 14524653783918637823151341863, 1729827408670303743846153, 0], [0, -204290969024288164409737155141, 472304812874578572607143, 0], [0, -60685860883621892453819197587, 1588065705980595401279532, 0], [-192752616833624667519359944500, 0, 0, -965692546584865583844798], [-328311610761629844561553504678, 0, 0, -112031568116591571741288], [0, 57186345231968084374174411513, 4008998885640495607556940, 0], [0, -91016174821091872689312691281, -1870360677246430907119476, 0], [0, 99112152144005817152613494763, -5281005834579952475104671, 0], [-656204687216274599248716094408, 0, 0, -1143347580640174217108805], [74152917659539174424330957682, 0, 0, 3854158662977117955417756], [800039479668537438289771645810, 0, 0, -1891127081774522707827156], [-71451796474635233503867215720, 0, 0, -1539216934778236701516450], [0, -101806523713786853428379717401, 6634305166452645405313323, 0], [0, 866765349487771044694839871453, 3469602905215186502877696, 0], [-105566547790748288261889642980, 0, 0, -1050989884056595736952678], [0, -44956466023137796957271537997, -1133726513339527915002825, 0], [-122150931680479611359906853508, 0, 0, -4923565780483181724385197], [0, 1350144879229231685004373523219, 1731031257308117237816592, 0], [148202407556635361821493080842, 0, 0, -2588834889285299886278064], [2237638529380428395103072428350, 0, 0, 5428864926380551970241564], [0, -939536637349196014813479210087, 16953507657099788144803500, 0], [0, -219135396721570892171808903421, 14125973954297747083619673, 0], [0, -1255233763662960999352574867661, 5776286924625105500137332, 0], [-2416118407793207017368378360090, 0, 0, -5196460377054680905506816], [-937345413301817790205119174208, 0, 0, 15885122032133435711693391], [773714335533532709789592511482, 0, 0, 15411852359432291158362372], [0, 909857846011039725787999887043, 2610097096144117105214439, 0], [0, 1514329062209491854285756297759, 31422770358835440477291441, 0], [-2954435500599700311628240720850, 0, 0, -6074064192019615738832544], [3424075233082104951403363004880, 0, 0, 16122697968742162873857834], [0, -816988428079352190631600715807, 26402677862908687465370076, 0], [0, 1645036701401599214445236250759, -33500670941203513517441496, 0], [-3147931133284948898110424223020, 0, 0, 12575297045629178844580398], [0, -2507231145035068746604287701997, 38272523681532481332628443, 0], [0, -2062210325243255716393116567061, -18667947093215169608825520, 0], [3191956292703305325822117724782, 0, 0, -14781549440277898094182290], [0, -3426130225535208263906314564217, 2111611470852346299589185, 0], [0, 563467177523522106104642525319, 68704941632224734667071195, 0], [0, -4650418545044497758005246968441, -37420210192280138195199951, 0], [17674172842882063037217085838412, 0, 0, 16174114231515167460635835], [-15545121286294582064932056758480, 0, 0, 20000871540947545801111818], [-4265434873459190086555620910230, 0, 0, -26292738064709323961597610], [0, 3657624422595410605686680416619, -83639623142760711037868460, 0], [6231868003642063505765434066302, 0, 0, -37169453327010085842915168], [0, -8028729397187943961294474626201, -70242021487187940944985555, 0], [0, -2735269103210081496632627920467, -107947428869006427772435392, 0], [0, -719717809268910631069545947941, -31880725479829344254066625, 0], [5666213293962202549777994934072, 0, 0, 31413027345713627626970865], [0, -4228473064600672080317522291001, -89981865514346904834945132, 0], [0, 2661152915514195428800012480743, 41919918285516847576912323, 0], [28717585076656062163622381800892, 0, 0, 5334521556863326242583695], [0, 5437990140788730744963564501419, 237718670688837436305775356, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_50_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_50_22_b_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_50_22_b_e(:prec:=4)
    chi := MakeCharacter_50_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 22));
    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_50_22_b_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_50_22_b_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_50_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,22,sign)));
    Vf := Kernel([<3,R![280466343274321395216, 0, 34453523592, 0, 1]>],Snew);
    return Vf;
end function;