
// Make newform 1185.2.a.h 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_h();".
// 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_h();".
// 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, 4, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-2, 0, 1, 0], [0, -3, 0, 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 := [[0, 0, -1, -1], [-1, 0, 0, 0], [1, 0, 0, 0], [0, -1, 0, 2], [-2, 0, 0, -1], [-1, 1, 1, -2], [-2, 2, 2, -1], [-3, -1, -1, 0], [3, -3, -1, 4], [1, 0, 1, 4], [-5, -2, 2, 0], [1, -2, 4, 3], [-4, 0, 1, 0], [0, 3, -4, -1], [-4, 4, 1, 1], [6, 0, 1, 0], [-7, 0, -1, -4], [-3, 3, 1, 5], [-7, 5, -2, -9], [-1, 1, 5, 7], [-4, 2, -4, -9], [1, 0, 0, 0], [-5, -4, -1, -4], [0, 5, -7, -4], [-2, -1, -6, -4], [5, -7, -2, 1], [-3, 3, -3, -9], [1, 6, 0, 4], [-2, -5, -8, 4], [0, 1, -1, -9], [3, -4, 0, 5], [2, -1, -6, -8], [6, -7, -1, 5], [-9, 3, -1, 1], [3, 2, -2, -3], [-10, -4, 1, -8], [6, -3, -2, 14], [2, 1, 4, 7], [-4, -3, 1, 1], [9, -12, -2, 7], [0, -6, 1, 5], [3, 0, 5, 6], [7, -1, 0, 9], [0, -9, 2, 0], [7, -2, 3, 0], [-8, 10, -2, -6], [-4, 8, 3, -10], [-2, 3, -1, -4], [6, -1, 4, 11], [-5, -10, 1, 6], [-1, -7, -7, -2], [-7, 6, 2, -18], [-5, -1, 9, 7], [-6, 7, 1, -2], [-10, -6, 3, -10], [4, 8, -12, -6], [8, -1, -8, -4], [-4, 9, 11, 0], [-3, 3, 7, -3], [-8, 10, 7, -3], [8, 1, 1, 1], [7, -8, -5, -2], [1, -9, 10, 9], [3, -14, -4, 10], [1, 9, -2, 6], [-8, 13, 1, -5], [-12, 9, 1, 2], [26, -7, 3, 23], [12, -1, 6, -5], [-4, 2, 9, -1], [-20, 9, -1, -12], [-23, 6, -6, -23], [0, -11, 7, 6], [11, 10, -7, 3], [-27, 0, 3, -5], [8, -4, 8, 11], [7, 1, -12, -6], [-8, -3, -4, -8], [-8, -1, -6, -3], [-11, 3, 3, -6], [6, 0, 1, 17], [7, -11, 4, 15], [9, 4, -13, -9], [1, -9, 5, 8], [-16, -1, 2, 1], [-11, -3, -9, -19], [2, -4, 18, 2], [-21, -6, 2, -4], [11, -3, -4, 27], [-6, -3, -5, 6], [6, -4, -11, 6], [16, 0, -9, 10], [13, 0, -7, 11], [7, 4, 14, 2], [-1, -4, -9, -9], [-5, 6, 13, 6], [19, -6, 10, 13], [-18, -8, 3, -16], [2, -7, 7, 11], [-5, 0, 6, -2], [12, -2, 3, 7], [3, 6, -1, -8], [3, -3, -2, 2], [25, -4, -2, 14], [-13, 1, -11, -33], [2, 12, 9, -12], [-12, -2, 3, 8], [-7, 0, 2, 24], [-6, 4, 8, -15], [-18, -1, -3, -10], [-5, 14, -1, -10], [-13, -2, 10, -6], [2, 8, -1, 2], [1, 16, 4, 0], [-5, 7, 16, 5], [-9, 2, -8, -21], [-9, 2, -2, 4], [-7, 6, 5, 15], [28, -5, 1, 12], [14, -10, 9, 25], [-37, 13, -1, -12], [-9, 7, -20, -27], [-4, 10, 15, 15], [-15, 10, -10, -17], [-3, -1, -10, 9], [-25, 11, 13, 1], [-4, -3, 7, 11], [10, 1, 4, -4], [3, 3, -20, -8], [22, -18, -9, 15], [18, -23, -6, 12], [10, 15, -9, -10], [13, -6, 4, 23], [18, 12, -7, -2], [15, -4, 25, 15], [-9, -7, 16, -5], [-17, 6, 12, -7], [14, 6, 3, -6], [-12, -3, 6, -11], [17, 14, 7, -8], [12, -3, 0, -4], [22, 1, -4, -3], [3, 5, 18, -4], [-19, -1, 10, -20], [13, -9, 14, 11], [-13, -3, 17, -4], [-8, -8, -14, -9], [-2, 1, -16, -10], [-8, 10, 3, -17], [-31, 11, 4, -20], [-8, 26, 12, -7], [25, -26, 4, 21], [-13, -2, 20, 5], [-10, -4, 18, 1], [-7, -13, 11, 9], [-14, -14, 21, 4], [-24, -15, 10, -13], [-15, 30, -1, -16], [39, 0, -1, 23], [-21, -14, 15, -4], [-8, 14, 6, -9], [23, -15, -1, 32], [31, -2, -4, 20], [-24, 0, 7, -7], [17, -12, -14, 7], [-13, 12, -24, -22], [13, -14, -8, 6], [-3, -15, -8, -13], [-14, 10, 16, 35], [48, 3, -1, 13], [23, -11, 15, 35], [-34, 1, -10, -21], [29, -5, -9, 18], [30, -15, 23, 27], [16, -3, -19, -25], [30, -1, 9, 1], [3, 21, 6, -3], [12, 23, -12, -5], [7, 2, 6, 35], [-1, 14, -5, -5], [33, -21, 16, 36], [-4, 0, 0, -20], [-20, 7, 7, -27], [5, -1, 24, 13], [-8, -3, 30, 2], [44, -12, 6, 10], [-17, -7, -9, -26], [18, -12, -13, -15], [23, -19, -9, 11], [-23, -1, 1, -9], [-13, 2, -12, -14], [3, 29, 5, -11], [14, -14, 26, 33], [-17, -5, -6, -29], [-3, 2, -1, 23], [-3, -1, -29, 5], [12, 3, -29, -21], [-20, 20, -6, -7], [0, -2, 5, 3], [6, 3, -14, 17], [41, -25, 7, 29], [17, 8, -23, 3], [12, -15, -6, -11], [20, 3, 1, 4], [-2, -8, -1, 10], [9, -23, -18, -10], [5, 6, -3, 36], [4, -5, -2, 15], [19, -33, 0, 25], [2, -3, 10, 2], [-24, 2, 4, -43], [19, -11, -6, 28], [10, -11, -16, -1], [-8, 4, -18, -2], [11, -20, 13, 14], [-33, 16, -12, -45], [-39, 20, -2, -22], [-28, 9, 5, 15], [-44, -8, 5, -19], [19, 3, -24, -28], [-12, 3, -14, -10], [7, -9, -37, -20], [10, -11, 1, -5], [-41, -10, 7, 10], [7, -8, -10, -21], [18, -6, -16, -35], [-16, -1, -5, 13], [-24, 12, -12, -21], [-1, -15, 15, 12], [5, -30, -7, 6], [37, -27, 1, 26], [-4, -4, -25, -3], [33, -8, -3, 46], [-33, 19, -20, -25], [-10, -7, -2, -11], [16, -2, 2, 8], [16, -14, -19, -13], [10, 5, 15, 18], [12, -9, -4, 22], [-20, 12, -18, -44], [-18, -9, -10, -37], [26, -30, -5, 14], [-33, 20, -2, -14], [12, -5, 8, 49], [-13, 17, -15, -2], [-37, 6, -2, -24], [-21, -7, -1, 22], [-15, 3, 24, -9], [-22, 14, 16, -21], [18, -29, 1, 25], [-5, 32, 15, -14], [8, 13, 12, 17], [-18, 30, -5, -6], [-17, 15, -11, -24], [-31, 20, 3, -25], [7, -32, -14, 0], [0, -9, -17, 23], [6, -15, 10, 23], [46, -13, 6, 39], [-7, 4, 30, 16], [0, -7, -12, 0], [15, -3, 10, -9], [9, 15, 12, 8], [-21, 17, 6, 23], [-38, 10, 5, -10], [-3, 1, 6, 46], [50, -1, 5, 19], [-9, 31, -9, -13], [-1, 0, 28, 17], [-12, 5, 24, -36], [1, -8, -15, 25], [19, -5, -1, 14], [-21, 10, 7, 17], [-20, -10, 8, -7], [3, -4, -18, 14], [-18, 29, 10, -11], [49, -1, 5, 23], [-5, 16, -24, -29], [4, -10, -1, -7], [9, 28, 2, 18], [-2, 7, -4, 15], [23, -31, -25, 0], [3, 24, -11, -25], [-17, -20, 5, 14], [24, 4, 29, 16], [-29, 48, 8, -15], [-2, 0, 12, -5], [6, 14, 0, -14], [-32, -8, -6, 13], [-39, 24, -32, -42], [-5, 1, -19, -16], [-38, 23, -4, -35], [-16, -6, -23, -11], [35, -12, -23, -33], [3, 31, 10, 2], [10, 13, -5, -26], [-43, 23, -2, -32], [47, -2, -10, -3], [-48, 21, -17, -39], [-7, 14, 11, 8], [-4, -1, -39, -22], [6, -5, -46, -39], [54, 6, 5, 10], [-7, 12, -14, 6], [-33, 12, -1, -44], [-11, -5, -8, 15], [41, 8, 4, -13], [-17, 3, -18, -12], [28, -4, 8, 35], [8, 30, -2, 7], [-45, 9, 1, 2], [8, 13, 3, -9], [14, -13, 25, 19], [4, 34, 16, -4], [40, -32, 8, 37], [4, -20, -14, 18], [-8, -21, 3, -26], [-12, 18, -16, -37], [11, 2, -4, 21], [-2, 1, 31, 51], [37, 13, -20, -2], [-2, 13, -26, 7], [-2, 13, 15, 8], [-40, -22, 7, -23], [26, -6, -3, 37], [11, 3, -3, -15], [-7, -7, 29, 12], [81, -8, 7, 27], [-2, 33, -21, -16], [-6, -3, -5, 30], [12, 2, 5, -39], [21, 11, 14, -22], [-33, -15, 15, -36], [13, -1, 14, -1], [-10, 6, -9, -30], [-6, -3, 27, 2], [-6, -13, -22, -26], [-22, -22, 12, 12], [13, -7, -3, 50], [37, -29, -11, -10], [39, -30, -21, -3], [-12, -7, 34, 12], [28, 9, 7, 27], [-12, -27, 9, 3], [-15, 19, 29, -15], [-35, 7, -1, -52], [-45, 15, 17, -5], [2, 18, -22, -35], [45, -6, 15, 22], [25, 28, -16, -6], [-12, 3, 0, -17], [10, -28, 30, 29], [3, 3, -51, -18], [13, 6, 3, 22], [-42, 28, 14, -31], [26, -10, -33, -21], [-10, -4, -3, 31], [-29, 10, 22, -5], [-3, -5, 11, 25], [-5, 4, -1, -15], [-16, -15, -14, -23], [-31, 19, 19, 14], [-11, 13, -4, -52], [-15, -9, -43, 2], [39, 7, 23, 7], [48, -22, 33, 44], [-1, -18, 12, 16], [-16, 24, 37, 17], [-4, 17, -17, -35], [5, 6, -24, -17], [-35, 11, -18, -29], [-53, 27, -1, -48], [19, 15, 22, -9], [17, 14, -11, -20], [-42, 8, 2, 6], [-35, 20, 22, 23], [-22, -4, 28, -3], [-6, -28, -4, 6], [11, -14, -23, 32], [1, -10, -4, -21], [-54, 29, 17, -4], [-15, -21, 19, 26], [-48, 4, 2, -10], [28, -23, -35, -7], [43, -38, -7, 35], [-6, -13, 37, 42], [24, -33, -27, -20], [58, -14, 5, 8], [62, 2, 9, -1], [-50, 20, -5, -61], [-3, 0, -15, -23], [-8, 25, 33, 19], [3, -32, -24, 32], [0, 18, 20, 34], [48, 4, 11, 0], [-3, 3, 14, 38], [22, 15, -6, 46], [-13, -8, -35, -37], [9, 1, -5, 36], [38, -7, -6, 49], [-7, 20, 17, 18], [-13, 3, 32, 3], [-26, -13, -6, 11], [-36, 15, -35, -52], [-9, 50, -15, -26], [71, 1, 13, 4], [-22, -5, -30, -8], [-1, -9, -18, 25], [7, -29, -30, -10], [-56, -14, 26, 2], [-13, -12, 35, 7], [5, 10, 1, -13], [-2, 1, 52, 50], [-32, -16, -1, 3], [58, 0, 11, 28], [-7, 9, -9, -22], [-53, 12, -13, -57], [-50, 28, 18, -8], [-2, -20, -26, -2], [-31, -1, -11, -39], [12, 22, 33, -40], [16, -24, -27, 27], [-17, -21, 38, 20], [18, 42, -12, -6], [8, 17, -10, 6], [-27, 8, 17, 40], [11, -48, -15, 13], [6, -27, -27, 15], [53, 0, 21, 12], [-54, -6, 0, 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_h();".
// 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_h(: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_h();".
// 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_h( : 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, -4, -1, 1]>,<7,R![-5, -10, 0, 5, 1]>,<11,R![1, 3, 1]>],Snew);
    return Vf;
end function;