
// Make newform 1150.2.a.d in Magma, downloaded from the LMFDB on 29 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1150_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_1150_2_a_d();".
// 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_1150_2_a_d();".
// 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_1150_a();"
function MakeCharacter_1150_a()
    N := 1150;
    order := 1;
    char_gens := [277, 51];
    v := [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_1150_a_Hecke( : Kf := Kf)
    return MakeCharacter_1150_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], [3], [0], [4], [3], [-6], [5], [-1], [1], [-8], [-8], [2], [-7], [4], [10], [-12], [4], [-8], [3], [4], [-7], [-6], [11], [-3], [-14], [4], [10], [5], [-10], [15], [-8], [12], [-3], [-19], [6], [20], [14], [5], [22], [4], [-3], [-22], [12], [-9], [-8], [18], [-1], [0], [-8], [-30], [-14], [-6], [23], [-7], [2], [-4], [-6], [10], [-28], [-30], [-33], [24], [-9], [2], [-10], [12], [25], [3], [7], [26], [18], [-20], [2], [-12], [5], [-6], [-36], [-12], [-5], [21], [3], [-14], [-4], [29], [-6], [-39], [5], [-7], [-24], [26], [28], [-4], [-30], [0], [-12], [-24], [36], [31], [37], [16], [-17], [-30], [-4], [-9], [4], [17], [17], [-35], [-20], [31], [10], [-8], [30], [28], [30], [30], [32], [28], [14], [5], [0], [34], [42], [35], [29], [-8], [16], [8], [-28], [38], [-4], [26], [24], [16], [-15], [-21], [4], [-52], [-18], [10], [4], [16], [-26], [-17], [24], [26], [12], [-21], [-11], [24], [38], [-30], [-37], [12], [-28], [-10], [52], [-22], [-9], [4], [12], [-27], [-28], [15], [17], [42], [2], [22], [7], [-28], [9], [-12], [-14], [-53], [10], [-23], [-25], [32], [-36], [8], [20], [7], [-46], [-43], [28], [-50], [26], [41], [45], [30], [1], [53], [-51], [-10], [37], [42], [17], [26], [59], [-54], [-50], [30], [64], [17], [-36], [-36], [20], [48], [6], [48], [-26], [-54], [40], [-15], [-52], [-45], [14], [45], [28], [-6], [-40], [-20], [-35], [54], [19], [-8], [-29], [-20], [-32], [23], [32], [-55], [-14], [-9], [12], [-66], [47], [24], [-33], [24], [-3], [-5], [58], [-60], [-67], [-68], [-16], [56], [-3], [-40], [-42], [25], [8], [1], [-30], [55], [-60], [-25], [12], [47], [40], [-5], [-16], [-68], [7], [3], [30], [54], [1], [60], [48], [-25], [27], [-14], [-22], [2], [39], [-54], [2], [15], [70], [-38], [-26], [-12], [13], [12], [-46], [22], [62], [66], [-8], [76], [53], [77], [6], [6], [-70], [-2], [-68], [-39], [57], [-16], [44], [-17], [13], [-57], [68], [38], [4], [2], [-54], [-2], [-9], [-60], [78], [2], [33], [36], [91], [-29], [-28], [-87], [-58], [46], [58], [38], [53], [-76], [10], [-10], [-50], [60], [26], [-17], [-69], [-56], [-2], [14], [-21], [50], [-44], [-75], [-12], [68], [-10], [-48], [-70], [-31], [-18], [50], [67], [62], [62], [-44], [-76], [-63], [-72], [-29], [-18], [48], [44], [39], [-16], [0], [-67], [13], [-70], [16], [39], [-4], [29], [70], [0], [-32], [-74], [-15], [88], [-61], [-5], [38], [-32], [-39], [82], [21], [92], [12], [-46], [52], [-32], [-42], [-91], [44], [75], [-63], [-36], [-79], [-14], [-37], [-49], [34], [-8], [43], [-14], [-3], [16], [-36], [50], [-86], [8], [-57], [1], [80], [3], [4], [-41], [-12], [50], [80], [49], [-86], [24], [22], [28], [-9], [43], [-38], [-84], [-81], [-35], [86]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1150_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1150_2_a_d();".
// 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_1150_2_a_d(:prec:=1)
    chi := MakeCharacter_1150_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_1150_2_a_d();".
// 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_1150_2_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1150_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-3, 1]>,<7,R![-4, 1]>,<11,R![-3, 1]>],Snew);
    return Vf;
end function;