
// Make newform 1344.4.a.bb in Magma, downloaded from the LMFDB on 16 September 2025.
// 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_bb();".
// 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_bb();".
// 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], [18], [7], [44], [-58], [-130], [92], [-84], [250], [72], [354], [334], [-416], [464], [450], [-516], [-58], [-656], [940], [178], [-1072], [660], [1254], [210], [186], [-472], [-1212], [1386], [114], [-792], [-428], [-2238], [300], [-1646], [1184], [1150], [-344], [2304], [-2742], [-3940], [-1970], [476], [-782], [2066], [-768], [4248], [3496], [-5620], [1982], [-1342], [2828], [2002], [1188], [-5506], [-4076], [5938], [-592], [-5254], [3410], [-2212], [2122], [2588], [-2728], [-6446], [4234], [-4592], [-1006], [4644], [-4786], [1302], [-11260], [-2792], [-4118], [8624], [-6488], [-1406], [-9378], [2890], [-10582], [-9500], [-598], [-3708], [13706], [8232], [2524], [-3630], [5386], [-11766], [10240], [6076], [-6480], [-4240], [-17892], [-4616], [-3696], [16738], [19062], [-12268], [17042], [-3656], [-14038], [-18332], [-10046], [-5704], [24610], [18516], [20038], [-2596], [-5190], [-6536], [-4702], [-8638], [-19676], [-26720], [-1990], [-6956], [15984], [-6614], [-29364], [3150], [8402], [-7854], [-14244], [22420], [-19814], [15986], [-22440], [-10264], [-9282], [12792], [-25644], [4528], [-31310], [16622], [-9814], [-7686], [5860], [15450], [-26726], [-3052], [-23838], [-19136], [-32556], [33086], [-35248], [-8922], [28126], [28916], [22308], [34970], [-858], [24088], [30960], [-37048], [-25228], [19336], [11926], [4698], [12986], [-17972], [-5414], [57496], [-36812], [26442], [-35240], [36472], [-25090], [21986], [15202], [38324], [27102], [-14292], [-13078], [24832], [16350], [-9744], [57506], [27264], [60022], [31144], [32732], [49202], [35646], [-56948], [-64894], [28450], [-45628], [52778], [-20216], [-62998], [45284], [-42872], [-37190], [53172], [30030], [-39854], [-25814], [24078], [13528], [-67862], [-3520], [48630], [-64598], [-77404], [-34494], [-21216], [-31844], [12490], [-43868], [48066], [30770], [81248], [-83868], [-41976], [1330], [47080], [16238], [-74604], [-5798], [-32878], [2272], [12546], [94352], [59908], [-73710], [14630], [45708], [5600], [1092], [-43718], [-27020], [-96680], [-86022], [-11604], [-22880], [91570], [-65262], [-6164], [29472], [-28652], [7284], [75512], [-2350], [-24290], [18960], [11648], [-28372], [30392], [54132], [-45502], [84470], [22172], [103922], [-10062], [61140], [89650], [-101628], [-29526], [26386], [-37192], [90660], [-65738], [-90138], [-39666], [32748], [69290], [21022], [-84800], [-56894], [-116402], [56000], [37458], [71984], [-114982], [-64832], [65500], [-31470], [8138], [21756], [688], [3984], [71160], [53630], [98564], [39060], [33026], [-13358], [-72008], [-153874], [-112182], [-129276], [-153870], [109772], [-10478], [22394], [-15896], [9018], [55284], [109004], [109266], [-75510], [-96976], [-59140], [-162552], [-84526], [-71676], [-34674], [-49884], [-55622], [114144], [-84398], [130250], [-40192], [-116028], [-67310], [-92324], [-107004], [-152614], [-102454], [180564], [67306], [2354], [88552], [71706], [48354], [171080], [-193172], [-161580], [-160350], [102626], [89626], [-108920], [-32316], [-134720], [178636], [182938], [-193522], [13202], [169688], [59290], [-59150], [207050], [-81464], [203834], [-133540], [10318], [51776], [-60512], [132730], [-153580], [140874], [89242], [197760], [-222214], [54942], [-65000], [-145980], [60098], [118020], [-97382], [6662], [191204], [-79596], [156916], [79402], [116162], [141496], [237162], [-113604], [208980], [50412], [106050], [237392], [-74414], [129556], [209276], [-148430], [26446], [-141462], [-197078], [18138], [-21704], [-125742], [102796], [194144], [244792], [106486], [-248528], [117024], [-141550], [-130862], [21188], [-81900], [-131852], [-13846], [161536], [-222682], [92448], [-14894], [7798], [139026], [55408], [180606], [42954], [-229456], [-62062], [84146], [33436], [-187900], [-161278], [82386], [-66540], [77432], [-121686], [108626], [140292], [225016], [168478], [189080], [-24230], [145294], [-123764], [302124], [161938], [48354], [-91660], [170946], [182284], [133552]];
    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_bb();".
// 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_bb(: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_bb();".
// 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_bb( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1344_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-18, 1]>,<11,R![-44, 1]>],Snew);
    return Vf;
end function;