
// Make newform 1344.3.d.b in Magma, downloaded from the LMFDB on 23 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_b();".
// 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_b();".
// 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 := [21, 0, 14, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [7, 0, 1, 0], [5, 13, 1, 1]];
    Rf_basisdens := [1, 1, 2, 4];
    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, -1, 1], [1, 0, -1, 2], [0, 0, 1, 0], [0, 2, 0, 0], [9, 0, -1, 0], [2, -2, -2, 4], [3, 0, -5, 0], [2, -8, -2, 4], [2, 2, -2, 4], [-34, 0, -2, 0], [-4, 0, -14, 0], [8, -22, -8, 16], [-40, 0, -6, 0], [-4, -8, 4, -8], [16, -10, -16, 32], [-1, -26, 1, -2], [39, 0, -7, 0], [-6, 0, -8, 0], [-6, -18, 6, -12], [-8, 0, 26, 0], [-32, 0, 36, 0], [-9, -18, 9, -18], [-16, 42, 16, -32], [-2, 0, 8, 0], [-7, -36, 7, -14], [88, 0, -12, 0], [-22, 30, 22, -44], [-64, 0, -38, 0], [22, -14, -22, 44], [26, 0, 4, 0], [5, -54, -5, 10], [-4, -8, 4, -8], [-65, 0, -49, 0], [-40, 70, 40, -80], [-134, 0, -12, 0], [99, 0, 77, 0], [-108, 0, -14, 0], [14, -64, -14, 28], [-3, 32, 3, -6], [58, -66, -58, 116], [9, 0, -85, 0], [22, -90, -22, 44], [-34, 0, -42, 0], [20, -46, -20, 40], [-76, 0, 4, 0], [30, 0, 4, 0], [-138, 0, 14, 0], [47, 34, -47, 94], [-17, 0, 9, 0], [4, -112, -4, 8], [-6, -12, 6, -12], [230, 0, -36, 0], [-53, 94, 53, -106], [-42, 58, 42, -84], [30, 22, -30, 60], [49, -16, -49, 98], [270, 0, -94, 0], [174, 0, 20, 0], [56, -136, -56, 112], [-15, 0, 145, 0], [-77, 28, 77, -154], [327, 0, 91, 0], [-2, 44, 2, -4], [80, 0, -90, 0], [-40, 118, 40, -80], [-52, 0, -78, 0], [366, 0, -14, 0], [-44, 150, 44, -88], [219, 0, -55, 0], [30, 14, -30, 60], [6, 104, -6, 12], [-34, 0, -74, 0], [-410, 0, -12, 0], [-236, 0, -70, 0], [80, 4, -80, 160], [-14, -202, 14, -28], [-157, 0, -95, 0], [-2, 194, 2, -4], [-316, 0, -126, 0], [9, -42, -9, 18], [-170, 0, 96, 0], [82, 68, -82, 164], [138, 0, -8, 0], [200, 0, 124, 0], [-50, 74, 50, -100], [84, -72, -84, 168], [-318, 0, -74, 0], [67, 148, -67, 134], [-72, 0, -268, 0], [-65, 242, 65, -130], [80, 84, -80, 160], [-330, 0, 92, 0], [98, 14, -98, 196], [-234, 0, 232, 0], [-78, 84, 78, -156], [-135, 188, 135, -270], [152, -302, -152, 304], [87, 0, -269, 0], [514, 0, -84, 0], [-12, 0, 82, 0], [24, 250, -24, 48], [-9, 134, 9, -18], [-94, 198, 94, -188], [8, 0, 42, 0], [-666, 0, 4, 0], [115, -86, -115, 230], [70, 242, -70, 140], [-14, 26, 14, -28], [-548, 0, 146, 0], [-374, 0, -210, 0], [300, 0, -226, 0], [-78, -306, 78, -156], [783, 0, -161, 0], [-44, 0, 324, 0], [122, -194, -122, 244], [89, 0, 21, 0], [146, -276, -146, 292], [-34, -98, 34, -68], [-108, 66, 108, -216], [435, 0, -199, 0], [-222, 0, 328, 0], [-19, 364, 19, -38], [2, -98, -2, 4], [-109, 0, 255, 0], [198, -450, -198, 396], [-928, 0, -62, 0], [164, -236, -164, 328], [-488, 0, 72, 0], [-31, 0, -161, 0], [-20, 0, -118, 0], [-30, 120, 30, -60], [654, 0, -16, 0], [-380, 0, 222, 0], [-44, -10, 44, -88], [-58, 0, -372, 0], [65, -144, -65, 130], [69, 0, 85, 0], [-121, 248, 121, -242], [38, -74, -38, 76], [257, 0, -303, 0], [216, -310, -216, 432], [-736, 0, -200, 0], [138, -174, -138, 276], [-377, 0, 105, 0], [38, -28, -38, 76], [1003, 0, 45, 0], [156, -214, -156, 312], [-1159, 0, -195, 0], [-202, 130, 202, -404], [276, 0, 26, 0], [-150, 450, 150, -300], [-838, 0, 96, 0], [30, 32, -30, 60], [-454, 0, -396, 0], [66, 300, -66, 132], [304, 0, -144, 0], [-246, 142, 246, -492], [-884, 0, 146, 0], [-43, 60, 43, -86], [144, -302, -144, 288], [32, -172, -32, 64], [-534, 0, -112, 0], [103, 350, -103, 206], [-88, 172, 88, -176], [94, -472, -94, 188], [-848, 0, 252, 0], [-321, 0, 569, 0], [450, 0, 322, 0], [-165, 296, 165, -330], [-322, 442, 322, -644], [-691, 0, -209, 0], [206, -374, -206, 412], [-370, 0, 252, 0], [1114, 0, -246, 0], [116, 458, -116, 232], [-978, 0, -56, 0], [90, -182, -90, 180], [128, 0, 340, 0], [711, 0, 485, 0], [94, 0, -420, 0], [105, 234, -105, 210], [-128, 0, 210, 0], [-132, 130, 132, -264], [-146, -484, 146, -292], [-265, 144, 265, -530], [-330, 0, 260, 0], [1035, 0, -29, 0], [-486, 0, -380, 0], [-252, 376, 252, -504], [-1026, 0, 64, 0], [-102, -222, 102, -204], [1166, 0, -168, 0], [-73, 376, 73, -146], [114, -214, -114, 228], [-148, 322, 148, -296], [1226, 0, 198, 0], [-1012, 0, 358, 0], [-186, -462, 186, -372], [146, 88, -146, 292], [224, -354, -224, 448], [394, 0, 198, 0], [557, 0, 571, 0], [762, 0, 592, 0], [299, -298, -299, 598], [287, -540, -287, 574], [1250, 0, -434, 0], [-8, 254, 8, -16], [198, -402, -198, 396], [1161, 0, 133, 0], [-38, 0, 350, 0], [105, -48, -105, 210], [138, 0, 224, 0], [95, 138, -95, 190], [134, 120, -134, 268], [108, 0, 334, 0], [76, 0, -120, 0], [90, 470, -90, 180], [130, 90, -130, 260], [354, -558, -354, 708], [640, 0, 198, 0], [-936, 0, 296, 0], [120, -152, -120, 240], [-242, 0, -120, 0], [-199, 518, 199, -398], [-44, 0, 210, 0], [92, 510, -92, 184], [266, -84, -266, 532], [-668, 0, -84, 0], [-260, 710, 260, -520], [-1968, 0, 98, 0], [951, 0, 439, 0], [460, 0, 312, 0], [336, -124, -336, 672], [-2249, 0, -25, 0], [4, 404, -4, 8], [-690, 0, -164, 0], [-36, 470, 36, -72], [222, 390, -222, 444], [286, -272, -286, 572], [224, -878, -224, 448], [-263, 0, -643, 0], [1604, 0, -224, 0], [738, 0, -796, 0], [102, -582, -102, 204], [-350, 468, 350, -700], [870, 0, -442, 0], [-41, 222, 41, -82], [-636, 0, -326, 0], [-306, 726, 306, -612], [-86, 0, -360, 0], [-2, -502, 2, -4], [-198, 922, 198, -396], [-828, 0, 310, 0], [-21, -416, 21, -42], [102, 346, -102, 204], [1000, 0, -474, 0], [2365, 0, -211, 0], [-81, 312, 81, -162], [2432, 0, -138, 0], [706, 0, 120, 0], [92, 326, -92, 184], [337, 0, 111, 0], [121, 0, 255, 0], [-98, -462, 98, -196], [2201, 0, 189, 0], [-24, 378, 24, -48], [28, -2, -28, 56], [1878, 0, -356, 0], [18, 310, -18, 36], [879, 0, -223, 0], [8, 0, 726, 0], [468, 0, -98, 0], [514, 0, -108, 0], [1818, 0, 448, 0], [256, 0, -228, 0], [440, 138, -440, 880], [-778, 0, -56, 0], [-1914, 0, 106, 0], [159, -2, -159, 318], [-304, -228, 304, -608], [-1240, 0, 448, 0], [-194, 172, 194, -388], [-999, 0, 203, 0], [2033, 0, 369, 0], [470, -548, -470, 940], [-678, 0, -584, 0], [-216, 414, 216, -432], [1828, 0, 348, 0], [-438, -234, 438, -876], [48, -110, -48, 96], [-351, 818, 351, -702], [358, -310, -358, 716], [465, -330, -465, 930], [1062, 0, 1004, 0], [219, 724, -219, 438], [354, 0, 362, 0], [-65, 136, 65, -130], [-81, -506, 81, -162], [-1087, 0, -711, 0], [-620, 0, 14, 0], [-82, -410, 82, -164], [-2052, 0, -280, 0]];
    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_b();".
// 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_b(: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_b();".
// 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_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1344_d();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![84, 0, 56, 0, 1]>,<19,R![-166, -6, 1]>],Snew);
    return Vf;
end function;