
// Make newform 528.6.a.r in Magma, downloaded from the LMFDB on 19 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_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_528_6_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 := [-102, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    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_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], [9, 0], [-15, -3], [-24, -2], [121, 0], [207, 27], [-587, 43], [-1347, 1], [-1137, 133], [641, 19], [860, 4], [-1428, 358], [-3599, -333], [3637, 109], [1681, 323], [-22069, -345], [13834, -1446], [-12525, 515], [-14540, -376], [1975, -1835], [-26392, -602], [48634, -1164], [7598, 570], [-113738, 1324], [-48498, -3152], [-11807, -6181], [60812, 3760], [-1350, -7138], [2971, -3225], [-80912, 2798], [-10082, 14120], [1632, -7028], [-6182, 5572], [65565, -3055], [-248887, -10921], [-121630, -6748], [231000, 16406], [-183870, 1622], [-210428, 13160], [-52659, -7425], [-173930, 1526], [140808, 12614], [352553, -2509], [49192, -42726], [-503099, -8273], [-653966, 7902], [-418125, -23221], [-650974, -26534], [12062, 55826], [381874, -38816], [-315347, 45719], [-69100, -42960], [-127526, -4268], [-639190, 19474], [-844278, 29272], [667910, 28942], [46983, -30917], [1109962, 13504], [918101, -44483], [-367485, -12855], [-70871, 79265], [-2040155, -12869], [1588317, -18055], [2234379, 24345], [1152340, -71342], [-1877249, -21161], [1441598, 109458], [1529932, 88442], [-389714, -60118], [53477, -24287], [867842, 30872], [2411038, 16642], [4163830, -26426], [292457, -32739], [-1214514, -52838], [-34641, -243467], [-1401287, -161499], [3390270, 101108], [-1157934, -227652], [2986682, 80428], [-3361690, -112010], [686794, -143924], [158558, -66090], [-67844, -120534], [3025652, -106602], [-1798458, 272478], [-777120, 307554], [3070990, -72152], [-870167, -311617], [1234084, 198520], [-4532700, 77544], [-216086, 136314], [4790754, 39366], [-2378938, 77410], [3405168, 272932], [-7301148, -110232], [1563247, 109043], [-370754, 354456], [-1746527, -341871], [-916405, 53519], [-4964273, -73445], [-1334607, -168609], [-11577188, -24896], [7332841, 2359], [-2796765, 19007], [1688944, -236502], [-6124450, -257962], [7024779, -24455], [-2530153, 125621], [-8309322, 240844], [609226, 454564], [5209243, -238957], [6890776, 197110], [-2350798, -223114], [7747444, 70132], [-10871248, 245090], [843810, -547610], [2069183, 245381], [-6505211, 342557], [-8530748, 446792], [4532752, -370186], [2727480, -124742], [-731199, 390483], [-13087990, -217574], [1415450, -55626], [-456767, 606455], [-13966774, 260920], [-1060949, -484111], [970786, -1059802], [-5791797, 537575], [-4195803, 254701], [19088830, 205762], [9843960, -520480], [-21159850, -81056], [-7887355, 809315], [-1343084, 720342], [-3449421, 280383], [7951177, 1162873], [-7456627, 371785], [-6924025, -1149703], [-17166277, 573363], [-4352675, -1204945], [5560434, 932594], [-12766050, -373078], [-11086944, 561050], [5525381, -1058281], [3314699, -109685], [11925171, 721653], [-15154958, -227346], [-12595263, 147467], [32795281, -37699], [6758524, -1345798], [-4368096, -1485220], [9203126, -1583294], [-15975442, 977178], [8468967, -429387], [-9983506, 1047204], [-6619994, 1552496], [51111570, 24008], [20274161, 1362115], [-14588680, -368660], [-12324021, 272029], [31510130, -587652], [33023534, 202750], [-12388326, 135212], [11191519, -711955], [-17918044, -309780], [17764749, -1143095], [43197310, 815584], [28271913, 1120401], [27678644, -1798720], [-17699518, -2028336], [37179726, 479362], [16026816, -2399314], [-16280766, 1268178], [-4616832, -2416282], [10199911, -1945413], [19822021, 580341], [-9454928, 1264598], [-43495791, 155485], [16406884, -2233660], [7100276, -266992], [-25557906, 1842696], [16394655, -846527], [31324899, 2257841], [-11571175, 1864601], [7067193, 1119001], [-19712798, -1039834], [-15789174, 3010812], [24897582, 1174566], [31638624, 1685810], [-16615378, -1398014], [8940260, -415040], [-62805727, 1070349], [46163280, -630204], [4543322, 399928], [-5527186, 786740], [16799604, -3624110], [11843451, 3594069], [-45736272, 1017416], [8323545, -2510425], [-26056388, -384414], [-86270416, 22782], [23935592, -1506426], [-50172878, -1534838], [1696467, -496701], [-24803308, -1067208], [19990416, -1209564], [-97719611, 264187], [41219100, 2470432], [-88737796, -291818], [6650853, 3079125], [-52133080, -69912], [9048184, 1604700], [-50124862, 211094], [-53328614, -3254588], [64168588, 1481310], [47792203, -123799], [79383523, -2833703], [7567733, -4199363], [-25185127, 195945], [-90725650, 1604128], [37833502, 2077072], [-76190562, -1292050], [103396804, -1043488], [-60466851, -1022583], [56298928, 1973686], [-34279907, 861919], [-10481716, 3382550], [-40078566, -1505850], [-89951800, 2582738], [-3578129, 4484151], [31003608, -4409290], [58629765, -476693], [-10083972, 2630768], [-62279128, 3301632], [-9414530, -6634692], [92980569, 1371471], [-47957058, 2750574], [-92792947, -1524177], [-85884400, 337604], [-55288639, 4127369], [-10730744, -1823640], [-58341708, -2853478], [-19901113, 557989], [-20318370, -2175014], [-144504238, 836630], [-8900288, 5646292], [38910655, -3517085], [-112675426, -652574], [-97748115, -1113851], [-14990139, -1789689], [-55109751, -137013], [134556998, -1217936], [73126401, -2879921], [20788666, 4285990], [74929640, 3399338], [20543879, 224591], [86072683, -5600885], [172584140, -356306], [-150521622, -1093392], [-4110320, 8672244], [74942651, 312343], [-43263227, -2771983], [-55420240, 7517066], [141254592, -1771900], [75500245, 4124549], [-80143988, 3011562], [49511077, 2417241], [139430605, 711223], [-84565430, -840296], [18192602, -1504730], [98083040, 2873850], [177442360, 1689450], [-69604332, -6454726], [87591994, 2162030], [6636004, -3227552], [-106372261, 6275603], [163388726, -4911948], [126533964, 4620552], [484154, 10280754], [112662218, -486930], [-5824718, -520754], [60668853, -7966967], [268827639, -572365], [214182063, 1005573], [198480854, 1102392], [50218537, -4741189], [38664562, 7813286], [-109219625, 7001861], [32134617, 5448837], [-48170554, 7787774], [90872439, 9842429], [281216284, 1123864], [-40722747, 2428785], [-135982103, 6666111], [-82480086, 6578318], [244478931, -3782505], [4708494, 4386778], [126698091, -9489629], [90190556, -1982154], [54268337, 7283887], [175199948, -1180254], [-29847712, -9781276], [182413332, 374288], [48917852, 4412266], [55137764, 521104], [-159833814, 362708], [-157471491, 146063], [284316513, 2542157], [197832188, -5576736], [13561195, -1876229], [-271429959, 777027], [-66492516, -3086400], [241512342, 317142], [208005336, 8154566], [-319485516, -3244192], [135731748, 983436], [-1053746, -13065268], [-15000753, -6901879], [225108017, -657467], [301125608, -366870], [8269921, -1938273], [-154519130, -3354198], [-204418749, -5925927], [-151538360, 6487410], [85604940, 5842488], [-265804356, 6168056], [-182832228, 8006448], [-232089279, 6650931], [-79241395, 13460917], [-110763675, 10665705], [-4428616, -1891098], [-151033654, 14545726], [85466293, -7628771], [-139800964, -4710040], [360136646, 2710204], [56265783, -2522619], [88128178, -1090600], [140072278, 8577600], [11000354, 13766072], [-198427408, -1597486], [205837925, 841027], [289971902, -7293714], [-14944961, 10339011], [-209627214, 11952798], [-30250116, 9540946], [-189120238, 1491598], [222185678, -2273062], [77282091, -6309337], [-167708213, 1189827], [-83693706, -993980], [-61168281, 6537307], [-248650806, -13626540], [-109665365, -2327701], [251870223, 9288417], [89464855, -7381475], [5024410, 2024710], [-353710725, 7843221], [-106151075, -4011233], [199969759, 10610967], [-82938249, -1163571], [123538387, 16551169], [-68801066, 12075466], [-443727088, 5461428], [-36671542, -15495952], [-381023971, 4753843], [-74690722, 3253792], [379997448, 8161354], [184323558, -6546786], [-79123498, 22135906], [-9174928, -11973704], [47703101, 12938591], [588897324, -2250138], [-282107698, -15444096], [-149180868, 14286864], [211133588, 12845624], [-105582166, 11961096], [-265333985, -17092743], [-204634270, 7774716], [-271920323, 9591241], [177148032, -6513902], [-193108602, -22836584], [-375332875, 7029379], [41172665, -27070335], [241955169, 18455739], [533145888, -6349920], [-267965480, -15010518], [52796577, -20126607], [-167856463, 715187], [-307210894, 14857740], [71813901, 24030949], [312949914, 1982970], [156913608, 21481348], [-53007207, -24970549], [44719218, -11086844], [-475778300, 7642802], [274321860, 6644766], [-389046114, 1510402], [-161851899, -5894105], [-513421209, 10116247], [129553834, -25136980], [63969284, 6810690], [42375012, 17313270], [363148917, -6684669], [48403784, 9125822], [33567524, 38257782], [-294609295, 16214971], [219874196, -421336], [-187343812, -26028360], [84461702, -12207772], [-70265215, 2140343], [-29618460, 3490680], [2350107, 25724279], [19499704, 8565478], [425687931, -2982453], [-320319944, -14684132], [40215464, -17242716], [186100024, 21605786], [140101324, 5060008], [293811965, -43787], [72530155, 4187075], [-453056665, 6894501], [-68457254, 2888654], [147214416, 922706], [104683851, -9881105], [-285727496, 11144532], [319278381, -10357513], [87195102, 5137618], [-486283902, 6109930]];
    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_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_528_6_a_r(:prec:=2)
    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_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_528_6_a_r( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_528_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![-3456, 30, 1]>,<7,R![-1060, 48, 1]>],Snew);
    return Vf;
end function;