
// Make newform 3025.2.a.f in Magma, downloaded from the LMFDB on 17 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3025_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_3025_2_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_3025_2_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_3025_a();"
function MakeCharacter_3025_a()
    N := 3025;
    order := 1;
    char_gens := [727, 2301];
    v := [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_3025_a_Hecke(Kf)
    return MakeCharacter_3025_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 := [[1], [0], [0], [0], [0], [2], [6], [4], [-4], [-6], [-8], [2], [-2], [4], [12], [2], [4], [10], [16], [8], [14], [-8], [-4], [10], [-10], [10], [4], [12], [18], [6], [16], [12], [-18], [-12], [10], [-8], [2], [-16], [-8], [-6], [4], [-10], [8], [-26], [2], [0], [-4], [4], [-20], [-10], [6], [-8], [-10], [12], [-18], [24], [-18], [0], [10], [-18], [4], [10], [20], [-24], [22], [18], [4], [6], [-4], [10], [-18], [32], [-4], [18], [20], [12], [6], [-30], [2], [6], [-28], [6], [24], [22], [8], [-8], [2], [-26], [34], [36], [0], [-24], [-28], [28], [-36], [-16], [14], [-6], [-20], [34], [12], [10], [36], [-26], [-36], [22], [24], [22], [24], [-2], [-32], [34], [-2], [-20], [40], [34], [16], [-20], [10], [-36], [-10], [-26], [-38], [16], [-28], [-22], [-10], [0], [-52], [42], [-4], [40], [16], [-6], [-10], [22], [-14], [52], [2], [-18], [12], [18], [36], [12], [-2], [-32], [2], [-18], [28], [-4], [-22], [18], [16], [56], [40], [8], [-24], [-14], [6], [2], [0], [-42], [8], [36], [-10], [4], [8], [-46], [-26], [-30], [-28], [-34], [-40], [-10], [32], [10], [-36], [6], [-16], [34], [36], [-28], [-22], [6], [36], [38], [-6], [24], [-58], [8], [-42], [-12], [-44], [30], [28], [38], [22], [-38], [-2], [-8], [-38], [40], [-62], [-10], [12], [50], [-40], [52], [30], [-44], [-18], [-58], [36], [-8], [48], [-6], [-56], [-34], [-36], [42], [-30], [32], [50], [-52], [68], [58], [-34], [24], [8], [36], [-14], [-20], [40], [-66], [16], [-72], [-14], [-54], [20], [0], [-64], [-76], [4], [-18], [30], [48], [28], [36], [52], [48], [2], [14], [12], [58], [-6], [-36], [-74], [36], [26], [-58], [32], [12], [-46], [-14], [62], [-20], [-66], [-38], [52], [42], [14], [-16], [-50], [-64], [14], [-52], [40], [-22], [-18], [-20], [-48], [16], [-32], [-22], [-28], [24], [6], [-22], [-40], [78], [-18], [40], [6], [84], [34], [50], [0], [2], [4], [68], [-74], [42], [64], [8], [-60], [30], [40], [-50], [-8], [-46], [56], [-42], [-50], [88], [24], [-18], [84], [80], [-26], [-50], [-52], [-2], [90], [36], [6], [82], [20], [-40], [56], [-78], [-22], [2], [-8], [-12], [-76], [-16], [-66], [46], [-54], [-40], [-86], [-58], [10], [0], [42], [68], [54], [96], [-72], [-46], [68], [-10], [30], [-56], [-62], [30], [-24], [20], [-2], [-28], [-70], [-42], [92], [-20], [-40], [-2], [42], [24], [30], [-28], [44], [16], [-22], [-48], [18], [36], [32], [14], [30], [38], [94], [-90], [-8], [-42], [52], [-28], [64], [-54], [-20], [4], [-30], [18], [-60], [-96], [-72], [-10], [-48], [-86], [-84], [-30], [-94], [6], [-8], [6], [-54], [88], [2], [78], [-40], [-52], [62], [42], [-8], [-76], [-34], [46], [-48], [28], [-66], [16], [-34], [74], [-28], [-36], [-26], [74], [-48], [6], [12], [96]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3025_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3025_2_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_3025_2_a_f(:prec:=1)
    chi := MakeCharacter_3025_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_3025_2_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_3025_2_a_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3025_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, 1]>,<3,R![0, 1]>,<19,R![-4, 1]>],Snew);
    return Vf;
end function;