
// Make newform 144.3.m.a in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_144_m();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_144_m_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_144_3_m_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_144_3_m_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 := [8, -8, 6, -6, 3, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [8, -2, 4, -3, 0, -1], [-4, 2, -2, 1, 0, 1], [4, 2, 2, -1, 0, -1], [5, -2, 4, -2, 1, -1], [-24, 10, -12, 11, -4, 5]];
    Rf_basisdens := [1, 4, 2, 2, 1, 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_144_m();"
function MakeCharacter_144_m()
    N := 144;
    order := 4;
    char_gens := [127, 37, 65];
    v := [2, 3, 4];
    // 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_144_m_Hecke();"
function MakeCharacter_144_m_Hecke(Kf)
    N := 144;
    order := 4;
    char_gens := [127, 37, 65];
    char_values := [[-1, 0, 0, 0, 0, 0], [0, -1, 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, 1, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 1, -1, 1, 1], [-1, 1, 3, -1, 1, -1], [2, 3, 3, 2, 1, -2], [-2, 2, 5, 1, -3, -1], [2, 2, 0, -2, -4, -2], [5, -6, -2, 3, -2, -1], [-11, -1, 1, 1, 3, 1], [0, 8, 9, 1, -7, -1], [0, -20, 0, -4, 0, 4], [14, -2, 5, -17, 5, -7], [0, 4, 0, -12, 0, 12], [-24, -17, 15, 8, 1, -8], [8, -36, -8, -4, 8, -12], [-10, 14, -1, -3, -1, -5], [-36, -35, 5, 4, 3, -4], [2, 6, 9, 5, 1, -5], [-39, 30, -14, 23, -14, -5], [37, -17, -15, 17, 19, 17], [-2, 0, 2, -20, -2, 24], [24, 48, -24, -32, 24, -16], [-47, 56, 0, -9, 0, -9], [-18, 16, 18, 28, -18, 8], [-2, -26, -48, 26, 4, 26], [-10, 38, 15, -43, 15, -13], [-77, -15, 7, 15, 37, 15], [54, 55, 7, 6, 5, -6], [56, 56, 15, 15, 15, -15], [-26, -20, -16, 20, 24, 20], [16, -76, -16, -60, 16, 28], [31, -54, -26, 49, -26, -3], [28, -20, -28, -44, 28, -12], [-28, 11, 59, 20, -19, -20], [76, -76, -19, 19, -19, -19], [67, 1, -41, -1, -43, -1], [-18, -22, 21, 25, 29, -25], [15, 0, -16, 1, -16, -31], [-15, 31, 45, -31, -17, -31], [-126, -146, -5, 15, 35, -15], [-39, 32, 8, -1, 8, 15], [92, -124, -5, 37, -5, 27], [16, -76, -16, -60, 16, 28], [14, -2, -16, 2, -12, 2], [40, -88, 9, 39, 9, 57], [39, 33, 75, -33, 9, -33], [-93, 68, 36, -11, 36, 61], [0, 60, 0, 12, 0, -12], [41, 40, 40, -121, 40, -41], [140, -100, -37, -3, -37, -77], [-30, -48, 30, 100, -30, -40], [-8, 176, 8, 32, -8, -16], [46, 6, 96, -6, 84, -6], [16, 65, 73, 24, -25, -24], [6, 28, 80, -28, 24, -28], [-259, 15, 41, -15, 11, -15], [232, 152, -111, -31, 49, 31], [-56, -36, 56, 124, -56, -12], [-218, 190, 45, -17, 45, 73], [26, -56, -26, -84, 26, 32], [-106, -163, -75, -18, 39, 18], [-184, 120, -55, 119, -55, 9], [-119, 182, 18, -81, 18, -45], [249, -17, 21, 17, 55, 17], [8, 100, -8, 36, 8, -52], [-76, -60, -35, -51, -67, 51], [238, 109, -147, -18, 111, 18], [162, 64, 0, -64, -128, -64], [36, -107, -211, -68, 75, 68], [-16, -56, -89, -49, -9, 49], [-106, 68, 80, -68, -56, -68], [-355, -49, -119, 49, -21, 49], [56, -92, -56, 4, 56, -116], [218, -254, -47, 83, -47, -11], [-140, -205, -53, 12, 77, -12], [0, -408, 0, 72, 0, -72], [154, -166, -29, 41, -29, -17], [-252, -196, 59, 3, -53, -3], [114, -22, -96, 22, -52, 22], [120, 52, -120, -236, 120, -4], [43, -98, 34, 21, 34, 89], [4, -172, -13, 181, -13, 155], [-72, 224, 72, 16, -72, 128], [-82, 54, 128, -54, 20, -54], [127, 81, 131, -81, -31, -81], [-198, -253, 27, 82, 137, -82], [2, 90, 112, -90, -68, -90], [-16, -20, 16, -100, -16, 132], [260, 316, 77, 21, -35, -21], [-104, 136, 104, 88, -104, 120], [7, 170, 30, -207, 30, -147], [-64, -220, 64, 84, -64, 44], [-209, 1, -77, -1, -79, -1], [180, 157, -131, -108, -85, 108], [-125, 52, 36, 37, 36, 109], [261, -33, -47, 33, 19, 33], [-162, -38, 151, 27, -97, -27], [-116, -84, 116, 244, -116, -12], [-70, 73, 169, 26, -117, -26], [18, 6, -39, -27, -15, 27], [153, 46, 18, -217, 18, -181], [-258, -334, -41, 35, 111, -35], [-477, 398, -22, 101, -22, 57], [52, -364, -52, -52, 52, -52], [-18, 69, 173, 86, -1, -86], [-14, -24, 32, 24, 80, 24], [326, 439, 23, -90, -203, 90], [-242, 56, -64, -56, -176, -56], [49, 111, 301, -111, 79, -111], [-166, 0, 166, 132, -166, 200], [48, -496, -48, -80, 48, -16], [108, -36, 59, -131, 59, -13], [102, -520, -102, -236, 102, 32], [38, -11, -187, -138, -89, 138], [627, -31, -57, 31, 5, 31], [-14, -142, -208, 142, 76, 142], [-287, 278, 26, -17, 26, 35], [-171, -177, -479, 177, -125, 177], [128, 64, -23, 41, 105, -41], [-567, 448, -40, 159, -40, 79], [-52, 132, -117, 37, -117, -197], [-498, -82, -176, 82, -12, 82], [-78, 2, 59, 17, 59, 135], [616, 705, 193, 104, 15, -104], [-157, 20, -188, 325, -188, -51], [-118, -370, -221, 31, 283, -31], [2, 2, -87, 83, -87, -91], [8, 80, -8, -288, 8, 272], [647, 17, 43, -17, 9, -17], [84, 164, 171, 91, 11, -91], [-141, 44, 4, 93, 4, 101], [-199, 191, 277, -191, -105, -191], [40, 672, -40, -208, 40, 128], [124, 36, 91, -251, 91, -69], [128, 300, -128, -132, 128, -124], [-18, -66, -176, 66, -44, 66], [238, 78, 199, -515, 199, -117], [-201, 160, -88, 129, -88, -47], [38, 290, 479, 227, -25, -227], [72, 500, -72, -12, 72, -132], [202, 393, 313, 122, -69, -122], [174, -474, -105, 405, -105, 195], [39, -175, -245, 175, 105, 175], [-430, -293, 211, 74, -63, -74], [-126, 38, 201, 37, -127, -37], [-295, -65, 245, 65, 375, 65], [218, -14, 177, -381, 177, -27], [-132, 276, 132, 28, -132, 236], [-140, 35, 203, 28, -147, -28], [32, -828, -32, -204, 32, 140], [-252, -340, -197, -109, -21, 109], [-370, 184, 256, -184, -112, -184], [225, -66, 74, -233, 74, -85], [425, 143, 325, -143, 39, -143], [232, 255, 79, 56, 33, -56], [-168, 100, 168, 516, -168, -180], [-5, 33, 239, -33, 173, -33], [706, -86, -304, 86, -132, 86], [-18, -656, 18, -4, -18, 40], [184, 376, -31, -223, -415, 223], [55, -54, -210, 209, -210, -211], [-180, -700, 180, 428, -180, -68], [-225, 193, 163, -193, -223, -193], [-204, -211, 253, 260, 267, -260], [-734, -30, 96, 30, 156, 30], [1161, -177, -283, 177, 71, 177], [144, -336, -144, -368, 144, 80], [-494, 386, -103, 211, -103, 5]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_144_m_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_144_3_m_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_144_3_m_a(:prec:=6)
    chi := MakeCharacter_144_m();
    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_144_3_m_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_144_3_m_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_144_m();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![8, -136, 1156, 64, 2, -2, 1]>],Snew);
    return Vf;
end function;