
// Make newform 150.12.c.f in Magma, downloaded from the LMFDB on 02 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_12_c_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_150_12_c_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_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 := 12;
    raw_aps := [[0, -32], [0, 243], [0, 0], [0, 72464], [-408948, 0], [0, -1367558], [0, 5422914], [-15166100, 0], [0, 52194072], [-118581150, 0], [-57652408, 0], [0, -375985186], [856316202, 0], [0, 1245189172], [0, -1306762656], [0, -409556358], [2882866260, 0], [5731767302, 0], [0, 3893272244], [-9075890088, 0], [0, 15571822822], [30196762600, 0], [0, -23135252628], [25614819990, 0], [0, -61937553406], [-94964150058, 0], [0, -54371908448], [0, 5713477884], [49672374010, 0], [0, -177802571058], [0, -473707536136], [168573812532, 0], [0, -801479261526], [-524839237820, 0], [-1257020226870, 0], [-492117459808, 0], [0, -997091613946], [0, 484141975612], [0, 2315373820584], [0, -3371566157598], [-1645977026340, 0], [2742173271902, 0], [4084089808512, 0], [0, 4472389991422], [0, -7370248975146], [-2693084564000, 0], [6634577708612, 0], [0, 5995589013832], [0, -7749301902396], [-3758040333710, 0], [0, -9026758358298], [4022692975920, 0], [-14999667337678, 0], [-14681681636868, 0], [0, -16447633968126], [0, 19681818745272], [11617411525650, 0], [7467876506792, 0], [0, 15956443695614], [39611493918282, 0], [0, -15000063411788], [0, -38825493139158], [0, 75819366414884], [-79990659222888, 0], [0, 68561413056022], [0, 6378911616414], [89020993584092, 0], [0, 142600806741554], [0, -133725973385316], [63047442118810, 0], [0, 28974898162302], [-43310836423800, 0], [0, -112470912775336], [0, -129947513379758], [94538171865220, 0], [0, -54511744524288], [51137944162170, 0], [0, -48723411062986], [376407484129122, 0], [-312467212549610, 0], [-281729092206660, 0], [-301063838733778, 0], [346694170280832, 0], [0, -482345467463378], [-118934088249200, 0], [0, 199914264990852], [506701914104430, 0], [0, -362768435523526], [65646585500862, 0], [0, 206748343519192], [0, -379400882843916], [-367939370639280, 0], [0, 631644906594224], [278183150638332, 0], [-459050093742500, 0], [0, 915702867160632], [-1085622825947550, 0], [-163924983100278, 0], [0, -46912694264588], [-1281958508682538, 0], [0, 1105639461244004], [0, 2121608950717374], [0, 2448882915166092], [738094760695590, 0], [-21010268758708, 0], [0, 1132487353279874], [0, -2912545182972516], [0, -1529013546440658], [-2715166624101000, 0], [-2591038342922998, 0], [0, 1687610876689304], [0, 535763782489282], [0, -2843668860910086], [-814487455941980, 0], [-1458684356311168, 0], [-1162971435762798, 0], [0, -4734612318417668], [0, 5475272623688664], [0, 887970661792482], [-3144543068000100, 0], [1329822392592302, 0], [0, 6844380693513502], [0, 888819607540614], [0, -2224018428599628], [4597206126295892, 0], [-2587014691966818, 0], [-2520806909453870, 0], [-3037163189811840, 0], [0, 6520856018525024], [0, 1482084159648202], [-5393426983129460, 0], [0, -8961919068060168], [-7787200900914568, 0], [0, -2419224924478786], [-5025522575565318, 0], [-12105571636854530, 0], [0, 7456300773991722], [0, -11257989560649676], [0, -10466895892615986], [12817970979489270, 0], [9792950640539852, 0], [7084100698669542, 0], [0, -19856913386391008], [0, -20553656994225396], [14592049502444170, 0], [-6549633589083960, 0], [0, -19924415074625198], [0, 15914882431310394], [1190195095374820, 0], [0, 1733431366649952], [0, 11660223223786454], [-16609123048628718, 0], [0, 12820490726271532], [0, -221358390467016], [0, -24836086882256116], [8102951455624752, 0], [33381374096334400, 0], [-35671257106709970, 0], [0, 39624761192998394], [5371931506709022, 0], [0, 22224103394043684], [0, -7668673573745178], [0, 28047373147337984], [-24342728765789268, 0], [0, -21914442147874206], [0, 7045855376252712], [40487293131612392, 0], [0, 17960734932482174]];
    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_12_c_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_150_12_c_f(:prec:=2)
    chi := MakeCharacter_150_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 12));
    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_12_c_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_150_12_c_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_150_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<7,R![5251031296, 0, 1]>],Snew);
    return Vf;
end function;