
// Make newform 950.4.a.c in Magma, downloaded from the LMFDB on 02 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_950_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_950_4_a_c();".
// 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_950_4_a_c();".
// 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_950_a();"
function MakeCharacter_950_a()
    N := 950;
    order := 1;
    char_gens := [77, 401];
    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_950_a_Hecke( : Kf := Kf)
    return MakeCharacter_950_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 := 4;
    raw_aps := [[2], [2], [0], [-8], [44], [0], [74], [19], [-84], [266], [136], [-424], [470], [236], [240], [-36], [736], [650], [830], [-216], [-254], [-1220], [688], [102], [1280], [1218], [-502], [-1622], [-906], [-608], [-514], [180], [2618], [-2196], [450], [1620], [-2546], [500], [-1694], [3572], [440], [1302], [3688], [1328], [-1710], [-2176], [-4760], [1042], [2850], [-2558], [-3242], [-2304], [-3802], [-4844], [-444], [-1412], [-914], [856], [6814], [6870], [4576], [-4372], [290], [-6256], [-8898], [-1392], [7544], [-8072], [24], [2030], [1050], [-8696], [-13064], [-4484], [-5468], [126], [5822], [-4250], [-11030], [6138], [16692], [-11318], [-11684], [-9776], [-3692], [1704], [12658], [-13274], [5478], [19412], [9864], [-936], [-5374], [-9356], [19724], [-7652], [-5510], [-9406], [1742], [-20238], [10962], [22182], [-17674], [-4206], [-1644], [1518], [19464], [-18010], [-15636], [7702], [-14166], [7174], [7482], [-1460], [-4936], [-19914], [3376], [17156], [-12162], [20760], [2602], [-24172], [-22884], [21702], [17260], [-8678], [25270], [18056], [-15696], [-34766], [-16484], [-7962], [17980], [36106], [-17306], [16110], [34512], [30602], [39508], [6026], [1436], [-8650], [37352], [454], [4094], [8148], [4898], [10284], [-12884], [33014], [10764], [-30818], [30932], [29454], [-7926], [3228], [44872], [7602], [-46326], [22886], [2656], [-26820], [19876], [53092], [-20036], [27030], [-31900], [26014], [38550], [3982], [-13684], [-6970], [-11480], [-11562], [-17392], [-56970], [12988], [-3710], [43342], [-2078], [2004], [34572], [-47784], [-41596], [28452], [-17994], [41732], [67726], [-27062], [40792], [11972], [-17512], [-72924], [-36654], [11924], [7624], [-13734], [-22102], [-1946], [-34344], [-40830], [-63772], [-62000], [37478], [-55764], [-50114], [-79472], [-42870], [85538], [-34292], [34502], [-13054], [52764], [-75354], [40160], [10534], [47424], [-35310], [-45306], [-20334], [-28398], [1416], [-11418], [-90212], [-86014], [-44402], [47732], [-78168], [53550], [-86244], [-39542], [13676], [-48300], [24550], [92792], [-99312], [-47122], [-50646], [-12108], [-18972], [79166], [-58996], [45368], [-3582], [-48728], [72080], [-90448], [89200], [77924], [-1664], [82466], [4866], [1164], [20618], [-75694], [-87220], [-105298], [24086], [-42636], [-28726], [-8766], [-120730], [-127102], [-7964], [17518], [8168], [-70190], [113038], [90434], [-35998], [-79130], [-2354], [-25510], [136400], [97272], [33928], [113828], [94602], [-10330], [-47900], [37518], [-29792], [134556], [112862], [-19192], [90264], [119062], [115112], [-57616], [-119662], [-143394], [-144932], [108312], [-9080], [-95692], [30162], [-96064], [-31478], [141652], [-74108], [16578], [32692], [-78520], [-145702], [38356], [100768], [93918], [49882], [-50576], [39050], [16856], [-93710], [-170270], [79662], [25108], [95526], [102204], [37452], [-130834], [-169118], [56868], [34834], [29066], [-132370], [-113598], [72942], [172952], [144854], [-27418], [-3314], [142090], [-169612], [173736], [-188900], [-35356], [158076], [-55162], [-90292], [-131894], [15436], [-628], [82354], [-203850], [17120], [122516], [5856], [162382], [-131146], [91824], [-89466], [-11340], [167276], [19498], [76046], [-6958], [108204], [12464], [47988], [102626], [86542], [-148546], [-20970], [-103134], [26380], [147432], [-54272], [-60906], [-153482], [-161562], [-188580], [-121784], [-203608], [151974], [-231544], [-135178], [32260], [-145328], [-225314], [-10142], [-38128], [-173658], [252510], [-160480], [-14898], [134080], [239826], [-114928], [-131242], [-163188], [-210838], [63722], [-173556], [183684], [-80560], [131156], [92988], [84436], [-59298], [-55292], [-178962], [23446], [-98218], [57698], [-199236], [146734], [-151144], [-169666], [96034], [-275354], [86444], [-29188], [-205878], [-29934], [-200188], [-62254], [-283514], [136324], [-65234], [95538], [-93114], [208078], [-153836], [157760], [174844], [-35096], [-259164], [268982], [170622], [133692], [-270944]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_950_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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