
// Make newform 4025.2.a.r in Magma, downloaded from the LMFDB on 25 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_r();".
// 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_r();".
// 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, 3, 4, -4, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [2, -3, -2, 1, 0], [1, 2, -3, -2, 1], [-2, -4, 4, 2, -1]];
    Rf_basisdens := [1, 1, 1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    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, 0, 0, 0], [1, 0, 0, 1, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 0], [-2, 0, 2, -1, 0], [0, 1, 1, 1, 2], [2, -2, 0, -3, -2], [2, -3, 0, 0, -1], [-1, 0, 0, 0, 0], [-2, 0, 1, 2, -3], [-2, -1, 1, 2, 2], [0, 2, 4, 1, -2], [-1, 4, 0, 0, 2], [1, 4, 3, 1, -1], [6, -1, -1, 0, -2], [3, 1, 1, 0, 2], [0, 1, -2, -1, -1], [1, 1, 3, 0, 0], [6, 1, 2, 1, 1], [-10, 5, 1, 4, 2], [1, 3, 2, -2, -1], [1, 5, 1, -1, 2], [2, -3, 4, -1, -1], [0, 0, -2, 5, -2], [1, -2, 1, -2, 5], [2, -1, 0, -4, 1], [-1, -2, -1, -2, 1], [13, 2, -1, 0, 1], [3, 3, 3, 2, -2], [1, -3, 1, 6, 0], [8, 1, 3, 0, -2], [4, -6, -1, -2, -3], [-1, -2, -1, 4, 3], [-5, 9, 0, 2, 3], [0, 2, 0, -9, 2], [1, 0, 4, -6, -2], [-7, 3, -5, 5, 4], [-4, 6, -1, 6, 1], [-3, 4, -3, 0, -3], [-6, 2, 2, 1, -6], [-14, 6, 5, -1, 3], [1, 2, 3, 2, 1], [-4, 3, -8, 5, 3], [2, -3, -7, -3, 4], [10, -7, 3, -6, -4], [7, -6, -3, -6, -1], [8, -3, -2, -5, -9], [4, 4, -2, -1, 0], [7, -1, -1, -4, -8], [5, -12, -1, -3, 1], [-1, 7, -4, 7, 1], [-8, -7, -3, 5, 4], [6, -7, -6, -5, -11], [-8, 12, 2, 3, 4], [4, 6, -5, 2, 5], [-1, 5, -3, 2, 6], [-8, -3, 1, -3, 4], [9, -12, -11, -2, -3], [11, -4, -4, 8, -6], [-11, 5, 3, 1, 6], [8, -1, -2, 0, -7], [-6, -5, -4, -3, 1], [-17, 12, -3, 7, 7], [-4, -2, 3, 2, -11], [-3, -1, -5, 1, 0], [17, -11, -1, -10, -10], [13, 0, -2, 2, -4], [4, -3, -4, 8, -5], [-3, 1, 5, -10, 0], [1, 7, -4, 4, -5], [5, -3, 0, 1, 1], [3, -8, 3, -3, 1], [6, -12, -12, -3, 4], [11, -2, 3, -3, 1], [-4, -5, 2, 5, 3], [0, 8, -10, 5, 4], [6, -10, -6, -2, -8], [5, -3, 6, 3, -1], [-16, -3, 4, 3, -5], [-6, 5, 7, 7, 10], [-13, -5, 3, -2, -2], [0, 10, 6, 1, 6], [0, 9, -4, 4, 11], [7, -2, 7, -7, -7], [-14, 3, 5, -3, 4], [7, 1, 0, -14, -1], [-11, 2, -5, 6, -3], [-2, -10, 4, -15, 2], [2, 7, -7, 6, 4], [-15, 6, -5, -1, 7], [8, -13, 8, 3, -5], [7, 1, 7, -6, -2], [14, -1, -7, 0, -6], [2, 0, -3, 7, 13], [-3, 3, 4, -2, 7], [9, -4, 1, -5, -11], [11, -12, 0, -5, 0], [-3, 10, 5, -12, 7], [-3, 4, 9, 6, 11], [-7, -1, 2, 9, 5], [-3, 10, 0, 10, 14], [-7, 15, 11, 9, 2], [-9, -5, -5, -18, 2], [5, 0, 1, -1, -9], [2, -7, 6, 4, 5], [-21, 15, -6, 19, 13], [3, -2, -10, 13, 0], [-7, 12, 15, -6, 3], [9, 1, -1, 11, -8], [13, -6, 6, -7, -4], [3, 8, -13, 4, 3], [11, -8, -7, -3, -13], [-24, 3, 0, 3, 7], [-3, 14, 17, 6, 1], [26, 2, 4, -13, -2], [-3, -12, -5, 1, -13], [-14, 1, 4, 8, -5], [-16, 5, -1, 1, -10], [13, 6, 10, 19, 4], [-6, -10, -10, -2, -4], [19, -1, -5, -1, 8], [-15, 15, -12, 14, 11], [-18, -2, 4, 0, 0], [17, 0, 6, -1, 0], [-8, 17, 8, 12, -1], [-10, 0, -2, -2, -12], [7, -2, -15, -1, -3], [-18, 16, 6, 12, 6], [-17, -4, 1, 10, 13], [9, -17, -11, -4, 4], [-1, 7, -4, 0, -9], [-4, -17, -16, 0, 7], [-3, 8, -7, -6, 3], [-19, 3, -7, -7, 0], [7, -9, -4, -13, 5], [-2, 4, -12, 2, -4], [2, -6, 6, 10, 8], [12, -8, -8, 0, -4], [-8, 12, 4, -9, -2], [-7, 7, 9, 11, 20], [-11, 20, 4, 16, -4], [-14, 14, 10, -11, 10], [17, 4, 10, -16, -2], [0, -11, 10, -9, -1], [-19, 9, 7, 0, -6], [19, -21, -9, 0, -14], [-6, 7, 10, 1, 9], [-9, 3, -2, 16, -9], [-23, 17, 12, 2, 7], [34, -17, -5, -9, 2], [21, -20, -11, 5, -13], [-22, 2, -4, 5, -4], [9, -19, 1, -8, 0], [10, 8, 7, 14, 5], [5, -12, -3, -7, 11], [-4, -9, -20, -3, 1], [10, 5, -4, 9, -5], [-8, -11, -5, 9, -6], [-19, -3, 3, 12, 0], [-3, 7, 5, -2, 10], [-12, 3, 11, -11, 2], [-9, 1, 5, -14, 4], [-4, 4, 17, 3, -1], [-37, 19, 1, 16, 8], [-24, 18, -2, 16, 14], [-8, -6, 4, -3, -2], [-18, -12, -4, 3, -2], [6, 0, 8, 20, 0], [2, -5, 12, 8, -3], [-24, 12, -7, 1, 7], [7, -12, -11, 8, -1], [0, 12, -7, -9, -7], [0, 4, 18, -5, -6], [0, 13, 0, 8, -3], [13, -20, -16, 1, -2], [-24, 17, 16, -2, 17], [47, -20, -6, -7, -10], [0, 7, -9, 7, -2], [5, -5, -7, -5, -16], [-2, -2, -8, -9, 10], [0, 6, 3, 4, 9], [-8, -1, -10, -17, -1], [9, 14, -4, -3, 14], [6, -19, -24, -6, 7], [-2, 4, 2, 11, 10], [9, 5, 3, 11, -10], [22, -20, -14, -7, -16], [-22, 21, -4, -2, 13], [-6, -9, 3, -7, 14], [-10, 20, 6, -2, -10], [5, 0, 8, -2, -8], [7, -10, -11, -15, -19], [7, 3, 11, -11, -6], [25, -17, -9, -6, 0], [24, -4, 0, 3, -10], [11, 3, 7, 6, -10], [13, -4, -1, -8, -15], [6, 9, -2, 8, 3], [-11, -10, -15, -18, -11], [-17, 17, 2, -6, 15], [10, -7, -4, -5, 7], [2, 4, -12, -3, 18], [25, 16, 2, -12, -10], [21, -19, -17, -10, 6], [-24, 13, 16, -8, 13], [-31, -7, -2, 2, 9], [-13, 19, 5, 14, 0], [4, -1, 5, -8, 2], [-3, 20, 20, -3, 2], [-9, -1, -24, 10, 17], [-16, 15, 13, 13, 14], [-24, 8, 9, -4, 15], [-33, -1, 3, -6, -4], [-8, 9, 2, -20, 11], [33, 3, -1, -11, -6], [4, 16, -8, 0, 0], [25, -4, -12, 3, -14], [-8, 20, 17, -1, 9], [11, 0, -5, 5, -11], [-20, 8, 19, 4, 9], [-6, 12, 7, 16, 3], [10, 2, -14, 9, 8], [10, -7, -5, 3, 0], [34, 11, 4, 1, 5], [20, 3, 7, -5, 12], [-21, 14, 6, 11, -6], [-28, 24, 2, -2, -2], [11, -8, 12, -4, -2], [5, -5, -9, -10, 10], [-11, -9, -5, 13, 2], [23, -3, 7, 25, -4], [14, 3, -4, -9, 1], [26, -11, -14, -5, -7], [1, -11, -5, 10, -14], [-38, 2, -6, -6, -6], [23, 7, 23, -8, -10], [-20, -3, -4, 8, -9], [12, -10, -4, -11, 8], [-11, 1, 18, -23, 5], [13, 5, -18, 10, -3], [1, 24, 17, 0, 7], [38, -28, 3, -21, -11], [23, -21, 12, -12, -9], [1, 4, 6, -14, -14], [-15, 14, 13, 17, 9], [-1, -11, 4, 5, 17], [27, -17, 4, -2, 3], [-44, 5, -2, 2, -7], [-5, 18, -5, 13, 17], [-1, -18, -3, -2, 5], [-7, 25, -17, -3, 8], [-31, 31, -1, 4, 14], [-2, -10, -26, 5, 0], [32, -27, 8, -30, -15], [-13, -10, -5, -3, -1], [27, -1, -4, 6, 3], [-8, -10, 10, 2, 2], [-22, 29, 20, -4, 17], [13, 0, -8, 13, -14], [23, -11, 8, -26, -21], [-9, 11, -11, -5, 6], [29, 1, -11, 6, 8], [31, -8, -11, -10, -19], [10, -5, 6, -6, -17], [-1, 20, -1, 27, 9], [-27, -9, 9, -15, 10], [-11, 19, -1, -2, 8], [-41, 15, -11, 3, 4], [-43, 33, -7, 13, 14], [-12, -4, -1, -23, 3], [-9, -13, 8, 5, -11], [47, -17, 5, -10, -10], [-6, -2, -12, -11, 4], [17, 10, 25, -18, -7], [3, -11, -4, 4, -1], [-9, 5, 8, 2, 1], [14, 13, -16, 3, 5], [0, -10, 0, 5, -12], [-24, 5, -10, -2, 7], [2, -1, -20, 7, 7], [7, 2, -12, 17, 6], [-7, 19, -9, 2, 4], [-25, -4, -9, 23, 19], [30, -35, -6, -1, -17], [18, -30, 8, 9, -12], [38, -24, 6, 2, 2], [-4, 27, 10, 6, -11], [25, -22, -3, 1, -9], [14, 13, 2, 6, -7], [-38, 5, 2, 9, 7], [18, 13, -2, 17, -5], [24, 11, -12, 12, 17], [-14, 19, 6, 7, 13], [-17, 7, -3, 20, 8], [2, 13, 7, 2, -24], [18, -9, 22, 13, -3], [25, 3, 15, 11, 8], [-13, 12, 12, -5, 14], [-32, -6, -13, -1, 3], [-26, 20, -5, 13, 3], [-31, 0, 5, 14, 13], [6, 5, -2, -17, 5], [23, -7, 3, -14, -18], [22, -3, 19, -7, -4], [24, 10, 14, -13, -16], [17, 5, 0, -18, -3], [14, 9, 0, 15, 25], [8, -17, 12, -4, -5], [-15, -10, -13, 32, -5], [1, 10, 15, -16, -3], [-38, 8, 5, 5, -7], [11, 8, 17, 2, 13], [-14, -23, 0, -9, -5], [-10, 6, 7, 23, 19], [15, 15, 1, 4, -8], [27, -15, 13, -39, -22], [40, -12, -17, -9, -27], [22, -5, 11, -19, 0], [0, 4, -14, -5, -8], [8, -3, -7, 24, -16], [32, 17, 6, -9, -1], [-39, -5, -9, -11, -12], [-21, -15, -4, 14, -3], [-17, 6, -9, 8, 13], [19, -8, 19, -11, -21], [-15, -1, -11, 16, 14], [4, 12, -6, 8, 20], [40, -28, -15, -21, 1], [-44, -4, 8, -9, -2], [-7, -6, 3, -7, -3], [0, 0, -5, -8, -25], [-18, 16, -21, -5, 15], [9, -8, -10, -8, 10], [-1, -25, -18, -14, 1], [-11, -12, -3, -3, 9], [36, -14, 5, 1, -5], [-20, -12, 12, -1, 6], [8, -9, -6, 31, -11], [-24, -10, -3, -22, -11], [17, -27, 5, 4, -2], [30, -22, -11, -22, -39], [22, 10, -2, -14, 10], [7, -11, -13, -11, 12], [28, 5, -14, 14, 13], [-8, -10, 12, 5, -4], [-62, 17, -4, -7, 5], [-30, 14, 21, 11, 23], [17, -20, 13, -2, -15], [17, 10, -7, -21, -19], [-57, 30, -1, 21, 9], [11, -26, -12, 17, -20], [31, -27, -18, -15, -23], [-44, 23, 8, 23, 31], [15, -24, 13, -24, -19], [-62, 4, -2, 16, 12], [-31, 24, 27, 8, 35], [39, 5, -11, 19, 0], [33, -10, 1, -9, -15], [11, 11, 14, -9, -17], [-21, -11, -3, -11, 10], [65, -19, -1, -2, -10], [28, -12, 9, -27, -3], [21, -26, -8, 14, -6], [-2, 23, -2, -11, 15], [48, -7, 1, -21, -20], [-1, 26, 0, 0, 4], [6, -27, -3, 2, 20], [22, -15, 4, -24, -1], [-2, -28, -2, 1, 10], [-39, 29, 6, 26, 19], [-9, -5, -5, -12, -8], [-8, 5, 5, -10, -12], [-24, -19, -18, -23, -3], [-36, 7, 28, -10, 7], [-29, -3, -16, 25, 19], [31, -8, 2, -29, -16], [5, 28, -25, 6, -3], [-21, 1, -11, 0, 0], [-13, 4, -13, 28, 5], [-7, -18, 22, -3, -14], [-10, 25, 0, 30, 3], [6, 4, -8, -4, 10], [-6, 12, 8, -5, -14], [-28, -19, 9, 9, 4], [32, -19, -6, -31, -3], [25, 12, 6, 7, 26], [-4, 29, -3, 4, 2], [14, 31, 4, 0, -27], [-11, 2, -1, 14, -19], [15, -10, 29, -9, -11], [-21, -20, -7, 11, 1], [-46, 8, -16, -12, 8], [-25, -21, -2, 0, -15], [51, -29, -3, -35, -32], [47, -17, -1, -16, -16], [-4, 25, 12, 11, 23], [30, -26, 26, -16, -26], [-8, -8, 10, -29, 10], [-3, 5, 21, -8, -4], [-26, 17, 8, 14, -25], [43, 6, 4, -2, 20], [20, 4, -21, 1, 23], [-2, 0, -16, 25, 6], [6, -8, -24, 1, -10], [22, -1, -27, -1, 6], [21, -18, 2, -11, -30], [-14, -26, 8, 10, 0], [-10, 3, 15, -29, 10], [23, -28, -3, -9, 9], [-13, 6, -29, 0, 1], [45, -14, -14, -9, 22], [-3, 37, -10, 9, -7], [37, 4, 1, -9, 1], [29, 5, 29, 15, 6], [-2, 13, 2, 29, 19], [20, 21, 29, -11, -4], [38, 16, 14, -12, 6], [-43, 5, 1, 18, 8], [17, -14, 1, 20, -1], [5, -14, -3, -10, 11], [-35, 26, 11, 7, 33], [24, -17, -2, -21, 1], [-47, 15, 11, 23, 26], [-10, 13, 2, 14, 17], [6, 2, -11, -23, -35], [-60, 26, -1, 14, 17], [50, -27, 4, -16, -27], [-10, 7, 4, 20, -3], [0, 18, -7, 35, -15], [-11, -6, -10, 3, -6]];
    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_r();".
// 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_r(:prec:=5)
    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_r();".
// 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_r( : 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, -4, 10, -2, -3, 1]>,<3,R![-1, -13, 7, 8, -6, 1]>,<11,R![-452, -612, -185, 14, 11, 1]>],Snew);
    return Vf;
end function;