
// Make newform 1512.2.a.m in Magma, downloaded from the LMFDB on 08 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1512_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_1512_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_1512_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 := [-3, 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_1512_a();"
function MakeCharacter_1512_a()
    N := 1512;
    order := 1;
    char_gens := [1135, 757, 785, 1081];
    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_1512_a_Hecke( : Kf := Kf)
    return MakeCharacter_1512_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], [-2, 1], [1, 0], [0, -3], [0, 2], [-4, 0], [1, -4], [-2, 1], [-2, 4], [-5, 2], [3, -2], [-4, -3], [2, 2], [-2, 2], [-8, 0], [-6, -2], [4, 4], [-12, 2], [-6, -5], [-2, 6], [-2, -6], [6, 4], [-16, 1], [-8, 4], [0, 0], [-9, -2], [0, 2], [7, 2], [0, 2], [-4, -6], [-2, -6], [10, 0], [0, -4], [20, -2], [-14, 4], [12, -6], [4, 6], [0, -2], [-2, -7], [-8, -2], [-10, -4], [14, 7], [6, 12], [0, -2], [-7, -2], [2, 0], [3, 2], [4, 10], [8, 4], [4, 2], [16, 6], [-14, -2], [8, -4], [-12, 7], [6, 5], [6, -9], [-16, 4], [7, 6], [-6, 10], [8, -4], [-12, 4], [13, -4], [-6, -8], [-16, -6], [30, 2], [8, -4], [-1, -4], [-12, -13], [2, -4], [0, -17], [24, -2], [5, 10], [-13, 2], [6, 10], [12, -2], [-4, 16], [10, 8], [18, 12], [6, -2], [-8, 14], [-17, 2], [-6, 11], [-8, 10], [0, -16], [-8, -1], [20, -10], [1, 8], [18, 9], [-10, 4], [-18, -10], [8, -8], [-2, -18], [12, 11], [-14, 6], [14, 0], [12, -4], [-12, 1], [-1, -12], [-17, -14], [28, -4], [-4, -2], [-34, 4], [0, -10], [-22, 0], [-18, -12], [8, 18], [0, -19], [2, 7], [-20, -6], [-8, 4], [-11, -18], [6, -6], [21, 12], [-22, 14], [-4, -22], [25, 12], [-6, 10], [34, 2], [-32, 5], [-4, 26], [-38, 4], [-6, -21], [-24, 3], [8, -8], [26, 8], [-17, -2], [6, -6], [-4, -12], [-2, -14], [-2, 24], [-2, -21], [-10, -18], [-14, -12], [0, -8], [-8, -22], [-22, 7], [4, -16], [-42, -5], [18, 16], [9, -4], [-42, -6], [-10, -8], [0, -15], [-10, -6], [18, 12], [-32, -4], [-12, 17], [37, 4], [16, -10], [26, -8], [8, -17], [28, -4], [-18, 16], [-22, 12], [-16, -2], [4, -4], [-16, -4], [24, -12], [-30, -15], [-16, -7], [-34, -4], [18, 16], [2, 20], [-12, 20], [-42, -2], [-24, 10], [10, 16], [27, 4], [14, 9], [32, -2], [-30, 10], [24, 14], [13, 4], [-27, 14], [4, -11], [-16, 0], [12, -14], [-11, -14], [52, 4], [-14, -12], [-20, -2], [-47, -6], [8, 4], [-42, -7], [6, 17], [-10, 28], [20, -16], [57, 0], [12, -4], [8, -10], [-12, -2], [14, -28], [0, -32], [8, 5], [24, 3], [19, 0], [38, 4], [44, 3], [-16, 6], [22, -8], [-9, -2], [-10, -22], [-20, -8], [30, 20], [12, -20], [-28, -12], [36, -19], [-14, -6], [-8, 28], [45, -12], [-30, 17], [22, 26], [6, 6], [16, 24], [24, 8], [-12, -6], [16, 5], [-6, 5], [-16, 28], [-18, -16], [40, -8], [46, -12], [18, 26], [-64, -2], [23, -2], [0, 35], [34, -15], [7, 14], [-36, 3], [19, 2], [47, 0], [-32, 2], [-4, -14], [13, -24], [42, -4], [-34, 12], [-18, 4], [44, -6], [-6, -40], [-8, 31], [-67, 4], [35, 6], [-23, -18], [-48, -9], [14, -22], [19, 18], [46, -4], [-12, -18], [-50, 13], [14, 0], [-32, -4], [-28, -6], [42, 0], [26, -13], [-12, 29], [-19, 30], [-13, -16], [12, -24], [66, -2], [2, -22], [-12, 15], [0, -34], [-2, 6], [-24, -15], [-43, -12], [-22, 0], [8, -8], [30, 8], [-6, 4], [10, 14], [-8, 8], [-28, -26], [-36, 10], [-6, -14], [-55, -10], [-20, 5], [46, 16], [50, 0], [30, 0], [6, 10], [38, 12], [24, -2], [42, -2], [23, 20], [-54, -17], [-15, 12], [-46, -6], [-15, 10], [0, 21], [24, -18], [38, -18], [-26, 0], [-52, -6], [-25, 22], [26, 5], [-21, 30], [-8, 0], [-54, -16], [11, -24], [-34, -24], [-42, 0], [54, 8], [-36, -3], [-18, 16], [23, 4], [24, -13], [10, -26], [14, -41], [-79, -6], [28, -14], [-14, -2], [-64, 8], [-32, 14], [-14, 13], [16, -8], [2, 16], [-58, 9], [-20, -12], [18, -30], [-28, 16], [47, -8], [-42, -7], [-38, 30], [40, 0], [20, 24], [34, -20], [43, -8], [0, -18], [-84, 2], [-39, 14], [-48, 22], [-29, 14], [-34, 16], [-16, -26], [-32, 16], [1, -2], [-16, 27], [38, 6], [37, -2], [15, -2], [78, -4], [0, -48], [32, -2], [-50, -22], [-12, 6], [10, -2], [-44, -6], [14, 12], [-32, 8], [35, 4], [-26, 8], [12, -28], [51, -2], [3, 10], [-12, -13], [30, 34], [-20, 24], [-30, 10], [-48, -10], [2, -8], [-48, -17], [12, -6], [-24, 17], [-24, 12], [23, 28], [54, -15], [42, 16], [25, 16], [28, -17], [-31, 0], [0, 42], [2, 6], [25, -18], [-69, 10], [26, -2], [36, -34], [-46, -4], [-8, 1], [4, 10], [38, 13], [-44, 26], [-8, 38], [18, 18], [-73, -12], [-42, -14], [-58, 16], [8, 4], [32, -12], [-52, -20], [-58, -20], [-10, 5], [0, -27], [-24, -24], [-40, 26], [-85, -4], [61, 18], [8, -13], [34, 6], [30, -28], [-30, 14], [-2, -4], [-30, 16], [24, 5], [46, 21], [-37, -18], [-1, -30], [26, 24], [-21, 12], [36, 4], [-36, -20], [-66, 14], [16, -30], [-44, 24], [6, 40], [-18, 29], [38, -7], [40, -12], [-48, 8], [-4, -26], [12, 16], [20, 36], [-18, 7], [-30, 6], [78, 12], [60, 16], [44, -6], [0, -12], [-79, 0], [-10, 52]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1512_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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