
// Make newform 150.16.c.a in Magma, downloaded from the LMFDB on 24 April 2024.
// 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_16_c_a();".
// 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_16_c_a();".
// 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)
    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 := 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 := 16;
    raw_aps := [[0, -128], [0, -2187], [0, 0], [0, 3034528], [-103451700, 0], [0, -104365834], [0, -997689762], [-4934015444, 0], [0, 8324920200], [-104128242846, 0], [-296696681512, 0], [0, 178337455666], [-1790882416086, 0], [0, -2863459422772], [0, -4332907521600], [0, 9732317104422], [13514837176500, 0], [5352663511190, 0], [0, 53233909720108], [-20229661643400, 0], [0, 26264166466106], [339031361615128, 0], [0, 131684771045076], [39352148322678, 0], [0, -1128750908801474], [37952841646518, 0], [0, -207297034803952], [0, 1996916424450084], [-13560287430710, 0], [0, -708793726473294], [0, 1230213691452760], [7948358663135700, 0], [0, 17813104378885398], [-3899408979365084, 0], [3487261020992394, 0], [6857123367527408, 0], [0, -36983550739590614], [0, 7425352410201668], [0, 14736477840451800], [0, 34003921380160254], [-38127604372411716, 0], [-51412399028168146, 0], [67556819305280256, 0], [0, -20723535041701246], [0, -17124405090220278], [105743289010769008, 0], [-313093105415521180, 0], [0, 335017421112670760], [0, -467560434596992836], [-361185847078402910, 0], [0, 361787480334552186], [1068421466081672304, 0], [-1005880905461877838, 0], [1747660725639158076, 0], [0, 277264028372899326], [0, 1733027782186595400], [51127071611870034, 0], [208455388042190744, 0], [0, -3297231489219247694], [-3983275627823919702, 0], [0, -2190510992135652244], [0, -5271828889113088458], [0, -4770665635740963140], [-6466655053798780200, 0], [0, -6001290916004682934], [0, 953942926372810914], [-5290708225748983108, 0], [0, -6224091232465949042], [0, 3220351184813723556], [6174072414603070090, 0], [0, -6142665745143477822], [5811034740391639656, 0], [0, 277147412192213656], [0, 23049810444843986078], [13439690713595024836, 0], [0, 26415142971160396800], [-39527481866174536326, 0], [0, -2828895630756644486], [-46368085050027127806, 0], [11709223060065410806, 0], [42010158909475520700, 0], [-15971838017103814210, 0], [-97636453701534972000, 0], [0, -69145547938116219502], [-54899007629774006432, 0], [0, 38050416037054976316], [-1119937923914054706, 0], [0, 97073378621042665318], [-97816539537650636130, 0], [0, -21715899646761475432], [0, 198442740143161397772], [37866103330572615216, 0], [0, -38926469914415133824], [140515953456399674844, 0], [153702802036419319996, 0], [0, 5622645909943499112], [-329307427651506526686, 0], [171774691187896377738, 0], [0, -159414111416092140340], [47412097410738622790, 0], [0, 280985626221573283036], [0, 349641543771367811874], [0, 268215364169513082804], [795690712374180967398, 0], [884470144164006418220, 0], [0, -315722143952664273794], [0, -733396890191567852796], [0, -325571463526754276910], [-661172632207579669224, 0], [-249466578916192435222, 0], [0, -1089168506723986371272], [0, 199450366978180006766], [0, -421127222003179850010], [1272718693187247521284, 0], [-342884489459899475248, 0], [1000753945406654965170, 0], [0, -135729277989846435772], [0, -2154617867614779783288], [0, -2061011052200171337666], [1613094071947656102588, 0], [1608876842927029216094, 0], [0, 1672937649996966180578], [0, -726999591126677493318], [0, 2859085319288623634124], [1712744252980801988564, 0], [-895519345176190105506, 0], [3996416519073015829378, 0], [266669153589302301600, 0], [0, 1694471472946915444816], [0, 3162386368459530392294], [-2013811680650183681492, 0], [0, 2114114301964084250568], [4950872878302528745160, 0], [0, 4858787939126156327986], [-3690920307004927958022, 0], [2338147271379881159422, 0], [0, -5206815110816071777674], [0, 1921955997240024091468], [0, 623880373158914477010], [-5728583662357207638474, 0], [4800140750898906605516, 0], [8897753268285649088838, 0], [0, -1399459724996911300240], [0, -6613432903214945715564], [-4147351056718798855142, 0], [-9578110364006117513496, 0], [0, -8153607980916852977698], [0, 15355223751924396165126], [4876166406888332621476, 0], [0, -4766667091106388995808], [0, -15794369333891910147494], [-11278909966267353189294, 0], [0, 4483072749374817329108], [0, 8562464010560314681800], [0, -7346377514348012194508], [-11899938843638775301008, 0], [-19262917598818994397776, 0], [-8781094485192734672946, 0], [0, 23542405059945580473958], [-23165994525982295376642, 0], [0, -20257756620274001937732], [0, -16635087576290294070822], [0, 21079436860185360230608], [-30926116556669798380116, 0], [0, -7857253427480056157826], [0, 12798107216203074249048], [-53938456910265101386696, 0], [0, 19967824628596036611538]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_150_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_150_16_c_a();".
// 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_16_c_a(:prec:=2)
    chi := MakeCharacter_150_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 16));
    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_16_c_a();".
// 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_16_c_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_150_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,16,sign)));
    Vf := Kernel([<7,R![9208360182784, 0, 1]>],Snew);
    return Vf;
end function;