
// Make newform 1230.2.a.b 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_b();".
// 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_b();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [1], [-1], [-1], [6], [-4], [0], [5], [-3], [6], [-1], [-7], [-1], [11], [12], [9], [9], [8], [-4], [12], [2], [-16], [12], [-15], [2], [6], [-4], [-18], [-13], [15], [8], [15], [12], [14], [6], [-10], [-10], [20], [-12], [-18], [-24], [17], [-9], [5], [12], [14], [8], [-4], [-27], [-10], [-6], [-27], [-25], [-24], [-18], [12], [9], [-25], [-13], [15], [-4], [9], [-7], [12], [-31], [-27], [-13], [14], [9], [14], [9], [12], [-10], [14], [-4], [6], [-3], [14], [12], [-7], [-15], [2], [24], [-28], [-10], [-42], [12], [38], [-3], [-4], [-42], [-15], [8], [12], [-4], [-24], [-18], [-18], [-7], [14], [44], [30], [-33], [12], [-7], [11], [-3], [42], [0], [-28], [14], [2], [18], [26], [17], [9], [-22], [-24], [30], [48], [-40], [29], [18], [15], [-40], [9], [23], [-33], [-1], [35], [-4], [0], [38], [-16], [0], [-1], [18], [5], [18], [39], [26], [-39], [-37], [-33], [-28], [9], [-19], [6], [-10], [21], [29], [-30], [-46], [-18], [-31], [-6], [20], [51], [11], [21], [6], [6], [23], [18], [-12], [15], [20], [26], [-43], [-39], [60], [-40], [-39], [-22], [-34], [-27], [17], [9], [8], [-10], [32], [60], [-22], [-3], [45], [42], [-34], [-28], [38], [51], [8], [9], [2], [-3], [-48], [-6], [-16], [-10], [12], [-24], [-30], [-64], [8], [8], [-54], [30], [-64], [-9], [0], [14], [50], [-36], [62], [18], [21], [-19], [-40], [-36], [-36], [-48], [-46], [32], [-3], [-13], [-30], [-1], [-27], [-24], [-64], [15], [29], [-49], [5], [30], [26], [0], [-22], [-6], [-57], [72], [9], [11], [32], [-70], [39], [72], [68], [36], [-34], [60], [-22], [-6], [-69], [-37], [-63], [39], [11], [8], [-9], [35], [26], [24], [-31], [-4], [-69], [56], [-48], [66], [-7], [54], [-34], [44], [20], [-40], [35], [-70], [-72], [-31], [-46], [-66], [12], [38], [51], [-28], [-58], [-81], [-49], [-12], [62], [9], [84], [36], [30], [45], [8], [-48], [38], [6], [60], [-82], [-40], [66], [-55], [-24], [-52], [44], [12], [32], [60], [56], [36], [-30], [-54], [-52], [21], [-49], [9], [-72], [-49], [-18], [8], [50], [45], [-40], [-9], [26], [-7], [8], [-36], [-78], [35], [6], [-31], [21], [74], [-63], [47], [-33], [-46], [-70], [-58], [-78], [0], [8], [-24], [-36], [-52], [83], [27], [36], [-4], [50], [-96], [-46], [95], [6], [48], [-93], [-45], [39], [-55], [51], [30], [12], [-58], [-31], [-27], [74], [-43], [24], [-85], [-27], [-30], [-37], [-82], [-39], [-30], [-34], [-3], [-10], [42], [9], [14], [-81], [-37], [0], [-10], [-46], [-28], [-54], [92], [-81], [60], [-25], [36], [41], [-28], [18], [-40], [-30], [86], [42], [-58], [72], [-18], [20], [86], [45], [50], [12], [-28], [-18], [33], [-100], [-31], [63], [54], [59], [-96], [39], [-27], [8], [72], [42], [68], [102], [-48], [-33], [65], [87]];
    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_b();".
// 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_b(:prec:=1)
    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_b();".
// 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_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1230_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![1, 1]>,<11,R![-6, 1]>,<13,R![4, 1]>],Snew);
    return Vf;
end function;