
// Make newform 150.11.d.a in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_150_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_150_d_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_150_11_d_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_150_11_d_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 := [531, 38, -37, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-240, 464, 48, -32], [-4548, 1824, 240, -36], [54576, 6880, -2880, -64]];
    Rf_basisdens := [1, 93, 31, 31];
    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_150_d();"
function MakeCharacter_150_d()
    N := 150;
    order := 2;
    char_gens := [101, 127];
    v := [1, 2];
    // 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_150_d_Hecke();"
function MakeCharacter_150_d_Hecke(Kf)
    N := 150;
    order := 2;
    char_gens := [101, 127];
    char_values := [[-1, 0, 0, 0], [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 := 11;
    raw_aps := [[0, 1, 0, 0], [-21, -3, 1, 0], [0, 0, 0, 0], [11278, -18, 48, 3], [0, 3696, 210, -105], [-68810, -360, 960, 60], [0, -74304, 1416, -708], [-392182, -1746, 4656, 291], [0, -90336, -4956, 2478], [0, -757128, -17682, 8841], [-5446462, 54810, -146160, -9135], [17753542, 102312, -272832, -17052], [0, 4121328, -80484, 40242], [117672166, -122094, 325584, 20349], [0, -4185600, 86760, -43380], [0, -9081864, -356034, 178017], [0, -17198448, -139638, 69819], [-296009686, 353592, -942912, -58932], [74341462, 898506, -2396016, -149751], [0, 14146272, 1281588, -640794], [-1633567250, 832032, -2218752, -138672], [49820642, -2886534, 7697424, 481089], [0, -24958608, 2330154, -1165077], [0, 118832112, 3522372, -1761186], [9794088766, 1435608, -3828288, -239268], [0, -611653656, 4244874, -2122437], [-2767094834, 8438526, -22502736, -1406421], [0, 205524720, 27323646, -13661823], [-5079939190, -533736, 1423296, 88956], [0, -599664864, -507528, 253764], [-4529901314, -54701514, 145870704, 9116919], [0, 2027679600, -6078642, 3039321], [0, 1406088336, 85237908, -42618954], [71403167066, 12284262, -32758032, -2047377], [0, 1006547016, 81403602, -40701801], [76625787986, -68936238, 183829968, 11489373], [30919534870, -192905064, 514413504, 32150844], [115761759766, 35670978, -95122608, -5945163], [0, -2003155104, 240213276, -120106638], [0, 9557715432, -126318726, 63159363], [0, 6315622128, 215612166, -107806083], [60571129178, 283033512, -754756032, -47172252], [0, 1166770752, -258857760, 129428880], [33381474430, 519710688, -1385895168, -86618448], [0, 742488408, 242233446, -121116723], [-30698724238, 122012658, -325367088, -20335443], [314017714058, 242467974, -646581264, -40411329], [420669605566, -278830458, 743547888, 46471743], [0, 5674321200, -779473278, 389736639], [695033891258, 514724328, -1372598208, -85787388], [0, -2481343056, 1535033220, -767516610], [0, -21084494208, -1066278024, 533139012], [-76175414686, -1450637568, 3868366848, 241772928], [0, 31594470768, -207871062, 103935531], [0, 20798882880, -2456008704, 1228004352], [0, -67651375200, -217600404, 108800202], [0, -55676057256, -112872426, 56436213], [-1587999049630, -249307686, 664820496, 41551281], [-1112878112282, -878143896, 2341717056, 146357316], [0, 56417622576, -1448875932, 724437966], [-658166758970, 2492555274, -6646814064, -415425879], [0, 58101807768, 366309462, -183154731], [1304508297526, 3003458778, -8009223408, -500576463], [0, 80282388000, -201490836, 100745418], [-742181883506, -1492906968, 3981085248, 248817828], [0, -74636741112, 4238018274, -2119009137], [1652588508122, 4620349062, -12320930832, -770058177], [-2510294481698, -2474421768, 6598458048, 412403628], [0, 212491043088, -573614874, 286807437], [-4060246031254, -7803132984, 20808354624, 1300522164], [0, 63528027456, -3309491280, 1654745640], [0, -214101700128, -1868457276, 934228638], [9154963984222, -1447974522, 3861265392, 241329087], [2631334128934, 9704458008, -25878554688, -1617409668], [11443448578682, 509550174, -1358800464, -84925029], [0, -52982481216, -7893383232, 3946691616], [0, -321237969816, 11194298682, -5597149341], [4950678330934, -9364482360, 24971952960, 1560747060], [0, 586738035840, 2455264056, -1227632028], [-6222369519310, 6807328416, -18152875776, -1134554736], [0, 682803038352, 9535662558, -4767831279], [-2757232534726, 4429268424, -11811382464, -738211404], [0, 548326617984, -8086775592, 4043387796], [-13958631539426, 10056021048, -26816056128, -1676003508], [2135655008018, -26205935886, 69882495696, 4367655981], [0, 1065408650832, -8107472394, 4053736197], [0, -125467360416, 15686780256, -7843390128], [-411256247570, -1554336, 4144896, 259056], [0, -1087452264, 267841974, -133920987], [3470712244510, -24409257642, 65091353712, 4068209607], [0, 767492524080, 7441456362, -3720728181], [0, -411168797184, -20576164752, 10288082376], [26541169644238, -22836147138, 60896392368, 3806024523], [0, 737802777936, 27024559170, -13512279585], [7042617774410, -30740230458, 81973947888, 5123371743], [0, -1282464598176, -9086336460, 4543168230], [0, -383334985608, -73060302786, 36530151393], [0, 1013259577968, -61120325460, 30560162730], [4507774800550, -85785946830, 228762524880, 14297657805], [48522783989738, 50469647256, -134585726016, -8411607876], [-27638231566058, 66090640770, -176241708720, -11015106795], [0, 1886583539880, -44167155270, 22083577635], [0, 675726764208, 90606156282, -45303078141], [0, 405297244176, -14267480556, 7133740278], [43445373118970, 97001263926, -258670037136, -16166877321], [-34384387036034, 1934855640, -5159615040, -322475940], [0, -5536228268688, 5962418382, -2981209191], [0, 1071163828512, -22171117848, 11085558924], [0, 1704111752928, -10344963972, 5172481986], [67386529626290, -58219432992, 155251821312, 9703238832], [70130154821566, -38228800842, 101943468912, 6371466807], [-7982019585722, -90121216248, 240323243328, 15020202708], [0, 1855441007088, -55435711548, 27717855774], [-17547319951462, 51140341926, -136374245136, -8523390321], [-12008973530734, -2586278142, 6896741712, 431046357], [0, -149790254304, -71356064640, 35678032320], [14079530354134, 62352089442, -166272238512, -10392014907], [0, -913345447968, -49116739284, 24558369642], [0, 3098160327912, -20242774230, 10121387115], [0, -366797138448, 225944191158, -112972095579], [-3177458178790, -308610938952, 822962503872, 51435156492], [44241164126398, 75752186328, -202005830208, -12625364388], [0, 996958166808, 207066219798, -103533109899], [0, -1489939496496, -266454754146, 133227377073], [27605723952842, -58178286450, 155142097200, 9696381075], [0, -1127565678024, -119916954402, 59958477201], [239148352305530, -46593487080, 124249298880, 7765581180], [0, 2689435309248, 300403033704, -150201516852], [123455582972974, 264558355902, -705488949072, -44093059317], [-220851797574506, 152046744408, -405457985088, -25341124068], [46803805786730, -180381222378, 481016593008, 30063537063], [0, -203952097056, 156724646652, -78362323326], [9410393862050, 262676505546, -700470681456, -43779417591], [220519660232230, -71512418376, 190699782336, 11918736396], [0, -5307439404336, 13946382900, -6973191450], [5636456292866, 338685161472, -903160430592, -56447526912], [0, -5762427456168, 394850309382, -197425154691], [-78324012926474, 633323329362, -1688862211632, -105553888227], [0, -14742002001144, -265820558958, 132910279479], [0, 10498379535216, 151318194972, -75659097486], [-7289480820454, 554618784366, -1478983424976, -92436464061], [0, -14486123317944, -477909453630, 238954726815], [-340839689718290, 447880968990, -1194349250640, -74646828165], [0, -11451170229840, 394649617782, -197324808891], [338305303970858, 639745926696, -1705989137856, -106624321116], [0, 7721584770912, -365230563660, 182615281830], [-91044351075482, -137290316040, 366107509440, 22881719340], [0, -21857132347728, -502171918596, 251085959298], [-46746690982726, 462195474750, -1232521266000, -77032579125], [0, 17474754371904, -173900756400, 86950378200], [-111235241656202, -118839544488, 316905451968, 19806590748], [0, 21104723880288, 189856122888, -94928061444], [325717892229814, 198323585586, -528862894896, -33053930931], [0, -8420738869920, -570627824268, 285313912134], [574921955413414, 333344302578, -888918140208, -55557383763], [0, -2779691170944, -747483872184, 373741936092], [520285979192402, 52774208802, -140731223472, -8795701467], [0, 14993998193760, -685652365584, 342826182792], [498724222043950, -288350455032, 768934546752, 48058409172], [0, 8573310314328, 97056236166, -48528118083], [0, -19385846358576, -1070164706310, 535082353155], [0, 16527117627504, -570844119636, 285422059818], [-143292297540722, 1702821855294, -4540858280784, -283803642549], [0, -22383001032912, -50468653134, 25234326567], [0, -3716517035712, 1456657540968, -728328770484], [0, -20273280500256, 1529157983556, -764578991778], [436979479411010, 86649009930, -231064026480, -14441501655], [-831232236581306, -1203208547256, 3208556126016, 200534757876]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_150_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_150_11_d_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_150_11_d_a(:prec:=4)
    chi := MakeCharacter_150_d();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 11));
    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_150_11_d_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_150_11_d_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_150_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,11,sign)));
    Vf := Kernel([<7,R![-15574076, -22556, 1]>],Snew);
    return Vf;
end function;