
// Make newform 1050.4.a.t in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1050_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_1050_4_a_t();".
// 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_1050_4_a_t();".
// 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_1050_a();"
function MakeCharacter_1050_a()
    N := 1050;
    order := 1;
    char_gens := [701, 127, 451];
    v := [1, 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_1050_a_Hecke(Kf)
    return MakeCharacter_1050_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+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 := [[2], [3], [0], [-7], [12], [-2], [18], [56], [156], [-186], [-52], [178], [-138], [412], [456], [198], [348], [110], [196], [-936], [-542], [992], [276], [630], [-110], [570], [304], [-216], [614], [498], [1888], [-2892], [-822], [-376], [3390], [-2968], [-1874], [-452], [1416], [-426], [2700], [-1978], [-2328], [3166], [414], [-1636], [-2860], [1096], [-6276], [-754], [-3870], [744], [5474], [1980], [210], [1428], [4122], [5780], [-4574], [3450], [700], [-7170], [-6644], [-5376], [-2126], [-1074], [-2788], [6334], [7032], [-1474], [-7950], [6624], [-1784], [1978], [-10780], [5880], [6438], [-2954], [-5574], [-15406], [2940], [254], [-13248], [-16598], [-6532], [-12216], [306], [6046], [7122], [11248], [18252], [-18168], [-19856], [11220], [-9268], [-18576], [-11190], [-306], [-17444], [-538], [-19820], [16686], [16788], [15906], [17084], [-25382], [-13764], [13266], [9600], [-19582], [-3944], [-20846], [-15342], [-5128], [31016], [15474], [-24644], [16632], [10542], [15276], [1478], [19366], [21390], [21672], [-5992], [17766], [-24514], [-13176], [-20792], [21742], [39044], [31116], [-29320], [2266], [-29946], [-23110], [31950], [-6284], [-5946], [27090], [-20104], [7302], [24136], [-22680], [-20338], [6600], [40174], [20778], [7400], [-684], [9754], [14310], [14092], [-45600], [-8012], [2136], [-15280], [20910], [38122], [42810], [-39864], [23850], [12832], [-15804], [33114], [58632], [55784], [23326], [48386], [-43890], [-5604], [-49066], [-23880], [30454], [-50596], [34638], [43508], [-20970], [-632], [48134], [20824], [-40884], [67210], [-25686], [31260], [67962], [44602], [-8012], [11306], [-9000], [-70958], [-264], [23276], [-11310], [30744], [17274], [11810], [-53534], [20562], [61560], [-68322], [-57868], [40894], [83810], [-29484], [-30618], [-81268], [-11904], [-44718], [26120], [-48458], [-11406], [16792], [-30180], [13128], [6914], [-35624], [35526], [17316], [87870], [37982], [-41020], [39786], [-61184], [-45924], [-6226], [-6150], [-46944], [65536], [-87612], [-83774], [-101032], [-2176], [-28830], [-22124], [-34608], [55658], [-58338], [-8220], [-79200], [-74568], [-35368], [58408], [35750], [18930], [-99960], [75760], [65580], [-34828], [-11484], [82762], [3222], [-88764], [77762], [-115482], [-32796], [25598], [110860], [-2322], [-26462], [42496], [-97824], [-107602], [-34994], [-20958], [-41848], [-12546], [-79890], [57436], [-61098], [94790], [7684], [-100982], [21944], [20626], [-128792], [38280], [-8170], [-92950], [-63852], [144048], [2504], [-60744], [-97954], [101932], [-104760], [-1226], [135030], [-94876], [-18450], [92190], [92772], [137010], [-26652], [41362], [104946], [36236], [20814], [-32436], [-98300], [-30710], [27054], [99704], [-47832], [-60532], [1006], [-23664], [167798], [66408], [-1910], [-175152], [50814], [-125430], [-50996], [-82404], [-72070], [137892], [190464], [-18830], [-63030], [13664], [-171938], [147330], [71728], [-20478], [120242], [-79756], [180844], [126636], [-66690], [-118474], [-64914], [203924], [2292], [-102652], [-10404], [-150010], [67314], [56954], [39472], [151738], [-8094], [-218766], [-61288], [-118866], [-71892], [21278], [-88796], [126840], [150894], [-10456], [-97922], [-37218], [81808], [-120130], [139770], [63960], [-190404], [205842], [-110388], [-132086], [64758], [-85356], [-97980], [98260], [166750], [40182], [56032], [-245446], [-120084], [-186136], [232644], [-205746], [117164], [-136838], [157380], [-61056], [-234614], [-9450], [-96446], [38802], [-32694], [102400], [105450], [-47536], [-76608], [15176], [-185546], [-43220], [-195144], [163442], [247902], [64116], [77740], [840], [48742], [-265444], [63246], [-151540], [144798], [-126826], [-173358], [-246296], [23178], [-112014], [31268], [99466], [-106062], [-116228], [70788], [-59870], [-194178], [-49176], [-27484], [-114554], [207594], [169560], [-260552], [-278910], [48144], [48990], [59758], [18996], [26628], [133810], [76278], [-222312], [-187470], [49520], [110136]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1050_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1050_4_a_t();".
// 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_1050_4_a_t(:prec:=1)
    chi := MakeCharacter_1050_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_1050_4_a_t();".
// 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_1050_4_a_t( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1050_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<11,R![-12, 1]>,<13,R![2, 1]>],Snew);
    return Vf;
end function;