
// Make newform 1230.2.a.p 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_p();".
// 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_p();".
// 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;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [1, 1];
    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_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], [3, 1], [0, 0], [-1, -1], [-1, -3], [-2, -2], [-3, -1], [-4, 0], [4, -2], [-1, 0], [0, 0], [7, -1], [0, 4], [-4, 4], [2, 0], [-8, 0], [8, 2], [0, 6], [-4, -2], [0, -4], [0, 2], [-11, -3], [-7, -1], [-8, -4], [0, 0], [-5, 5], [6, -4], [8, 4], [-2, 2], [-3, 1], [-4, 0], [-3, -5], [8, -2], [0, 0], [-4, 4], [15, -1], [6, 4], [9, 3], [-3, -9], [8, -2], [-9, 3], [6, 4], [0, 6], [1, 3], [-10, -6], [12, 4], [-17, -3], [-5, 7], [-6, 0], [8, 2], [0, 0], [11, -1], [17, 5], [-12, 2], [2, 6], [16, -2], [12, -2], [-16, 4], [6, 2], [8, 12], [-6, -4], [-9, 3], [12, 0], [-3, -9], [2, -8], [8, -8], [-26, 0], [-4, -14], [-6, -6], [10, 6], [-8, -2], [-2, -2], [1, 1], [4, 14], [-6, -6], [-16, 2], [-16, -10], [24, 0], [-5, 9], [2, 10], [0, 6], [-12, -6], [20, -8], [-32, -2], [15, 3], [-6, 8], [13, 5], [16, -4], [12, -6], [0, -12], [-2, -14], [-9, -3], [15, -5], [21, 7], [-40, -2], [-4, 12], [12, -6], [-4, 0], [-2, -14], [-6, -10], [-6, -12], [23, -3], [25, 5], [6, 6], [33, 1], [24, 4], [8, -14], [14, -6], [-4, -6], [0, -10], [-10, 14], [22, 6], [-18, -8], [26, -2], [26, 10], [22, 10], [19, 13], [-28, 2], [3, -9], [6, -12], [2, 10], [-17, -15], [-28, -10], [7, -3], [-8, -10], [23, -1], [4, 6], [10, -14], [6, 14], [30, 0], [26, 10], [-26, 8], [12, -6], [-12, 12], [-28, -4], [6, 8], [6, 8], [28, 0], [10, 8], [35, 3], [2, -2], [22, 8], [6, -12], [24, -6], [-32, -2], [-22, 10], [8, -8], [32, -6], [-32, 2], [14, -10], [-9, 15], [-28, -8], [-32, -8], [32, 10], [-8, -10], [13, 9], [-30, -8], [12, 8], [-24, 6], [-41, -1], [-27, 7], [-9, -1], [-30, -6], [10, 20], [32, 8], [46, 0], [12, -4], [39, -7], [14, -4], [24, -10], [-14, 20], [-10, -4], [0, 10], [5, 3], [-24, 2], [-9, 15], [23, 1], [-32, -12], [8, 8], [30, -6], [-40, 2], [-12, -12], [30, -4], [28, -2], [4, -12], [-20, 18], [8, 2], [-34, -8], [4, -4], [14, 6], [-28, -14], [-24, 4], [-30, 16], [20, 6], [-8, -8], [-33, -13], [9, 13], [-6, 0], [10, -6], [-20, 20], [-16, 2], [-17, -7], [-54, -6], [2, 6], [-30, 2], [40, -10], [-50, -2], [-13, -9], [3, 21], [-32, 12], [40, -4], [-6, 12], [-8, -10], [-15, 21], [6, 12], [-15, -7], [-14, -16], [3, 9], [-46, -6], [30, 0], [-11, 17], [24, 0], [-11, 7], [-42, 0], [-6, 18], [-23, -19], [70, 2], [52, 2], [-19, 15], [-2, -22], [0, -18], [16, 12], [21, 13], [-4, -6], [36, 0], [-54, -2], [6, -20], [58, 2], [15, 21], [-29, 7], [8, -14], [-34, -8], [40, 4], [-2, 18], [-33, -7], [2, 2], [-12, -12], [-12, -6], [48, -2], [-6, 18], [-10, -16], [32, 20], [30, -6], [15, -15], [-32, 0], [24, 16], [5, -11], [14, -6], [-18, 6], [-7, -9], [30, -6], [30, 8], [26, 18], [15, 9], [2, 20], [4, 4], [14, -2], [3, -3], [-4, -20], [28, -18], [-32, 4], [23, -17], [-2, 18], [-6, -18], [31, 13], [-4, 30], [19, -23], [9, 9], [14, -8], [12, -4], [68, 6], [-30, 6], [28, -2], [-29, 7], [34, -20], [-22, 20], [18, -24], [33, -21], [8, 16], [51, -9], [12, 4], [22, -2], [3, -7], [0, 18], [22, -8], [5, -25], [-2, -30], [-14, 12], [6, -10], [56, -8], [30, 18], [10, -6], [18, -12], [-72, -4], [4, -6], [30, 8], [4, 12], [59, 7], [-11, -1], [18, 4], [76, 4], [-6, -14], [-22, -28], [-26, 2], [-18, -30], [-29, -13], [30, 4], [-6, 18], [-38, 4], [18, -8], [1, 5], [16, 14], [-30, 12], [67, -7], [-38, -6], [-31, 13], [54, 0], [23, -11], [22, 4], [-28, -8], [-32, -16], [-36, 24], [12, 20], [5, 15], [-66, -8], [-40, -22], [8, -12], [48, 0], [-80, 2], [-45, -7], [50, 0], [-26, 8], [-16, 8], [-52, 6], [4, 24], [-18, -28], [42, 20], [-65, -7], [-22, 12], [13, 23], [-60, 0], [37, 11], [21, 13], [-30, -18], [-12, 12], [36, 22], [-72, -8], [40, 6], [-42, -20], [-75, 1], [60, -4], [2, -22], [-13, -21], [8, -28], [-10, -30], [-80, 2], [57, -13], [5, 3], [8, 16], [-9, -3], [-48, 0], [6, -42], [10, 22], [-52, 8], [-28, 10], [-36, 18], [5, -11], [-47, -17], [-6, -8], [10, -18], [0, -6], [19, 37], [-74, -2], [-8, 2], [2, -14], [-64, -4], [-87, -3], [-74, -12], [30, -6], [5, -1], [8, -12], [26, -2], [-11, -3], [58, 12], [8, -2], [-8, -36], [-21, -27], [-72, 6], [19, -5], [8, -12], [21, -31], [18, -12], [-22, 0], [48, -6], [0, -18], [4, 24], [30, -30], [-50, 4], [2, 16], [-12, -16], [67, 13], [49, 13], [20, 14], [36, 4], [-47, 17], [-51, -15], [-14, 34], [-66, 12], [40, -12], [60, 12], [-63, 11], [4, -18], [-42, 16], [0, 24], [54, -4], [-35, -9], [-68, 14]];
    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_p();".
// 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_p(: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_p();".
// 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_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1230_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-4, -2, 1]>,<11,R![4, -6, 1]>,<13,R![0, 1]>],Snew);
    return Vf;
end function;