
// Make newform 1344.4.a.d in Magma, downloaded from the LMFDB on 14 March 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_1344_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_1344_4_a_d();".
// 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_1344_4_a_d();".
// 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_1344_a();"
function MakeCharacter_1344_a()
    N := 1344;
    order := 1;
    char_gens := [127, 1093, 449, 577];
    v := [1, 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_1344_a_Hecke( : Kf := Kf)
    return MakeCharacter_1344_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 := [[0], [-3], [-6], [-7], [36], [-62], [114], [-76], [24], [-54], [112], [178], [378], [-172], [192], [402], [396], [-254], [-1012], [-840], [890], [-80], [-108], [-1638], [1010], [-6], [472], [-972], [1786], [-2286], [-1328], [-1212], [-1254], [-340], [-1038], [-2936], [1330], [-3364], [-3048], [2706], [4716], [-1910], [-4080], [-2686], [-510], [-1352], [-3364], [4768], [420], [1882], [5082], [5424], [-2590], [-4932], [-3438], [-6120], [18], [-6896], [-6254], [1194], [-7156], [3738], [-844], [-6312], [8282], [-9318], [1652], [-1294], [3636], [-10478], [-7566], [8040], [-7568], [13522], [2468], [12336], [3762], [8770], [6642], [-1510], [-1260], [-3998], [2736], [2690], [1240], [-3900], [-10878], [2330], [-15150], [2992], [8724], [-9744], [-4136], [16212], [2396], [-13128], [-12798], [7386], [5180], [-4070], [14780], [6858], [6660], [-150], [-8188], [-5854], [17580], [17154], [18120], [17546], [14560], [4498], [-5478], [6044], [15352], [-22398], [3764], [17688], [-19878], [-20004], [1306], [-13054], [-5046], [12468], [-23212], [-35958], [-6446], [4704], [10600], [-12542], [23324], [6312], [-35840], [34594], [23946], [18770], [-30342], [-26188], [34818], [-21702], [-20356], [19890], [-4232], [9636], [-35294], [3768], [39466], [-34038], [-3364], [-13104], [40858], [-37374], [9788], [-50424], [-12412], [-6576], [-8264], [39426], [-4678], [17346], [19452], [4458], [-52520], [-10404], [-7566], [-44376], [27328], [-2774], [-36526], [-18438], [-39324], [-2990], [-58632], [45146], [-16928], [5274], [-36940], [16242], [6568], [-782], [25072], [25236], [-56270], [26346], [-2832], [-16326], [68506], [-51388], [-43750], [23760], [-29758], [11316], [76124], [3810], [-26244], [30282], [-47470], [7306], [-48174], [2952], [330], [-19232], [-14150], [36290], [30684], [-36750], [-64496], [-41748], [-4710], [-42100], [-20590], [-14454], [-18488], [-49428], [-20184], [27914], [-61904], [24882], [-45336], [-76566], [-5966], [49912], [68418], [-45056], [-54636], [-48350], [-16038], [45408], [-632], [69924], [-15590], [33860], [-92672], [-11238], [-11140], [-85008], [68450], [-8910], [3300], [-65592], [109692], [20492], [103816], [49354], [35778], [-48984], [40384], [-88188], [11540], [90912], [-15302], [49170], [-114408], [60026], [28482], [-30420], [-4766], [68828], [97914], [118298], [27472], [-30132], [78538], [133666], [52866], [89492], [-22806], [65562], [4628], [37458], [125314], [107660], [33098], [110416], [-8206], [-107336], [2196], [-135014], [99674], [-122124], [39072], [-83480], [46824], [-149558], [102044], [-79728], [44018], [30546], [135400], [-41646], [93546], [27636], [27786], [-57732], [-97238], [73794], [-33920], [-89286], [116796], [-55180], [-83446], [108858], [132784], [-2916], [-115036], [770], [53028], [-135566], [-72], [-52862], [-15408], [-67518], [122274], [-6820], [-57576], [116378], [111012], [132624], [-33310], [35922], [109412], [-9238], [-41262], [112672], [-54918], [52130], [55388], [-53908], [142944], [-79662], [-104054], [197706], [-112880], [-142956], [-186748], [145356], [170602], [-59118], [-46342], [30688], [-179342], [-34902], [-95286], [177640], [31722], [-15444], [-213446], [-162700], [80880], [11370], [-22444], [-95398], [-95862], [-155360], [193810], [206682], [-76464], [-168708], [-62958], [29208], [-40286], [-108630], [184560], [19428], [212228], [-90502], [108402], [-45224], [-2230], [-181476], [-155860], [108288], [28818], [207832], [2746], [-75948], [188448], [125858], [191922], [-61894], [-28638], [-59622], [106936], [-39966], [-80332], [35592], [-155216], [-182918], [49748], [151536], [-121150], [10362], [-89004], [-49948], [-142344], [60842], [-110576], [-67206], [-72220], [-140094], [-198398], [-258942], [74032], [113802], [-49014], [115768], [-20342], [242514], [-155164], [-149964], [100658], [-83646], [-33516], [12908], [108218], [-215406], [-212400], [157720], [120978], [102072], [-107958], [98218], [69504], [223356], [68042], [-170526], [113052], [-50262], [159068], [53736]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1344_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1344_4_a_d();".
// 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_1344_4_a_d(:prec:=1)
    chi := MakeCharacter_1344_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_1344_4_a_d();".
// 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_1344_4_a_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1344_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![6, 1]>,<11,R![-36, 1]>],Snew);
    return Vf;
end function;