
// Make newform 528.6.a.y in Magma, downloaded from the LMFDB on 11 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_528_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_528_6_a_y();".
// 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_528_6_a_y();".
// 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 := [-22146, -2527, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 2, 0], [-1688, -7, 1]];
    Rf_basisdens := [1, 1, 10];
    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_528_a();"
function MakeCharacter_528_a()
    N := 528;
    order := 1;
    char_gens := [463, 133, 353, 145];
    v := [1, 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_528_a_Hecke(Kf)
    return MakeCharacter_528_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 := 6;
    raw_aps := [[0, 0, 0], [9, 0, 0], [12, -1, 0], [17, 2, -1], [121, 0, 0], [-298, 1, -6], [505, 1, -1], [-467, -5, -15], [-340, 15, 10], [3629, -47, -17], [880, -28, 72], [10964, -14, -18], [-89, 17, -103], [-8313, -193, 79], [8860, -103, 38], [8158, 61, 290], [13236, -66, 180], [5712, -263, 8], [-16604, 64, -216], [16928, 559, 70], [21652, -286, -14], [-21571, 692, 95], [39162, 326, -426], [-40746, 388, 204], [50040, 1240, -70], [-9339, 89, -465], [-18026, 8, 282], [114266, -102, 478], [44034, 645, 230], [-104272, 618, -242], [85377, -576, 787], [175964, -324, -8], [100168, 2476, -2110], [-56487, 427, 493], [52083, 1949, 2145], [-47083, 228, -2305], [372402, 146, 32], [-118362, -5230, 1498], [-262098, -4488, 1506], [90833, 3381, -3821], [221956, 4482, -556], [257638, 6162, -2348], [330640, 185, -1870], [-87410, -2226, -1424], [649321, -987, 1763], [104920, 642, -4380], [-317559, -503, 3025], [469278, 3270, 4486], [140994, -3018, -2058], [67168, 5728, 5086], [526879, 6237, 1721], [274694, -7840, 274], [-379132, -2596, -5778], [-208648, 7622, 880], [-1285486, 1080, -128], [-659482, -9782, 1774], [-619646, 5641, -12994], [-216217, -8440, -9355], [-381406, -18441, 4914], [-601133, 15115, 8297], [-85077, -9205, 12499], [953363, -10759, -10679], [-1167559, 17811, 2453], [305428, -16421, -5494], [-813312, 10694, 14942], [1439024, -6179, 3136], [-126530, -17898, 24498], [733116, -22914, -5974], [-1435082, 28422, -2302], [494804, 4387, 12936], [-577530, -7800, 60], [-2021240, 2534, 4796], [1915078, 31530, -10458], [1185024, 10423, 23852], [-68926, -11986, 24974], [-1849928, -10353, 6566], [-2576716, -22169, 424], [-1115836, -4276, 24810], [-717716, 36324, 1766], [-996092, 2292, -31226], [1484748, 5298, -26004], [-2167026, 20180, -21232], [-356950, 36706, 12802], [-1655244, -63346, 12770], [-740985, 18746, 15793], [-752164, -42582, 32644], [1603070, 33078, 5584], [-2790972, 18616, 29294], [1321475, -27003, 27385], [-1306910, -45088, 22518], [3332944, -17368, 15572], [4271410, -5938, -19774], [-1872124, 52250, 13160], [983602, -42762, -20050], [3534476, -45652, -31264], [1431134, 6104, -52622], [-3493094, -31103, 32774], [-4630788, 46920, -25434], [1405495, 15627, 46935], [5878766, 44573, -534], [-2686765, 18281, 3551], [1253071, 45317, -34627], [-1063384, 30000, 6604], [2986541, 48965, 907], [-11145493, -9819, -13753], [2058598, -121418, -1952], [-3875692, -79166, 26236], [5558107, -124549, -21031], [6864216, 60447, -31938], [6082214, 14660, 57084], [-1789315, -63084, 21023], [5262480, -69975, 70736], [-6576612, 2114, 29946], [-3049042, 115418, 14018], [-498776, 32164, 21624], [3302982, -18906, -27096], [-4981238, -104886, 60030], [5081988, -70865, -64398], [4771398, -7137, 161334], [-9697064, -135064, 57500], [-1213526, 97106, -66176], [7321310, 49038, -2160], [6891185, 28241, -104429], [-968380, 66286, -668], [-2035802, 149546, -31182], [3897315, 59181, -38439], [1607816, -130616, 87558], [11507548, 178403, -91222], [-1952468, 63674, -80208], [-3812174, -239387, 33958], [16326379, -90225, -36093], [3532456, -156746, 101852], [10237964, -117400, 35972], [-7888458, 34016, -70528], [-4946719, 81769, -90353], [-12472350, 223234, 13268], [3203462, 126997, 136474], [6241907, -2829, -95725], [-7337884, 154483, -190712], [16145373, -97037, 6591], [-4991379, 87025, -207659], [6754341, -76187, 156711], [19469238, -3122, 14374], [-4526186, 209670, -99598], [710012, 13598, 110550], [12878964, 39813, -91266], [-1181516, 71441, -188900], [14090073, 3623, 150603], [-8216370, 76682, 66826], [-15737144, 155313, -121174], [6819344, -300281, -9900], [-8084988, 260398, 96546], [-27576076, 43980, 72224], [12250020, 254454, -120192], [4763374, 43942, -164598], [-23400868, -112097, -23630], [-3007865, -204156, 176085], [6529944, -5904, 14226], [-8789382, -32216, 55952], [8899461, 208017, 238695], [-12894980, 330644, -40336], [-20709303, 257535, 50187], [14868065, 254076, 36371], [-14460280, 161722, 10600], [-20921208, -75964, 218730], [-31421224, -57545, -106610], [-20336776, 212252, 215984], [2343928, 167883, -82772], [7465468, 408960, 82222], [-28042562, 49243, 61598], [41213884, 22152, 170552], [-6622796, -277472, 139666], [-37598136, 249510, -66228], [7967628, 191258, -201958], [34661874, -188850, -3566], [1553440, -164094, 397190], [-41267077, -54391, -146737], [35304558, 88023, -159978], [-29676855, -224070, -142361], [-15904896, -210553, 16676], [-194316, -490540, 297028], [24392664, -308232, -162300], [46351414, 66536, -157136], [-17138371, -649493, 218863], [18111008, 274675, -147914], [-20217982, -539373, 273178], [-3847418, 107083, 166798], [-43817046, -171654, -28418], [29546796, -123180, 411854], [28824218, 154482, 168754], [-6534398, 360766, 108244], [-35530414, 194206, -114890], [1685428, -177136, 231408], [29901360, 69231, -149148], [-25607524, 272396, -402128], [26517838, -19688, -182164], [27748658, 83404, 289656], [22841510, -227418, 642036], [-24040863, 601287, 262731], [4272112, 149432, 11144], [-46033969, -330979, 116989], [6425137, 700510, -138897], [17299382, 785882, -74316], [6189368, 475042, -265386], [27457784, -342530, 413824], [-42370632, -234847, 99840], [19214578, 355008, -230058], [3595008, 523076, -566364], [43670277, 876705, -463509], [4260616, -196440, -180324], [9400374, 556770, 59552], [-38243850, 38967, -55458], [-6335260, 663744, -479308], [-48762760, -305516, 42844], [50257404, -413934, -26496], [87262364, -360396, 85926], [-14950933, -180894, -51643], [-24996677, 86523, -567511], [-24123824, -693845, 442574], [25573366, -695313, -288778], [-36215894, -26757, 462082], [22625785, -487160, -256461], [-37770124, -366736, 392758], [13769254, -32414, 67014], [-8688084, 789760, 410760], [-33127048, 636667, 129852], [-26559448, -390382, -162002], [-16672248, 601629, 21282], [43223515, -109574, -171891], [-16807362, -797406, 991626], [-60161356, 924390, 241758], [-3972963, -303859, -986411], [-16668247, -263494, 23231], [-111859523, -380271, -14509], [-42688676, 492384, -94416], [51050684, -411488, -100364], [-8636074, -56748, -1092012], [40946551, 953669, -472051], [15069168, -294390, -545040], [-24553780, -313011, -319706], [26547828, 551004, 642600], [60537523, -591213, -293109], [-41098468, -245136, 326636], [8413714, -1034306, -198008], [53999487, 1415711, -279699], [-104448420, -506690, 91368], [76248448, 1025114, -187644], [28183316, 1025820, -973304], [74082715, 1209105, -464289], [-52975580, 888918, -562312], [-58532354, -115761, 182302], [-55941281, -100723, 839825], [28002168, 237425, -1123854], [64163112, -1720584, -344590], [35529239, -217035, 819685], [45099534, 195690, 903498], [-29664284, 1105966, 931654], [9461753, -230715, -651343], [75953316, -1092759, -206436], [-47788258, 1351258, -589392], [-58830273, -657064, -175139], [-64619104, 775828, 147220], [-33367250, 986501, -260702], [-4205940, -130941, 27536], [-9059406, -569826, 714396], [57819984, -37148, -981980], [-102371654, 689703, 507458], [30545424, -61314, -40338], [-49929575, -484573, 1091757], [-5740095, 174509, -480165], [-26564052, 338600, -547606], [-7399746, 635370, 882586], [1262354, -1069450, 1052268], [-150826393, -61530, 198497], [-79429456, -1140130, 424374], [-36661740, -1175054, -352760], [-50015128, -1158624, -586364], [77448116, 35097, 1226676], [54350530, -1700628, -184064], [64202628, -1244120, -648288], [-76054594, -1701098, 578134], [15267220, 24466, 1921272], [-39978456, 436074, -1548492], [47534756, 1630923, -906480], [-43134121, 1464481, -445741], [-42363696, -1816737, -137586], [-41159224, 594512, -531894], [97978265, 833353, -807653], [-168836884, 1119370, 299072], [-93276401, 1066719, -805939], [-124017232, 593463, -1815068], [84372272, -2311670, -662120], [101780711, 1211911, 482557], [6049904, -397016, 699724], [-109913260, -1152013, 29688], [103878659, -1979355, 632281], [-42243000, 432434, -979700], [-89942014, -2184003, 1025326], [102586502, 126406, 1340482], [-71770103, 912465, 954225], [140186922, -44062, 1278644], [-91862489, 1823829, -207643], [-173824127, -1219922, 922959], [147188772, -383316, 1823880], [-173924444, 1577032, -504336], [-108714484, -1012082, -294438], [86146848, -1633152, -14196], [135936494, -157476, 30264], [-131701956, -554355, -296634], [-147146460, -400153, -1364632], [150948410, 941296, -1205330], [-75713612, -507703, 1724540], [-43293601, 1706785, -1546919], [172109448, 672144, 932716], [-65719150, 1309842, 94546], [28022988, 1630162, -1711366], [43331652, -1584416, 159408], [-85627400, -2197980, -836608], [-45447282, -413340, 462668], [-78131859, -1200573, 378423], [-30476911, -546473, -2095867], [21422566, 1147014, 959176], [25751111, -3835, 93829], [38002636, -1077146, -872784], [-106012805, -2637045, 309089], [11363702, 716190, 1785600], [-236905288, 1850224, -515404], [71406152, 2048936, 40484], [-61104694, 104416, 427822], [91134793, -2527503, -1906837], [-136406882, -1916305, 1441582], [190266888, 1548387, 20724], [-50086423, 683594, 775439], [26836390, -970470, -1842598], [6175807, 3330383, -387273], [-200384688, 218280, -1765956], [-16370660, -1794220, 648994], [149596031, -917121, 2389597], [204044522, -438968, 217680], [186802241, 688776, -557773], [15748132, -319080, -2513654], [325693090, 405638, 1096052], [279540287, -443599, 1452445], [5118458, -289854, 771098], [-169710054, 1600161, 732006], [8194294, -558542, 1379762], [-1887666, -2094650, -1353004], [-8336722, 975050, -1936534], [335193984, -182930, 459420], [107538030, 2869213, -2686446], [-157914319, -1755775, 142841], [-122019510, 1749932, -1284616], [302986578, 2386569, -994290], [102504125, 671716, -1736689], [143338484, 112321, -895812], [-238632211, 2067659, 457423], [-137992472, -429513, 714134], [204661686, 2120146, -2517726], [179457561, -3216345, 245091], [87294796, 895741, -509338], [-75162540, -1288987, -2912524], [-56604009, 518935, -239235], [111072536, -1821453, -588530], [-12557762, 172062, 3214610], [180860856, 1381060, 1561804], [140228898, -3103408, 89096], [25759543, 4714609, 211277], [-44520615, 3392280, -2096957], [-167607222, 638510, 2338940], [-48845256, -164982, 3625440], [-44496590, -1254202, 1822782], [67912668, 516888, 1856676], [22919645, -1118027, -3216017], [351627915, 2465658, -1391987], [-55520410, 297600, -2909160], [141346936, 2572176, 710252], [-161789198, -475640, -2876986], [21883498, 2678392, 3472840], [-61654451, -1211565, 1094807], [69243976, 236596, -383630], [-317259700, -901965, 40960], [35196202, 171206, -1924756], [373689137, -57376, 615851], [98692461, -3520327, 3167019], [-193420353, -1157429, 810199], [208836756, -1454607, 2553318], [92625832, 475144, -3508968], [145457252, 5148830, -2418186], [-372332865, -1474197, 385471], [-189365116, -621143, 479326], [259444168, -1668516, -762878], [-64843614, -844569, 492498], [-256874068, -4258962, 363484], [172553496, -61524, -1609964], [334385440, -3090927, -1494742], [224600980, 1276204, 389014], [-109692051, 5502030, 600595], [490642842, 257914, 170532], [-91270338, -1524666, 2687362], [-454582779, 1872861, -1820361], [83101572, 3960661, -2195908], [-261411672, 2795652, -3347910], [28260605, 2357886, 891827], [74693374, -3873630, 1927520], [-333445145, 3723345, -430027], [-191604823, 4358690, 1656695], [105892788, -2039422, 1220198], [-38656945, -4519607, 3618505], [-84852780, 1661216, -1193000], [-42089420, -2254088, -3530608], [265310366, 2907324, -2136996], [-213552105, 5787229, 1014285], [41307164, 1856680, -1839440], [-94952401, 6414061, -2353237], [95047892, -2753326, -2578494], [59508040, 5520745, -2269552], [-219034322, -2707068, -1893982], [202936686, -3343612, 572650], [31430310, -377074, 3432696], [-4804078, -4437560, 3393022], [-424566410, 3365831, -2423098], [-246987088, 707977, 1731504], [-110274596, 2311695, 1101602], [-188683254, 1498554, -4678146], [478571742, -1544146, -2200096], [62787662, -2399243, 902362], [-61373864, 3313676, 1809812], [171736871, -2269347, 3037537], [26937590, 579654, -1460374], [-50653166, 4224830, 1831994]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_528_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_528_6_a_y();".
// 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_528_6_a_y(:prec:=3)
    chi := MakeCharacter_528_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_528_6_a_y();".
// 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_528_6_a_y( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_528_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![296736, -9676, -36, 1]>,<7,R![4559728, -44980, -52, 1]>],Snew);
    return Vf;
end function;