
// Make newform 4725.2.a.m in Magma, downloaded from the LMFDB on 21 May 2024.
// 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_m();".
// 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_m();".
// 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)
    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+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 := 2;
    raw_aps := [[0], [0], [0], [1], [6], [-1], [6], [-4], [6], [0], [5], [-1], [-6], [-1], [-6], [-6], [6], [2], [5], [-12], [-1], [-1], [6], [18], [14], [6], [-1], [-12], [-19], [6], [8], [0], [18], [11], [-18], [-16], [17], [23], [-24], [0], [-6], [11], [-12], [14], [12], [-19], [11], [17], [12], [23], [18], [-6], [-25], [18], [24], [0], [-6], [-7], [17], [-18], [23], [-24], [11], [6], [-19], [-24], [17], [-31], [-30], [17], [-12], [30], [17], [26], [-19], [30], [12], [29], [6], [-25], [36], [-7], [-12], [-7], [5], [-18], [-12], [2], [36], [41], [-6], [-30], [11], [0], [17], [-12], [-24], [-36], [-16], [2], [-19], [12], [0], [42], [-4], [-34], [30], [6], [-30], [-31], [-1], [-25], [48], [-28], [-31], [0], [-4], [18], [-18], [30], [29], [-1], [-18], [-24], [-16], [-6], [14], [-36], [29], [2], [-28], [-24], [-1], [-22], [0], [41], [36], [-28], [-30], [-6], [47], [24], [29], [-30], [47], [24], [17], [-36], [23], [12], [-22], [-30], [32], [-54], [-1], [-42], [29], [48], [2], [-42], [24], [42], [-37], [-42], [12], [-30], [-16], [-10], [-34], [-30], [0], [-7], [24], [26], [-19], [0], [-55], [54], [-37], [53], [53], [-36], [41], [-36], [54], [-24], [-7], [53], [50], [24], [14], [-24], [-52], [24], [-18], [0], [-49], [-55], [-42], [60], [36], [-19], [23], [35], [-36], [-36], [44], [60], [-30], [35], [-37], [60], [-19], [54], [30], [-7], [-37], [18], [-24], [-54], [-58], [35], [-12], [-52], [54], [-13], [-48], [-12], [17], [24], [-58], [-16], [5], [-18], [23], [-30], [-13], [-36], [-12], [-30], [-24], [-25], [56], [11], [54], [-6], [-16], [66], [59], [-36], [-58], [-36], [-6], [35], [-42], [-54], [38], [-4], [-30], [-70], [-16], [42], [-37], [-34], [-30], [-4], [-6], [-48], [-4], [-60], [50], [65], [-22], [-31], [23], [32], [-66], [35], [-61], [42], [-48], [-16], [-42], [17], [41], [-6], [5], [-54], [11], [-30], [6], [36], [-54], [6], [11], [0], [80], [48], [-42], [53], [-67], [6], [-85], [36], [29], [17], [-72], [2], [-36], [47], [66], [42], [66], [20], [12], [-25], [72], [66], [-1], [54], [77], [59], [-36], [83], [-42], [35], [65], [11], [66], [-54], [53], [30], [-1], [48], [-7], [-24], [-94], [84], [-49], [92], [-10], [0], [-78], [80], [-54], [12], [-49], [-7], [-60], [-30], [-4], [29], [24], [59], [-49], [-48], [-30], [-60], [-24], [-30], [-22], [-84], [0], [54], [-97], [26], [12], [-7], [35], [-36], [-52], [-66], [-36], [59], [-34], [-30], [6], [17], [42], [-22], [-42], [42], [47], [18], [5], [36], [11], [59], [-7], [-12], [-19], [-42], [-30], [23], [-84], [-46], [59], [-6], [-61], [18], [14], [-48], [77], [42], [-90], [-40], [-58], [30], [77], [24], [89], [66], [24], [35], [-58], [-30], [90], [-16], [-6], [-102], [-36], [-79], [-30], [0], [74], [-66], [-18], [6], [-19], [-36]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4725_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4725_2_a_m();".
// 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_m(: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_m();".
// 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_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4725_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![0, 1]>,<11,R![-6, 1]>,<13,R![1, 1]>,<37,R![1, 1]>],Snew);
    return Vf;
end function;