
// Make newform 4025.2.a.h in Magma, downloaded from the LMFDB on 07 May 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_h();".
// 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_h();".
// 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
        poly := [-1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
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 := [[-1, -1], [-1, 2], [0, 0], [1, 0], [6, 0], [-3, 0], [0, -2], [6, -4], [-1, 0], [5, -4], [-3, 4], [6, -2], [3, -6], [0, 6], [3, -2], [10, 2], [-4, 4], [2, 6], [-2, 2], [-3, 2], [-9, 0], [-6, 12], [0, 6], [-8, 2], [4, 6], [2, -8], [4, 8], [6, -16], [8, -6], [0, 12], [-3, 0], [13, 4], [0, 2], [-9, 4], [6, 2], [21, -2], [16, 2], [17, 0], [-12, 8], [-2, -8], [15, -6], [-10, 0], [-2, -4], [3, 2], [-9, -6], [-6, -12], [-12, 8], [8, -8], [12, -12], [-12, 0], [-3, 6], [9, -14], [-18, 18], [-4, 8], [5, -20], [10, -22], [-3, 6], [-20, -4], [-9, 26], [8, -10], [18, -18], [16, 10], [0, -12], [9, -12], [16, -6], [10, -4], [-9, 18], [-12, 12], [-24, -4], [-15, 2], [-25, 8], [-10, 8], [8, -2], [10, 2], [-4, 22], [4, -4], [0, 16], [-19, 12], [22, -22], [21, 10], [8, -14], [32, 0], [16, -8], [-14, 6], [-9, 0], [-25, 20], [-6, -12], [32, -2], [-19, 14], [4, -24], [-22, 8], [12, -24], [21, 12], [7, -10], [1, -6], [-30, 2], [-15, 34], [-20, 16], [16, -30], [13, 0], [-27, -4], [12, 0], [-16, -10], [-34, 4], [0, 0], [31, -16], [-5, 26], [10, -32], [0, 0], [1, -22], [4, 12], [40, -4], [-10, -4], [0, -14], [-24, 2], [12, 18], [18, 16], [11, 10], [29, -22], [28, -8], [-22, 6], [-31, -6], [30, -10], [-31, 20], [32, -24], [0, 6], [-4, -8], [16, 8], [18, 0], [0, 6], [-9, 18], [-4, 26], [36, -18], [-18, 28], [1, -2], [-22, 24], [-36, 24], [-36, 20], [2, -8], [-26, 16], [9, 0], [22, -20], [19, -24], [16, -28], [-30, 0], [36, -18], [22, -28], [5, 8], [-23, -4], [-15, 20], [-14, -12], [0, -24], [-28, 16], [-21, 34], [22, -36], [6, 6], [24, -18], [-21, 42], [-6, -14], [-4, 28], [15, -12], [2, 8], [-43, 16], [-14, 10], [-42, -2], [30, -34], [4, 0], [-10, -24], [18, -44], [29, -16], [50, -10], [49, -10], [24, -22], [4, -18], [3, -12], [-32, 2], [7, -10], [-1, 28], [30, 0], [48, -2], [45, -16], [20, 14], [27, -2], [-22, 40], [14, -22], [-12, 34], [-14, -24], [18, -42], [41, -12], [12, 16], [-3, 8], [36, -40], [-14, -12], [10, 16], [-2, -20], [-4, -34], [-18, 6], [-12, 18], [-48, 30], [-39, 30], [52, -14], [-12, -24], [-29, -16], [-2, 12], [12, -18], [-45, 36], [10, 2], [-33, 0], [-33, 24], [27, -24], [-11, -30], [-41, 22], [16, -24], [34, -2], [-20, 8], [-24, 8], [-37, 4], [9, -18], [30, -12], [5, 26], [63, -12], [26, -38], [-27, 12], [-40, 30], [-37, 2], [-41, 20], [-2, 8], [-37, -14], [42, 10], [-4, -8], [26, -36], [24, 30], [10, 26], [-2, -4], [24, -46], [0, -26], [-48, 16], [30, -48], [-35, 26], [3, 4], [-16, -26], [-31, 24], [-13, -6], [7, -12], [-10, 20], [-23, 4], [11, -18], [-38, 44], [38, -18], [-22, 2], [32, -36], [30, 30], [26, -46], [32, -2], [-6, -44], [23, -62], [30, -10], [-18, 30], [-17, -20], [31, -24], [-36, -10], [-4, -4], [-46, 0], [56, 0], [46, -44], [14, -42], [6, -12], [-4, -28], [10, 8], [-49, 26], [49, -46], [42, 24], [-24, 4], [52, -18], [-53, 12], [-13, 30], [48, -12], [38, -24], [-18, 6], [64, -4], [-7, 22], [-26, 0], [10, 10], [-66, 12], [-48, 12], [-20, -8], [-30, 62], [-26, 26], [24, 0], [6, -24], [18, -24], [-48, 24], [-58, 28], [6, -14], [-13, 54], [10, -20], [56, -26], [-19, 52], [-21, -20], [21, 18], [-28, -8], [-14, -38], [8, -44], [-7, -16], [-24, -6], [13, 6], [0, 36], [24, -30], [-38, -2], [6, 12], [-17, -22], [-18, 12], [60, -30], [-55, -8], [-6, 6], [0, 0], [-25, 20], [-7, -46], [8, -44], [59, 8], [-64, 28], [0, -10], [-33, 10], [52, 0], [10, -34], [48, -60], [-38, 66], [13, -42], [38, -4], [-24, 10], [-15, -24], [-15, 50], [-53, 0], [77, 2], [18, 30], [9, 46], [-50, -24], [24, -36], [-9, 18], [56, -2], [-15, -18], [44, -26], [-34, 16], [14, -44], [-42, 44], [20, -32], [15, -30], [28, -16], [-34, 20], [-22, 70], [-19, 48], [-9, 22], [14, 40], [-10, -36], [60, -10], [42, -12], [32, -22], [10, -20], [-17, -2], [0, -20], [14, 52], [-15, -18], [-3, 4], [62, -46], [-43, 30], [-9, 46], [53, -8], [2, 28], [-30, 66], [27, -10], [40, -12], [-49, 20], [48, -10], [56, 18], [41, -26], [-25, 44], [26, 22], [-38, 24], [32, 14], [53, -20], [-10, 56], [-42, 42], [-52, 48], [-43, 2], [-40, -30], [-27, 6], [-25, -18], [42, -8], [18, 0], [-52, 20], [8, 22], [42, -40], [-75, 14], [16, 24], [-44, 52], [42, -78], [68, -18], [-12, 6], [48, 32], [-38, -20], [-49, 6], [-21, -30], [68, -36], [-24, 4], [3, -38], [33, 16], [-26, 62], [5, 20], [-36, 10], [52, 16], [-79, 12], [-35, 22], [-18, 14], [-26, -28], [14, -44], [5, 10], [-32, 8], [-60, 36], [-8, -44], [-68, 16], [-36, 18], [0, 12], [-60, 4], [0, 0], [-9, -40], [73, 16], [-18, 26], [-6, 0], [-27, -36], [9, -12]];
    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_h();".
// 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_h(:prec:=2)
    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_h();".
// 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_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_4025_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![1, 3, 1]>,<3,R![-5, 0, 1]>,<11,R![-6, 1]>],Snew);
    return Vf;
end function;