
// Make newform 144.3.o.c in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_144_o();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_144_o_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_o_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_3_o_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 := [4, 0, 32, 0, 36, 0, 11, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [2, 10, 0, 7, 0, 1, 0, 0], [26, 14, 36, -1, 6, -1, 0, 0], [-14, -6, -14, -25, -2, -10, 0, -1], [-10, 30, -22, 31, -4, 10, 0, 1], [14, 22, 28, 35, 10, 11, 1, 1], [-16, 52, -6, 88, 0, 31, 0, 3], [2, -40, 10, -63, 7, -21, 1, -2]];
    Rf_basisdens := [1, 4, 4, 4, 4, 2, 4, 2];
    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_o();"
function MakeCharacter_144_o()
    N := 144;
    order := 6;
    char_gens := [127, 37, 65];
    v := [3, 6, 2];
    // 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_o_Hecke();"
function MakeCharacter_144_o_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, -1, 0, 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, -1, 1, 0, 0, 0], [1, 0, -1, 1, -1, 1, 0, 0], [0, -1, 0, 0, 0, 2, 1, 1], [-2, -2, 0, -1, 2, 2, 0, 1], [-1, 1, 1, 0, 3, 0, -1, 0], [1, -1, -3, 1, 3, -2, -2, -2], [-2, -3, 4, -3, 6, -1, 3, 1], [13, -5, -1, -3, 0, 0, -2, 0], [15, -14, -4, -9, 2, 0, -1, 2], [-5, 5, 1, 3, -6, -2, -2, -4], [-7, 6, 3, -12, 3, 3, -3, 3], [6, 12, -6, 9, -12, -3, -3, 0], [1, 3, 3, 0, -9, -4, 4, -2], [-18, -15, -2, 2, 2, -10, -7, -5], [-33, -6, -3, 0, 9, 9, 3, 9], [54, -21, 2, 1, -11, -2, -5, -4], [-3, -2, 10, 3, 0, 0, 5, 12], [-2, -8, 6, 12, 3, 3, 12, 6], [-27, 66, -11, -4, -7, 5, -1, -5], [11, 1, -1, 3, -3, -6, -2, -6], [-13, 4, 3, -15, 21, -4, -11, -2], [-52, -43, 6, -14, 10, 10, 3, 5], [-19, 4, 3, 2, -9, -7, -1, -7], [0, 2, -13, -9, 9, 0, -2, -15], [78, -87, 15, 18, 3, 0, 9, 3], [35, -16, -3, -24, 12, 9, -3, 18], [-64, 89, 26, -7, 32, -7, 13, 7], [-13, -2, -7, 12, -3, -15, -5, -15], [-13, 18, 13, -19, 31, 11, 6, 0], [24, -26, -4, 30, -24, -2, -18, 2], [93, -36, -1, 10, -20, -11, -11, -22], [-42, 32, 25, 21, -5, 0, 10, 19], [-32, 15, -16, -3, 15, -10, -7, -20], [-1, 123, 1, -10, 7, 14, 9, 0], [67, 46, -21, 27, 9, -12, -21, -6], [-7, 42, 7, -9, -21, -33, 2, 0], [-52, 76, 16, -24, 12, -16, 12, 16], [73, -38, -17, 10, 10, -17, -7, -34], [78, -65, -1, 24, -25, 0, -13, -13], [-34, 104, -18, 28, -26, 10, -18, -10], [45, -4, -5, 18, -9, -15, -1, -15], [-4, -25, -16, 32, -16, -22, -11, -11], [-10, -84, 10, -27, 24, 21, 17, 0], [-110, 2, 0, -2, 0, -2, -2, -2], [11, -12, -1, 18, -9, 1, -9, -1], [123, -71, 13, 33, -12, -2, 16, -4], [-64, -45, 12, -36, 36, 34, 5, 17], [52, 16, -18, 17, 20, 38, 0, 19], [7, -6, -7, 27, 21, 15, -20, 0], [152, 1, -12, -19, 30, 5, -13, 5], [-7, 23, -37, -67, 32, -4, -38, -8], [47, -41, 6, 24, -18, 0, -6, -6], [48, -81, -10, 31, 16, 31, -5, -31], [52, -189, -52, 58, -52, 46, -6, 0], [-23, 28, 29, -63, 39, 24, 7, 12], [5, -50, -33, 68, 15, -1, 17, -1], [-98, 208, -6, 24, 6, 18, -6, -18], [80, -83, 33, 54, -27, 0, 3, 9], [-237, 274, -46, -33, -28, 0, -37, -22], [-67, -14, 23, 12, 48, 35, 59, 70], [31, 84, -31, 37, -19, 37, -6, 0], [12, -9, -6, 39, 12, 27, -9, -27], [-135, 57, 19, 59, -28, -10, 20, -20], [-137, 95, 66, 48, 18, 0, 42, 42], [-27, 8, 22, -51, 16, 0, 19, 76], [-65, -52, -3, 21, -33, -68, -19, -34], [8, -5, -8, 18, 0, 6, -10, 0], [-278, 154, 2, 42, -45, -27, -14, -54], [38, 21, -37, -18, -81, 0, -59, 3], [-204, 192, 27, 21, -3, 0, 12, 21], [38, -94, 30, 34, -2, -20, -12, 20], [161, 218, 21, -33, 3, -48, -15, -24], [-13, 63, 13, -54, 27, 42, 41, 0], [-173, 395, -19, 33, -57, -8, -30, 8], [-307, 170, 19, -18, -30, 15, -7, 30], [168, -195, 9, -42, 45, 0, 27, 33], [151, -58, 13, 60, -15, 69, 71, 69], [-50, -174, 50, -29, 56, -65, -21, 0], [54, -169, -54, 90, -78, -6, -36, 0], [-65, 19, -87, -85, 128, -16, -30, -32], [-271, 226, 18, -57, 72, 0, 45, 48], [142, -242, -34, 30, 6, 48, -8, -48], [-101, -85, -5, 141, -51, 24, 80, 24], [-87, -198, -39, 87, -57, 48, 33, 24], [19, 25, 41, -18, -87, 24, 76, 12], [195, -45, 27, 93, -75, 24, 72, 24], [156, -202, 11, -21, 81, 0, 46, -3], [-9, 42, -12, 111, -54, 0, -33, -102], [-429, 187, 25, -39, 42, 52, 40, 104], [242, -469, -28, -61, -22, -7, 13, 7], [61, 28, -35, 25, 55, 16, -37, 8], [-154, 318, -58, -114, 30, 40, 48, -40], [-208, 29, 32, 83, 47, 20, 91, 40], [-174, 159, 30, -63, -99, 18, -57, 36], [7, -218, 103, -92, 211, 7, 101, -7], [21, 9, -21, -24, -39, 48, 45, 0], [336, 27, 60, -21, -66, 27, 33, 27], [97, -122, -51, -36, -99, -27, -21, 27], [-398, -42, 24, 66, -48, 42, 66, 42], [-232, -46, 30, -117, 144, -138, -126, -69], [79, 68, -15, -62, 9, -89, -83, -89], [122, -112, -38, -12, 111, 3, 32, 6], [-285, 187, 62, -84, 134, 0, 98, 110], [-316, 114, -32, -6, 93, 1, 28, 2], [-95, 5, -23, 15, 3, -48, -28, -48], [209, 35, -37, 128, -145, 92, 100, 46], [-145, 148, 9, -214, 57, -73, -139, -73], [265, -122, 47, 102, -102, -21, 13, -42], [96, -104, -29, -51, 45, 0, 8, -15], [-239, 96, 47, 132, -66, -19, 47, -38], [107, 90, 81, 0, -171, -99, -9, -99], [-8, -546, 8, -53, 38, 67, 45, 0], [-236, -74, 30, -105, 120, -114, -102, -57], [58, 56, -130, -48, -174, -2, -42, 2], [123, -25, -62, -24, -134, 0, -98, -2], [828, -390, 0, 6, -39, -15, -24, -30], [-6, 54, 2, 118, -14, 28, -44, -28], [51, 78, -51, 99, 45, 99, -48, 0], [-125, -152, -75, 89, 47, -124, -123, -62], [77, -6, -77, 99, -93, 39, -22, 0], [89, -168, 104, 21, 54, 0, 79, 108], [162, -51, -93, -90, -129, 0, -111, 15], [-296, 421, 114, -19, 152, -19, 57, 19], [374, 459, 60, -96, 12, 22, 35, 11], [-91, -20, -21, -22, 63, 41, -1, 41], [424, -345, 13, 96, -171, 0, -79, 9], [-192, 432, 16, 80, -112, -64, -64, 64], [-195, -300, -39, 57, 3, 96, 27, 48], [-57, -49, 57, -90, 99, 18, 33, 0], [33, -149, 59, 69, 141, 58, 24, -58], [247, -32, 41, 0, -168, -15, -71, -30], [773, -390, 43, 6, -30, 31, 25, 62], [-566, 108, 0, -108, 0, -108, -108, -108], [79, -285, -79, 148, -31, 58, -69, 0], [55, 44, -55, 207, -21, -63, -152, 0], [-503, 56, -9, -50, 3, -71, -65, -71], [-791, 400, 51, 6, -48, 33, 21, 66], [-91, -159, 91, -88, 49, -136, -3, 0], [-73, -17, -129, -55, 201, -40, -112, -40], [-354, 599, 40, -105, 102, -7, 69, 7], [795, -802, 4, 3, 10, 0, 7, -2], [51, -79, -127, -45, 198, -46, -10, -92], [-78, -96, 162, -84, 186, -66, 90, 66], [251, 64, -91, -234, 261, 15, -155, 15], [-256, -415, -92, 90, 96, 138, -25, 69], [-749, 758, -36, 27, 18, 0, -9, -90], [-147, 200, -80, 21, -26, 0, -53, -128], [736, -312, -28, 0, -63, -49, -70, -98], [-358, 824, -42, 88, -110, -2, -66, 2], [-27, -263, 27, -72, 105, 96, 45, 0], [-459, -60, 51, 138, -129, 33, 111, 33], [422, -753, -64, 15, -66, 25, -27, -25], [-297, 75, 61, 125, 2, 20, 104, 40], [515, 331, -51, 168, -183, 32, 82, 16], [-39, -342, -83, 239, -229, 128, 137, 64], [-558, 1158, 18, 78, -102, -60, -60, 60], [561, -584, -16, -123, 62, 0, 23, 68], [839, -84, -87, 186, -15, -105, -3, -105], [65, -264, -65, 5, 67, 257, 60, 0], [-62, 88, 44, -39, -54, -222, -62, -111], [-85, 127, 99, -79, -147, -76, -28, -76], [1069, -599, 111, 75, -24, 78, 120, 156], [-257, 346, 139, 28, 115, -53, 29, 53], [78, 561, -78, 168, 6, 72, -90, 0], [-291, -366, 29, 127, -341, -104, 133, -52], [374, -604, -78, 36, -162, -18, -66, 18], [66, -107, -53, -258, 135, 0, 41, 111]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_144_o_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_144_3_o_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_3_o_c(:prec:=8)
    chi := MakeCharacter_144_o();
    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_o_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_3_o_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_144_o();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![1296, -324, 2133, 729, 3186, 189, 66, -3, 1]>,<7,R![2566404, 446958, -161487, -32643, 12366, -351, -114, 3, 1]>],Snew);
    return Vf;
end function;