
// Make newform 1344.3.d.e in Magma, downloaded from the LMFDB on 17 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1344_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1344_d_Hecke();"
// 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_3_d_e();".
// 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_3_d_e();".
// 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
        poly := [9, 0, 8, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 5, 0, 1], [0, 11, 0, 1], [4, 0, 1, 0]];
    Rf_basisdens := [1, 3, 3, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_1344_d();"
function MakeCharacter_1344_d()
    N := 1344;
    order := 2;
    char_gens := [127, 1093, 449, 577];
    v := [2, 2, 1, 2];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1344_d_Hecke();"
function MakeCharacter_1344_d_Hecke(Kf)
    N := 1344;
    order := 2;
    char_gens := [127, 1093, 449, 577];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [-1, 0, 0, 0], [1, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 3;
    raw_aps := [[0, 0, 0, 0], [0, 1, 0, 1], [0, -2, 1, 0], [0, 0, 0, 1], [0, -5, -2, 0], [-10, 0, 0, 4], [0, -2, -5, 0], [-16, 0, 0, 0], [0, -1, -10, 0], [0, -20, -2, 0], [32, 0, 0, 10], [-20, 0, 0, 0], [0, -30, 9, 0], [20, 0, 0, -12], [0, 6, 0, 0], [0, 36, 0, 0], [0, 20, 8, 0], [14, 0, 0, -20], [60, 0, 0, 4], [0, -25, 14, 0], [30, 0, 0, 16], [32, 0, 0, -20], [0, -50, -20, 0], [0, 30, 3, 0], [-90, 0, 0, -8], [0, 70, -11, 0], [40, 0, 0, 30], [0, -3, -30, 0], [18, 0, 0, -40], [0, -4, 20, 0], [80, 0, 0, -20], [0, 50, 20, 0], [0, 44, -10, 0], [120, 0, 0, 10], [0, -60, -36, 0], [0, 0, 0, 80], [-50, 0, 0, -60], [140, 0, 0, 48], [0, 58, -20, 0], [0, 70, 25, 0], [0, -15, -6, 0], [134, 0, 0, -20], [0, 105, -54, 0], [80, 0, 0, -72], [0, 8, 20, 0], [88, 0, 0, 0], [-220, 0, 0, 60], [40, 0, 0, -72], [0, 24, -60, 0], [90, 0, 0, 20], [0, -32, 10, 0], [0, 135, 6, 0], [-130, 0, 0, 0], [0, 180, 36, 0], [0, -198, -15, 0], [0, -231, -30, 0], [0, 130, -53, 0], [-88, 0, 0, 10], [40, 0, 0, -72], [0, -80, -50, 0], [120, 0, 0, -8], [0, -114, 45, 0], [0, 0, 0, 40], [0, -230, 16, 0], [90, 0, 0, 64], [0, -132, 60, 0], [-172, 0, 0, 120], [-50, 0, 0, -208], [0, 57, -30, 0], [222, 0, 0, 140], [0, 162, 105, 0], [0, 295, 22, 0], [-200, 0, 0, 48], [390, 0, 0, 32], [-12, 0, 0, -80], [0, -4, 140, 0], [0, 100, -26, 0], [-310, 0, 0, 4], [0, -180, -6, 0], [-106, 0, 0, -240], [0, 0, -24, 0], [248, 0, 0, -200], [0, 285, 42, 0], [-670, 0, 0, 48], [-448, 0, 0, 40], [0, 415, -50, 0], [0, 500, 8, 0], [750, 0, 0, -32], [0, 10, -89, 0], [-360, 0, 0, -16], [0, 440, 20, 0], [0, -10, -40, 0], [40, 0, 0, 24], [0, -165, -90, 0], [-276, 0, 0, -80], [0, 228, -60, 0], [0, 90, 51, 0], [0, -30, -183, 0], [-160, 0, 0, -18], [-496, 0, 0, -200], [-740, 0, 0, 68], [0, 460, -20, 0], [0, -92, 160, 0], [0, 120, 90, 0], [-20, 0, 0, 20], [150, 0, 0, -152], [0, -524, 100, 0], [0, 558, -45, 0], [0, -225, 78, 0], [-22, 0, 0, 360], [440, 0, 0, -248], [290, 0, 0, -8], [0, 508, -50, 0], [240, 0, 0, 70], [136, 0, 0, 120], [0, 460, -50, 0], [440, 0, 0, 144], [0, 546, 60, 0], [0, -144, 150, 0], [0, 325, -158, 0], [198, 0, 0, 20], [260, 0, 0, -24], [0, -78, 15, 0], [0, -609, 30, 0], [872, 0, 0, -150], [0, 160, 274, 0], [334, 0, 0, -120], [0, -780, -60, 0], [-120, 0, 0, 122], [-190, 0, 0, 292], [484, 0, 0, -280], [0, 309, -270, 0], [632, 0, 0, -20], [-130, 0, 0, -392], [0, -230, 301, 0], [-666, 0, 0, 160], [0, -86, -305, 0], [40, 0, 0, 494], [0, -102, -285, 0], [0, 140, -136, 0], [384, 0, 0, -170], [0, -220, -16, 0], [-240, 0, 0, -76], [0, 3, 30, 0], [1146, 0, 0, -100], [0, -370, -220, 0], [490, 0, 0, 180], [0, 258, 165, 0], [992, 0, 0, 120], [0, 523, 70, 0], [-750, 0, 0, 296], [0, -150, 309, 0], [500, 0, 0, -168], [0, 462, -180, 0], [-500, 0, 0, 272], [0, 315, 102, 0], [24, 0, 0, 380], [0, -630, -147, 0], [1010, 0, 0, 0], [0, -170, 13, 0], [0, 23, 230, 0], [0, 496, 160, 0], [280, 0, 0, 36], [0, 150, -336, 0], [0, 72, -150, 0], [0, -708, 240, 0], [-536, 0, 0, -300], [-950, 0, 0, 108], [-232, 0, 0, -360], [0, 150, 165, 0], [0, 365, -22, 0], [270, 0, 0, 380], [0, -135, -30, 0], [-20, 0, 0, 248], [800, 0, 0, -320], [0, 170, -103, 0], [-908, 0, 0, -280], [0, -40, 350, 0], [160, 0, 0, 126], [382, 0, 0, 180], [80, 0, 0, -152], [0, -290, 208, 0], [-660, 0, 0, -208], [0, 182, 95, 0], [0, 679, 70, 0], [0, 990, 129, 0], [-310, 0, 0, -176], [1400, 0, 0, 198], [436, 0, 0, -280], [0, -840, -228, 0], [1170, 0, 0, 328], [0, 255, -90, 0], [-588, 0, 0, 460], [0, -370, -355, 0], [0, -147, 330, 0], [0, 898, -155, 0], [500, 0, 0, -120], [-660, 0, 0, 608], [0, 666, -75, 0], [0, -486, -360, 0], [0, -840, -60, 0], [-400, 0, 0, -200], [670, 0, 0, 228], [2122, 0, 0, -40], [0, -30, -120, 0], [0, 870, -255, 0], [400, 0, 0, 240], [0, 165, -390, 0], [0, 720, 96, 0], [-592, 0, 0, -600], [-370, 0, 0, -336], [0, 370, 355, 0], [-400, 0, 0, 160], [0, 86, -40, 0], [0, 1410, 120, 0], [-958, 0, 0, 360], [-1560, 0, 0, -316], [0, 310, 151, 0], [0, -1267, 50, 0], [0, -172, 350, 0], [558, 0, 0, 200], [0, 0, 0, -430], [0, 780, -288, 0], [-600, 0, 0, -388], [0, -762, 60, 0], [1348, 0, 0, 480], [0, -98, -365, 0], [0, -365, 190, 0], [-400, 0, 0, 286], [0, -765, 438, 0], [1310, 0, 0, 136], [504, 0, 0, 400], [-2448, 0, 0, 20], [0, -660, 0, 0], [200, 0, 0, -552], [0, -120, 0, 0], [-954, 0, 0, 160], [0, -1272, -300, 0], [0, -645, 294, 0], [0, 940, 388, 0], [0, 583, -530, 0], [-1216, 0, 0, -30], [1600, 0, 0, 384], [704, 0, 0, 280], [0, -674, 55, 0], [0, -150, 204, 0], [-1240, 0, 0, -386], [0, -20, -20, 0], [-1108, 0, 0, 180], [0, 1137, -150, 0], [210, 0, 0, 32], [0, 90, -279, 0], [0, 105, 210, 0], [1026, 0, 0, -80], [0, 638, 365, 0], [0, -5, 406, 0], [-1340, 0, 0, -240], [640, 0, 0, 8], [0, 418, 235, 0], [-1030, 0, 0, 264], [1560, 0, 0, -232], [0, 335, 110, 0], [210, 0, 0, -580], [90, 0, 0, -148], [0, -366, -75, 0], [432, 0, 0, -530], [0, -1440, 108, 0], [0, 170, 197, 0], [-300, 0, 0, -752], [0, 1848, 90, 0], [686, 0, 0, -740], [-1180, 0, 0, -48], [730, 0, 0, 440], [928, 0, 0, -540], [930, 0, 0, -728], [320, 0, 0, 274], [0, -1631, -110, 0], [104, 0, 0, -200], [-1440, 0, 0, 40], [0, 900, 204, 0], [0, -1092, 120, 0], [224, 0, 0, 1120], [0, 156, 600, 0], [-1190, 0, 0, -60], [640, 0, 0, 158], [0, -325, 830, 0], [-650, 0, 0, 368], [0, 512, 80, 0], [712, 0, 0, -210], [0, 1050, -507, 0], [0, 2040, -180, 0], [0, 1158, -300, 0], [0, -540, 390, 0], [0, -400, 344, 0], [1030, 0, 0, 288], [0, -570, -555, 0], [-2408, 0, 0, -360], [0, -1410, 105, 0], [0, -1680, 156, 0], [-1520, 0, 0, 98], [1710, 0, 0, -560], [0, -660, 330, 0], [192, 0, 0, -1360]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1344_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1344_3_d_e();".
// 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_3_d_e(:prec:=4)
    chi := MakeCharacter_1344_d();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(1999) - 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_3_d_e();".
// 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_3_d_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1344_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![36, 0, 44, 0, 1]>,<19,R![16, 1]>],Snew);
    return Vf;
end function;