
// Make newform 150.8.c.b in Magma, downloaded from the LMFDB on 03 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_150_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_150_c_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_150_8_c_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_150_8_c_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
        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_150_c();"
function MakeCharacter_150_c()
    N := 150;
    order := 2;
    char_gens := [101, 127];
    v := [2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_150_c_Hecke();"
function MakeCharacter_150_c_Hecke( : Kf := false)
    N := 150;
    order := 2;
    char_gens := [101, 127];
    char_values := [[1, 0], [-1, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), 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]];
    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 := 8;
    raw_aps := [[0, 8], [0, 27], [0, 0], [0, 232], [-60, 0], [0, 14054], [0, -13938], [-53564, 0], [0, -27000], [88554, 0], [-120352, 0], [0, -469646], [-510246, 0], [0, 145412], [0, -304560], [0, 94398], [1885740, 0], [-271690, 0], [0, -1074668], [-2505480, 0], [0, -2954566], [7354768, 0], [0, -3846756], [-5685162, 0], [0, -7981346], [15462798, 0], [0, -20902408], [0, -20564484], [-13985030, 0], [0, 26443794], [0, 9340000], [-44679540, 0], [0, 56992902], [-30682244, 0], [-28362846, 0], [-34565272, 0], [0, -50066006], [0, -1633588], [0, 99481800], [0, -100775034], [-85916316, 0], [-7349506, 0], [25552896, 0], [0, 136814786], [0, 138052818], [-6204152, 0], [-165041860, 0], [0, -54311680], [0, -133927884], [-20984270, 0], [0, 12168474], [46923504, 0], [-229326958, 0], [450379476, 0], [0, -66525186], [0, -110722920], [131053914, 0], [-566889616, 0], [0, -130574366], [-270368022, 0], [0, -91107436], [0, -622671282], [0, 113281540], [378343560, 0], [0, -111400246], [0, 670098186], [-544095868, 0], [0, -962373938], [0, 592828524], [973267690, 0], [0, 1591265442], [-837928344, 0], [0, 1144475344], [0, 1366732862], [491619436, 0], [0, 532012320], [-683512686, 0], [0, 1468424986], [708291954, 0], [-2136030314, 0], [-1221300780, 0], [-117753970, 0], [-2927493360, 0], [0, -922065838], [2694312568, 0], [0, 1509278964], [-794655426, 0], [0, -1822702778], [-179582490, 0], [0, 395890832], [0, -570281052], [-4368232224, 0], [0, -329328056], [-2546657436, 0], [-1424952284, 0], [0, -2183971032], [5256234954, 0], [3194805498, 0], [0, -1922192860], [1623521750, 0], [0, 876823924], [0, 229688826], [0, 786151356], [-3300875082, 0], [-1540329580, 0], [0, 3797687614], [0, -8296760484], [0, 4931956530], [-6511516584, 0], [-4174601302, 0], [0, -5469791168], [0, -7927644466], [0, 9702766950], [-534840356, 0], [-8981448568, 0], [681488130, 0], [0, -3680069908], [0, -9032687832], [0, 2904771366], [288225348, 0], [4043262494, 0], [0, 6389004002], [0, 10825631538], [0, 881962116], [5368826204, 0], [4373411574, 0], [-4603831022, 0], [-5783244720, 0], [0, -14287082696], [0, -11889570154], [-14199256172, 0], [0, -8295394248], [-10733403760, 0], [0, -1283887166], [11399124618, 0], [12638828542, 0], [0, 17893523694], [0, -16508481308], [0, 1820520810], [21744506406, 0], [-19386943324, 0], [-11656477122, 0], [0, -4640543320], [0, -10060358196], [-15625564982, 0], [28355659464, 0], [0, 15207182558], [0, -26977599786], [15996420556, 0], [0, 22264678848], [0, -20835862406], [24136328466, 0], [0, 8171266172], [0, -26472630120], [0, -38488001252], [-8734296528, 0], [-19169501096, 0], [-9513520866, 0], [0, 20987145382], [1923017478, 0], [0, -15248286588], [0, -16005149238], [0, 30525365032], [38573240964, 0], [0, 19080515406], [0, -48833018808], [38373184544, 0], [0, 22252065202]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_150_c_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_150_8_c_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_150_8_c_b(:prec:=2)
    chi := MakeCharacter_150_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 8));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_150_8_c_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_150_8_c_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_150_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<7,R![53824, 0, 1]>],Snew);
    return Vf;
end function;