
// Make newform 3936.2.a.m in Magma, downloaded from the LMFDB on 02 August 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_3936_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_3936_2_a_m();".
// 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_3936_2_a_m();".
// 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 := [2, 1, -7, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-4, -7, 0, 1], [4, -5, -2, 1]];
    Rf_basisdens := [1, 1, 2, 2];
    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_3936_a();"
function MakeCharacter_3936_a()
    N := 3936;
    order := 1;
    char_gens := [3199, 1477, 1313, 1441];
    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_3936_a_Hecke( : Kf := Kf)
    return MakeCharacter_3936_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, 0, 0], [1, 0, 0, 0], [-1, 0, 0, -1], [-1, 0, 1, 0], [1, -1, 0, 1], [-1, 0, -1, 0], [-1, 1, 0, 1], [-1, 2, -1, 0], [-1, 0, -2, -1], [-3, 1, 1, 2], [-4, 1, -3, -1], [0, -3, 2, 2], [-1, 0, 0, 0], [0, -1, 2, 0], [-1, -1, 1, 2], [-4, 2, 1, 1], [2, 2, 0, -2], [-2, 3, 1, -1], [0, -4, 0, 0], [-1, -3, 3, 0], [-2, -1, -3, -1], [0, -2, 2, 0], [1, 6, -2, 1], [-2, -4, 0, -4], [-1, 0, 3, -2], [-3, -5, 2, 3], [-4, -1, 2, 0], [4, 0, -4, -4], [-1, -4, 1, 2], [-1, 0, 2, -3], [-10, 2, -7, -1], [9, -4, 2, 1], [-3, 1, 1, -4], [0, 2, 1, -7], [-8, -2, 2, 6], [-6, 2, 4, -4], [2, 0, -2, -8], [-4, 3, -4, -2], [0, 6, 1, -1], [-3, -2, 2, 3], [9, -3, 5, 2], [-14, 2, -6, -4], [4, -2, 4, 2], [-7, 6, 1, -2], [-3, -2, -4, -3], [-1, -4, -1, 2], [6, 0, 8, 2], [-4, -4, 4, 4], [15, 1, 0, 3], [-3, 2, -3, 0], [-4, 0, -6, 0], [10, -6, 2, -2], [-8, -1, 2, -6], [2, 2, 0, -10], [-13, 9, -4, -3], [5, 1, -2, 5], [0, -4, -4, -2], [-2, 7, -3, 1], [-8, -1, 0, -4], [1, 1, 1, 4], [-8, 11, 1, -1], [-1, 9, -4, 3], [12, -9, -3, -1], [0, -2, -8, 2], [-13, 2, 1, 4], [3, -5, -7, 4], [1, -4, 5, 8], [6, -11, -2, 8], [13, -5, 7, 0], [6, -3, 7, 5], [10, -4, 4, 4], [7, -4, -8, -3], [-2, -1, -4, 12], [0, 1, 1, -3], [2, -6, 5, 3], [-11, 13, -5, -2], [7, 0, 6, -7], [13, 6, 5, 8], [14, 2, 6, 2], [-14, 5, -5, 1], [9, 6, 0, -5], [-4, 0, -4, 8], [-13, 6, 6, 3], [6, -5, 6, 0], [-4, 14, -6, -8], [0, -2, -8, -8], [4, 0, 0, 6], [-2, 6, 6, 2], [-2, 10, -8, -4], [-5, 6, -5, -6], [20, -14, 0, 4], [-11, 1, 4, 7], [-18, 5, -1, -1], [-17, -2, 6, 3], [6, 4, 4, 14], [-7, 3, 8, -5], [-9, -3, -3, -4], [-11, -3, -3, 8], [-12, -6, 1, 13], [4, 8, 6, 8], [4, 6, 10, -2], [19, -1, 9, 8], [7, 5, 3, -10], [-3, 2, 6, -9], [-16, 8, -8, -8], [6, -8, 4, 0], [11, 1, 1, 4], [5, -1, -6, -3], [11, 2, -6, -5], [-20, 4, 2, 0], [-4, -10, 7, 11], [16, -10, 11, 5], [7, -8, 8, -1], [-4, -3, -9, -11], [-20, 5, -3, 3], [11, -3, -3, 2], [4, -10, 2, 2], [-3, 2, 6, -11], [-9, -1, -9, -6], [2, 4, -4, 10], [-8, 2, 1, -5], [-10, -6, -2, -6], [-3, -2, -6, -9], [-6, 0, -9, 1], [17, 0, 5, 4], [-4, -4, 10, -12], [0, 0, -6, -14], [-3, 5, -4, -1], [-5, 2, -7, 4], [14, -7, 9, -5], [-2, 5, -8, -4], [4, -8, 2, 2], [-8, -2, 6, 16], [9, 8, -5, -10], [-4, 8, 12, -2], [-2, 1, 1, 3], [5, 17, -9, -8], [22, 3, -2, -2], [-8, 10, 10, -8], [4, 12, 0, -6], [-20, -1, -1, 9], [7, -8, 4, 15], [-8, -4, 2, -8], [1, 3, -3, -6], [-2, 7, -7, 3], [20, 14, -6, -4], [-4, 18, -7, -13], [-4, 4, 4, -14], [8, -17, 8, 6], [-3, 0, -2, -11], [38, -3, -1, 5], [22, 2, 6, 2], [3, -10, -5, 12], [11, 1, 1, 10], [-8, 10, -3, 5], [1, -6, -8, -9], [9, -2, 3, -4], [-17, 1, -17, 0], [8, 0, 14, 16], [-26, 18, -16, -4], [24, -2, 6, 6], [9, -2, -2, -1], [4, 6, -10, 4], [-15, 9, 1, 6], [21, 5, 4, -1], [5, 4, 4, 15], [-16, -10, -4, -10], [21, -4, 3, 6], [4, 17, 0, -8], [4, -6, -6, -2], [30, -8, 17, 3], [0, 6, -9, -19], [12, 2, 17, 7], [-20, -3, -3, -11], [18, -10, 10, 6], [31, -13, 8, 9], [-35, -6, 1, 0], [12, -4, -14, -12], [3, 4, 9, 0], [-2, -4, 10, -8], [-18, 3, 0, -4], [-8, 6, -8, -16], [0, 8, -2, 2], [-10, -2, 8, 12], [-12, -12, 0, -12], [-35, 4, -4, -7], [34, 2, -3, 5], [-12, 18, -13, -17], [-1, -6, -3, 12], [-31, 5, 0, 3], [-6, -9, 2, 16], [-16, -8, 4, 4], [-14, 6, -7, 7], [-24, -4, 2, -12], [7, 4, 0, -7], [-18, 8, -10, -10], [-8, 0, 8, -6], [17, 12, -9, 14], [12, -4, -6, 16], [13, -9, 17, 12], [-10, 12, -10, -18], [14, 9, 14, 18], [-17, -12, 1, 2], [-10, 4, 12, -8], [-1, -1, -11, 4], [5, -21, -2, -1], [10, 2, 1, 3], [13, -11, 14, 15], [11, -2, -4, 3], [4, 9, -2, 4], [5, 4, -13, -8], [1, -15, 3, 20], [18, -10, -3, -1], [-6, 6, -12, 10], [21, 7, -10, -11], [-6, 1, -16, -18], [5, 4, 7, -4], [-1, -12, 2, 9], [23, -5, 19, -8], [0, -14, -4, 2], [7, 6, -5, 4], [42, -9, 14, 2], [-1, 5, 8, 9], [-3, -4, -17, -12], [-3, 0, -6, -11], [9, -4, 7, 10], [18, 2, 12, 0], [-3, -6, 14, 25], [34, -20, -10, 2], [-9, 6, -2, -5], [8, -4, -2, -8], [-23, -2, 1, -8], [-6, 1, -1, -13], [15, 8, -12, 3], [3, -12, 1, 6], [-4, -6, 7, 21], [-11, 2, 3, -12], [-24, 2, 8, -4], [-36, 6, -16, -12], [-17, 3, -10, -1], [-12, -4, 0, 24], [-2, 2, 4, -14], [6, 10, -8, 8], [-8, 25, -8, 0], [-18, -6, -16, 0], [19, -18, -16, -7], [-24, 14, -9, -1], [-5, -25, 12, -1], [-4, -15, 9, 7], [10, 2, 2, 12], [-10, -21, 6, 4], [-41, 4, -16, -9], [26, -2, 18, 0], [8, -23, 15, 3], [-38, 14, -4, -2], [12, 12, -12, -12], [1, -16, -1, -10], [-39, 6, -9, 6], [-3, 13, -2, 7], [-29, 6, -7, 4], [-8, -19, -1, 1], [-41, 9, -2, -3], [-22, -2, 0, 14], [4, -6, 2, -10], [7, -10, 4, 15], [6, 1, -1, 19], [-19, 17, -22, -1], [8, 0, -12, -22], [12, -14, 11, -9], [-5, -15, -2, 13], [6, 2, 16, -6], [-10, 1, 0, 4], [-36, -7, 5, -7], [-6, 15, -1, 7], [24, -10, -8, 14], [18, 8, 4, -10], [-11, -15, 8, 5], [6, -20, 2, 4], [-39, -2, -11, 14], [-11, -13, -3, 2], [-5, -17, 0, 1], [43, 2, 7, 2], [-8, 10, 8, -4], [38, 10, -11, -11], [16, 6, -4, -16], [7, 23, -4, 13], [-43, 10, 7, -8], [8, 6, -8, 14], [21, 10, -11, 22], [1, -3, -19, -8], [-37, 11, -4, -5], [-20, 18, 8, -12], [-7, -13, -5, 18], [-29, 14, -14, -13], [3, 22, -11, 2], [-55, -1, 2, 3], [-6, -4, -4, 20], [-28, 4, -10, 8], [-10, 8, -18, 12], [3, -14, -13, -16], [-24, -6, 5, 15], [26, -10, -4, 6], [-12, -9, 8, 26], [5, -3, -7, -10], [-22, 17, -15, -7], [4, 24, -6, -20], [15, -8, 18, 11], [-16, 25, 2, -2], [8, -10, 19, 5], [-25, -4, 7, 8], [-13, 1, 10, -17], [34, -18, 24, 6], [-20, -4, 0, 2], [20, 19, -1, 1], [-25, -2, -6, -9], [-36, 2, -9, 5], [12, -12, 2, -14], [3, -22, -4, 13], [-14, 10, 0, 20], [-57, -9, 7, 16], [-4, -18, 1, 13], [28, -10, 21, 3], [-15, -8, -4, 13], [-13, -12, 5, 20], [17, 14, 0, 9], [-20, -22, -2, -12], [-7, 0, 9, 4], [-3, 8, 13, 8], [-23, 23, 6, -11], [28, 8, 12, -2], [-26, 8, 6, -8], [42, 8, 10, -2], [36, -8, 16, 4], [-24, 32, 0, -8], [28, -21, -9, 1], [19, -25, 3, 22], [33, -10, -1, 6], [-9, -22, -4, -9], [-7, 20, 13, 10], [26, 5, 8, -4], [-18, 6, -22, 12], [34, 8, 4, -8], [28, -22, 11, -1], [4, 0, 12, 2], [-38, -14, 6, 10], [-24, 4, -10, -6], [-16, 14, -1, 5], [12, 11, -13, -3], [4, -10, -10, 24], [28, 20, -12, -6], [65, -6, 5, 8], [18, -17, 6, 4], [11, -23, 0, 19], [-2, 21, 2, -14], [-58, 4, 8, -2], [-2, -20, -9, -13], [-1, -2, -12, -15], [-36, -16, 8, 8], [-13, -14, -4, 23], [-21, -4, -4, -3], [36, -7, -11, 5], [6, -16, 18, 14], [-29, -19, 8, -15], [-58, -2, -10, -8], [-6, -2, 12, 26], [-13, -4, -19, -24], [-2, 6, 16, 6], [8, 1, -11, 15], [26, 5, -2, 8], [-2, -12, -8, -2], [-32, -4, -16, 4], [-2, 10, -12, 18], [-35, 9, -13, -20], [-10, -26, -5, -19], [11, 0, -13, 12], [-3, 14, -6, 17], [-45, 8, -10, 3], [-14, 10, 11, 3], [-17, 7, -6, -9], [3, 10, -13, 6], [-15, -19, 8, 9], [-9, 2, 4, 19], [-18, 1, -7, -11], [30, -16, 24, 8], [50, 6, -10, -4], [28, 0, 0, 8], [33, 8, -13, -24], [-20, -2, -4, -12], [20, -3, -8, -2], [-4, -10, 14, 32], [58, 2, 2, 6], [35, -13, -10, 5], [28, -8, 14, -18], [38, -12, -4, 10], [-16, 6, -12, -12], [0, 16, -2, 4], [-59, -4, -3, 10], [28, -6, 12, 14], [34, 9, -2, -18], [16, 18, -20, -24], [-12, -7, -1, -9], [-22, 24, -6, 6], [26, 9, 10, 6], [10, -28, 10, -2], [37, 8, -8, -15], [-1, -12, 19, 26], [28, -5, -15, 5], [1, 31, -18, -15], [37, -14, 1, 0], [-19, -22, 8, -25], [-18, -21, -4, -14], [2, -2, -4, -8], [8, 4, -10, -30], [40, 2, 14, 14], [-39, 18, 9, -6], [-15, 16, 8, 1], [-3, -6, 20, 7], [-3, -12, -9, -24], [-5, 9, 9, 14], [-60, 18, 0, -4], [-73, -2, 0, -1], [20, -18, 24, 8], [31, 18, 0, 1], [9, -11, -12, 1], [50, 9, -6, -16], [1, 0, 20, -19], [41, -27, -8, 9], [-27, -1, -11, 16], [15, 14, -1, 16], [31, -39, 2, 15]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3936_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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