
// Make newform 144.3.q.e in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_144_q();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_144_q_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_q_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_144_3_q_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 := [144, 144, 276, -84, 133, -2, 15, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [-19236, 64128, -20091, 3180, -2647, 466, -169, -6], [72936, 432972, 16116, 73845, -4178, 8709, -756, 331], [80388, -156924, 132153, -82215, 6901, -10353, 1827, -677], [-401472, 247356, -232782, 143085, -19444, 16707, -2688, 1013], [-95112, 41526, -39297, -64440, -12374, -5853, 252, -602], [194364, 129078, -107691, 68730, -7447, 9966, -2019, 644], [-259974, -104598, -62319, -139005, -14198, -12981, 729, -1004]];
    Rf_basisdens := [1, 17700, 159300, 159300, 159300, 79650, 79650, 79650];
    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_q();"
function MakeCharacter_144_q()
    N := 144;
    order := 6;
    char_gens := [127, 37, 65];
    v := [6, 6, 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_144_q_Hecke();"
function MakeCharacter_144_q_Hecke(Kf)
    N := 144;
    order := 6;
    char_gens := [127, 37, 65];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 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], [-1, 0, 1, -1, 0, 0, 0, 0], [-1, 1, -1, 1, 0, 0, 1, -1], [-1, 1, 1, 1, 0, -1, 0, -1], [-5, 1, -2, -2, 2, 4, 0, -2], [-1, 1, 1, 3, 6, 2, 3, -1], [1, 5, 4, -1, 1, -3, 1, -2], [1, 1, -2, 1, 0, -3, 0, -6], [14, 1, -7, -5, 0, 6, -4, 2], [-11, 2, 1, -10, -3, 3, 0, 1], [0, -1, -1, 13, -12, 0, -6, 0], [16, 0, 0, 0, -6, -2, 6, -2], [42, 2, -6, -19, 0, 4, 0, 0], [7, -7, 14, -14, 6, 0, 12, 0], [-13, 3, 5, -15, -6, 1, 0, 5], [-6, -8, -12, 16, -4, 2, -4, 6], [21, 6, 0, -9, 0, -6, 14, -9], [7, 12, -3, -2, -9, -7, -18, -7], [-5, 0, 0, 5, 0, 10, 0, -5], [-30, 12, 0, 72, -4, -12, -4, 0], [3, -7, 14, -7, -9, -25, 9, -4], [-7, 5, -13, 13, 12, 1, 24, 1], [-21, -1, -3, -19, -2, 1, 0, -3], [-22, -4, 20, 20, 0, 14, 0, -10], [-57, 10, -8, 63, 0, -4, 0, -4], [-9, -12, 15, -36, 15, -39, 0, 15], [-6, 1, 1, -37, -12, 12, -6, -6], [-35, -1, 4, 65, 18, 3, 18, -2], [-66, 18, -36, 18, 6, 56, -6, 2], [93, 7, 9, -47, 0, -16, -3, -15], [-82, 4, -8, 4, -6, 6, 6, -6], [-12, -17, 3, 1, 0, 14, -38, 24], [-13, -6, -16, -3, -42, 4, 0, -16], [29, 6, 6, -21, 0, -58, 0, 29], [-19, -27, 47, -9, 0, -20, 35, 17], [17, 17, -7, -9, -12, -9, -24, -9], [11, 35, 35, -59, -6, -22, -3, 11], [-12, 6, -12, 6, -30, 12, 30, -6], [102, -3, -3, -51, 0, 6, 42, 6], [-5, -16, 31, -52, -15, -63, 0, 31], [28, -12, -32, -36, -42, -4, -42, 16], [-50, 14, -28, 14, 12, 40, -12, -2], [-69, -1, -21, -49, 12, 19, 0, -21], [0, -10, -10, 3, -36, 0, -18, 0], [-4, -44, -40, 4, -24, 24, -24, 20], [60, 4, -8, 4, -30, -2, 30, -14], [-14, 21, 21, 1, 48, 28, 24, -14], [-69, -27, 39, 47, -6, 5, -12, 5], [43, 25, 34, 34, 12, 16, 0, 34], [-11, -19, -19, 25, -66, 22, -33, -11], [91, -15, 16, -213, 77, 23, 77, -8], [162, 13, 45, -89, 0, -58, -32, -42], [1, 36, 24, 3, 6, -32, 12, -32], [89, 47, 44, -175, -16, -25, -16, -22], [10, 48, -80, 27, 0, 32, -28, -32], [-139, 11, 5, -133, -82, 17, 0, 5], [34, 24, 28, -72, -44, -10, -44, -14], [-30, 0, 0, 0, 12, 2, -12, 2], [-103, 66, 39, 112, 33, -57, 66, -57], [5, 22, -13, 40, -1, 57, 0, -13], [-12, -29, -29, 183, -12, 24, -6, -12], [-49, -27, -13, 21, 0, 40, 51, 47], [307, -9, 18, -9, 30, -17, -30, 10], [32, 23, -133, 23, 0, 110, -54, 32], [125, -52, 80, -169, 0, 8, 0, 8], [-47, 18, -17, -12, 105, 53, 0, -17], [-195, 33, 3, 205, 48, -23, 96, -23], [-10, 18, 18, 177, -12, 20, -6, -10], [-157, -60, 74, 45, 0, -14, -66, 53], [61, -86, -29, -80, -45, 67, -90, 67], [19, -6, 28, -15, -130, -40, 0, 28], [14, -58, -64, -22, -108, 26, -108, 32], [-147, -39, -117, 173, -48, 65, -96, 65], [-45, -51, -51, -89, 54, 90, 27, -45], [-327, -25, 50, -25, -24, -85, 24, -10], [186, -39, 33, -111, 0, 6, 54, 42], [307, -12, 55, 240, -83, -79, 0, 55], [-92, -16, 32, -16, -42, -10, 42, 38], [-244, -28, 8, 113, 0, 20, 84, 38], [34, 18, 18, -207, 156, -68, 78, 34], [-458, 9, 1, 231, 0, -10, -108, -14], [-37, -56, 19, 12, -57, 31, -114, 31], [-170, -18, -32, 354, 104, 2, 104, 16], [-89, 33, -66, 33, -21, 99, 21, 0], [-187, 29, -19, 203, 6, -13, 12, -13], [181, -43, -74, 212, -14, -12, 0, -74], [-85, -25, 20, 125, 179, 35, 179, -10], [239, 110, -52, -185, -18, -56, -36, -56], [57, 30, -9, 96, -35, 69, 0, -9], [50, 29, 29, -251, 24, -100, 12, 50], [93, 55, -36, -95, 126, -73, 126, 18], [109, -21, -71, 159, -146, 29, 0, -71], [-180, 98, -196, 98, 60, 232, -60, -62], [-381, 28, 90, 175, 0, -118, 168, -87], [25, 102, 102, 339, 96, -50, 48, 25], [4, 30, -80, 102, -150, -70, -150, 40], [205, 1, 139, -137, 0, -140, 105, -71], [21, -9, -96, 45, 1, -39, 1, 48], [164, 4, -8, 4, 0, 42, 0, 30], [-282, 24, -48, 24, -42, -60, 42, -132], [41, -119, 40, -94, -66, 66, -132, 66], [-60, -126, -84, 78, -22, 84, -22, 42], [-561, 32, -162, 329, 0, 130, -40, 33], [301, -20, 76, 205, 28, -116, 0, 76], [47, 12, 12, -327, -72, -94, -36, 47], [375, -15, 30, -15, -27, -5, 27, 40], [333, -3, 108, 222, -166, -114, 0, 108], [-98, -44, -140, 292, -124, -26, -124, 70], [142, -75, 37, -99, 0, 38, 54, 94], [-161, 22, -104, 203, -108, 20, -216, 20], [-58, -91, -91, 151, 120, 116, 60, -58], [76, -36, 72, -36, 30, -10, -30, 98], [-184, 36, -112, 129, 0, 76, 48, 2], [-255, -19, -166, 304, -84, 68, -168, 68], [664, 2, -4, 2, -6, -52, 6, -58], [-107, -68, 82, -257, 4, -218, 0, 82], [-31, 62, 62, -31, -36, 62, -18, -31], [-98, 38, 16, 218, 260, -30, 260, -8], [331, -59, -5, -179, 0, 64, -57, 91], [-99, 15, -129, 45, -24, 159, 0, -129], [-35, 41, 41, 717, 138, 70, 69, -35], [695, -52, 203, -780, 69, -33, 138, -33], [-41, -4, 25, -70, -161, -33, 0, 25], [87, 5, -132, -37, 10, -71, 10, 66], [427, 65, 161, -459, -42, -97, -84, -97], [-82, 96, 140, 120, -78, -26, -78, -70], [-523, -114, -81, 512, 39, 103, 78, 103], [-270, -158, 48, 334, -74, 182, -74, -24], [669, 93, 201, -705, -48, -129, -96, -129], [-127, 39, 39, -305, 6, 254, 3, -127], [247, 81, -162, 81, -114, 69, 114, -174], [58, 141, -299, 81, 0, 158, -28, -62], [-24, -13, -13, -145, 12, 48, 6, -24], [-310, 56, -112, 56, 132, 24, -132, -144], [-283, 77, -73, 179, 0, -4, -91, -79], [29, -91, -91, 717, -18, -58, -9, 29], [170, 156, -4, -180, 18, -158, 18, 2], [0, -13, -13, -129, 204, 0, 102, 0], [1075, 23, -11, -529, 0, -12, 61, -29], [83, 43, 68, -191, -71, -9, -71, -34], [-263, -43, 86, -43, 60, -103, -60, 26], [-143, 86, -23, -34, 201, 195, 0, -23], [-118, 113, 113, 229, 72, 236, 36, -118], [-220, -8, 128, 304, -94, 72, -94, -64], [-320, -44, 88, -44, 12, -66, -12, 66], [151, -9, 73, 69, 60, -91, 0, 73], [-69, 140, -7, 118, -123, -91, -246, -91], [-283, 74, -157, -52, 27, 305, 0, -157], [57, -26, -26, -443, 216, -114, 108, 57], [98, 126, 8, -78, -26, -122, -26, -4], [-5, -75, -75, 123, -390, 10, -195, -5], [-226, -168, -76, 360, -68, 130, -68, 38], [153, 85, -170, 85, -78, 101, 78, -154], [156, 95, -165, -13, 0, 70, 172, -60], [495, -211, -70, -542, -96, 164, -192, 164], [117, -117, -33, 33, -286, -201, 0, -33], [546, -152, 304, -152, -102, -146, 102, 310], [-163, -46, -133, -76, -145, 41, 0, -133], [-240, -96, 192, -96, 24, -306, -24, -18], [465, -73, -63, -235, 0, 136, 9, 141], [-305, -115, 58, -478, -246, -288, 0, 58], [189, 9, -12, -357, 39, -15, 39, 6], [50, 105, 105, 53, 276, -100, 138, 50], [-348, -154, -72, 614, 132, 118, 132, 36], [808, -66, 34, -429, 0, 32, 0, 82], [141, 75, 237, -21, 48, -87, 0, 237], [-534, 44, -88, 44, 168, 166, -168, 34], [773, -78, -177, -740, -9, 111, -18, 111]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_144_q_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_144_3_q_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_144_3_q_e(:prec:=8)
    chi := MakeCharacter_144_q();
    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_q_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_144_3_q_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_144_q();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![16, 528, 5612, -6468, 2661, -294, -37, 6, 1]>],Snew);
    return Vf;
end function;