
// Make newform 1350.4.a.t in Magma, downloaded from the LMFDB on 21 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1350_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_1350_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_1350_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_1350_a();"
function MakeCharacter_1350_a()
    N := 1350;
    order := 1;
    char_gens := [1001, 1027];
    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_1350_a_Hecke( : Kf := Kf)
    return MakeCharacter_1350_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], [0], [0], [-8], [-18], [-8], [15], [23], [63], [-156], [-85], [-74], [-246], [190], [288], [-177], [-792], [-907], [322], [270], [-254], [-1123], [-771], [198], [1192], [1692], [-1748], [-948], [593], [-1062], [-326], [990], [-147], [1604], [-1218], [-2248], [2998], [-3470], [387], [-855], [264], [-2551], [2238], [-2180], [2577], [1412], [-307], [-5234], [1509], [1211], [6246], [-4650], [-3145], [-1020], [6741], [2340], [6198], [875], [-5486], [3204], [-7322], [1353], [-1658], [1044], [-2588], [-1449], [4880], [7744], [804], [-2815], [-3738], [11022], [-7544], [5404], [-2335], [-6633], [7566], [7420], [8502], [-1903], [-13482], [-1537], [10368], [13168], [7319], [-4119], [5388], [2752], [4314], [5794], [6309], [-14826], [-6758], [14574], [12611], [15639], [-15420], [-10494], [10708], [23030], [3814], [22266], [-23844], [-7488], [5111], [-6986], [20571], [23241], [-20208], [-9055], [-15554], [5632], [-9141], [-13372], [11165], [912], [27952], [-6285], [-16497], [-14844], [31934], [24352], [-10374], [-7347], [-5371], [-7086], [17186], [23814], [22732], [-4664], [5501], [-27096], [-5659], [-37694], [6588], [-19], [33639], [-23474], [7917], [41202], [35492], [7146], [-8882], [-21705], [29018], [-31164], [-49160], [-2349], [-28195], [-23997], [-46286], [-39636], [16744], [1251], [36988], [-16404], [-664], [39642], [36028], [-23058], [19953], [25638], [27034], [-14802], [-9186], [31647], [-48823], [13066], [-24361], [23013], [-31260], [-8953], [-2760], [-55628], [11321], [-17064], [-59629], [-55644], [44794], [38114], [-2030], [-47892], [-29162], [32118], [22689], [42180], [17044], [-70844], [-57379], [18636], [13954], [-62709], [-28783], [29208], [-14643], [31929], [-50407], [-53876], [-32046], [-71448], [50706], [-12400], [-11774], [22979], [-65556], [-9174], [-48280], [-70743], [86340], [-11020], [-7016], [-44142], [-33680], [-34788], [-64356], [-72655], [29746], [-52968], [-62661], [43923], [30434], [9299], [46164], [-19370], [34041], [-68293], [-60087], [-74466], [20074], [-9012], [1918], [32339], [48320], [-94338], [36340], [-36015], [9461], [-58239], [29886], [28146], [56700], [22871], [-37478], [84161], [106422], [-33198], [-115484], [-79008], [96476], [-74823], [-7958], [13902], [94245], [-85147], [1875], [-85632], [110693], [-49376], [93147], [46960], [-44402], [-56973], [88823], [-1772], [78021], [19028], [-3192], [-76434], [84022], [64938], [-11773], [-84998], [134206], [52571], [29002], [89152], [-44253], [-40783], [-34663], [129258], [62640], [95807], [113535], [6311], [94084], [59988], [60418], [-85566], [-93751], [-22440], [-32568], [100995], [11850], [122166], [31930], [139104], [-25213], [165102], [-73872], [-80012], [112246], [13251], [-2800], [-30867], [24293], [32266], [6180], [-79621], [115314], [143458], [-84123], [-65424], [85140], [-112064], [-102051], [49895], [-85536], [-97098], [123268], [86070], [127217], [-72836], [-40392], [17572], [81483], [-24298], [-114019], [-50708], [103296], [-153699], [112754], [149682], [162248], [-40512], [-181636], [139572], [39143], [44679], [-38854], [45142], [-149612], [172671], [-85008], [-52147], [148266], [-165354], [-145861], [-53936], [85752], [4857], [165500], [191878], [-17844], [45988], [-89674], [52431], [-215880], [-87792], [-130494], [-25041], [-63572], [-126546], [180468], [90], [22192], [-165896], [133899], [-131582], [76058], [-23466], [-106705], [-142815], [-91938], [-131821], [57964], [-38994], [67974], [-145898], [65694], [-86186], [168984], [-196815], [-9164], [-184749], [-30976], [-58872], [213257], [-83432], [-119882], [126696], [106538], [21675], [-15594], [142798], [-8322], [-180182], [80141], [-117420], [-143767], [238752], [-24046], [-82950], [-44960], [19638], [66360], [-265273], [86818], [-218802], [18232], [192036], [-50342], [85041], [243687], [-241621], [-254582], [136392], [-88158], [151744], [58353], [112533], [-82704], [229546], [-181155], [66078], [-288866], [308001], [-119253], [280626], [-52279], [72762]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1350_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1350_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_1350_4_a_t(:prec:=1)
    chi := MakeCharacter_1350_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_1350_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_1350_4_a_t( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1350_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![8, 1]>,<11,R![18, 1]>,<17,R![-15, 1]>],Snew);
    return Vf;
end function;