
// Make newform 9408.2.a.cd in Magma, downloaded from the LMFDB on 25 September 2025.
// 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_cd();".
// 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_cd();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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 := 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]];
    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], [-2], [0], [6], [3], [4], [5], [-4], [4], [7], [9], [-2], [1], [2], [-8], [0], [-10], [15], [-6], [-11], [1], [-6], [-8], [-14], [6], [-9], [12], [11], [6], [-1], [-14], [20], [9], [-4], [-8], [-18], [-4], [18], [-20], [-26], [7], [10], [3], [12], [-16], [4], [24], [-14], [7], [26], [2], [-2], [-4], [-18], [-12], [18], [8], [-1], [0], [1], [0], [11], [-18], [-1], [0], [-5], [29], [-12], [22], [6], [-12], [-7], [13], [15], [0], [26], [5], [0], [-3], [-26], [35], [-18], [31], [24], [16], [-38], [13], [12], [17], [-30], [16], [25], [-36], [17], [-14], [-6], [-12], [-29], [-1], [-4], [2], [2], [-18], [-23], [39], [-16], [-30], [4], [31], [1], [38], [-6], [-9], [-40], [-20], [17], [-18], [22], [40], [-35], [7], [-12], [0], [7], [-28], [50], [-30], [5], [11], [5], [-34], [-37], [-10], [-12], [7], [50], [32], [-12], [-30], [-24], [18], [8], [-18], [43], [12], [17], [0], [-16], [14], [-2], [52], [-1], [-54], [-17], [28], [1], [58], [-33], [-48], [38], [-8], [-27], [56], [-18], [0], [-33], [17], [-27], [8], [-16], [-30], [-12], [61], [-45], [-40], [7], [-54], [40], [-19], [43], [-56], [35], [16], [6], [12], [-38], [19], [33], [-66], [-7], [6], [16], [24], [8], [-24], [-53], [-14], [-14], [-56], [-14], [-15], [-38], [-38], [-42], [30], [-40], [6], [44], [-28], [-33], [-24], [-20], [24], [-64], [-57], [24], [44], [48], [26], [-57], [43], [-58], [-48], [50], [-50], [48], [14], [1], [30], [-25], [52], [1], [70], [53], [66], [5], [-6], [-4], [-30], [-14], [61], [-37], [50], [-24], [64], [-11], [70], [48], [8], [-17], [44], [-74], [-51], [-40], [48], [43], [-53], [42], [-18], [-67], [-48], [-9], [65], [54], [-35], [62], [-2], [-36], [18], [17], [20], [-19], [9], [-30], [44], [-26], [29], [35], [-60], [24], [-55], [-66], [-27], [-20], [18], [9], [-10], [75], [6], [36], [-4], [-46], [-4], [1], [-22], [39], [-80], [-6], [19], [86], [-18], [36], [36], [-63], [29], [-42], [11], [-8], [-71], [-40], [10], [-62], [8], [-88], [73], [-34], [4], [1], [18], [25], [47], [18], [-23], [-58], [-7], [11], [89], [12], [-66], [-45], [54], [-17], [50], [55], [-26], [86], [-20], [53], [-29], [-75], [48], [12], [-13], [-50], [-18], [-61], [-28], [-38], [-2], [52], [-14], [-42], [-48], [45], [-90], [30], [-80], [84], [90], [-26], [42], [66], [-30], [-51], [-34], [-96], [39], [-50], [88], [97], [-6], [50], [-47], [-21], [-28], [60], [86], [-100], [-23], [68], [-28], [40], [72], [-44], [36], [-31], [-38], [7], [-2], [41], [50], [-84], [27], [22], [2], [-20], [-62], [11], [-66], [-30], [56], [-72], [42], [-50], [-1], [-62], [-68], [-39], [-84], [18], [84], [16], [-4], [57], [30], [-26], [-41], [-36], [52], [-12], [-11], [24], [30], [30], [-30], [14], [48], [-92], [-32], [41], [-80], [-41], [78], [17], [-84], [-55], [61], [37], [-16], [-84], [32], [-47], [-102], [26], [-48], [-12], [18], [-10], [-65], [29], [-90], [46], [-16], [49], [24], [71], [-58], [-106], [-20], [-36], [-31], [-20], [-31], [88], [34], [13], [36], [-90], [-7], [55], [-8], [64], [93], [24], [90], [82], [109], [72], [-12], [49], [36], [-31], [-8], [-60], [-54], [-45], [40], [4], [40], [46], [-20], [59], [66], [-4], [-107], [-73], [36], [-39], [57], [72]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9408_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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