
// Make newform 4725.2.a.g in Magma, downloaded from the LMFDB on 10 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_4725_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_4725_2_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_4725_2_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_4725_a();"
function MakeCharacter_4725_a()
    N := 4725;
    order := 1;
    char_gens := [4376, 1702, 2026];
    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_4725_a_Hecke( : Kf := Kf)
    return MakeCharacter_4725_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 := 2;
    raw_aps := [[-1], [0], [0], [1], [-3], [3], [4], [-2], [-5], [2], [-2], [-11], [-6], [10], [-11], [2], [5], [13], [-8], [3], [10], [-4], [4], [0], [-3], [-8], [-10], [-9], [18], [-18], [2], [1], [-2], [0], [-14], [-10], [22], [6], [-23], [12], [-3], [19], [-4], [6], [-24], [2], [-8], [6], [-11], [-5], [-24], [13], [-3], [-15], [0], [-13], [28], [12], [2], [-18], [-10], [-20], [-6], [15], [-10], [-2], [-18], [10], [-28], [-34], [6], [9], [-8], [-22], [-10], [-19], [30], [-31], [24], [-31], [-36], [-17], [-7], [19], [16], [21], [30], [-3], [8], [-42], [-43], [-32], [-40], [12], [8], [-4], [-34], [20], [20], [15], [36], [-8], [-13], [-30], [-42], [43], [-12], [36], [28], [3], [2], [-39], [30], [-30], [18], [48], [22], [45], [16], [36], [5], [-1], [26], [-9], [-30], [32], [19], [1], [52], [-1], [-4], [-33], [-4], [-37], [-30], [2], [-54], [-8], [-6], [-54], [12], [-18], [-34], [21], [-45], [-3], [21], [12], [14], [24], [17], [36], [-8], [-25], [-50], [45], [30], [-58], [7], [0], [-8], [-28], [40], [61], [16], [-11], [24], [-55], [-15], [16], [16], [2], [5], [1], [48], [-38], [56], [-42], [14], [25], [-10], [11], [15], [-34], [28], [-46], [-46], [-64], [41], [-43], [-31], [-53], [32], [22], [-3], [24], [-9], [31], [58], [40], [6], [58], [43], [37], [19], [22], [12], [31], [38], [48], [22], [20], [-2], [-13], [63], [14], [14], [42], [-55], [-26], [7], [-4], [18], [70], [9], [5], [38], [35], [-40], [48], [-49], [-28], [28], [44], [-18], [19], [9], [-8], [12], [-63], [4], [-30], [10], [-23], [58], [-29], [-32], [-45], [36], [-35], [-37], [60], [21], [-23], [-66], [-37], [-30], [-38], [-74], [-17], [34], [-44], [-26], [-55], [2], [-38], [48], [-50], [34], [70], [33], [14], [49], [-40], [-27], [-62], [-40], [-58], [-5], [-53], [57], [46], [-75], [-55], [-44], [-59], [-39], [78], [46], [10], [66], [-60], [28], [-15], [50], [-60], [-50], [-10], [-36], [86], [-61], [24], [-80], [-69], [12], [57], [29], [50], [25], [-18], [-24], [36], [66], [-60], [40], [1], [-44], [3], [-2], [48], [-52], [55], [-12], [4], [16], [29], [60], [-50], [-69], [36], [67], [-74], [-32], [-87], [-70], [-24], [62], [-90], [65], [88], [-7], [90], [-22], [-62], [-24], [92], [-14], [-44], [17], [-60], [22], [13], [48], [-64], [-2], [18], [63], [-60], [-74], [47], [57], [18], [-27], [15], [92], [10], [18], [4], [-65], [-36], [-68], [3], [-62], [42], [74], [60], [87], [70], [22], [-70], [-6], [-16], [-92], [-66], [94], [0], [68], [-17], [-54], [48], [-46], [80], [72], [22], [-56], [58], [-60], [-26], [-12], [82], [77], [30], [22], [-56], [-18], [70], [51], [-20], [-64], [45], [19], [28], [-27], [-56], [-94], [10], [-64], [-74], [92], [48], [12], [86], [-71], [-40], [-26], [-18], [76], [12], [4], [15]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4725_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4725_2_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_4725_2_a_g(:prec:=1)
    chi := MakeCharacter_4725_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    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_4725_2_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_4725_2_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4725_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![1, 1]>,<11,R![3, 1]>,<13,R![-3, 1]>,<37,R![11, 1]>],Snew);
    return Vf;
end function;