
// Make newform 3408.2.a.i in Magma, downloaded from the LMFDB on 04 October 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_3408_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_3408_2_a_i();".
// 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_3408_2_a_i();".
// 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_3408_a();"
function MakeCharacter_3408_a()
    N := 3408;
    order := 1;
    char_gens := [1279, 853, 2273, 433];
    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_3408_a_Hecke( : Kf := Kf)
    return MakeCharacter_3408_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, 0], [-1, 0], [-2, -1], [3, -2], [3, 2], [1, -3], [-3, 2], [5, -2], [3, -3], [5, -7], [-2, -4], [-3, 5], [-8, -1], [9, -3], [-6, -3], [4, 1], [-7, 10], [5, 0], [-3, 11], [-1, 0], [2, -2], [2, 1], [7, -2], [-9, 4], [6, -7], [-5, 10], [-5, 12], [9, -1], [11, -12], [2, -2], [9, 4], [-4, -8], [4, 2], [6, -3], [-9, 1], [12, 7], [-8, 14], [15, -6], [3, 6], [3, 0], [7, -11], [10, -9], [7, -8], [9, 6], [11, -7], [10, -6], [-10, -6], [15, 8], [23, -10], [3, 12], [-15, 1], [5, -10], [9, -3], [0, -15], [6, 8], [-6, 9], [6, 6], [-18, 6], [4, 17], [-13, 11], [-24, 6], [-4, -17], [14, -3], [7, -1], [6, 0], [-8, 1], [20, -9], [15, -18], [-12, 18], [9, 6], [3, -23], [-1, 14], [12, 7], [-28, 7], [3, -6], [-3, 12], [0, 4], [-9, 27], [-5, 13], [-1, -3], [7, -11], [-33, 6], [-9, 0], [-5, 21], [-6, 15], [-8, -5], [20, -2], [19, -24], [-19, 28], [1, -1], [9, 16], [15, 3], [12, 7], [6, 12], [-24, 18], [-20, 11], [24, 6], [-14, -2], [19, 3], [17, 6], [-12, 1], [17, 2], [-24, 13], [13, -28], [36, -9], [0, -3], [2, 14], [11, 16], [-11, 7], [10, 11], [-13, -8], [-36, -6], [2, -10], [-9, 15], [-13, 18], [-34, -2], [-13, 9], [-7, 5], [-3, -9], [33, 4], [-36, 4], [4, 9], [25, -11], [7, -20], [-5, -13], [-14, -8], [-17, 12], [0, -13], [31, -15], [37, -6], [37, -7], [26, -34], [-28, 4], [22, -3], [-18, 11], [35, 6], [-37, 10], [-9, 1], [0, 3], [-21, -18], [-28, 19], [-21, 6], [9, -21], [-13, -7], [25, 0], [-30, -10], [13, -33], [46, 1], [-9, -16], [-4, 13], [-24, -12], [22, 1], [-33, 18], [-24, 16], [34, -3], [4, 17], [-33, 12], [-46, 16], [-28, 43], [4, 14], [34, -8], [-21, 0], [-20, -21], [-1, 8], [5, -10], [-31, 25], [18, -27], [-23, 33], [-24, -12], [-15, 12], [-16, -8], [-3, -30], [-25, 46], [-39, 15], [-9, 21], [-13, 14], [20, 6], [27, -18], [-9, -14], [-13, 21], [9, -12], [23, -23], [-9, 6], [17, -31], [-33, 14], [-13, 26], [-42, -10], [30, -33], [27, 10], [12, -41], [45, -26], [36, 0], [54, -2], [26, -34], [-30, 16], [14, -16], [14, 0], [-41, -12], [5, -32], [19, -5], [38, 14], [-37, 22], [-21, -12], [-8, -4], [-34, 44], [-18, -8], [-35, -3], [54, -11], [-10, 23], [16, -18], [23, 10], [27, -15], [-29, 21], [1, 7], [-18, 4], [44, 3], [-24, 0], [3, 12], [4, -29], [-24, 57], [-30, 50], [-9, 45], [11, 16], [3, -24], [66, 2], [6, -3], [0, -9], [4, 19], [19, 15], [17, -43], [4, 0], [-21, 17], [3, 5], [-42, 24], [-39, -4], [0, -14], [-45, 12], [-50, 28], [-22, 26], [-14, 8], [59, -22], [5, 33], [7, -25], [34, -4], [43, -38], [-33, 39], [45, -24], [-12, 55], [-22, 18], [-9, -32], [-20, -28], [-45, -12], [69, -8], [7, 20], [15, -57], [-8, -11], [26, -35], [-47, 39], [14, 16], [-12, -24], [42, -20], [-9, 19], [-44, 29], [9, -24], [-53, 28], [-51, 0], [35, 23], [37, -10], [-7, 43], [39, -39], [-44, 3], [0, -19], [6, 15], [-29, -22], [-45, 27], [27, -11], [57, -34], [27, -9], [-3, 12], [17, -46], [-28, 28], [24, -22], [-46, 26], [-16, 1], [-15, -36], [26, -29], [-14, 48], [15, -24], [-32, -4], [24, -33], [21, 13], [-12, -2], [75, -3], [9, 27], [-37, 24], [28, -22], [1, 6], [37, -46], [-13, 29], [-10, 43], [19, 14], [-27, 15], [-12, 48], [8, -49], [2, 0], [-23, -1], [37, -56], [-14, -3], [51, -30], [29, -36], [25, 4], [-11, 58], [-11, -23], [-32, 41], [57, -12], [-11, -18], [-22, 41], [16, -47], [-49, 0], [-6, 56], [2, 21], [43, 20], [-49, 32], [0, -2], [-45, 38], [26, -23], [-43, 34], [-32, -9], [-9, 4], [41, 26], [-40, 46], [36, -12], [-3, 12], [-12, 26], [-30, 67], [-75, 24], [3, -18], [-69, -3], [36, 8], [-7, 48], [-18, -5], [-1, -44], [33, -25], [18, 33], [39, -58], [-19, 62], [1, 12], [15, 20], [-54, 12], [27, 28], [-20, 18], [-1, -17], [67, -35], [39, -60], [20, -6], [-41, 79], [48, -9], [-21, -9], [26, -58], [5, 11], [-2, 36], [-28, 17], [-68, 23], [45, -18], [68, -20], [3, 22], [-15, 48], [-11, 36], [-55, -9], [6, -27], [-65, 42], [47, -31], [55, -34], [52, -27], [40, -16], [64, -58], [-16, 1], [0, 27], [-51, -6], [29, -63], [18, -15], [18, -36], [40, 14], [14, -62], [-69, -8], [22, -19], [-46, 28], [-47, 30], [-16, -42], [0, 12], [-34, 78], [-29, -10], [-60, 17], [-18, 26], [-39, -30], [3, 36], [-78, 3], [-34, 19], [11, -50], [-75, 38], [-17, 69], [27, -71], [-71, 17], [-42, -15], [63, -57], [-54, -10], [30, -27], [-39, 29], [0, -37], [-16, 35], [-33, 18], [-42, 8], [63, 3], [21, -44], [-21, 24], [30, -2], [-10, 40], [11, 48], [-53, 20], [27, 24], [-51, 68], [-15, 39], [3, 33], [57, -5], [78, -12], [7, 37], [-51, 57], [-69, 4], [-16, 72], [-23, 34]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3408_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3408_2_a_i();".
// 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_3408_2_a_i(:prec:=2)
    chi := MakeCharacter_3408_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_3408_2_a_i();".
// 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_3408_2_a_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3408_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![5, 5, 1]>,<7,R![-1, -4, 1]>,<11,R![11, -8, 1]>],Snew);
    return Vf;
end function;