
// Make newform 525.4.a.f in Magma, downloaded from the LMFDB on 25 April 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_4_a_f();".
// 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_4_a_f();".
// 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 := 4;
    raw_aps := [[2], [-3], [0], [7], [-21], [-24], [22], [16], [25], [167], [10], [133], [-168], [97], [400], [182], [488], [28], [967], [-285], [838], [-469], [406], [324], [114], [34], [1976], [-828], [-1467], [-783], [515], [-1526], [1822], [-3042], [349], [-2167], [1204], [-3252], [1276], [-1140], [2724], [4474], [3932], [-3441], [201], [-1384], [3964], [762], [5764], [1510], [-5937], [1456], [-588], [6510], [2898], [-2953], [3394], [-1284], [3506], [5823], [3830], [-3572], [-7278], [3786], [-448], [4081], [1071], [-2102], [11471], [-6448], [10050], [-6597], [-6500], [-8665], [-217], [4640], [-3021], [7826], [-3405], [4052], [11322], [-1757], [-9304], [5752], [2344], [15132], [-5055], [3795], [8300], [5052], [-2482], [14176], [-1039], [9255], [14396], [6998], [-6400], [15158], [-4120], [3291], [20547], [3169], [24878], [-1425], [-14649], [-2108], [-24366], [-17892], [8077], [-7836], [24092], [-13647], [-12813], [-300], [24615], [-24117], [14020], [-2430], [27514], [-20772], [32132], [-23542], [-30814], [-9009], [-25860], [24170], [-8426], [-30752], [-11570], [-32836], [-22351], [21720], [-6352], [7685], [-12], [-24832], [-28242], [-12542], [-11058], [-17307], [-2706], [-38862], [-27217], [-11301], [6786], [8358], [16500], [-3372], [39026], [41487], [158], [36594], [17839], [-13996], [31168], [1881], [42447], [7514], [-33284], [-10962], [6172], [-26263], [5920], [13372], [35155], [1858], [-16401], [22952], [27399], [-41678], [35977], [-57160], [-41875], [-31934], [15078], [33238], [-41377], [47694], [32432], [43114], [-7639], [-25420], [-5619], [-21418], [60133], [52634], [-50581], [-10222], [4205], [-4642], [49982], [21625], [-32863], [69706], [-9741], [67236], [-495], [-30635], [-6488], [-67982], [79854], [-37898], [-55862], [-75476], [-52784], [29236], [88518], [33388], [-90967], [-20472], [-65651], [38942], [27013], [12644], [10350], [-21070], [-18547], [37392], [-70831], [-72725], [79813], [-50362], [-48267], [27799], [19800], [-30970], [-87178], [72917], [30914], [55083], [51977], [19826], [-43016], [68765], [-52992], [72394], [48852], [-28619], [-48201], [-47052], [102385], [59064], [2506], [-110201], [-93548], [-10670], [-8906], [-118170], [67680], [-70712], [28058], [95712], [10992], [-37898], [-114996], [1196], [118545], [90706], [-49304], [-22472], [-12776], [-6401], [-2030], [-36658], [16154], [-55472], [-41019], [-39122], [24841], [59635], [-4620], [4964], [-54440], [-119509], [-10386], [103582], [30071], [39590], [134455], [142018], [64362], [132736], [-103440], [-121570], [117202], [-95909], [88359], [57453], [116404], [-85994], [-78207], [24726], [106627], [-31650], [-29305], [-115134], [-162260], [-16432], [-89388], [165734], [10862], [59766], [74035], [22935], [-57885], [17418], [-48451], [163820], [-146195], [79938], [-1626], [56250], [-39417], [-26844], [49297], [67474], [-143678], [-13524], [-17348], [51339], [94442], [-60494], [-60384], [66163], [-61151], [-54106], [59631], [-123902], [23673], [-11673], [-72350], [78895], [67438], [-55374], [86240], [106860], [15389], [-124452], [52640], [-136802], [-182038], [-91341], [-130120], [-92873], [-213], [-146473], [169726], [-90551], [-92932], [162858], [118582], [71383], [-37122], [-195928], [-92897], [162684], [-185670], [147342], [24202], [7664], [-91977], [-7722], [-179892], [-110649], [-65104], [70918], [-185094], [-181535], [-160085], [-21033], [16546], [92829], [57310], [232206], [-178261], [-234372], [-114645], [-107966], [-91400], [39578], [-57102], [-181063], [-244145], [130821], [90970], [-120384], [-152443], [-74390], [106497], [-75984], [-243259], [-196702], [-54441], [135046], [-241205], [-39899], [-11256], [86812], [154932], [-9797], [-62836], [146577], [-16805], [-35144], [103320], [150712], [248991], [130], [71168], [19746], [60820], [244483], [229464], [-104153], [-121867], [-214064], [19304], [-213314], [-194380], [-186306], [23466], [-40450], [-249536], [14600], [268858], [59634], [-138509], [275574], [128074], [211614]];
    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_4_a_f();".
// 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_4_a_f(:prec:=1)
    chi := MakeCharacter_525_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_4_a_f();".
// 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_4_a_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_525_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-2, 1]>,<11,R![21, 1]>],Snew);
    return Vf;
end function;