
// Make newform 525.6.a.a in Magma, downloaded from the LMFDB on 19 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_525_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_525_6_a_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_525_6_a_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_525_a();"
function MakeCharacter_525_a()
    N := 525;
    order := 1;
    char_gens := [176, 127, 451];
    v := [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_525_a_Hecke(Kf)
    return MakeCharacter_525_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 := [[-10], [-9], [0], [49], [92], [-670], [222], [-908], [1176], [1118], [3696], [-4182], [-6662], [3700], [7056], [37578], [32700], [-10802], [-64996], [-61320], [-38922], [-88096], [-71892], [111818], [150846], [-137354], [-28760], [-22556], [19998], [-17906], [-66864], [153764], [-255978], [282924], [408054], [362504], [152786], [150428], [7288], [289154], [199492], [240550], [290384], [171454], [-401990], [-259176], [-1191788], [218384], [-582852], [961046], [-605994], [1170144], [-1236910], [959708], [1212590], [1252744], [-136866], [-960896], [-905830], [-33062], [863588], [1337546], [1328204], [-665832], [3090214], [974178], [781772], [-348754], [-2506252], [3058606], [3492910], [2120344], [-746592], [939034], [5165340], [-400512], [306822], [3834210], [-3293550], [-1354726], [5081988], [628022], [-3000864], [-1214962], [4006536], [5447508], [-1815774], [5300822], [3203806], [1118528], [3851340], [1435360], [-4610968], [7405180], [3934324], [-3409752], [-7723826], [-4776582], [9287540], [7729166], [8603612], [1777234], [-2688596], [5326298], [13399196], [1105022], [-5972876], [11194494], [10905480], [7397370], [-7133552], [17126378], [-2299242], [-1851764], [9259784], [17941890], [-6700196], [11254904], [-13170414], [-14345340], [-14138], [-13778722], [-12615510], [1086564], [19122932], [11499966], [6975510], [-1442640], [19033432], [-5455854], [7851972], [14869512], [-25130912], [19787386], [-14964150], [5064194], [-26302486], [-10052500], [-27851630], [-19693590], [5056172], [-2823242], [-25474056], [17561556], [9147278], [-10989112], [13485370], [-10703210], [-13374724], [-19976784], [-8811070], [40107810], [-14966420], [575144], [33336724], [21745056], [-4039864], [7696786], [453558], [-24385250], [21874460], [39331910], [-38523448], [24354252], [-16253394], [252456], [-24972784], [36098282], [-50905358], [19936346], [4045164], [34794510], [30981720], [-18921194], [63104000], [18236458], [-48154820], [-7271386], [-66671448], [-57714242], [42977968], [-67357308], [-77115734], [30640934], [55594176], [20790982], [5270066], [-47295172], [27777034], [-68748352], [-42736162], [-10099260], [58243220], [5197230], [36407980], [-60896634], [-2224654], [-12487854], [-19471698], [89793048], [7996942], [86319776], [-28256070], [80785474], [66274924], [65503442], [84123792], [75699180], [-69775062], [-31507028], [-34478418], [26646630], [75499928], [15233092], [39858088], [108486922], [24107680], [-11842270], [-85322312], [-76865406], [-81758602], [-42325592], [30719074], [102717088], [12510380], [61852550], [-98649866], [-15510416], [49895464], [12286716], [39588002], [-43995692], [-49148080], [-27304726], [34313364], [137893968], [30491122], [21328778], [-25597620], [-2037944], [-69756324], [-130655844], [-99708024], [-147866402], [28835742], [81296984], [116379344], [-81843932], [45903244], [-157500192], [57217810], [-84422478], [99108616], [-65955062], [146646274], [31060996], [-10921882], [198139428], [-169881078], [-19372058], [-216493040], [-71370772], [-122489674], [180070162], [-25679218], [147733124], [77084718], [16158794], [-208211836], [-124367558], [-168928610], [67751212], [-74091226], [-1859824], [-89795602], [-62491688], [-147244172], [-167648946], [-181044950], [111456148], [78632192], [147909336], [-31259608], [58791670], [-11805452], [-23768736], [98619182], [102341898], [-180515608], [294126834], [-55643410], [161849836], [146754054], [-252922932], [-125314846], [87520430], [208162096], [114520154], [5926300], [-276202820], [46108950], [178926162], [-176666720], [-269879492], [39080988], [-104088162], [-60912156], [-131852418], [230365928], [214118666], [225439728], [-34936586], [319093602], [189491004], [372887720], [-289442710], [-137001324], [195234768], [-38595298], [-241764366], [-368601772], [-168424762], [-301129074], [-313718480], [-166579434], [-179429870], [-111326780], [371884036], [157341968], [-293851494], [164947870], [-64546206], [350072048], [315676476], [375393580], [334081348], [-45827410], [262362894], [100530794], [-415455328], [296451674], [-260474458], [-240959178], [-225936488], [231050018], [94734836], [215681878], [69544916], [392622096], [278429882], [383315812], [132960726], [-441399058], [-303798624], [55356550], [524603798], [-4839072], [83452428], [-431804434], [-440263944], [-169275126], [478353530], [403905312], [530268652], [28860412], [49171382], [60588866], [63964520], [-518577606], [-540075372], [-624191796], [-155208768], [-51196746], [176670536], [-314731822], [78357908], [-649659376], [-125079266], [-243109374], [-549624378], [86982286], [384191862], [-109011208], [-101147554], [208672740], [-61913896], [-392308384], [-664507942], [51582820], [400800000], [-4722110], [525077418], [604146300], [-75847604], [318174568], [-14158330], [9118960], [541380186], [306024108], [280610358], [-346092274], [287763614], [204229184], [86564118], [235910742], [498008920], [-531238686], [-565122158], [492581836], [737528484], [52068334], [-28560022], [479902388], [-627247868], [-71149962], [489302334], [65291760], [-161731352], [76245534], [253056936], [-635041602], [137412842], [-518726272], [-283004612], [121162198], [-905580606], [749666428], [626480346], [-800676], [353442552]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_525_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_525_6_a_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_525_6_a_a(:prec:=1)
    chi := MakeCharacter_525_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_525_6_a_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_525_6_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_525_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![10, 1]>],Snew);
    return Vf;
end function;