
// Make newform 525.4.a.g in Magma, downloaded from the LMFDB on 06 January 2026.
// 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_g();".
// 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_g();".
// 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 := 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]];
    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 := [[3], [3], [0], [-7], [-36], [34], [-42], [-124], [0], [102], [-160], [-398], [-318], [268], [-240], [498], [-132], [398], [-92], [-720], [502], [-1024], [204], [354], [286], [414], [-56], [-12], [1478], [-402], [-1280], [1764], [2358], [-52], [-1746], [-232], [-1694], [2932], [-1176], [-870], [-2316], [-106], [-1128], [-4034], [1314], [5096], [-3076], [1888], [4716], [-1690], [-138], [1896], [-3598], [-3060], [6822], [-2592], [8214], [-5344], [6514], [6618], [-3260], [-5118], [-452], [5016], [-5402], [-10086], [-8044], [-4178], [-156], [-12418], [7830], [-9312], [3760], [-5870], [-1852], [-2160], [-6786], [6514], [3330], [-5398], [13092], [-322], [2616], [-4322], [-9016], [5268], [-5310], [-15770], [-5370], [3328], [-4548], [-8064], [-16616], [-7140], [-9124], [6552], [2790], [-14862], [-17660], [-19834], [-20972], [-21174], [17772], [8250], [20756], [-2], [-26364], [-2298], [3072], [24554], [-16832], [2482], [15798], [-15460], [-7720], [-17262], [12220], [-13560], [-23094], [22548], [17462], [22462], [25554], [-9276], [27380], [25830], [-6226], [-15072], [32920], [6946], [-2356], [23520], [3008], [20770], [11538], [8498], [32322], [-26228], [43338], [-28902], [27164], [-17202], [5992], [-25884], [-1474], [33528], [-1190], [-34578], [-44404], [38328], [38842], [-35046], [-14204], [26136], [9052], [5016], [44552], [24234], [13894], [46758], [-13812], [58518], [-19640], [-58308], [23550], [-15768], [35264], [29338], [-18286], [64098], [13212], [-33730], [29520], [-17786], [-34432], [978], [-32092], [14334], [-20072], [7454], [-55136], [22260], [33874], [10878], [49272], [4734], [2266], [-3908], [43130], [-3792], [-46802], [-8940], [-17188], [71286], [-25044], [14334], [2450], [-52310], [6918], [312], [42294], [-1888], [-10118], [-19726], [-49284], [2874], [2288], [30492], [39738], [39548], [-24914], [-24258], [59272], [70356], [-55320], [-5110], [79792], [20682], [-76944], [-33990], [-22642], [-34792], [6498], [-15104], [-40020], [-35170], [-104802], [-76008], [-3944], [-108372], [23578], [-45484], [64064], [-23910], [-83468], [-8784], [46802], [-43086], [-21396], [-56232], [85500], [30764], [-11576], [25814], [-8682], [93480], [-67664], [-61260], [92900], [-21528], [-47558], [51402], [-84432], [27722], [-5814], [-81564], [-97090], [58804], [74754], [54502], [-25184], [-10164], [99830], [99538], [105126], [-81772], [-124074], [14898], [-22916], [54690], [31790], [-26444], [-84890], [-115504], [-109154], [130408], [-78156], [22790], [-21670], [-15132], [32928], [105896], [-24600], [77510], [143908], [-81384], [11086], [-92238], [-81016], [23706], [55638], [-14676], [28998], [136140], [28330], [-65994], [-160], [7602], [47532], [-28244], [106198], [-65046], [156800], [-35700], [99380], [98782], [-77004], [-61810], [12240], [-52958], [-28464], [-121170], [-140142], [-51356], [-68832], [-148246], [-115548], [-125304], [-140402], [105954], [-27628], [-5546], [108486], [93472], [-42714], [189074], [-11284], [-143228], [-145608], [-702], [-41290], [-57990], [-15712], [43164], [-132460], [166500], [145334], [179622], [-147670], [-81488], [-31502], [174246], [121470], [81272], [-76902], [177732], [-189754], [84076], [-28752], [158802], [-65788], [-141338], [-2442], [50848], [27758], [97326], [42480], [48732], [-25362], [-52464], [137122], [-33582], [-110328], [223836], [177244], [4102], [-30486], [45160], [49610], [-2268], [-217924], [-185544], [-143250], [59096], [212506], [-122892], [-92520], [7486], [71850], [14902], [-37962], [68358], [27160], [226494], [243380], [29064], [53552], [30490], [143548], [-220416], [-94174], [-18798], [-107796], [49804], [43440], [59254], [64784], [40242], [-168748], [242958], [-23506], [-43842], [37600], [-168786], [137310], [188552], [-110486], [157170], [-67268], [-227964], [-129170], [-13038], [-197244], [275852], [-112538], [98166], [44904], [44584], [-41130], [-7704], [-245754], [-19910], [48696], [-119460], [183382], [-141654], [-130596], [23994], [-157156], [81864]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_525_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_525_4_a_g();".
// 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_g(: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_g();".
// 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_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_525_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![-3, 1]>,<11,R![36, 1]>],Snew);
    return Vf;
end function;