
// Make newform 9408.2.a.dw in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9408_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_9408_2_a_dw();".
// 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_9408_2_a_dw();".
// 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 := [-14, -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_9408_a();"
function MakeCharacter_9408_a()
    N := 9408;
    order := 1;
    char_gens := [1471, 6469, 3137, 4609];
    v := [1, 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_9408_a_Hecke(Kf)
    return MakeCharacter_9408_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, 0], [1, 0], [0, -1], [0, 0], [0, -1], [3, -1], [4, 0], [3, -1], [-4, 0], [-2, 1], [-1, 0], [-1, -1], [-2, -2], [-3, -1], [-6, 0], [-6, 1], [-2, -1], [10, 0], [3, 1], [-2, 0], [1, -1], [-5, 2], [-4, 1], [4, -2], [-12, -1], [-6, 0], [1, -3], [-6, 3], [-7, 3], [2, 2], [13, 2], [-4, 1], [8, 2], [-5, 1], [8, -2], [-6, 5], [6, 2], [-12, 0], [-6, 0], [-16, 2], [-10, 2], [-9, 3], [2, 2], [7, 2], [8, 2], [8, 4], [-8, 6], [2, 1], [8, -1], [15, -1], [6, 2], [-22, -2], [0, 3], [2, -5], [2, 4], [16, 2], [24, 1], [-2, -1], [17, -3], [-20, 2], [3, -7], [-18, 3], [5, 5], [2, 2], [13, -2], [18, -3], [11, 3], [-11, 4], [4, -8], [-6, 0], [14, -2], [0, -6], [9, -4], [3, -1], [23, 3], [4, -2], [2, 0], [13, 5], [24, 0], [-17, -2], [-22, 2], [1, 3], [-2, -6], [-13, -3], [14, -1], [10, 5], [14, -2], [17, -6], [16, 6], [-23, -3], [-34, 2], [-12, -2], [-1, 0], [14, -7], [29, -1], [-18, 6], [-8, 1], [8, -2], [21, 1], [5, -1], [-28, 0], [20, -3], [-12, 1], [18, 2], [5, -1], [25, 0], [-6, 1], [-6, -2], [-16, 2], [9, 4], [-7, 0], [2, -2], [-6, 0], [-19, 3], [-10, 3], [16, 6], [11, 5], [-34, 0], [-16, -7], [-16, 8], [17, 3], [35, -2], [-10, 1], [22, 3], [1, -3], [-10, -7], [2, -8], [2, -8], [25, -2], [-17, -7], [-15, -5], [18, -8], [17, 2], [22, 0], [12, -4], [13, -6], [-10, -4], [4, 2], [-2, 9], [-10, 6], [36, -2], [-16, -1], [8, -8], [-8, 11], [27, -1], [-4, 8], [-3, -5], [20, 2], [36, -6], [-6, 4], [-14, 10], [-16, -2], [-9, -5], [14, -6], [-33, -1], [-8, 14], [-7, -3], [14, -8], [-7, -4], [42, -3], [-26, -2], [36, -6], [47, -2], [-14, 13], [22, 4], [0, -12], [1, -4], [-35, 3], [9, 10], [10, -3], [38, -1], [-10, -4], [36, -4], [13, 0], [7, -10], [48, -4], [11, 9], [12, 9], [8, -8], [25, -1], [-11, -12], [2, 1], [-15, 3], [-44, -2], [26, 8], [-10, 5], [2, 12], [-15, -9], [5, -14], [50, 2], [7, 8], [-28, 5], [-32, 0], [12, -10], [-46, 5], [12, 2], [33, -1], [-6, 4], [-26, 12], [20, 2], [4, -3], [7, -13], [38, 0], [-26, 8], [-22, 2], [-4, -7], [-8, 8], [-52, 5], [28, 8], [32, 6], [-11, 7], [-6, -3], [14, -15], [42, -7], [8, 0], [-13, 1], [-2, -9], [4, 8], [-4, 2], [-22, -4], [-39, 5], [29, -7], [-10, -4], [-6, -7], [-16, -13], [18, 2], [4, 10], [-10, 2], [29, 2], [30, 2], [-35, 7], [-4, -12], [-21, 2], [-34, 4], [-9, 9], [-42, -2], [15, 2], [-12, 1], [20, 0], [14, -14], [18, 6], [-21, -1], [23, -14], [-6, 4], [8, 8], [-48, 4], [33, 2], [-22, 14], [64, 0], [-24, 8], [45, 3], [-32, 10], [18, -4], [-7, 15], [-2, 7], [10, 1], [-55, -5], [5, -3], [40, 1], [-12, 13], [21, 1], [-46, 5], [35, 1], [25, 1], [-14, -4], [39, 5], [-48, 5], [-10, -2], [20, 0], [12, -7], [-47, -3], [32, -6], [35, 0], [-33, -8], [-8, 17], [52, -4], [4, -11], [-5, 3], [-23, -9], [-12, 4], [-20, 18], [-21, -2], [-30, 2], [-3, 13], [-48, 2], [-6, -2], [21, -2], [16, 13], [15, -2], [54, 2], [-32, 14], [46, -11], [14, -14], [-20, -8], [-1, -13], [-20, 15], [17, -3], [-12, 6], [22, -14], [-71, 3], [-6, -16], [32, -11], [-30, -1], [22, -15], [-59, -5], [-9, 1], [-16, 11], [55, 5], [-28, -2], [-37, -11], [36, -6], [-22, -4], [30, -2], [24, 8], [16, -4], [-35, -9], [-16, -7], [52, -8], [7, -12], [-50, -2], [15, -5], [-11, 15], [-16, -3], [1, 5], [-6, 2], [-13, 14], [55, 1], [-21, -15], [32, 6], [-48, 9], [49, -13], [-32, 13], [57, -3], [-2, -2], [-53, 1], [58, -2], [-6, 10], [48, 6], [-13, 4], [-49, 2], [39, 13], [-16, -16], [18, -9], [-15, 6], [-68, -1], [-36, -7], [-49, 5], [8, -2], [-62, 4], [28, -7], [-20, 4], [-44, 5], [-10, 0], [66, -3], [-17, -3], [-22, 4], [62, 4], [-2, -9], [12, -16], [-42, 0], [-2, 12], [-46, 2], [6, 12], [26, 6], [-61, 3], [-8, 1], [4, -14], [47, 3], [52, -9], [6, -17], [7, -5], [30, -16], [16, -13], [-25, 19], [29, -11], [36, 12], [52, 4], [-16, 15], [-32, -2], [45, -1], [56, 2], [40, 2], [72, 0], [16, 16], [48, -2], [48, 6], [-39, -3], [50, 6], [-1, -5], [-54, -6], [25, -24], [14, 16], [30, 9], [9, -9], [34, 4], [-4, 1], [-10, -7], [86, -4], [59, 3], [-24, 13], [-14, 2], [24, 12], [-32, -4], [-2, -12], [-28, 13], [-45, -10], [-14, 8], [-24, 6], [67, -3], [2, -1], [-44, -9], [50, 3], [30, -5], [24, -22], [43, -11], [-12, 5], [-2, 10], [49, 5], [-28, -16], [24, -2], [74, -5], [-31, -9], [-28, 22], [-40, -11], [26, -12], [-66, 4], [-68, -3], [40, 4], [16, -2], [-24, -4], [-51, 7], [-38, -11], [31, 11], [14, -8], [-19, 3], [-4, 0], [1, -4], [-29, 15], [-47, 11], [14, 19], [26, -13], [68, -6], [7, -25], [-82, -4], [32, 9], [36, 6], [4, 0], [-2, -18], [-46, -12], [-5, 1], [49, -1], [46, 8], [32, -17], [-40, -4], [-71, 12], [14, 11], [57, 5], [-44, -5], [54, -2], [4, -8], [-8, 2], [25, -19], [-18, 1], [-73, -9], [-36, -14], [56, 7], [13, 5], [-6, 7], [34, -22], [19, 21], [-23, 12], [16, 12], [52, 2], [-51, 0], [-56, -8], [54, 0], [20, 21], [11, -9], [-8, -16], [-54, 11], [-37, 14], [32, 2], [35, -6], [30, -5], [-6, 7], [8, 17], [21, -11], [-34, -9], [-32, -10], [-54, -3], [-46, -8], [-4, 12], [35, -12], [46, 0], [-90, -3], [-7, -5], [9, -15], [-74, -7], [-19, 14], [-19, -13], [-30, -11]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9408_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9408_2_a_dw();".
// 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_9408_2_a_dw(:prec:=2)
    chi := MakeCharacter_9408_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(3581) - 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_9408_2_a_dw();".
// 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_9408_2_a_dw( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9408_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-14, 1, 1]>,<11,R![-14, 1, 1]>,<13,R![-8, -5, 1]>,<17,R![-4, 1]>,<19,R![-8, -5, 1]>,<31,R![1, 1]>],Snew);
    return Vf;
end function;