
// Make newform 156.3.j.a in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_156_j();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_156_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_156_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_156_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 := [484, -352, 200, 8, -38, 28, -4, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [1881, -2792, 1768, -720, -27, 150, -46, 1], [91398, 35024, -19856, 8710, 384, -490, 607, 118], [-2421122, 1327644, -635936, -126360, 200494, -45670, -21163, 3448], [2421122, 179576, 635936, 126360, -200494, 45670, 21163, -3448], [13662, -8408, 8124, -1794, 758, 162, -227, 86], [-3038343, 1944346, -521764, -199615, 222466, -45875, -11052, 3777], [-40743, 75416, -107134, 51805, -12944, -3465, 3803, -1123]];
    Rf_basisdens := [1, 935, 68510, 753610, 753610, 8866, 376805, 34255];
    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_156_j();"
function MakeCharacter_156_j()
    N := 156;
    order := 4;
    char_gens := [79, 53, 145];
    v := [4, 4, 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_156_j_Hecke();"
function MakeCharacter_156_j_Hecke(Kf)
    N := 156;
    order := 4;
    char_gens := [79, 53, 145];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 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, 1, 0, 0, 0, 0, 0], [1, -1, 0, 0, 1, 1, 0, 0], [-2, -1, 1, 0, 0, 2, 2, 0], [0, -3, 0, -2, 0, 0, 3, 2], [3, 2, 3, 2, 0, -2, 0, 3], [-1, 0, 0, 0, 1, -3, 1, 6], [10, -2, 0, -3, 2, 10, 0, -3], [2, 10, 0, 0, -2, 6, -2, 6], [3, 0, -8, -4, 3, -3, -3, 0], [0, -3, 7, -2, -4, 0, 0, -2], [9, 13, 3, 7, 0, -9, -10, -7], [-21, 7, -4, 4, -3, -21, 0, 4], [4, -4, 0, 0, -4, 6, -4, -10], [8, -11, -18, -4, 0, -8, -7, 4], [-9, 0, -26, -6, 7, -7, -7, 0], [-28, 3, 2, -2, 0, 28, -1, 2], [-24, 0, -6, 8, 6, -6, -6, 0], [4, 2, 2, -1, -4, 4, 0, -1], [13, 27, -10, 6, -17, 13, 0, 6], [15, -28, -18, 6, 0, -15, 10, -6], [6, 0, -22, -10, -6, 6, 6, 0], [3, -37, 40, 8, -3, 3, 0, 8], [-2, 13, 32, -4, 0, 2, 19, 4], [39, -8, -18, 6, 26, 39, 0, 6], [-10, 26, 0, 0, 10, 12, 10, -18], [-4, 6, 0, 0, 4, 18, 4, 24], [72, 0, -22, 14, 4, -4, -4, 0], [5, -35, 47, -3, -12, 5, 0, -3], [84, 0, 10, -26, -2, 2, 2, 0], [-6, 68, 0, 0, 6, 2, 6, -6], [36, 0, -54, 34, -4, 4, 4, 0], [-24, 47, 56, 4, 0, 24, 9, -4], [-16, 0, -40, -28, -10, 10, 10, 0], [-29, 13, 10, -26, -23, -29, 0, -26], [24, -11, -39, -20, 0, -24, -28, 20], [-56, 0, -128, 24, 18, -18, -18, 0], [56, 38, 12, 23, 0, -56, -26, -23], [72, 41, 26, 36, 0, -72, -15, -36], [38, -2, 0, 0, -38, 72, -38, -42], [19, 108, 0, 0, -19, 3, -19, -6], [28, 26, 0, 0, -28, 84, -28, -50], [-9, 0, -26, 78, 17, -17, -17, 0], [-135, -8, 20, -18, 0, 135, 28, 18], [-145, 9, 4, -24, -13, -145, 0, -24], [-4, -40, 0, 0, 4, -16, 4, -50], [6, 0, -80, -52, 18, -18, -18, 0], [96, 1, -5, 8, 4, 96, 0, 8], [-105, -3, -78, 32, 81, -105, 0, 32], [-39, -69, -65, -11, 0, 39, 4, 11], [-25, -50, 0, 0, 25, 9, 25, 4], [73, -73, 90, -10, -17, 73, 0, -10], [63, 30, 68, -18, 0, -63, 38, 18], [3, -22, 0, 0, -3, 135, -3, 84], [-37, 38, 0, 0, 37, -87, 37, 44], [165, 0, -40, -8, -57, 57, 57, 0], [201, 0, -76, -44, -3, 3, 3, 0], [-36, 43, 69, 48, 0, 36, 26, -48], [-18, -106, 0, 0, 18, -114, 18, -6], [-112, -107, -24, -24, 0, 112, 83, 24], [-26, 48, 0, 0, 26, 106, 26, 14], [-128, 97, 74, -26, 0, 128, -23, 26], [56, -62, -22, 85, 0, -56, 40, -85], [14, 34, 0, 0, -14, -234, -14, 22], [30, 0, -76, -22, 4, -4, -4, 0], [5, 25, -78, 46, 53, 5, 0, 46], [42, 94, -38, -35, -56, 42, 0, -35], [22, 44, 0, 0, -22, -122, -22, 98], [36, 0, -52, -100, 12, -12, -12, 0], [-189, -53, -43, 9, 0, 189, 10, -9], [-311, 57, -64, 0, 7, -311, 0, 0], [-292, -3, 8, 38, 0, 292, 11, -38], [-86, 0, -124, 84, 108, -108, -108, 0], [-216, 0, -50, 24, 22, -22, -22, 0], [186, -42, 136, -61, -94, 186, 0, -61], [27, 13, -46, -40, 33, 27, 0, -40], [46, 16, 0, 0, -46, -264, -46, 4], [165, 145, 71, 61, 0, -165, -74, -61], [226, -91, -90, 46, 0, -226, 1, -46], [-47, 36, 10, 90, -46, -47, 0, 90], [156, 0, -30, -22, -64, 64, 64, 0], [-41, 125, -133, -45, 8, -41, 0, -45], [-249, -11, 74, -28, -63, -249, 0, -28], [-6, -96, 0, 0, 6, -158, 6, -114], [30, -78, 0, 0, -30, 108, -30, 72], [162, 0, 158, -38, -22, 22, 22, 0], [-406, 13, 78, 34, 0, 406, 65, -34], [89, -12, -130, -4, 142, 89, 0, -4], [-27, -171, 162, 90, 9, -27, 0, 90], [-8, 7, 61, -124, 0, 8, 54, 124], [-29, 98, 0, 0, 29, -465, 29, 4], [368, 71, 46, 34, 0, -368, -25, -34], [142, 57, -9, 20, -48, 142, 0, 20], [9, -126, 0, 0, -9, 213, -9, -16], [-10, 78, -130, 23, 52, -10, 0, 23], [-27, 0, 208, -28, -125, 125, 125, 0], [-277, -149, 30, -34, 119, -277, 0, -34], [270, 0, 42, 158, 72, -72, -72, 0], [-152, 0, 68, 48, -54, 54, 54, 0], [-13, 251, 299, -17, 0, 13, 48, 17], [-190, 0, 300, 132, -72, 72, 72, 0], [172, -211, -90, 22, 0, -172, 121, -22], [-67, 240, 0, 0, 67, 177, 67, 38], [-25, -390, 0, 0, 25, 117, 25, -32], [60, 188, 0, 0, -60, 272, -60, 18], [-257, 78, -198, 40, 120, -257, 0, 40], [-375, -53, 38, -54, 15, -375, 0, -54], [-114, 149, 80, 80, 0, 114, -69, -80], [-27, 0, 468, -64, -25, 25, 25, 0], [-126, 0, 216, -166, 44, -44, -44, 0], [88, 0, -120, 0, 78, -78, -78, 0], [319, 149, 13, -19, -162, 319, 0, -19], [-161, 1, 202, 10, -203, -161, 0, 10], [300, 2, -30, 87, 0, -300, -32, -87], [134, -197, -257, -2, 0, -134, -60, 2], [51, -60, 0, 0, -51, 489, -51, -2], [-110, -124, 8, -77, 116, -110, 0, -77], [30, -4, 0, 0, -30, -534, -30, -116], [111, 0, 48, 204, 11, -11, -11, 0], [156, 0, -20, -76, 68, -68, -68, 0], [75, -261, -235, -29, 0, -75, 26, 29], [200, 120, 0, 0, -200, 24, -200, -100], [195, 0, 10, -190, 23, -23, -23, 0], [-256, -163, -182, -92, 0, 256, -19, 92], [-104, -128, -28, 75, 156, -104, 0, 75], [-70, -516, 0, 0, 70, 312, 70, 96], [55, 319, 271, -7, 0, -55, -48, 7], [-2, 410, 0, 0, 2, -102, 2, -14], [38, 184, 0, 0, -38, 694, -38, -38], [-81, 277, -237, 85, -40, -81, 0, 85], [-210, 50, -18, 85, 0, 210, -68, -85], [11, -79, 38, -54, 41, 11, 0, -54], [-10, -114, 0, 0, 10, -828, 10, -84], [78, 0, 166, 20, -156, 156, 156, 0], [-236, -143, -94, 2, 0, 236, 49, -2], [345, 188, -112, 36, -76, 345, 0, 36], [-387, -331, 136, -40, 195, -387, 0, -40], [606, -96, -196, 9, 0, -606, -100, -9], [-40, 104, 0, 0, 40, 966, 40, 8], [-174, 0, 318, -98, -20, 20, 20, 0], [104, -22, 124, -141, -102, 104, 0, -141], [-137, -33, -52, 188, 85, -137, 0, 188], [-168, -54, 0, 0, 168, 450, 168, -88], [-428, -157, 0, -186, 0, 428, 157, 186], [-180, -332, 0, 0, 180, -140, 180, 186], [-92, -139, -96, 0, 0, 92, 43, 0], [143, 83, 105, -73, 0, -143, 22, 73], [-9, 382, 0, 0, 9, 309, 9, 80], [294, 0, 376, -108, -38, 38, 38, 0], [69, -133, -74, 132, 207, 69, 0, 132], [335, -193, 243, -57, -50, 335, 0, -57], [41, -90, 0, 0, -41, 291, -41, 96], [-142, -208, 0, 0, 142, 62, 142, 226], [849, 0, 38, -238, 35, -35, -35, 0], [126, 44, 0, 0, -126, 602, -126, -90], [-495, 0, 130, 366, -77, 77, 77, 0], [156, 0, -34, -22, 68, -68, -68, 0], [-303, -67, -32, -136, 99, -303, 0, -136], [-192, 0, -316, -30, -106, 106, 106, 0], [87, -177, -24, 100, 201, 87, 0, 100], [-368, -35, 20, 8, 0, 368, 55, -8], [155, -198, 0, 0, -155, -459, -155, 36], [514, 69, 175, -174, -244, 514, 0, -174], [-498, 0, -100, 100, -50, 50, 50, 0], [-283, -39, -86, -186, 125, -283, 0, -186], [-212, 189, 52, 16, 0, 212, -137, -16], [-808, 0, -332, -132, -102, 102, 102, 0], [-182, 0, -72, 112, 28, -28, -28, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_156_j_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_156_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_156_3_j_a(:prec:=8)
    chi := MakeCharacter_156_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(997) - 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_156_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_156_3_j_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_156_j();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;