
// Make newform 4025.2.a.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_4025_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_4025_2_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_4025_2_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_4025_a();"
function MakeCharacter_4025_a()
    N := 4025;
    order := 1;
    char_gens := [2577, 1151, 3501];
    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_4025_a_Hecke(Kf)
    return MakeCharacter_4025_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 := [[-2], [-3], [0], [1], [-1], [-7], [-3], [-8], [-1], [-5], [-2], [4], [-8], [-6], [-3], [-2], [2], [-14], [4], [8], [6], [-3], [-12], [-2], [-7], [-14], [-1], [-18], [11], [-18], [4], [12], [6], [8], [-2], [-9], [-2], [-24], [-3], [15], [24], [-14], [-9], [2], [-28], [26], [15], [13], [-13], [-16], [-10], [-17], [-6], [-20], [14], [-28], [-30], [-2], [24], [-15], [1], [9], [11], [4], [-9], [12], [8], [14], [-12], [-28], [-25], [-24], [7], [-26], [-12], [16], [19], [-25], [-25], [-14], [30], [7], [19], [-2], [26], [-10], [-9], [8], [16], [34], [21], [6], [-2], [-9], [25], [-39], [-12], [30], [16], [-17], [30], [-2], [-4], [-18], [-16], [37], [-44], [25], [21], [24], [43], [-16], [-4], [-18], [-17], [26], [23], [8], [-36], [-33], [40], [-28], [-33], [28], [10], [9], [-39], [-22], [32], [43], [-19], [-10], [-31], [8], [12], [-40], [31], [-53], [-35], [-15], [6], [-11], [-26], [20], [-24], [-12], [2], [50], [40], [-30], [32], [22], [32], [8], [28], [8], [-7], [-6], [-59], [-12], [28], [-26], [16], [36], [-24], [21], [-40], [7], [19], [-6], [20], [-16], [27], [8], [42], [32], [21], [57], [28], [-64], [-62], [-26], [-22], [-22], [-24], [-2], [-62], [-53], [25], [10], [6], [52], [13], [6], [12], [-53], [61], [38], [41], [-15], [-14], [28], [10], [-40], [-22], [55], [-6], [44], [-30], [-20], [-4], [-12], [44], [27], [-10], [-48], [26], [-2], [-36], [-50], [34], [30], [49], [24], [-3], [-2], [-31], [-3], [-21], [12], [30], [-38], [16], [-7], [-57], [39], [-10], [-54], [27], [0], [-40], [-52], [49], [46], [-7], [-8], [48], [-30], [-19], [22], [0], [-32], [-60], [-60], [2], [-75], [34], [-32], [-3], [37], [54], [-6], [-14], [39], [-38], [60], [3], [-36], [-22], [-54], [28], [-8], [-27], [-8], [-14], [-71], [22], [14], [-13], [-46], [61], [-19], [-60], [-34], [77], [-3], [-30], [-24], [10], [-66], [-13], [33], [-24], [-28], [-56], [46], [-60], [9], [-48], [21], [-23], [78], [-33], [-48], [81], [-32], [-30], [54], [64], [-56], [0], [-39], [34], [-46], [2], [64], [-46], [-75], [-51], [-27], [46], [32], [-16], [-14], [46], [-6], [57], [-8], [14], [54], [66], [-12], [-70], [-45], [-92], [-63], [11], [-30], [82], [-25], [-66], [12], [30], [27], [-24], [-20], [-66], [-20], [-38], [-15], [44], [86], [-7], [31], [83], [-6], [-24], [-48], [54], [-58], [48], [48], [56], [-45], [-32], [16], [-65], [-20], [-25], [-59], [70], [-82], [-15], [34], [-44], [70], [-93], [7], [54], [-47], [12], [-54], [-32], [40], [-8], [-55], [-15], [-23], [22], [57], [-17], [71], [-1], [-92], [-9], [78], [24], [-96], [95], [2], [-56], [4], [-14], [41], [24], [-48], [4], [-49], [-24], [0], [7], [12], [26], [36], [-62], [18], [65], [32], [-58], [91], [27], [-22], [-50], [28], [-79], [-65], [-102], [-6], [-8], [-52]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_4025_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_4025_2_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_4025_2_a_a(:prec:=1)
    chi := MakeCharacter_4025_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_4025_2_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_4025_2_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4025_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![2, 1]>,<3,R![3, 1]>,<11,R![1, 1]>],Snew);
    return Vf;
end function;