
// Make newform 1440.3.j.a in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1440_j();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1440_j_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_1440_3_j_a();".
// 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_1440_3_j_a();".
// 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 := [1, 0, 14, 0, 9, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [-7, 48, 10, 20, 2, 2], [0, -76, 0, -40, 0, -4], [21, 0, 30, 0, 4, 0], [23, 48, 20, 20, 2, 2], [0, -312, 0, -240, 0, -28]];
    Rf_basisdens := [1, 5, 5, 5, 5, 5];
    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_1440_j();"
function MakeCharacter_1440_j()
    N := 1440;
    order := 2;
    char_gens := [991, 901, 641, 577];
    v := [1, 2, 2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1440_j_Hecke();"
function MakeCharacter_1440_j_Hecke(Kf)
    N := 1440;
    order := 2;
    char_gens := [991, 901, 641, 577];
    char_values := [[-1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [-1, 0, 0, 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, 0], [0, 0, 0, 0, 0, 0], [1, 1, 0, -1, 0, 0], [-2, -1, 0, 0, 1, 0], [-2, -2, -1, 2, -2, 0], [0, 0, 0, 0, 0, 1], [1, 1, 4, -1, 1, -1], [0, 0, -1, 0, 0, -2], [-12, 3, 0, 2, -3, 0], [-10, 0, 0, 8, 0, 0], [-2, -2, -4, 2, -2, 2], [1, 1, -8, -1, 1, -2], [13, 1, 0, -5, -1, 0], [13, 6, 0, -1, -6, 0], [42, 1, 0, 8, -1, 0], [-8, -8, -8, 8, -8, -3], [0, 0, 15, 0, 0, -2], [-17, 7, 0, 1, -7, 0], [-47, 2, 0, -13, -2, 0], [-6, -6, 2, 6, -6, 2], [1, 1, 4, -1, 1, -3], [6, 6, 24, -6, 6, 2], [-33, 14, 0, -3, -14, 0], [-10, 16, 0, -8, -16, 0], [-5, -5, -12, 5, -5, 1], [-58, 16, 0, 8, -16, 0], [-20, -3, 0, -2, 3, 0], [61, 20, 0, -21, -20, 0], [39, 7, 0, -7, -7, 0], [12, 12, 0, -12, 12, -8], [20, -3, 0, -26, 3, 0], [-12, -12, -3, 12, -12, -10], [2, 2, 8, -2, 2, -4], [-6, -6, -31, 6, -6, -8], [-7, 17, 0, 23, -17, 0], [-12, -12, -26, 12, -12, 8], [3, 3, 32, -3, 3, -6], [-141, 20, 0, 21, -20, 0], [-16, -1, 0, -34, 1, 0], [13, 13, -8, -13, 13, 10], [14, 14, 29, -14, 14, 12], [10, 16, 0, 72, -16, 0], [-20, -20, -8, 20, -20, -12], [13, 13, -20, -13, 13, -1], [-6, -6, -32, 6, -6, -1], [-34, -34, 14, 34, -34, 6], [12, 12, 39, -12, 12, -14], [-72, -31, 0, -54, 31, 0], [-123, 4, 0, 35, -4, 0], [-54, 0, 0, -24, 0, 0], [31, 31, 28, -31, 31, -5], [-6, -6, 0, 6, -6, -2], [139, 7, 0, 29, -7, 0], [-6, -6, 27, 6, -6, -4], [-28, -28, -56, 28, -28, -12], [-18, -3, 0, -20, 3, 0], [-111, -7, 0, -65, 7, 0], [-6, -6, -32, 6, -6, 14], [-35, -35, 24, 35, -35, -2], [213, 33, 0, -13, -33, 0], [-389, -12, 0, 13, 12, 0], [-19, -19, -32, 19, -19, -20], [253, -2, 0, -1, 2, 0], [12, 12, -46, -12, 12, 24], [-10, -10, -72, 10, -10, -8], [14, 14, 0, -14, 14, 5], [44, 44, 13, -44, 44, 14], [26, 26, 16, -26, 26, 26], [-165, -14, 0, 41, 14, 0], [-118, -48, 0, 56, 48, 0], [-18, -18, -24, 18, -18, 34], [20, 20, 54, -20, 20, 24], [108, 21, 0, -34, -21, 0], [-31, -31, -72, 31, -31, 18], [-34, -34, 21, 34, -34, -4], [-116, -45, 0, 122, 45, 0], [281, -47, 0, -9, 47, 0], [54, 54, 64, -54, 54, -21], [-266, -16, 0, -24, 16, 0], [179, -17, 0, -91, 17, 0], [26, 26, -103, -26, 26, -8], [439, 15, 0, -71, -15, 0], [6, 6, -104, -6, 6, -14], [-3, -3, -92, 3, -3, -13], [-52, -52, -98, 52, -52, -16], [-351, 8, 0, -17, -8, 0], [293, 9, 0, -77, -9, 0], [-80, -80, -16, 80, -80, 26], [470, 16, 0, 8, -16, 0], [-306, -25, 0, 112, 25, 0], [361, -56, 0, -25, 56, 0], [40, 40, 88, -40, 40, 24], [-62, -45, 0, -124, 45, 0], [16, 16, 131, -16, 16, 6], [86, 86, 75, -86, 86, 0], [-252, 35, 0, 18, -35, 0], [-42, 0, 0, 136, 0, 0], [350, -48, 0, 80, 48, 0], [-281, 48, 0, 89, -48, 0], [-230, -80, 0, 40, 80, 0], [-225, -16, 0, 161, 16, 0], [25, 25, 48, -25, 25, 22], [-99, -4, 0, 59, 4, 0], [-131, 65, 0, -117, -65, 0], [26, 26, 61, -26, 26, -32], [78, 78, -24, -78, 78, -22], [523, 34, 0, 89, -34, 0], [12, 12, -152, -12, 12, 24], [26, 26, 126, -26, 26, -54], [-229, -33, 0, -67, 33, 0], [54, -17, 0, 184, 17, 0], [-14, -14, -24, 14, -14, -59], [13, 13, 44, -13, 13, 13], [40, 40, 61, -40, 40, 50], [-52, -52, -18, 52, -52, -32], [-347, -39, 0, -13, 39, 0], [53, -58, 0, -73, 58, 0], [-366, -63, 0, 208, 63, 0], [78, 78, 56, -78, 78, 9], [26, 26, -51, -26, 26, -16], [463, 31, 0, -207, -31, 0], [87, 87, 4, -87, 87, 37], [-72, -72, 96, 72, -72, 9], [111, -106, 0, -99, 106, 0], [-64, -64, -9, 64, -64, 14], [-119, -55, 0, 311, 55, 0], [-118, 16, 0, -120, -16, 0], [34, 34, 120, -34, 34, -42], [-214, 75, 0, 12, -75, 0], [65, 65, -200, -65, 65, 4], [-22, -22, 31, 22, -22, 20], [-342, -7, 0, -216, 7, 0], [76, 76, -60, -76, 76, -36], [35, 35, 216, -35, 35, -48], [438, 112, 0, 40, -112, 0], [2, -48, 0, 16, 48, 0], [32, 32, 40, -32, 32, -15], [569, -118, 0, -37, 118, 0], [-48, -48, -216, 48, -48, -45], [-418, 80, 0, 144, -80, 0], [-98, -98, 49, 98, -98, 36], [-399, 177, 0, 47, -177, 0], [-184, 41, 0, 58, -41, 0], [343, 126, 0, -59, -126, 0], [-769, 87, 0, 17, -87, 0], [-100, -100, 14, 100, -100, 48], [-24, -24, -208, 24, -24, 51], [-108, -108, -144, 108, -108, -66], [-72, -72, -183, 72, -72, -22], [-114, 133, 0, 268, -133, 0], [-27, -27, -48, 27, -27, 92], [-547, -55, 0, -37, 55, 0], [-441, -56, 0, -183, 56, 0], [-502, 41, 0, 40, -41, 0], [1195, 68, 0, -67, -68, 0], [58, 58, -8, -58, 58, 78], [-26, -26, 50, 26, -26, -10], [-75, -7, 0, 323, 7, 0], [45, 45, 92, -45, 45, 17], [390, -48, 0, 120, 48, 0], [-401, 14, 0, -243, -14, 0], [-24, -24, 16, 24, -24, 18], [88, 25, 0, -22, -25, 0], [-184, -184, -69, 184, -184, 30], [27, 27, -4, -27, 27, 13], [846, -3, 0, 44, 3, 0], [-200, -200, -56, 200, -200, -8], [72, 72, 280, -72, 72, -1], [-286, 80, 0, 208, -80, 0], [-86, -86, 24, 86, -86, 27], [-6, -6, -53, 6, -6, 44], [394, 48, 0, -8, -48, 0], [-8, -8, -90, 8, -8, -76], [-21, -21, -132, 21, -21, -69], [-28, -28, 124, 28, -28, -12], [-210, 16, 0, -112, -16, 0], [-66, -66, 189, 66, -66, -52], [-74, 64, 0, -72, -64, 0], [-76, 229, 0, 70, -229, 0], [567, -25, 0, 169, 25, 0], [0, 25, 0, 18, -25, 0], [8, 8, 405, -8, 8, -46], [-62, -62, 184, 62, -62, 29], [-31, -31, -132, 31, -31, 49], [-66, 213, 0, 28, -213, 0], [198, -112, 0, -312, 112, 0], [179, 179, 40, -179, 179, -30], [117, 86, 0, -265, -86, 0], [35, -129, 0, -203, 129, 0], [8, 8, -176, -8, 8, 8], [130, 130, -64, -130, 130, -50], [-447, 136, 0, 15, -136, 0], [-8, -8, 303, 8, -8, -10], [-279, 121, 0, -137, -121, 0], [1255, -186, 0, -123, 186, 0], [-23, -23, 12, 23, -23, 33], [291, -121, 0, -91, 121, 0], [-184, -184, -152, 184, -184, -51], [164, 164, 296, -164, 164, 36], [-312, 151, 0, -138, -151, 0], [-1626, 64, 0, -8, -64, 0], [216, 216, 132, -216, 216, 0], [-188, -188, -152, 188, -188, -17], [218, -160, 0, 56, 160, 0], [32, 32, 19, -32, 32, 22], [3, 3, 208, -3, 3, -8], [-102, -102, 188, 102, -102, -26], [1343, 126, 0, -99, -126, 0], [-498, 80, 0, -112, -80, 0], [40, 40, -59, -40, 40, 34], [-75, -75, -44, 75, -75, -157], [121, -79, 0, -41, 79, 0], [-118, 59, 0, 172, -59, 0], [-29, 202, 0, 241, -202, 0], [46, 46, 162, -46, 46, 94], [371, 79, 0, 325, -79, 0], [-1480, -95, 0, -214, 95, 0], [822, 144, 0, -88, -144, 0], [848, 31, 0, -290, -31, 0], [-90, -90, -312, 90, -90, 109], [-33, -97, 0, -31, 97, 0], [220, 220, 206, -220, 220, -96], [470, -208, 0, -152, 208, 0], [864, -7, 0, -174, 7, 0], [151, 54, 0, 629, -54, 0], [1295, 207, 0, -239, -207, 0], [201, 201, 276, -201, 201, 29], [102, 102, 348, -102, 102, -38], [280, -55, 0, -86, 55, 0], [104, 104, 291, -104, 104, -146], [130, 130, 152, -130, 130, -33], [-186, -186, 43, 186, -186, -16], [-60, -60, -312, 60, -60, -68], [341, 33, 0, -173, -33, 0], [349, 22, 0, -177, -22, 0], [1268, -245, 0, -62, 245, 0], [731, -153, 0, -83, 153, 0], [10, 10, -240, -10, 10, 59], [220, 220, -1, -220, 220, 34], [24, 24, -178, -24, 24, -76], [-1461, -70, 0, 393, 70, 0], [-110, -110, -67, 110, -110, -8], [-54, -245, 0, 140, 245, 0], [602, 64, 0, 328, -64, 0], [-54, -54, 232, 54, -54, -38], [0, 0, 82, 0, 0, 20], [-140, 109, 0, -314, -109, 0], [82, 82, 137, -82, 82, -32], [320, 320, 45, -320, 320, -86], [-146, -235, 0, 204, 235, 0], [-98, -98, -184, 98, -98, 183], [838, -96, 0, -280, 96, 0], [-2026, -43, 0, 212, 43, 0], [-805, -81, 0, 221, 81, 0], [-57, -57, 272, 57, -57, 32], [-72, -72, -431, 72, -72, 26], [-1142, 128, 0, -184, -128, 0], [-1231, -102, 0, -125, 102, 0], [-113, -113, 144, 113, -113, 42], [-208, -208, 168, 208, -208, 46], [1850, -205, 0, 60, 205, 0], [-23, 40, 0, 423, -40, 0], [698, 176, 0, -328, -176, 0], [293, 293, 448, -293, 293, 88], [11, 11, -660, -11, 11, -7], [134, 134, 103, -134, 134, -136], [-1530, -64, 0, -520, 64, 0], [302, -176, 0, -240, 176, 0], [1823, 8, 0, 337, -8, 0], [67, 67, 416, -67, 67, -82], [1258, -320, 0, -296, 320, 0], [47, 336, 0, -15, -336, 0], [-319, -319, -260, 319, -319, 9], [-2, -2, -116, 2, -2, 114], [-178, -178, -336, 178, -178, 46], [-402, -241, 0, -176, 241, 0], [-1211, -116, 0, -461, 116, 0], [-1798, 0, 0, -248, 0, 0], [219, -241, 0, 221, 241, 0], [-66, -66, -11, 66, -66, -180], [1794, 57, 0, 64, -57, 0], [50, 50, 62, -50, 50, 146], [80, -257, 0, 30, 257, 0], [-230, -80, 0, -264, 80, 0], [-471, 66, 0, 315, -66, 0], [388, 388, 228, -388, 388, -44], [-115, -115, 412, 115, -115, -45], [-192, -192, -296, 192, -192, 13], [246, 246, 258, -246, 246, 54], [909, -167, 0, 43, 167, 0], [353, -55, 0, 143, 55, 0], [-901, -70, 0, -711, 70, 0], [-139, -139, 220, 139, -139, 81], [76, 76, 659, -76, 76, -22], [-99, -99, -24, 99, -99, 36], [1409, 169, 0, -17, -169, 0], [-208, -208, -280, 208, -208, 144], [-187, -187, -296, 187, -187, 136], [92, 92, 39, -92, 92, 50], [-41, -120, 0, -103, 120, 0], [90, 90, 128, -90, 90, 16], [-111, -111, -576, 111, -111, -90], [-216, -216, -188, 216, -216, -16]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1440_j_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1440_3_j_a();".
// 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_1440_3_j_a(:prec:=6)
    chi := MakeCharacter_1440_j();
    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_1440_3_j_a();".
// 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_1440_3_j_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1440_j();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![8, -40, 6, 1]>,<23,R![-9160, -152, 34, 1]>],Snew);
    return Vf;
end function;