
// Make newform 1185.2.a.g in Magma, downloaded from the LMFDB on 03 June 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_1185_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_1185_2_a_g();".
// 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_1185_2_a_g();".
// 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, -3, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-1, -1, 1, 0], [1, -2, -1, 1]];
    Rf_basisdens := [1, 1, 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_1185_a();"
function MakeCharacter_1185_a()
    N := 1185;
    order := 1;
    char_gens := [791, 712, 556];
    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_1185_a_Hecke( : Kf := Kf)
    return MakeCharacter_1185_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, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0], [-2, -1, -1, 2], [-2, 0, -2, -1], [-2, 0, 3, -1], [2, 2, 0, -5], [-2, -2, 1, -1], [-2, 0, 1, -3], [-6, 1, 0, 5], [-7, 4, 2, 2], [-1, -4, 0, 5], [1, -1, -2, 3], [0, -3, 3, 3], [-1, 3, -2, -2], [-5, 5, 0, -1], [-8, -1, 0, -1], [4, 2, -1, -4], [-1, -5, -5, 5], [-4, -2, 1, 2], [-4, 4, 2, -1], [-1, 0, 0, 0], [-2, 5, 6, -1], [-5, 2, 3, -1], [6, -5, -9, 2], [-1, 7, -1, -3], [4, -6, -5, 4], [3, 0, -10, -2], [6, -5, -1, 0], [-7, -2, 5, 8], [-7, -6, 2, 7], [6, -5, -3, -4], [7, -6, -7, -2], [-4, 12, -1, -6], [-9, 2, 2, -7], [1, -1, -2, 13], [-6, 7, 9, 0], [4, 9, -7, -1], [-11, -6, -5, 14], [15, -2, -6, -7], [-3, 1, 4, -6], [2, 15, 2, -9], [-13, -7, 5, 5], [8, 5, -5, -14], [4, -13, -2, 3], [-6, 8, 6, -8], [1, -7, -4, 3], [-3, 8, -1, -5], [4, 5, 11, -5], [-4, 1, 2, 15], [10, 4, 7, -7], [-7, -2, -8, 8], [-2, -16, 1, 14], [5, 6, 3, -13], [13, -7, 0, -11], [8, 8, 4, -2], [-6, -7, -3, 6], [-3, -6, 9, -7], [14, 2, -15, 8], [11, -5, -16, -4], [13, 10, 1, -6], [16, -15, -4, 1], [-9, 3, 5, -7], [-1, 4, 8, -12], [-17, 1, -1, 4], [1, 10, -1, -4], [-21, 4, 5, 17], [5, 8, -3, -6], [2, 1, -1, 17], [-7, -3, 14, -4], [-13, 0, 7, 19], [1, 2, -6, -7], [7, -6, -7, 9], [16, -15, -2, -8], [6, 1, 0, -4], [-4, 2, 6, -19], [-5, -3, -11, 4], [-6, -1, 9, 8], [-10, -15, -9, 21], [4, 20, 11, -19], [1, -1, -20, -4], [7, -1, -11, -15], [-10, -5, -4, 14], [-8, 6, -3, 1], [2, -13, 3, -3], [16, -4, 1, -24], [8, -22, -4, 8], [7, 0, 8, -6], [11, 23, -5, -9], [1, 4, 3, -1], [3, 1, 14, -9], [11, -7, 4, -11], [-2, -1, 10, 0], [-15, 4, 2, -2], [-24, -11, -2, 16], [-2, -3, 2, 19], [-13, -18, 6, 9], [1, 1, 14, -11], [-7, -12, 1, 18], [1, 2, 4, -4], [5, -1, 10, -14], [14, 3, -12, -1], [9, -1, -5, 6], [-7, -8, -2, 16], [-14, 18, 15, 2], [-11, -3, 22, 7], [-1, 1, 6, 9], [15, -12, -4, 2], [-10, 0, 10, -15], [-11, 2, 7, -11], [-36, 1, 10, 1], [-11, 8, -4, -2], [-11, -13, 2, -3], [15, -4, -8, 2], [-33, 3, -1, 9], [-15, -4, 10, 15], [-5, -8, 0, -2], [14, 31, 4, -22], [-15, -18, -17, 27], [-7, -11, 10, 16], [22, -14, -23, -5], [-1, -11, 5, -1], [3, -9, -18, 4], [3, 0, -12, 15], [15, -15, -1, 7], [-4, -12, -5, 0], [31, 2, -7, -2], [0, -5, 11, -26], [11, 1, -11, -12], [-1, -9, -14, 6], [-20, 11, 17, 6], [-3, 4, 3, -13], [-23, 6, 14, 9], [17, -11, 12, 7], [-14, 21, 24, -8], [15, -27, -3, 11], [-21, 22, 12, -5], [-13, -3, -18, 5], [-8, 21, 1, -5], [14, 1, -4, -21], [-12, 11, 5, -4], [-28, 7, 13, -5], [-29, 15, 19, 4], [17, 11, 5, -10], [31, 5, -9, -3], [-20, -16, -11, 19], [0, 12, -12, -11], [6, -9, -5, 20], [7, -25, -2, 2], [-11, 15, 17, -2], [0, 0, 2, 13], [35, -8, -14, -5], [17, 8, -4, 15], [20, -4, 6, -7], [10, -30, 1, 8], [15, -15, -30, 13], [-2, 33, 1, -17], [28, 5, 6, -9], [2, 13, -16, 14], [-16, -23, -8, 23], [-20, -10, -4, 7], [-18, 24, 5, -15], [13, 10, -12, -32], [19, 9, 6, -12], [-5, 2, 6, 29], [-23, 2, 4, 4], [-25, 6, -6, 0], [-3, -11, -1, 31], [16, 22, -6, -19], [-1, 14, 13, -20], [2, 16, -19, -8], [8, 1, -23, 3], [12, -20, -1, 3], [-13, -2, 19, 4], [-27, 8, -3, 0], [-7, 8, -13, 4], [25, 3, -15, 7], [4, -1, -1, -39], [19, 2, 12, 5], [-4, -9, 4, 20], [7, 19, 9, -30], [-8, -28, 0, 28], [21, 28, -3, -10], [-7, -17, 15, 39], [-34, 1, 7, -14], [-18, 6, 4, 0], [8, 18, -9, 5], [9, 13, -2, -38], [24, 0, -1, 4], [-30, 22, 17, 10], [-9, 2, 4, 32], [4, -6, 21, 2], [-40, 16, -2, -11], [-23, -5, 25, 17], [36, 17, 10, -20], [-12, 24, -7, -24], [25, 18, 1, -28], [12, 28, -4, -25], [13, 5, -6, -42], [20, 9, -1, -5], [-44, 28, 9, 2], [12, -9, -6, -10], [8, -13, -15, 11], [31, 8, -19, -3], [21, -15, -18, 19], [7, 11, 11, -22], [-42, 9, -6, -7], [-30, -3, 3, 45], [-13, 19, 5, 19], [-12, 3, -11, 4], [-18, 4, -18, 9], [-9, -11, -15, -2], [6, -1, 9, 7], [22, -2, -8, -20], [-10, -19, -2, 3], [7, 16, 0, 19], [-13, 14, 10, 26], [3, 2, -3, 34], [3, 15, 2, -34], [-35, -23, -3, 24], [-18, -1, -5, 36], [-22, -4, 19, -9], [-17, 36, 19, -20], [34, -3, -16, 9], [-3, 18, 2, -5], [44, 10, -10, -9], [23, -2, -31, 16], [-14, 12, 14, 3], [-24, -38, -1, 39], [18, 23, 10, -13], [-36, -12, 19, -9], [-25, 9, 40, 4], [-36, -13, 6, 3], [11, 21, 9, -37], [-44, 9, 21, -1], [-46, 4, 6, 10], [11, 25, -4, -26], [33, -24, -41, -3], [-22, -5, 9, 28], [-6, -2, 36, 22], [12, -3, 15, 9], [23, -13, -26, -13], [-13, -14, 26, -16], [34, 3, 11, -33], [-12, -38, 9, 5], [-3, -10, -8, 4], [-42, 8, -7, -7], [-35, -11, 1, -1], [4, -18, 6, 33], [5, 14, -9, -28], [12, 15, -16, 5], [-6, 23, 1, -17], [-19, -23, 18, -9], [20, 6, -9, 5], [-48, -5, 2, 24], [-3, -12, 10, 8], [27, -8, -25, 2], [-16, 5, 25, -31], [2, -29, 19, 17], [-5, -2, 6, 36], [-22, 19, -15, -32], [-27, -23, -7, 17], [13, -11, 3, -20], [17, 5, 7, -33], [-13, -9, 4, -5], [-9, 33, 13, -4], [-19, 8, 11, 14], [2, -4, -11, -28], [5, 38, -2, -43], [28, 9, -1, -38], [-36, -1, -12, -4], [32, -4, 5, -11], [14, -37, -22, 16], [24, 10, 18, -29], [5, -6, -30, -6], [10, -33, -23, 15], [-6, -22, 21, -12], [-1, 24, -16, -15], [-9, -13, 18, -20], [-7, 8, 6, 40], [-8, -11, -9, 39], [10, 22, -19, -13], [48, 1, -14, 2], [-14, 27, 6, 7], [-41, -11, 4, 37], [-3, -6, 0, 27], [0, 18, -4, 11], [-30, -6, 18, 14], [10, 18, -12, -23], [31, -2, -6, -2], [-44, 24, 21, -1], [14, -37, 15, 25], [7, -7, -8, 14], [-18, -31, -6, 12], [-9, -23, 13, 34], [-13, -18, 25, 33], [-25, 23, -1, -30], [33, 20, -4, -33], [57, -12, -11, -22], [42, -3, 2, 7], [5, 6, 3, 31], [-20, -15, -25, -1], [-7, 1, 6, -11], [49, -12, -4, -18], [12, 5, -14, -1], [-15, -13, 1, -9], [-11, 0, 14, -11], [19, 13, 11, 16], [4, 44, -6, -25], [56, 14, -2, -11], [-20, -6, 21, -11], [7, -22, 3, 18], [-9, 10, -7, -32], [24, -22, -2, -8], [-2, 26, 14, -17], [-42, -2, 28, -8], [29, 38, 9, -25], [2, -10, -32, -5], [-31, 8, 40, -25], [21, -2, -17, -42], [-1, -15, -35, 24], [-6, 15, 21, -19], [-5, -12, 3, 25], [9, -25, -34, 12], [-9, -27, 10, 28], [22, -10, -21, -20], [4, -22, 15, 17], [-16, 13, -4, -38], [-31, -8, -1, 7], [-31, -2, 25, 27], [39, -15, -40, 4], [51, -19, -31, -14], [-6, 22, 29, -21], [19, 11, -9, 1], [7, 3, 14, 19], [-23, -10, 33, 11], [4, -3, 11, -16], [26, -30, -26, 12], [2, -12, 37, 35], [6, 4, -17, -49], [-2, -37, -4, 28], [-46, 39, 19, -12], [17, 20, -15, -24], [23, 10, -21, 2], [-6, -18, -11, 10], [14, 38, -7, -7], [6, -28, -43, 22], [30, -22, -2, -9], [-28, 9, -18, 13], [-37, 10, 20, 4], [-4, 25, 27, -35], [-42, 12, 16, 19], [-12, 34, 15, 5], [-48, -15, 12, 33], [-52, 22, 24, -3], [-39, -17, 10, 20], [-35, -1, 0, -22], [-21, 18, 18, -5], [-32, 14, -9, 16], [18, -1, -10, -6], [0, 23, 21, 3], [38, -2, 13, 23], [-21, 47, 11, 4], [38, -2, 11, -39], [-20, 26, -11, -6], [15, -13, 12, -21], [-3, -8, 10, 14], [41, 35, 14, -40], [21, -52, -17, 18], [19, 0, 10, -43], [-37, -21, 3, 3], [-28, 12, 13, 29], [13, 1, 9, 7], [-32, -23, -12, 29], [-28, -6, 36, -4], [53, 0, -20, -19], [0, -60, -18, 33], [-14, -24, -12, -10], [-2, -33, -44, 33], [-13, 0, 4, 15], [53, -20, -23, -19], [0, 50, -13, -45], [18, 6, 12, -24], [-71, 38, 19, 34], [-10, -27, 24, 18], [47, -16, 1, -45], [-33, 16, 53, 1], [-35, 15, 4, 15], [-7, 17, -14, 12], [-11, -31, 24, 8], [-8, -9, -4, -24], [-61, 0, 21, -14], [41, -30, -2, 4], [-24, 14, 18, -18], [-21, -3, 20, 11], [-19, -27, -31, 26], [-40, -47, -13, 40], [6, 5, -22, 48], [46, 4, -25, -13], [18, 33, 21, -31], [30, -9, -36, 23], [-9, -35, 11, 35], [22, -11, -9, 21], [-43, 12, 41, 1], [-52, 19, 6, 35], [-6, -26, -25, 21], [-34, 31, -1, -34], [-15, -3, 25, 21], [17, -33, -19, 24], [50, 12, -34, -8], [-14, -15, 8, 18], [22, 11, -38, 6], [-10, -11, 11, -16], [23, 9, -32, -42], [43, -25, -48, 11], [-58, -8, 11, 11], [28, -17, -54, 22], [20, 58, -4, -34], [-32, -30, -12, 12], [18, 20, -25, 30], [9, -15, -26, 1], [-21, -1, 32, -36], [-7, 21, -19, 0], [-6, 54, 2, -30], [-20, 15, -35, -36], [4, 7, -4, -7], [24, 17, 12, 4], [33, -14, -7, 14], [-2, -49, 20, 33], [2, -34, 28, 7]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1185_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1185_2_a_g();".
// 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_1185_2_a_g(:prec:=4)
    chi := MakeCharacter_1185_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_1185_2_a_g();".
// 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_1185_2_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1185_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, -4, 0, 3, 1]>,<7,R![-49, -28, 8, 7, 1]>,<11,R![-109, 36, 57, 14, 1]>],Snew);
    return Vf;
end function;