
// Make newform 1150.4.b.f in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1150_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1150_b_Hecke();"
// 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_4_b_f();".
// 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_4_b_f();".
// 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, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_1150_b();"
function MakeCharacter_1150_b()
    N := 1150;
    order := 2;
    char_gens := [277, 51];
    v := [1, 2];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1150_b_Hecke();"
function MakeCharacter_1150_b_Hecke(Kf)
    N := 1150;
    order := 2;
    char_gens := [277, 51];
    char_values := [[-1, 0], [1, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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+1)]];
    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 := 4;
    raw_aps := [[0, -2], [0, 1], [0, 0], [0, 18], [-32, 0], [0, -47], [0, -20], [-36, 0], [0, -23], [27, 0], [-33, 0], [0, -56], [-157, 0], [0, 18], [0, -65], [0, -14], [744, 0], [552, 0], [0, 156], [699, 0], [0, -609], [644, 0], [0, 512], [102, 0], [0, -578], [-6, 0], [0, -160], [0, -380], [-250, 0], [0, -390], [0, 769], [-213, 0], [0, -2836], [1631, 0], [1966, 0], [35, 0], [0, -1702], [0, -2045], [0, -1016], [0, 598], [4607, 0], [-1212, 0], [-1058, 0], [0, 1047], [0, -251], [3508, 0], [-3296, 0], [0, -2720], [0, 4134], [4510, 0], [0, -5003], [6309, 0], [3038, 0], [-1332, 0], [0, -3301], [0, 2072], [-5721, 0], [-5900, 0], [0, -6371], [3190, 0], [0, -4226], [0, 6048], [0, -8628], [8247, 0], [0, 2620], [0, -9906], [-8115, 0], [0, 7586], [0, -1356], [-6649, 0], [0, 10691], [6420, 0], [0, 524], [0, 5566], [-2240, 0], [0, 8778], [-4056, 0], [0, 9151], [15930, 0], [5891, 0], [-15282, 0], [-10934, 0], [-2794, 0], [0, -15062], [-261, 0], [0, -7083], [10370, 0], [0, 10496], [18021, 0], [0, -17188], [0, 15246], [8556, 0], [0, 1805], [5245, 0], [-9027, 0], [0, 3522], [-3949, 0], [3236, 0], [0, 12394], [-7159, 0], [0, 19761], [0, -18010], [0, -2648], [1566, 0], [2864, 0], [0, 929], [0, 19499], [0, 6570], [-1880, 0], [3701, 0], [0, 3080], [0, 24004], [0, -780], [-21892, 0], [8050, 0], [-25890, 0], [0, 4774], [0, -3349], [0, 24813], [-18180, 0], [-29250, 0], [0, -23027], [0, -20106], [0, -18745], [24424, 0], [-27278, 0], [-12214, 0], [-12932, 0], [0, -10046], [0, -5924], [-829, 0], [0, 7072], [16234, 0], [0, -9128], [165, 0], [20834, 0], [0, -31782], [0, -33104], [0, -4736], [7470, 0], [19919, 0], [-22694, 0], [0, -31907], [0, 15236], [-27286, 0], [-23054, 0], [0, -34506], [0, 22263], [-12851, 0], [0, 15723], [0, 886], [-37120, 0], [0, -7524], [0, -9221], [0, -29116], [11440, 0], [-2958, 0], [-20907, 0], [0, -9748], [19624, 0], [0, 41859], [0, 29226], [0, 29849], [-9390, 0], [0, -33536], [0, 28994], [11272, 0], [0, -61186], [23172, 0], [0, -5651], [29844, 0], [32253, 0], [-51684, 0], [0, 14464], [34455, 0], [57722, 0], [20165, 0], [13187, 0], [0, -31952], [-60652, 0], [0, -44435], [9882, 0], [0, 3743], [0, 31554], [0, 18086], [-20940, 0], [0, -54778], [0, -11288], [-27905, 0], [55120, 0], [0, -4343], [0, 58256], [33434, 0], [23850, 0], [0, 22954], [0, -57546], [3632, 0], [0, -62448], [0, 58868], [0, -14553], [1340, 0], [-46480, 0], [0, 37233], [30772, 0], [-18816, 0], [0, -24307], [-42140, 0], [0, -63019], [34881, 0], [1673, 0], [0, -8237], [-22989, 0], [0, -69070], [0, 85010], [-22332, 0], [-79230, 0], [0, 9803], [-64395, 0], [0, 77126], [0, -32827], [59715, 0], [25720, 0], [17335, 0], [0, -79042], [0, -6057], [-3983, 0], [0, 59252], [36175, 0], [0, 25786], [-76572, 0], [0, -40326], [-7630, 0], [-42094, 0], [2026, 0], [0, -81436], [0, 104418], [-102788, 0], [0, 85128], [59597, 0], [-49271, 0], [0, 87144], [71615, 0], [0, -24479], [38985, 0], [0, 57866], [-82103, 0], [0, 15083], [-4254, 0], [24002, 0], [0, 210], [0, 15856], [77550, 0], [0, 61106], [-33494, 0], [0, 77670], [-62925, 0], [-28560, 0], [0, -44290], [0, -29151], [0, 49969], [0, -14180], [0, 48890], [-61766, 0], [0, 29594], [0, -119586], [83068, 0], [-14120, 0], [14734, 0], [0, -89028], [0, 22735], [26293, 0], [0, 4930], [0, 62314], [125926, 0], [0, -40419], [0, 143489], [0, 53268], [-95174, 0], [-150298, 0], [37840, 0], [0, 59175], [112682, 0], [0, 49028], [-47862, 0], [0, -146944], [-70488, 0], [0, 130578], [0, -26996], [1652, 0], [98766, 0], [44962, 0], [0, 80752], [0, -18774], [-55608, 0], [0, -134093], [32826, 0], [6500, 0], [0, 141], [129307, 0], [0, -27223], [0, -66706], [0, 155468], [104304, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1150_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1150_4_b_f();".
// 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_4_b_f(:prec:=2)
    chi := MakeCharacter_1150_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(1999) - 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_4_b_f();".
// 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_4_b_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1150_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![1, 0, 1]>,<7,R![324, 0, 1]>],Snew);
    return Vf;
end function;