
// Make newform 528.6.a.i in Magma, downloaded from the LMFDB on 26 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_i();".
// 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_i();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [9], [46], [-148], [-121], [574], [-722], [-2160], [2536], [4650], [-5032], [8118], [-5138], [-8304], [-24728], [-28746], [5860], [-53658], [-30908], [69648], [-18446], [25300], [17556], [132570], [70658], [-101998], [-130904], [141612], [-239810], [-42726], [-51788], [-53652], [-228862], [-374920], [-65830], [-154052], [287678], [-105124], [-150528], [-2166], [-672780], [-526778], [305608], [116434], [-247742], [513360], [620688], [1318016], [887412], [-237450], [-914706], [-1408920], [-826358], [1603868], [397618], [-2131664], [-725810], [1467868], [1520998], [464382], [415136], [-2593206], [930832], [-2485272], [1317194], [2255398], [3170708], [1276298], [-3693028], [1709190], [4368594], [3512840], [2152592], [-2242466], [2409860], [1010656], [1277790], [5453998], [-1489798], [-4398990], [280420], [817462], [-1885992], [5840674], [509540], [-4102684], [513410], [1227378], [-6409998], [-6630304], [4147692], [5051320], [-2662208], [5546588], [6820], [451136], [393390], [3284322], [1682656], [9481582], [6092392], [8495938], [7022156], [9418470], [-7296992], [-3295902], [-4398268], [9217814], [-3771400], [4197242], [1001332], [-7382386], [-15402462], [7124020], [-11669632], [-11027118], [9560236], [10994152], [-295346], [16561340], [1970422], [-1637326], [-6358782], [-11103284], [-17018852], [15802082], [12483350], [-2007240], [-6973008], [-23496546], [13990120], [-24274504], [-15365992], [20760518], [5838102], [-13919710], [-4178826], [-9667048], [-5798842], [-19254330], [13193768], [13377922], [18861336], [-16267988], [-21809810], [-11777080], [-14399266], [6276038], [4717380], [-7539264], [-10433082], [39107642], [-12928204], [-33646568], [41962932], [1925208], [17248100], [2511450], [17985338], [-32258598], [-44165868], [18748774], [-10867348], [47912308], [40138458], [-3226824], [5953448], [32078318], [-23533270], [-11989386], [-46036700], [26382622], [20996488], [-7675966], [-3892160], [36495410], [-24366512], [-55875418], [-42417284], [58410790], [-17790008], [-5100452], [21094614], [-59023002], [-48452904], [-14732250], [-74139762], [-7014804], [-62055310], [-14076152], [-40897006], [4959596], [-33200172], [-13836378], [-13630788], [-406806], [36013442], [-47221106], [-33261522], [55440136], [-71711070], [59816148], [40154118], [63758890], [13139980], [35737078], [-7982160], [6599196], [-7013130], [-17815972], [4325298], [16146102], [-31641024], [-71880988], [-40657560], [-51568198], [55169692], [-66366378], [-66478368], [33408174], [-62411498], [-31955700], [115322730], [297376], [98508732], [83844350], [-12507246], [39082320], [-100561948], [-111847972], [-55651586], [129032240], [-82771852], [145504502], [-66544324], [68868752], [17175330], [-57198486], [-150882580], [-75086872], [61087436], [-103746752], [49090896], [-32291730], [-134116346], [-118972200], [30707992], [-24228812], [154222800], [158209616], [100674478], [-24438298], [47872752], [-104922790], [74846274], [-46316380], [109146502], [49871592], [81663918], [-134854982], [103386476], [-26905188], [-185495290], [46795014], [107436258], [193434020], [-89251650], [167522082], [-171678824], [-234310206], [160624622], [-123415428], [189471274], [-174925700], [-75583942], [-163155584], [-31198788], [134335750], [-175387718], [-46288932], [167335736], [18146608], [-7708568], [-45259858], [-17871088], [-120380832], [-5600046], [-236065422], [271292960], [37015510], [-16062778], [-227079908], [-113602386], [-49587132], [323219094], [113215010], [186342488], [-65888186], [6181500], [83215552], [-18658566], [15189858], [121146260], [101467196], [257898748], [-26803502], [-161410308], [336891870], [-153149400], [-168439266], [-143630904], [76395070], [304023942], [275792836], [60922272], [283145330], [60146380], [112389008], [-44423246], [377809070], [-127954672], [140245978], [-181215118], [-99885704], [44521774], [184870802], [-148304700], [-338344724], [-197609928], [-132764126], [125855182], [100747398], [-324981020], [-125732284], [116743008], [80157252], [263203390], [217674454], [117097162], [-69973628], [-387703306], [143307978], [-235602150], [-153836552], [-60555826], [-86399980], [-168311018], [292265332], [-203734272], [-352670202], [358248208], [-366087222], [528607662], [-399554364], [85381630], [82516854], [-341039640], [551371948], [-54797122], [-300629744], [-132893122], [-564961218], [-226842528], [268882700], [-402924108], [-42645206], [358758498], [-181710644], [394261002], [-357452532], [96625140], [-326065024], [-419175230], [188451908], [582823918], [181906180], [343381288], [-636918766], [80700750], [231337218], [-143188298], [-259829526], [-550665908], [-640287442], [-298368280], [-367429824], [-573600072], [-423155482], [-105282224], [-262107608], [-440123710], [-188494106], [375029260], [-307027228], [-100251912], [-678341486], [-472991420], [-593922630], [524813588], [67829282], [-178597450], [574746394], [295536852], [-6075702], [95751130], [37748028], [694414878], [651488182], [-393681644], [-295930940], [1619874], [353016298], [-22002724], [-718452152], [-828251422], [-280936218], [269375080], [796154472], [-372610462], [-412892064], [-680902450], [-632744402], [-61701768], [153206060], [549684394], [444988158], [-251138844], [929706430], [545626628], [620531360]];
    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_i();".
// 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_i(:prec:=1)
    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_i();".
// 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_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_528_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![-46, 1]>,<7,R![148, 1]>],Snew);
    return Vf;
end function;