
// Make newform 1536.2.a.l in Magma, downloaded from the LMFDB on 24 August 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_1536_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_1536_2_a_l();".
// 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_1536_2_a_l();".
// 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, 0, 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_1536_a();"
function MakeCharacter_1536_a()
    N := 1536;
    order := 1;
    char_gens := [511, 517, 1025];
    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_1536_a_Hecke( : Kf := Kf)
    return MakeCharacter_1536_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], [2, -1], [2, 0], [0, -2], [-2, -4], [0, 4], [4, 2], [2, 1], [6, 1], [-4, 4], [-6, 4], [-4, -4], [4, -6], [2, -7], [-4, 0], [-4, 4], [-8, 0], [12, 2], [4, 4], [10, 3], [-2, -8], [2, 0], [2, -8], [-2, 11], [2, -5], [-4, 8], [-16, -2], [6, 0], [-6, -9], [-4, 0], [10, 4], [8, -8], [10, -3], [6, 1], [-20, 0], [12, 4], [-16, 4], [6, -9], [-4, 0], [0, -6], [0, 12], [-16, 4], [10, 5], [2, 11], [-8, 8], [-2, -7], [18, -8], [-8, 6], [-2, -8], [0, -12], [-12, 4], [-22, 0], [10, 8], [-8, 4], [-2, 3], [-18, 1], [-16, -6], [-2, 0], [4, -8], [18, -7], [-16, 0], [0, -8], [0, -12], [-2, -5], [0, 0], [4, -12], [14, -8], [-12, -8], [-2, 8], [4, 14], [-10, 9], [4, 20], [-24, -4], [-8, 8], [-18, 3], [-4, 0], [-26, 4], [-10, -8], [10, 8], [8, -10], [4, -22], [6, 16], [-6, 7], [6, 24], [-2, 4], [-6, 8], [-18, -5], [18, 11], [2, 8], [4, 6], [10, 11], [-12, -8], [12, -8], [4, 6], [2, -15], [6, 12], [32, 4], [-8, -2], [12, -12], [-6, 5], [-6, 16], [2, -12], [-20, 0], [0, -20], [-20, -8], [-2, 0], [20, -6], [0, -4], [-6, 7], [12, -16], [-10, 24], [4, 0], [26, -5], [26, -12], [-4, -20], [-20, -2], [22, -1], [-28, -8], [28, 8], [14, -16], [-14, -15], [-14, 8], [-12, 4], [6, -1], [0, -22], [28, 2], [-18, -3], [32, -6], [12, -16], [40, 0], [18, -9], [24, 6], [30, 4], [-8, 4], [6, -9], [16, 4], [34, 1], [-22, 12], [-24, 4], [-18, 19], [18, 15], [4, -24], [-16, -26], [20, 6], [12, 16], [2, 28], [28, 12], [32, -12], [-12, -8], [34, 8], [36, -4], [-24, -4], [12, 28], [40, -8], [18, -25], [-10, 28], [14, 16], [-2, -13], [-12, -16], [14, 12], [6, -3], [18, 8], [-2, -20], [24, -20], [2, 7], [-4, 12], [-34, -8], [38, -9], [-28, 24], [36, 12], [0, 28], [-26, 0], [10, -5], [-18, -16], [-20, 8], [-54, 5], [-6, 15], [20, 24], [-54, 3], [-26, -8], [-8, -6], [54, 0], [8, 16], [-26, -25], [8, 30], [28, -24], [28, -12], [-8, -12], [-2, 16], [-12, 0], [4, 8], [-34, 11], [-20, -16], [-26, -8], [32, 12], [-16, 10], [-18, -16], [-8, 4], [34, 17], [10, -9], [8, -30], [-20, 4], [30, 0], [26, 5], [6, -3], [18, 16], [14, -16], [36, -12], [8, 4], [-14, -15], [10, 15], [-12, 32], [20, 6], [18, -16], [-34, -27], [-14, 28], [8, 32], [34, 25], [24, -14], [-2, 33], [10, 28], [6, 45], [6, 40], [52, -12], [10, -24], [-4, -14], [-66, 1], [-20, 24], [24, -14], [4, 4], [18, 27], [46, 0], [4, 4], [-20, 10], [2, 40], [-6, 21], [26, -24], [-4, -18], [26, 0], [-8, -40], [46, -11], [-36, 16], [-34, 24], [-4, 2], [-22, 27], [-36, 8], [24, 24], [16, 16], [-48, -10], [30, 16], [-20, -34], [10, -32], [-22, -11], [28, 8], [32, -10], [-28, -8], [2, -7], [-42, 0], [2, 19], [44, 0], [-8, 42], [12, 24], [-22, 4], [-24, 24], [2, 1], [14, -32], [56, -12], [-6, 13], [12, -4], [-20, -40], [-6, 16], [-10, 9], [-18, 16], [-2, -47], [-10, 0], [-4, -24], [-8, -20], [20, -24], [44, -22], [58, -1], [-20, 30], [-20, -8], [-56, 4], [-40, 4], [-28, -12], [42, -19], [66, 7], [30, 24], [-10, -9], [20, -32], [18, -8], [36, 0], [-28, -24], [62, -5], [-2, -15], [-2, 27], [54, 16], [0, -12], [-40, -28], [14, 11], [42, 3], [-4, 32], [-28, -36], [-4, -28], [74, 0], [-8, 30], [28, -22], [-36, -24], [-8, 48], [30, -21], [-22, -12], [-16, 12], [64, 0], [-10, -32], [-44, -24], [36, -18], [-44, -12], [2, -32], [4, 56], [72, 4], [-62, -15], [6, -7], [-14, 28], [-34, -8], [80, -4], [-12, -20], [-40, -12], [-10, -25], [0, -10], [2, -15], [-2, 33], [44, -24], [0, -24], [-10, 32], [12, -24], [18, -8], [36, 20], [-2, 33], [20, 12], [-18, 36], [58, -19], [62, -23], [50, -7], [2, 16], [-24, -6], [56, -8], [-4, 10], [-14, -7], [16, 36], [-26, 24], [26, -27], [6, -43], [-28, 20], [-54, -8], [0, -28], [-44, 8], [34, -28], [88, 4], [4, -32], [2, -16], [24, 16], [-26, -16], [-76, -8], [40, 12], [6, 15], [-38, 11], [-14, 48], [-18, -16], [40, -4], [8, -20], [-14, 33], [-2, 5], [-16, 18], [-6, -48], [16, -12], [10, 0], [-38, 36], [36, 20], [-26, 23], [14, -12], [22, -39], [18, -32], [-20, -36], [0, 28], [-30, -1], [-72, -2], [-40, -24], [4, -6], [-2, 16], [-42, -1], [-68, -16], [40, -12], [8, 16], [58, 8], [34, 11], [-34, -44], [24, -44], [38, 23], [-4, -16], [-30, 4], [-34, 17], [-62, -12], [-42, -25], [46, 29], [-40, 2], [-2, -28], [16, 36], [-6, -48], [48, -4], [10, 45], [-30, 16], [-60, 28], [28, 4], [6, 39], [-32, -44], [-6, -5], [-10, -4], [-12, 14], [10, -43], [-60, 12], [16, -56], [34, -24], [40, -44], [70, -1], [-14, -24], [50, 16], [12, -44], [-4, -58]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1536_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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