
// Make newform 1230.2.a.m in Magma, downloaded from the LMFDB on 14 July 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_1230_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_1230_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_1230_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 := [-4, -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_1230_a();"
function MakeCharacter_1230_a()
    N := 1230;
    order := 1;
    char_gens := [821, 247, 211];
    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_1230_a_Hecke( : Kf := Kf)
    return MakeCharacter_1230_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 := [[-1, 0], [1, 0], [1, 0], [1, 1], [2, 0], [0, -2], [4, 0], [-3, 1], [1, 3], [6, -2], [-5, 1], [3, -5], [1, 0], [1, -1], [4, 2], [1, -3], [3, -7], [-8, 2], [4, 0], [-4, 4], [-2, 4], [4, 0], [4, 0], [7, 3], [-2, 2], [-10, -2], [0, -4], [10, 2], [11, -3], [3, -9], [0, 4], [-3, -1], [16, 0], [2, 6], [2, -6], [2, -6], [2, 4], [-12, 0], [8, -2], [-6, 12], [-20, 2], [-15, 3], [-7, 3], [11, 5], [16, -2], [-18, -2], [8, -10], [-16, 4], [5, -5], [-2, -10], [-22, 2], [11, 5], [3, -1], [-8, -4], [-6, 2], [-4, -2], [-13, 7], [-29, 1], [-15, 9], [-15, 1], [12, -8], [-7, 1], [3, -11], [-20, 8], [7, -7], [-3, -7], [-5, 7], [6, 4], [-7, 7], [-22, 4], [13, -3], [-24, 8], [-14, -2], [-6, 8], [0, 12], [-18, 4], [15, -1], [14, -4], [-8, -2], [-11, -3], [-13, -7], [18, -6], [-32, 0], [-4, -10], [26, 2], [2, 2], [0, 6], [-30, 2], [7, -1], [-12, 10], [-2, 6], [-1, -11], [0, -8], [12, -8], [12, -2], [-4, -14], [-10, 14], [10, 4], [3, 5], [26, 4], [4, 0], [-2, 0], [-9, 5], [4, -18], [25, 5], [-11, -1], [13, 7], [6, 10], [0, -8], [20, 2], [-6, -6], [14, -4], [-6, 12], [-6, -6], [5, -17], [15, 7], [2, -2], [0, -12], [-18, 8], [20, 6], [-4, 10], [-5, -11], [2, 0], [-9, -3], [-8, 10], [11, -13], [7, 1], [1, -13], [-31, 5], [33, -3], [24, -8], [24, -8], [2, 6], [-16, 10], [40, 2], [19, -9], [-38, 0], [31, 9], [14, 16], [33, -3], [-42, 6], [35, -5], [21, -15], [15, 5], [-16, -2], [-25, 9], [-1, -1], [-2, 16], [26, -10], [-39, 11], [-9, -5], [-2, 0], [-10, 2], [26, -12], [27, -11], [-30, 6], [-20, 16], [29, -19], [-27, -9], [-17, -1], [-22, -14], [6, 0], [1, 5], [2, 12], [-8, 4], [-5, 21], [-24, 0], [-46, -4], [-31, -3], [1, 5], [12, -2], [24, 2], [-17, -3], [50, 4], [6, 2], [27, -9], [17, 9], [11, 19], [0, -22], [14, 14], [24, 0], [-28, 4], [-30, 16], [25, -11], [41, -13], [-18, 12], [-30, 12], [4, 0], [14, 0], [13, -1], [0, 6], [-15, -9], [-14, 22], [23, -21], [20, 16], [10, 4], [24, -2], [-50, 0], [44, 0], [28, -10], [38, -4], [32, -8], [-40, -10], [-12, -6], [22, 4], [14, -24], [24, -16], [-33, 5], [8, 6], [58, -6], [-18, 30], [-32, -8], [-10, 22], [34, 10], [59, -3], [-23, 25], [16, -18], [56, 2], [-36, 6], [12, -10], [42, 2], [-16, -8], [-37, -13], [-3, -11], [18, 18], [-9, -3], [49, -11], [4, 20], [-48, 6], [29, 7], [7, -5], [15, 11], [-39, 11], [22, 0], [-10, 30], [12, -2], [-62, 4], [-22, 16], [5, -21], [-32, 12], [17, -5], [-13, -13], [32, -6], [10, 8], [-13, 11], [-12, 4], [-16, -20], [-32, 2], [58, -2], [-52, 0], [-42, 16], [18, -20], [31, 1], [-1, -17], [33, -3], [29, 3], [11, -27], [60, 0], [-49, -1], [-11, 15], [-42, -10], [16, 0], [9, -5], [-20, 14], [-1, -1], [-32, 16], [12, 4], [6, 20], [3, -19], [14, 16], [-26, 22], [12, 16], [-16, -26], [-32, 32], [-19, 19], [-22, 18], [16, -8], [-15, -17], [-38, 28], [38, 12], [48, -6], [-2, 18], [15, -19], [-32, 18], [58, 6], [-15, 3], [65, -1], [-36, 18], [-2, 18], [23, -25], [28, 0], [12, 0], [78, -2], [-9, 33], [-28, -18], [-36, -4], [2, -22], [26, 0], [-4, -30], [26, 6], [32, -10], [34, -12], [13, 15], [-32, 0], [-24, -12], [-12, 10], [64, -4], [-20, -22], [12, 0], [-28, -22], [28, -22], [-18, -2], [-38, 24], [68, 8], [-7, 15], [3, 11], [-5, -23], [-4, 4], [17, 23], [-46, -8], [12, -4], [14, -24], [-9, -9], [-8, 22], [-45, -9], [-22, -24], [1, -19], [-44, -12], [-8, -14], [6, 4], [-37, -11], [26, 4], [-19, -17], [21, 11], [22, 18], [-55, 7], [15, -3], [51, 3], [22, 16], [-58, 2], [10, 12], [10, -16], [-60, -12], [60, -4], [24, 14], [-44, 16], [-36, 30], [25, -17], [21, 11], [20, 26], [-36, 6], [6, -8], [56, 12], [-22, 30], [7, 21], [-26, 26], [-32, 32], [-31, -9], [23, -41], [19, -11], [-13, -13], [21, 17], [78, 4], [-28, -12], [-10, -22], [7, 9], [61, -7], [-34, 30], [25, 25], [-24, 30], [19, -41], [33, -9], [-18, 10], [-17, 5], [34, -40], [11, -15], [34, -10], [6, 20], [-77, 7], [-78, 6], [10, -6], [21, -11], [-10, 10], [35, -37], [-13, 11], [8, 12], [-18, 6], [-70, 0], [-36, -24], [-14, -8], [12, 6], [-17, -5], [16, 30], [13, 19], [64, -8], [-9, -19], [-36, 4], [-34, 24], [-16, -24], [-42, 10], [10, -20], [-86, 10], [30, -18], [-24, -8], [18, 4], [-56, 24], [-46, 12], [27, -9], [2, 2], [-20, -24], [36, -18], [46, 12], [9, -33], [52, -2], [87, -11], [29, 25], [14, 10], [-3, 5], [-84, -4], [3, 1], [39, -9], [0, -10], [-32, 32], [-82, 8], [-8, 22], [-66, 20], [8, 4], [-39, -11], [-7, -31], [-15, -29]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1230_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1230_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_1230_2_a_m(:prec:=2)
    chi := MakeCharacter_1230_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_1230_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_1230_2_a_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1230_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-2, -3, 1]>,<11,R![-2, 1]>,<13,R![-16, 2, 1]>],Snew);
    return Vf;
end function;