
// Make newform 1425.2.a.q in Magma, downloaded from the LMFDB on 13 September 2025.
// 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_q();".
// 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_q();".
// 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_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 := 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]];
    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], [-1, 0], [0, 0], [-1, 2], [-4, 0], [4, -4], [0, -2], [-1, 0], [2, -2], [5, -4], [-8, 4], [4, 2], [-5, 0], [4, 0], [-2, -4], [-5, 0], [-11, 6], [3, -8], [-6, 8], [3, -10], [1, -4], [-6, -6], [-2, 8], [-5, 8], [2, 6], [-8, 10], [12, -8], [-15, 2], [-4, 6], [-10, 4], [12, 2], [-2, 8], [8, 6], [-17, -2], [-12, 12], [8, -6], [7, 0], [-5, 10], [-11, 22], [-11, 4], [11, -18], [8, -4], [0, -12], [-2, 2], [-14, 14], [3, 2], [12, 10], [8, -2], [17, -18], [-2, 4], [-2, -8], [4, 6], [-10, 10], [0, -6], [-13, 0], [-14, -6], [18, -4], [-3, -10], [13, 12], [-2, -16], [0, -16], [2, 0], [-8, -8], [4, 0], [-26, 8], [-3, 8], [-14, 20], [-6, 4], [2, 6], [-3, 24], [-24, 4], [-24, 2], [16, -28], [6, -10], [8, 2], [5, -18], [8, 0], [10, -20], [-6, 24], [10, 2], [22, -28], [14, 4], [1, 10], [-22, -4], [-18, -2], [6, -12], [-23, 4], [-1, -16], [-8, -10], [16, 12], [-20, 10], [-40, -2], [24, 0], [-12, -6], [-25, 10], [-12, -4], [-9, 0], [-21, 24], [30, -18], [10, -24], [-4, 6], [-24, 16], [15, -14], [-11, 16], [-7, 14], [6, 12], [4, -14], [-4, 16], [-20, 0], [-16, 32], [-8, 18], [23, 0], [22, 0], [27, -6], [-36, 12], [2, -8], [-11, 10], [0, -28], [16, -16], [20, -8], [-12, 18], [-12, 36], [-9, -24], [17, 14], [-12, -8], [26, 14], [-33, 12], [-40, -4], [-17, -2], [-5, 12], [9, 22], [31, -18], [-18, 4], [23, 0], [-14, 18], [-13, -12], [1, 8], [-28, -14], [-19, 20], [-2, 24], [22, -40], [-6, -18], [-27, 10], [-32, 8], [26, -48], [-37, 2], [-27, 16], [13, -32], [-25, -6], [41, 10], [-40, 8], [4, 8], [37, -14], [-4, 24], [-36, -10], [13, 2], [45, 6], [34, -22], [35, -8], [34, -4], [-32, 8], [31, -36], [9, -22], [5, -26], [10, 8], [40, -28], [-42, -8], [10, -4], [0, 0], [-38, -6], [-27, 30], [28, 6], [2, 8], [2, -32], [-12, -12], [-4, 6], [-7, -30], [28, -44], [-48, 2], [-9, 12], [-20, 4], [9, 10], [46, 6], [-29, -16], [32, -16], [-18, -22], [52, 2], [6, -42], [24, -48], [-24, 28], [-16, 44], [26, -2], [-10, 22], [26, -8], [-12, -2], [-50, 8], [41, 12], [11, -16], [30, 24], [8, 22], [34, -28], [-36, 8], [32, -30], [62, 0], [-20, 18], [48, -24], [20, -28], [-13, 34], [-4, -4], [-28, 20], [-23, -24], [20, 4], [-13, -10], [23, -2], [13, 30], [30, 10], [41, -2], [38, -40], [24, -12], [42, -6], [48, -20], [-14, 0], [54, -20], [-5, 22], [20, 16], [-45, 36], [-5, 32], [33, -10], [8, -22], [22, -34], [-1, 24], [32, -38], [36, -52], [39, 12], [9, -6], [62, -4], [11, -20], [40, -32], [10, -34], [-7, 6], [33, -18], [-29, 62], [-24, 36], [-12, 12], [-38, -8], [-18, 2], [45, -22], [-12, 4], [-32, 64], [-34, 0], [-45, 44], [-36, 30], [-8, -8], [-24, 10], [38, -22], [44, -14], [23, -40], [-30, 32], [7, 24], [-30, 24], [6, -10], [19, 2], [-39, 8], [-22, 42], [-14, 32], [6, 24], [-3, 24], [-36, 6], [-8, 46], [-66, 18], [54, 10], [30, -14], [6, 40], [21, -30], [22, -6], [-16, 24], [-4, 10], [0, 10], [20, -26], [-12, 40], [7, -50], [-31, 18], [54, 12], [28, -60], [-31, -22], [-38, 52], [50, -8], [-50, 24], [-53, 22], [-3, 36], [-40, -18], [-76, 6], [-25, -36], [81, -2], [-30, 0], [-26, -6], [10, -2], [-8, -32], [0, 16], [-8, -12], [23, 0], [46, -20], [-24, -20], [37, 22], [-36, -32], [-30, -8], [52, -24], [-42, 6], [-40, 20], [42, 12], [-6, 26], [-18, -12], [15, -8], [-14, 8], [-8, 12], [58, 12], [10, 38], [-35, -34], [-62, 8], [-4, 44], [22, -30], [27, -60], [-39, 44], [10, -6], [-62, -6], [-30, 42], [-24, 6], [-36, 0], [-36, 48], [-28, -28], [-70, 12], [-25, -36], [-53, 14], [28, -4], [-11, -30], [4, -44], [44, -58], [-11, 36], [21, -12], [-13, -34], [24, -8], [8, 50], [-31, 0], [4, -2], [27, -52], [51, 18], [-43, 56], [48, -18], [-16, 8], [-50, 50], [64, -10], [-18, 60], [24, -10], [-32, 6], [24, -16], [-18, -20], [-38, 22], [26, -2], [-20, 24], [-40, -28], [3, -32], [-8, -2], [-1, 26], [0, 0], [-36, 40], [16, 46], [46, -54], [4, -24], [36, -6], [64, -24], [54, 0], [18, 42], [33, -32], [4, 32], [-22, 0], [55, -54], [-22, 48], [-67, 4], [54, -48], [48, -54], [53, 4], [-8, 22], [7, 54], [46, -52], [-30, -38], [48, -32], [32, -68], [-23, 16], [23, -54], [41, 6], [52, -36], [-6, 24], [-10, 6], [-53, 14], [7, 30], [14, 0], [-28, 6], [-7, -36], [40, -10], [20, 40], [32, -38], [-56, 50], [46, 8], [27, -20], [47, -20], [-24, 12], [66, -40], [-3, 16], [-60, 6], [24, -34], [48, -64], [-60, 50], [-16, 24], [47, -6], [61, -24], [14, -4], [-51, 14], [6, -52], [74, 16], [-55, 6], [-59, 68], [8, 0], [44, 8], [-7, 14], [-48, 24], [-51, 12], [-49, 14], [32, -14], [3, 50], [-50, -18]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1425_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1425_2_a_q();".
// 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_q(:prec:=2)
    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_q();".
// 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_q( : 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, -1, 1]>,<7,R![-5, 0, 1]>,<11,R![4, 1]>],Snew);
    return Vf;
end function;