
// Make newform 528.6.a.s in Magma, downloaded from the LMFDB on 16 April 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_s();".
// 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_s();".
// 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 := [-44, -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+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 := 6;
    raw_aps := [[0, 0], [9, 0], [29, -5], [143, -5], [121, 0], [-83, 19], [-400, 30], [738, 6], [1685, -183], [3300, 206], [3764, -172], [-14958, -68], [-2890, -356], [8328, 748], [-3925, 1263], [7089, 1103], [-8650, 738], [-1473, 1165], [-15668, -1600], [16905, 1549], [30322, 3768], [-935, 4741], [29148, -1296], [46194, 7528], [3560, -10650], [-20300, 4278], [30502, -5690], [-2832, 2324], [-35915, 155], [204054, -2668], [124033, 15997], [-124872, 15692], [-287108, 6810], [51038, -23622], [-19922, -23864], [-80255, 17877], [-14560, 1498], [274484, 17184], [146790, 32902], [-97452, 3150], [192210, -30618], [406372, 20726], [-124273, 16083], [163984, 37062], [618908, 7630], [195294, -25266], [-148992, 19612], [318464, 44224], [1189308, 12616], [-87840, -19326], [-601038, -43640], [828582, -7890], [-454136, 63774], [-283982, -91314], [-268726, -18296], [769436, -69436], [1370201, 67711], [939247, -93517], [-484349, -30071], [1339920, 51894], [-1436272, 8468], [-1288350, -91556], [-1152314, 21130], [-516447, -55947], [-198406, 39488], [145667, -83823], [-1248136, -61236], [470942, -250644], [-290072, 196948], [-1592967, 191071], [-777954, -96052], [2041330, -69326], [-2179420, -144460], [-2413775, -85057], [-3183676, -3704], [1423985, 172861], [-1480947, 35467], [-1037048, 50370], [2863576, -124226], [-203136, 38926], [-4944454, -78578], [-3297398, 7460], [5198472, 3496], [1105894, 326244], [36653, 477089], [-2569262, 22990], [-246296, 323006], [-1146228, -295478], [-2908458, -67912], [-665062, -401310], [2359128, 70628], [-1134172, -355900], [2297074, -246398], [-2067236, -291392], [-326048, -471364], [492790, 531094], [3222921, 109471], [5149716, -345150], [-5087348, 91200], [-8336951, 218511], [396298, 34350], [1686914, -45164], [-338360, -429772], [-1459872, 413030], [1299286, -142558], [3319512, 57846], [202882, -132642], [-8645432, -17386], [8600689, -107419], [-9508318, 354200], [-3340727, 889269], [-4382545, 819733], [5100810, 520192], [-13718180, 18760], [13674908, -212268], [1085904, -781658], [-3872696, -729348], [12285965, -31807], [2127911, 762101], [-9749792, 386332], [-10995656, 39450], [-11083936, 432550], [-2405592, 312874], [12184742, 152754], [17082580, 522168], [2059486, -533776], [4879232, 1041474], [-8887503, -72243], [-73638, 1333690], [445797, -1332965], [9544876, -322024], [832114, -469038], [7830620, 539452], [16439894, -810656], [6829104, 920534], [24998192, -348954], [4741617, -1054849], [1270448, -1062884], [14943697, -459705], [10103178, -711264], [-13025812, -2352], [-2487496, 2450346], [-16691088, -213592], [-14970712, 611268], [3032062, 324192], [9487639, 2203891], [-18844981, 576113], [-21387854, -128136], [15134580, -172328], [17928879, 894611], [-22119615, -1233033], [-6770234, -1836428], [-8064256, 1424180], [-28249138, -1145138], [-411312, 708796], [-359547, 530497], [-702973, 818287], [9385512, -175106], [5404610, -283992], [-12056436, -1150426], [-38961768, -290972], [-2340214, 2285104], [35781413, -278679], [-31827682, -1310166], [-29073564, 1235498], [13439721, -1500515], [-32639452, 732836], [7835333, -1959917], [-13428676, -1457230], [13797123, 2782361], [-21286372, 336536], [-21935996, -1337890], [-10122670, -1070142], [-20002414, 3404040], [25805932, -277316], [2787742, -2815676], [10202290, 777982], [20841511, 1618493], [-2297057, 4611515], [12294481, -1785017], [-6314312, 158520], [394472, 4484188], [-23374050, 3150376], [-22265022, -3560552], [83061, -1663007], [14641455, -2608747], [-54021357, 1026257], [14721576, -1198500], [39219704, -2758442], [-68552152, -1272440], [12759836, 4079386], [-10216388, -2222936], [3409908, 662320], [-26337327, 12935], [-21158736, -1568788], [8648454, -2680804], [52208246, 3187284], [-41183840, 343306], [-62420310, 2696616], [4973432, -612016], [-17541798, 4521404], [11640291, 1239847], [7009356, -914978], [37765270, 3182612], [40840394, 2100390], [29104871, -3216379], [-733878, 5678434], [75346644, 1584264], [56615964, -82094], [62099720, 410708], [75311268, -567622], [11801967, -4745099], [38873244, 2310660], [39922468, -2352312], [-17035830, -5038374], [14949104, -5205370], [18082969, -7390523], [-77066232, 3752870], [-4475571, -8533183], [1840791, -209835], [69830791, 3616269], [25934865, 2366885], [27343428, -1642406], [41742892, -5418228], [-10277652, -3448904], [-24113467, -1332573], [51501462, 4525164], [-48876429, -4616217], [-76834975, -2325659], [78476284, 3344384], [50040334, -6883232], [6264848, -933460], [-109640449, -3714461], [2461444, -4187718], [71369708, -2333664], [97637692, -3486452], [77772930, -6143024], [-158989446, 418964], [-107286026, -66958], [7307911, -5277677], [-28950584, 9323540], [16664416, 1921108], [22984116, -1372980], [10149588, -7047410], [55895336, 4656022], [84071550, -4209906], [-89218850, 2678678], [15391928, 8834436], [-32608806, 3603110], [80268334, 5011062], [91806343, -6336747], [-87131582, -7340768], [-164549649, 232027], [136292888, 1367278], [66721914, -10350404], [136648204, 1373680], [59214646, 1588000], [-152479260, 3375064], [96285435, 1016193], [-60126620, 7046738], [98752535, 3433467], [-3434556, 7148616], [-108473359, -3543889], [-124566879, -343289], [-25257564, -1297750], [211950692, -1904120], [120732291, -1653951], [-137274270, 6092760], [5755174, 11080658], [-18327108, -2929202], [-229509724, 90846], [19640412, -10764736], [128911636, -7913030], [86365297, -544995], [53367122, -5599968], [-28392566, 1189370], [94552104, -5269828], [-227662253, 462609], [-199060058, -4665684], [-189057492, -867592], [4234600, -16284840], [-23114774, -368470], [128266382, -5077106], [1209233, -12655729], [-42751834, 10808930], [-47554119, 13147109], [-59348256, -9048370], [114118632, -12804022], [141798074, -7413974], [-210609544, -5045386], [52734217, -15527185], [26176934, -1619654], [61947336, -1718482], [-57867864, -5866852], [-119473431, 11552959], [-76547258, 2189960], [-19623394, -10678634], [168454181, 8430163], [36271656, -10963708], [185008984, 4995844], [-5658216, 5685350], [-72024726, -2664612], [-74542381, 2036039], [26849656, -11183340], [-111330476, -10724944], [-64469954, 3264876], [26080272, 3213604], [-36849774, 9020628], [-110440617, -7826221], [-213516987, -11030573], [-16763958, -16617950], [-181087237, 3574609], [241364670, -4339572], [-70096760, -173132], [-145177584, -9464680], [162810218, -4227568], [-159126652, 12343760], [104455636, 13944564], [-68913782, -10041720], [-117899174, -20897208], [-254830726, -11943858], [-81240488, 11571310], [83424922, 22689772], [19382446, -3089098], [162987032, -3801698], [134115152, 1394734], [1174512, 5670948], [-327385856, 1283780], [282587274, 8980850], [131358512, 1725186], [-113805833, -5915371], [-193225899, -9795685], [114567631, -8490749], [-172732868, 4142296], [-154927920, 10343796], [-56314728, 28155068], [-31492856, -10876318], [-92558200, 5710150], [106557538, 27057752], [73809817, -24240923], [-180464452, -5946114], [249545244, 411210], [412470, -5162944], [140101312, -24148872], [-60303815, 9792815], [132881164, 6933328], [177173512, -22555990], [167220532, 11731160], [-86993886, -6151622], [331254657, -6688673], [-223185632, -6019268], [153403422, 17042980], [90640137, -20885617], [-189058887, -4269611], [-237711221, 20826865], [62172306, -1756520], [12076281, 20581909], [-132640204, -29591992], [-223948142, -22258176], [201440327, 16332979], [214524839, 2842125], [89989992, -15425026], [297952173, 3630537], [147231088, -9546092], [-162056292, -16055184], [82505938, -19058168], [-49845810, -1633872], [512378161, -5552715], [290977884, 22778826], [-78520146, -15361166], [117071676, -5494544], [217856980, -12450140], [4526432, 29999410], [-161484607, 11758741], [214534630, 14491624], [115779944, 38533924], [-1617382, -12175950], [-59381902, -377072], [413926266, -17064440], [441563700, -2588590], [-113985991, 25459663], [-178313340, -7512014], [271457185, 14241557], [-173311220, 24286506], [384846212, 10892592], [-220117125, -22385897], [13380504, 25789384], [112617590, -31583408], [32235796, -31046248], [-145878685, 224359], [-447394876, 20001026], [346340843, -2467663], [148017038, 1993274], [-115482004, 15247560], [-316117305, -25043693], [202485448, 17107334], [-419631953, -8964237], [184127280, -10719698], [284114696, 3353388], [307183216, 7981506], [-189151177, -30980667], [-155626204, 28898682], [535332495, -720829], [-208326996, 829370], [45892094, -34699768], [-46955097, 23513667], [261274434, 6038516], [21734342, -49328476], [21153436, 51243632], [-378704212, -21036104], [510104178, -12326048], [639989810, -9439684], [7675732, -35047688], [179817970, -10024698], [220841138, 21326856], [-534510657, -15368851], [180172682, -10688910], [221838306, 41916034], [-121542488, -20741570], [-68274102, -15708150], [156380815, -5847539], [659459647, -4780571], [698736981, -9539391], [157387120, 15468548], [132079192, 47196878], [492960681, 29297263], [-503560932, 22980216], [549883514, 4570016], [-30756784, 28016340], [473464660, -14189252]];
    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_s();".
// 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_s(: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_s();".
// 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_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_528_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![-3584, -58, 1]>,<7,R![16024, -286, 1]>],Snew);
    return Vf;
end function;