
// Make newform 1425.2.a.w in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1425_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_1425_2_a_w();".
// 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_1425_2_a_w();".
// 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, -6, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-4, 0, 1]];
    Rf_basisdens := [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_1425_a();"
function MakeCharacter_1425_a()
    N := 1425;
    order := 1;
    char_gens := [476, 1027, 1351];
    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_1425_a_Hecke(Kf)
    return MakeCharacter_1425_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, -1, 0], [1, 0, 0], [0, 0, 0], [0, -1, -1], [-1, -1, 1], [4, 0, 0], [-2, 0, -2], [-1, 0, 0], [-3, 1, 1], [-5, 0, 0], [5, 1, -1], [4, 2, 0], [4, -1, 1], [4, 0, 0], [4, 2, -2], [-3, -4, 0], [4, 3, -1], [1, -2, 2], [5, -1, 1], [6, 3, -1], [1, 4, 0], [1, -3, -3], [1, -1, 1], [-1, -2, -2], [-4, -4, 2], [2, 0, -2], [-5, 7, 1], [-2, 5, 1], [-4, 2, 4], [-1, 5, -5], [3, 5, -3], [1, 3, 1], [-10, 4, 2], [-2, 1, 1], [0, 0, 0], [10, -4, 2], [-4, 1, -5], [6, 9, -3], [-14, 1, 1], [7, -4, 4], [4, -7, 1], [-12, -8, 4], [5, 1, 7], [12, -4, 2], [-2, 10, 0], [10, 5, 1], [3, -3, -3], [1, -1, -1], [-6, -3, 5], [-1, -7, 7], [8, -2, -2], [-2, -4, 6], [-14, -2, 0], [22, 0, 2], [7, -2, 6], [-3, 1, 1], [10, 0, 4], [6, 3, -1], [7, -2, 6], [-13, 5, -1], [0, -8, 0], [13, 3, 1], [9, -3, 3], [8, -8, 0], [3, -7, 3], [-17, 0, -4], [-1, 9, -1], [-8, -2, -2], [14, 2, 0], [3, 6, 2], [-16, 0, -4], [-22, -4, 2], [-10, -6, 2], [-2, -2, 4], [6, -8, 2], [-14, 9, 1], [18, 6, -2], [-1, -3, 3], [-7, 7, -3], [4, -12, -2], [0, 10, -2], [-2, -8, 8], [10, 1, -3], [-6, 0, 0], [9, -7, 5], [-15, -13, 5], [1, 2, -2], [12, -7, 3], [10, -4, -2], [-24, 4, 0], [-15, -1, -5], [15, 5, -7], [-4, -4, -8], [10, -4, -2], [8, -9, 7], [12, -4, -4], [17, 4, 0], [-13, 10, 2], [-6, 10, -4], [-3, 15, -3], [13, -5, -1], [-24, -4, 4], [-14, -1, -9], [-24, -3, 3], [2, -5, -1], [7, -7, -1], [-5, -11, 1], [0, 12, 0], [-4, -8, -8], [-2, 2, 2], [19, -3, 1], [0, -3, -1], [-10, 4, 0], [0, -5, 3], [16, 8, 4], [-18, 0, -8], [-6, -5, 3], [5, -11, -5], [-4, 4, 8], [-12, 16, 8], [10, -4, -6], [-4, 4, 4], [-3, 8, 4], [-2, -7, -7], [14, -6, 6], [22, 10, -4], [5, 10, -6], [21, -3, -5], [-10, 9, 9], [-7, 18, 2], [20, 5, -3], [-8, 1, -7], [4, 14, -6], [37, -2, 2], [4, -16, 6], [-25, 0, -4], [-12, 13, 3], [13, -5, 3], [-12, 5, 7], [4, -2, -2], [15, 1, -9], [-12, 12, -6], [6, -1, -1], [-8, 8, 0], [2, -16, -4], [8, 1, 13], [4, -5, -7], [12, -7, -1], [-22, 1, -11], [4, -5, 11], [-2, -10, 6], [4, 4, 0], [-6, -5, 11], [16, -4, 12], [6, -4, -10], [18, -3, -7], [-14, 7, 3], [-2, 6, 4], [-36, -3, -1], [3, -3, -5], [-4, -4, 4], [-17, -2, -6], [6, 11, 3], [0, -9, 11], [22, 8, 0], [-6, -10, -2], [-1, 9, -1], [-1, -3, -5], [26, 2, 2], [44, 0, 6], [-8, -1, 11], [-6, -16, 2], [32, -10, -6], [5, 7, -3], [-7, 1, 11], [16, 2, -4], [-8, 5, -15], [26, -2, 2], [34, 0, -2], [-7, 6, 6], [-6, 2, 2], [-6, 9, 13], [16, 4, 2], [3, 10, 2], [21, -11, 7], [-18, 14, 0], [-18, -12, 2], [-39, 9, 5], [-40, 0, 4], [3, 7, -11], [-12, 8, -12], [5, -3, -11], [-11, -11, 13], [21, 3, -7], [18, 0, 2], [-18, -4, 4], [-43, 0, -4], [17, 6, -6], [30, 4, 0], [11, -11, 9], [13, -9, -7], [28, -8, 12], [-6, -8, 14], [-40, -10, -2], [3, 1, -15], [-4, 16, -8], [30, -10, -2], [4, 5, 1], [18, 6, -2], [-12, 12, 4], [13, 20, -12], [-10, -14, 10], [-8, -9, 11], [26, 11, -1], [8, -9, 3], [12, 20, -10], [30, -1, 11], [-31, 19, 9], [-34, -14, 2], [-24, 4, -18], [-22, 22, 2], [1, 7, -3], [-6, -12, 16], [-10, -3, 5], [-42, 10, 6], [-8, -11, -5], [3, 18, -6], [-10, 25, 1], [-34, -4, -10], [31, 3, 11], [44, -15, -5], [11, -3, -7], [17, 5, 11], [-13, 10, -18], [-18, 11, -13], [32, -2, 6], [40, 5, 3], [-22, -2, -2], [-14, 2, 4], [22, -15, 1], [-20, 7, -5], [-20, 11, -1], [2, 6, 6], [-26, 18, 10], [-18, 16, 8], [-7, 1, -7], [40, 9, 5], [-6, -6, 10], [-37, 11, 5], [5, 7, 9], [17, 18, 2], [24, -6, 8], [-5, -1, -19], [-4, -18, 12], [-6, 10, -4], [3, -19, -7], [-12, 17, 11], [-33, -7, 11], [-4, 11, -3], [-26, 12, 12], [-21, 15, 3], [4, -3, -7], [11, 2, 6], [-8, -24, -2], [-42, 0, 0], [39, -7, 11], [44, -7, 7], [-58, 0, -2], [-31, 15, -9], [10, 2, 4], [42, 10, 0], [3, -5, 3], [-17, -27, 7], [-14, -13, 3], [-42, -10, 4], [20, 12, -12], [23, 5, 1], [-10, 20, -10], [-10, -4, 2], [-1, -1, 13], [8, -7, 17], [36, -7, -3], [0, -6, -14], [-38, 10, -6], [-12, -15, 13], [-12, -18, -2], [33, 3, 9], [-31, -13, 1], [60, -5, -1], [25, -10, -6], [0, 6, -20], [19, -3, 17], [-52, -17, 5], [14, 9, -15], [-4, -6, -10], [-8, 4, -2], [-46, 14, 0], [-4, 4, 0], [-14, 2, -2], [10, 14, -10], [15, -8, 8], [11, 1, 7], [-2, -14, -14], [-20, 27, -1], [2, -10, 2], [28, 10, -6], [40, 4, -4], [26, -18, -12], [-13, 19, 1], [21, -21, 5], [27, 11, 3], [6, 12, -8], [-1, -6, -6], [-9, 9, -5], [52, 8, 4], [4, 18, -2], [-7, 1, -15], [10, 1, 1], [-26, 20, -4], [30, 10, -10], [6, -2, -8], [-32, 5, 3], [4, 9, 11], [38, -2, 8], [46, 14, -4], [0, -4, 2], [-10, 0, -10], [0, -8, -12], [24, -28, -4], [62, -14, -6], [-19, 3, -3], [13, -20, 4], [40, 15, -13], [29, 5, -9], [-26, -1, -1], [27, -17, 13], [-52, 6, -8], [29, 10, 14], [29, 4, 0], [16, -9, -13], [40, 12, -4], [0, -6, -4], [-9, -28, 0], [-55, 11, -1], [-43, 16, -8], [-14, -13, 11], [39, -6, -2], [21, -29, -9], [0, -24, 0], [2, -2, -8], [21, 3, -1], [-20, 14, -10], [-14, -12, -14], [-59, -1, -13], [32, 4, -4], [-33, -19, 3], [23, -29, -9], [31, 3, 3], [10, -6, 10], [-12, 8, -12], [1, 6, -6], [-26, 4, 2], [-54, -9, 7], [14, -2, -6], [32, -12, 4], [-54, 4, -2], [-24, -24, 6], [16, -16, -8], [-22, 32, 6], [13, -3, 19], [-11, 3, 1], [18, -22, 8], [-25, 20, 16], [44, 24, -8], [-22, 0, -8], [30, -5, -13], [-11, 19, 1], [13, -12, 8], [8, -14, 14], [-52, -10, 0], [28, -3, 7], [20, 22, -12], [-52, 15, 3], [4, -18, 14], [-49, 7, 7], [16, -16, -8], [24, 4, 0], [4, 7, -11], [0, 7, -9], [2, 13, -11], [-32, -4, 12], [-37, -7, 3], [-11, -7, 5], [-30, 9, -23], [-2, 7, -21], [6, 4, -8], [6, 12, -10], [21, -18, -6], [-33, 5, 9], [-8, 20, 0], [-8, -6, -12], [40, 2, 12], [32, 38, -14], [-33, 18, 14], [9, 8, -8], [-38, -10, -10], [9, -13, 25], [-43, -10, -10], [59, 25, -7], [-49, 17, 5], [12, 36, 0], [-32, -10, 4], [44, 20, 4], [24, -1, 23], [5, -16, 8], [-38, 20, -4], [20, -5, 15], [-21, -23, 7], [-16, 22, -6], [-2, -7, 17], [-16, -7, 11], [26, -14, 2], [23, -25, -15], [-26, -7, 1], [-24, 4, -20], [0, 9, -5], [32, 1, 1], [14, -32, -10], [-12, 7, -25], [5, 25, -7]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1425_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1425_2_a_w();".
// 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_1425_2_a_w(:prec:=3)
    chi := MakeCharacter_1425_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_1425_2_a_w();".
// 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_1425_2_a_w( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1425_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![1, -6, 0, 1]>,<7,R![16, -21, 0, 1]>,<11,R![-16, -12, 3, 1]>],Snew);
    return Vf;
end function;