
// Make newform 144.4.i.c in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_144_i();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_144_i_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_4_i_c();".
// 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_4_i_c();".
// 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 := [9, -3, -2, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-3, -2, 2, 1], [0, 5, 1, -1], [-9, 2, 1, 2]];
    Rf_basisdens := [1, 6, 3, 3];
    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_i();"
function MakeCharacter_144_i()
    N := 144;
    order := 3;
    char_gens := [127, 37, 65];
    v := [3, 3, 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_i_Hecke();"
function MakeCharacter_144_i_Hecke(Kf)
    N := 144;
    order := 3;
    char_gens := [127, 37, 65];
    char_values := [[1, 0, 0, 0], [1, 0, 0, 0], [-1, 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 := 4;
    raw_aps := [[0, 0, 0, 0], [2, -2, 1, 1], [-8, 7, -1, 1], [0, 5, 0, -3], [0, 29, 0, 8], [-2, -13, -15, 15], [45, 0, -9, 0], [25, 0, -27, 0], [26, -7, 19, -19], [0, 25, 0, 1], [20, -23, -3, 3], [-52, 0, -54, 0], [-17, 115, 98, -98], [0, 41, 0, 6], [0, 245, 0, -91], [108, 0, 162, 0], [467, -331, 136, -136], [0, -167, 0, -105], [461, -527, -66, 66], [-612, 0, 144, 0], [-349, 0, -243, 0], [0, -247, 0, -309], [0, 353, 0, 107], [-234, 0, -72, 0], [0, -419, 0, 102], [0, 781, 0, 91], [-1042, 1021, -21, 21], [837, 0, 81, 0], [1136, 0, 270, 0], [1234, -1073, 161, -161], [1078, 0, 54, 0], [80, -547, -467, 467], [0, 2077, 0, -242], [533, -563, -30, 30], [550, -1397, -847, 847], [0, -391, 0, 573], [988, -49, 939, -939], [-1460, 0, 216, 0], [1196, -1411, -215, 215], [0, -947, 0, 937], [-2340, 0, -288, 0], [-1402, 0, 756, 0], [0, 29, 0, 1025], [-749, 131, -618, 618], [-3420, 0, -234, 0], [-110, 0, 702, 0], [-124, 913, 789, -789], [0, -1075, 0, -435], [0, -835, 0, -640], [754, 743, 1497, -1497], [-1845, 0, -1575, 0], [3158, -3895, -737, 737], [0, -4127, 0, 1038], [-2709, 0, 423, 0], [3493, -3449, 44, -44], [0, 5537, 0, -415], [2376, 0, 1566, 0], [2428, 0, 324, 0], [0, 6205, 0, -915], [0, 997, 0, -1763], [-3940, 3685, -255, 255], [-5534, 4975, -559, 559], [-2297, 0, -1701, 0], [7118, -7135, -17, 17], [0, 2281, 0, -1086], [0, -1055, 0, 2737], [0, -5827, 0, -1137], [6721, -7465, -744, 744], [-3943, 5177, 1234, -1234], [0, -6827, 0, -1581], [0, 1861, 0, -1808], [-1062, 0, 666, 0], [0, -175, 0, -1317], [-3278, 2651, -627, 627], [2833, 0, -351, 0], [-3880, 5933, 2053, -2053], [0, -1379, 0, 289], [-1564, 0, 1890, 0], [4915, -2693, 2222, -2222], [-6473, 6287, -186, 186], [-604, 3017, 2413, -2413], [0, -1391, 0, -141], [-1674, 0, 2430, 0], [569, 0, 27, 0], [0, -5287, 0, -1785], [0, -9583, 0, 386], [1017, 0, 2475, 0], [0, -5963, 0, 498], [0, -9047, 0, -1403], [3692, -2831, 861, -861], [12303, 0, -1413, 0], [0, 4889, 0, 1421], [-10370, 0, 702, 0], [-6823, 3125, -3698, 3698], [-1213, -2363, -3576, 3576], [-7200, 0, -5796, 0], [-4184, 1195, -2989, 2989], [7245, 0, 603, 0], [6532, 0, -972, 0], [11180, 0, 918, 0], [0, -5179, 0, 7962], [6282, 0, 504, 0], [-14959, 11441, -3518, 3518], [0, -6023, 0, 6130], [13115, -8879, 4236, -4236], [-781, 0, 3645, 0], [0, -8935, 0, 2366], [-2106, 0, -6264, 0], [980, -4003, -3023, 3023], [0, -1571, 0, 1272], [5132, -203, 4929, -4929], [-21328, 0, 486, 0], [-3131, -317, -3448, 3448], [0, 1373, 0, -5466], [376, 0, 5400, 0], [0, -22223, 0, 1738], [-25369, 24241, -1128, 1128], [-14202, 0, -2970, 0], [-1898, 2167, 269, -269], [0, -16171, 0, 1223], [2428, -8977, -6549, 6549], [0, 949, 0, -1095], [0, -20819, 0, -1241], [1665, 0, 1341, 0], [0, -7735, 0, 3327], [16470, 0, -324, 0], [0, -18203, 0, 759], [-6444, 0, 5652, 0], [0, -19903, 0, 1689], [-12062, 5963, -6099, 6099], [-7319, 0, 5481, 0], [2150, -9619, -7469, 7469], [-3472, 1453, -2019, 2019], [5834, 0, -8100, 0], [1342, -4205, -2863, 2863], [-2378, 11543, 9165, -9165], [-4086, 0, 936, 0], [-4084, -2291, -6375, 6375], [-12140, 17179, 5039, -5039], [-11583, 0, 7371, 0], [-5753, 0, -7317, 0], [0, 14497, 0, -1439], [-12472, 3577, -8895, 8895], [22500, 0, 1440, 0], [1838, 0, -12852, 0], [0, 16013, 0, -4537], [0, 17185, 0, 3909], [0, -4835, 0, -1259], [7571, 265, 7836, -7836], [22680, 0, 7344, 0], [-4592, -4117, -8709, 8709], [342, 0, -1008, 0], [-28973, 0, -4401, 0], [32696, -30895, 1801, -1801], [0, 32009, 0, -8688], [0, 15473, 0, 2231], [41794, 0, -1134, 0], [0, 22597, 0, 3961], [-9826, 0, 1080, 0], [-10124, 11239, 1115, -1115], [0, 8669, 0, 1430], [-18999, 0, 2115, 0], [-6982, 6097, -885, 885], [-11556, 0, 8964, 0], [-11429, 11671, 242, -242], [0, 22601, 0, -8929], [-29216, 0, -7128, 0], [0, -33827, 0, -3417]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_144_i_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_144_4_i_c();".
// 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_4_i_c(:prec:=4)
    chi := MakeCharacter_144_i();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_4_i_c();".
// 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_4_i_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_144_i();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![2304, 720, 177, 15, 1]>],Snew);
    return Vf;
end function;